Skip to content

Commit

Permalink
address review remarks #25
Browse files Browse the repository at this point in the history
  • Loading branch information
bossie committed Oct 4, 2023
1 parent 2d0c3b2 commit ca31a03
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ object OpenSearchResponses {
implicit val decodeFeature: Decoder[Feature] = new Decoder[Feature] {
override def apply(c: HCursor): Decoder.Result[Feature] = {
for {
id <- c.downField("properties").downField("productIdentifier").as[String]
id <- c.downField("properties").downField("productIdentifier").as[String] // TODO: that's not the feature ID
geometry <- c.downField("geometry").as[Json]
nominalDate <- c.downField("properties").downField("startDate").as[ZonedDateTime]
links <- c.downField("properties").downField("links").as[Array[Link]]
Expand Down Expand Up @@ -698,10 +698,10 @@ object OpenSearchResponses {
case Some(pattern) => features.filter(feature => feature.tileID match {
case Some(tileId) =>
val matchesPattern = tileId matches pattern.replace("*", ".*")
logger.debug(s"${if (matchesPattern) "retaining" else "omitting"} feature with tileId $tileId")
logger.debug(s"${if (matchesPattern) "retaining" else "omitting"} feature ${feature.id} with tileId $tileId")
matchesPattern
case _ =>
logger.debug(s"omitting feature with unknown tileId")
logger.debug(s"omitting feature ${feature.id} with unknown tileId")
false
})
case _ => features
Expand Down
29 changes: 18 additions & 11 deletions src/test/scala/org/openeo/CreodiasAPITest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package org.openeo

import geotrellis.proj4.{CRS, LatLng}
import geotrellis.vector.{Extent, ProjectedExtent}
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
import org.openeo.opensearch.OpenSearchResponses
import org.openeo.opensearch.backends.CreodiasClient

import java.time.ZoneOffset.UTC
Expand Down Expand Up @@ -38,20 +40,25 @@ class CreodiasAPITest {
// The parser in getProducts should be able to handle these incorrect multipolygons.
new CreodiasClient().getProducts(
"Sentinel1", Some(fromDate, toDate),
bbox, attributeValues, "", ""
bbox, attributeValues
)
}

@Test
def testTileIdWithWildcardIsNotPropagatedToApi(): Unit = {
// propagating it makes the API return a 400 error
new CreodiasClient().getProducts(
"Sentinel2",
dateRange = LocalDate.of(2023, 9, 24) -> LocalDate.of(2023, 9, 24),
bbox = ProjectedExtent(Extent(4.912844218500582, 51.02816932187383, 4.918160603369832, 51.029815337603594), LatLng),
attributeValues = Map("tileId" -> "31*"),
correlationId = "",
processingLevel = ""
)
def testTileIdWithWildcard(): Unit = {
def getProducts(tileIdPattern: Option[String]): Seq[OpenSearchResponses.Feature] = {
new CreodiasClient().getProducts(
"Sentinel2",
dateRange = LocalDate.of(2023, 9, 24) -> LocalDate.of(2023, 9, 24),
bbox = ProjectedExtent(
Extent(4.912844218500582, 51.02816932187383, 4.918160603369832, 51.029815337603594), LatLng),
attributeValues = tileIdPattern.map("tileId" -> _).toMap,
correlationId = "",
processingLevel = ""
)
}

assertTrue(getProducts(tileIdPattern = None).nonEmpty) // sanity check
assertTrue(getProducts(tileIdPattern = Some("30*")).isEmpty)
}
}

0 comments on commit ca31a03

Please sign in to comment.