Skip to content

Commit

Permalink
Odip: Fix in findProductsByClassAndStartStop, use Map<...> instead of…
Browse files Browse the repository at this point in the history
… RestProduct
  • Loading branch information
emelchinger committed Aug 26, 2024
1 parent 641a1df commit 5bc08db
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1210,13 +1210,15 @@ public List<Product> findProductsByClassAndStartStop(String productType, Instant

try {
@SuppressWarnings("unchecked")
List<RestProduct> restProducts = (List<RestProduct>) serviceConnection.getFromService(config.getAipUrl(),
List<Map<String, Object>> restProductList = (List<Map<String, Object>>) serviceConnection.getFromService(config.getAipUrl(),
URI_PATH_DOWNLOAD_ALLBYTIME + "?productType=" + productType + "&startTime=" + OrbitTimeFormatter.format(start)
+ "&stopTime=" + OrbitTimeFormatter.format(stop) + "&facility=" + config.getFacility(),
RestProduct.class, securityConfig.getMission() + "-" + securityConfig.getUser(), securityConfig.getPassword());
if (restProducts != null) {
for (RestProduct restProduct : restProducts) {
products.add(ProductUtil.toModelProduct(restProduct));
List.class, securityConfig.getMission() + "-" + securityConfig.getUser(), securityConfig.getPassword());
if (logger.isTraceEnabled())
logger.trace(">>> restProductList: ", restProductList);
if (restProductList != null) {
for (Map<String, Object> restProductMap : restProductList) {
products.add(ProductUtil.toModelProduct(restProductMap));
}
}
} catch (HttpClientErrorException e) {
Expand Down
159 changes: 159 additions & 0 deletions api/odip/src/main/java/de/dlr/proseo/api/odip/util/ProductUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import java.time.DateTimeException;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import de.dlr.proseo.logging.logger.ProseoLogger;
Expand Down Expand Up @@ -174,4 +176,161 @@ public static Product toModelProduct(RestProduct restProduct) throws IllegalArgu
return modelProduct;
}

/**
* Convert a REST product represented as map into a prosEO model product (scalar and embedded attributes only, no object references); does not
* create or update the download history.
*
* @param restProductMap the REST product map
* @return a (roughly) equivalent model product or null, if no REST product map was given
* @throws IllegalArgumentException if the REST product map violates syntax rules for date, enum or numeric values
*/
@SuppressWarnings("unchecked")
public static Product toModelProduct(Map<String, Object> restProductMap) throws IllegalArgumentException {
if (logger.isTraceEnabled())
logger.trace(">>> restProductMap({})", (null == restProductMap ? "MISSING" : restProductMap));

if (logger.isTraceEnabled())
logger.trace(">>> toModelProduct({})", (null == restProductMap ? "MISSING" : restProductMap.get("productClass")));

if (null == restProductMap)
return null;

Product modelProduct = new Product();
Long id = 0L;
if (null != restProductMap.get("id")) {
id = ((Integer)(restProductMap.get("id"))).longValue();
}
if (0 != id) {
modelProduct.setId(id);
while (modelProduct.getVersion() < (Integer)(restProductMap.get("version"))) {
modelProduct.incrementVersion();
}
}

if (null != restProductMap.get("uuid")) {
try {
modelProduct.setUuid(UUID.fromString((String)(restProductMap.get("uuid"))));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(logger.log(IngestorMessage.PRODUCT_UUID_INVALID, (String)(restProductMap.get("uuid"))));
}
}

modelProduct.setFileClass((String)(restProductMap.get("fileClass")));
modelProduct.setMode((String)(restProductMap.get("mode")));

if (null != restProductMap.get("productQuality")) {
modelProduct.setProductQuality(ProductQuality.valueOf((String)(restProductMap.get("productQuality"))));
}

try {
modelProduct.setSensingStartTime(Instant.from(OrbitTimeFormatter.parse((String)(restProductMap.get("sensingStartTime")))));
} catch (DateTimeException e) {
throw new IllegalArgumentException(
logger.log(IngestorMessage.INVALID_SENSING_START_TIME, (String)(restProductMap.get("sensingStartTime"))));
}

try {
modelProduct.setSensingStopTime(Instant.from(OrbitTimeFormatter.parse((String)(restProductMap.get("sensingStopTime")))));
} catch (DateTimeException e) {
throw new IllegalArgumentException(
logger.log(IngestorMessage.INVALID_SENSING_STOP_TIME, (String)(restProductMap.get("sensingStopTime"))));
}

if (null == restProductMap.get("rawDataAvailabilityTime")) {
modelProduct.setRawDataAvailabilityTime(null);
} else {
try {
modelProduct
.setRawDataAvailabilityTime(Instant.from(OrbitTimeFormatter.parse((String)(restProductMap.get("rawDataAvailabilityTime")))));
} catch (DateTimeException e) {
throw new IllegalArgumentException(
logger.log(IngestorMessage.INVALID_RAW_DATA_AVAILABILITY_TIME, (String)(restProductMap.get("rawDataAvailabilityTime"))));
}
}

try {
modelProduct.setGenerationTime(Instant.from(OrbitTimeFormatter.parse((String)(restProductMap.get("generationTime")))));
} catch (DateTimeException e) {
throw new IllegalArgumentException(
logger.log(IngestorMessage.INVALID_PRODUCT_GENERATION_TIME, (String)(restProductMap.get("generationTime"))));
}

if (null == restProductMap.get("publicationTime")) {
modelProduct.setPublicationTime(null);
} else {
try {
modelProduct.setPublicationTime(Instant.from(OrbitTimeFormatter.parse((String)(restProductMap.get("publicationTime")))));
} catch (DateTimeException e) {
throw new IllegalArgumentException(
logger.log(IngestorMessage.INVALID_PUBLICATION_TIME, (String)(restProductMap.get("publicationTime"))));
}
}

if (null == restProductMap.get("evictionTime")) {
modelProduct.setEvictionTime(null);
} else {
try {
modelProduct.setEvictionTime(Instant.from(OrbitTimeFormatter.parse((String)(restProductMap.get("evictionTime")))));
} catch (DateTimeException e) {
throw new IllegalArgumentException(
logger.log(IngestorMessage.INVALID_EVICTION_TIME, (String)(restProductMap.get("evictionTime"))));
}
}

if (null == restProductMap.get("productionType")) {
modelProduct.setProductionType(null);
} else {
try {
modelProduct.setProductionType(ProductionType.valueOf((String)(restProductMap.get("productionType"))));
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException(
logger.log(IngestorMessage.INVALID_PRODUCTION_TYPE, (String)(restProductMap.get("productionType"))));
}
}
List<Map<String, String>> restParameterMapList = null;
if (restProductMap.get("parameters") != null) {
restParameterMapList = (List<Map<String, String>>)(restProductMap.get("parameters"));
}
if (restParameterMapList != null) {
for (Map<String, String> restParameterMap : restParameterMapList) {
de.dlr.proseo.model.Parameter modelParameter = new de.dlr.proseo.model.Parameter();
if (restParameterMap.get("parameterType") != null && !((String)(restParameterMap.get("parameterType"))).equals("null")) {
try {
modelParameter.setParameterType(ParameterType.valueOf(((String)(restParameterMap.get("parameterType")))));
} catch (Exception e) {
throw new IllegalArgumentException(
logger.log(IngestorMessage.INVALID_PARAMETER_TYPE, ((String)(restParameterMap.get("parameterType")))));
}
} else {
modelParameter.setParameterType(ParameterType.STRING);
}
try {
switch (modelParameter.getParameterType()) {
case INTEGER:
modelParameter.setIntegerValue(Integer.parseInt((String)(restParameterMap.get("parameterValue"))));
break;
case STRING:
modelParameter.setStringValue((String)(restParameterMap.get("parameterValue")));
break;
case BOOLEAN:
modelParameter.setBooleanValue(Boolean.parseBoolean((String)(restParameterMap.get("parameterValue"))));
break;
case DOUBLE:
modelParameter.setDoubleValue(Double.parseDouble((String)(restParameterMap.get("parameterValue"))));
break;
case INSTANT:
modelParameter.setInstantValue(OrbitTimeFormatter.parseDateTime((String)(restParameterMap.get("parameterValue"))));
break;
}
} catch (Exception e) {
throw new IllegalArgumentException(logger.log(IngestorMessage.INVALID_PARAMETER_VALUE,
(String)(restParameterMap.get("parameterValue")), (String)(restParameterMap.get("parameterType"))));
}
modelProduct.getParameters().put((String)(restParameterMap.get("key")), modelParameter);
}
}

return modelProduct;
}

}

0 comments on commit 5bc08db

Please sign in to comment.