Skip to content

Commit

Permalink
ENVRI-specific ATC instrument URL validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mirzov committed Dec 20, 2024
1 parent b4021bc commit 689a904
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import se.lu.nateko.cp.meta.services.CpVocab
import se.lu.nateko.cp.meta.services.upload.DataObjectInstanceServers
import eu.icoscp.envri.Envri
import se.lu.nateko.cp.meta.services.MetadataException
import se.lu.nateko.cp.meta.api.UriId

given CanEqual[URI, URI] = CanEqual.derived
given CanEqual[IRI, IRI] = CanEqual.derived
Expand Down Expand Up @@ -357,8 +358,7 @@ class UploadValidator(servers: DataObjectInstanceServers):

if(subm.submittingOrganization === vocab.atc){
val instruments = stationMeta.instruments
if(instruments.exists(uri => !isAtcInstrument(uri)))
errors += s"Instrument URL is expected to start with '$atcInstrumentPrefix'"
errors ++= instruments.flatMap(atcInstrumentError)
if(instruments.isEmpty)
errors += "Instrument URL(s) expected for ATC time series"
if(stationMeta.samplingHeight.isEmpty && spec.dataLevel > 0) errors += "Must provide sampling height"
Expand All @@ -370,8 +370,10 @@ class UploadValidator(servers: DataObjectInstanceServers):
new Validated(Some(NotUsed).filter(_ => errors.isEmpty), errors.toSeq)
end validateForFormat

private val atcInstrumentPrefix = "http://meta.icos-cp.eu/resources/instruments/ATC_"
private def isAtcInstrument(uri: URI): Boolean = uri.toString.startsWith(atcInstrumentPrefix)
private def atcInstrumentError(uri: URI)(using Envri): Option[String] =
val base = vocab.getInstrument(UriId("ATC_"))
if uri.toString.startsWith(base.toString) then None
else Some(s"ATC instrument URL is expected to start with $base")


private def validatePreviousCollectionVersion(prevVers: OptionalOneOrSeq[Sha256Sum], newCollHash: Sha256Sum)(using Envri, CollConn): Try[NotUsed] =
Expand Down

0 comments on commit 689a904

Please sign in to comment.