diff --git a/CHANGELOG.md b/CHANGELOG.md index 0123df8..47633a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - [#23913] Integrated with GUI presentation configurations read from IS - [#23927] Integrated with Relationship definition in UCD - [#23834] Integrated with the create/view/delete Relationship facility +- [#24136] Integrated the temporal dimension on the front-end side ## [v1.4.0] - 2022-06-08 diff --git a/pom.xml b/pom.xml index 34eb079..4583da5 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,12 @@ compile + + org.json + json + 20140107 + + org.projectlombok diff --git a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java index 265a5a5..036ffb0 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java +++ b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataValueObjectModel.java @@ -55,11 +55,13 @@ import org.gcube.application.geoportalcommon.shared.geoportal.project.LifecycleI import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.PublicationInfoDV; import org.gcube.application.geoportalcommon.shared.geoportal.project.RelationshipDV; +import org.gcube.application.geoportalcommon.shared.geoportal.project.TemporalReferenceDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_CONFIGURATION_TYPE; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.HandlerDeclarationDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.RelationshipDefinitionDV; import org.gcube.application.geoportalcommon.shared.geoportal.ucd.UseCaseDescriptorDV; +import org.gcube.application.geoportalcommon.util.DateUtils; import org.json.JSONException; import org.json.JSONObject; import org.slf4j.Logger; @@ -73,6 +75,9 @@ import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.jayway.jsonpath.DocumentContext; +import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.Option; /** * The Class ConvertToDataValueObjectModel. @@ -586,6 +591,12 @@ public class ConvertToDataValueObjectModel { } + /** + * To spatial reference. + * + * @param geoJSONObject the geo JSON object + * @return the geo JSON + */ public static GeoJSON toSpatialReference(String geoJSONObject) { LOG.debug("toSpatialReference called"); @@ -1159,6 +1170,12 @@ public class ConvertToDataValueObjectModel { } } + /** + * To relationship definition. + * + * @param relationshipDefinition the relationship definition + * @return the relationship definition DV + */ public static RelationshipDefinitionDV toRelationshipDefinition(RelationshipDefinition relationshipDefinition) { RelationshipDefinitionDV rdv = new RelationshipDefinitionDV(); @@ -1170,6 +1187,12 @@ public class ConvertToDataValueObjectModel { } + /** + * To payload DV. + * + * @param payload the payload + * @return the payload DV + */ public static PayloadDV toPayloadDV(Payload payload) { PayloadDV p = new PayloadDV(); p.setName(payload.getName()); @@ -1179,6 +1202,13 @@ public class ConvertToDataValueObjectModel { return p; } + /** + * Convert. + * + * @param toConvert the to convert + * @return the index layer DV + * @throws InvalidObjectException the invalid object exception + */ public static IndexLayerDV convert(Index toConvert) throws InvalidObjectException { if (toConvert == null || toConvert.getType() == null) @@ -1203,4 +1233,78 @@ public class ConvertToDataValueObjectModel { return toReturn; } + /** + * To timeline JSON model. + * + * @param theProject the the project + * @param sourceJsonTemplate the source json template + * @param targetUCD the target UCD + * @param targetProjectID the target project ID + * @param relationName the relation name + * @return the JSON object + */ + public static JSONObject toTimelineJSONModel(Project theProject, JSONObject sourceJsonTemplate, String targetUCD, + String targetProjectID, String relationName) { + + com.jayway.jsonpath.Configuration jsonPathConfig = com.jayway.jsonpath.Configuration.defaultConfiguration() + .addOptions(Option.ALWAYS_RETURN_LIST); + + DocumentContext targetDoc = JsonPath.using(jsonPathConfig).parse(theProject.getTheDocument().toJson()); + + JSONObject targetJsonObject = new JSONObject(); + targetJsonObject.put("id", targetUCD + "," + targetProjectID); + + if (relationName != null) + targetJsonObject.put("relationship_name", relationName); + + for (Object key : sourceJsonTemplate.keySet()) { + String jsonPath = null; + String theKey = null; + try { + theKey = key + ""; + LOG.debug("Searching key: " + theKey); + jsonPath = sourceJsonTemplate.getString(theKey); + LOG.debug("with key: " + theKey + " read JSON path: " + jsonPath); + List listValue = targetDoc.read(jsonPath); + String result = ""; + for (int i = 0; i < listValue.size() - 1; i++) { + result += listValue.get(i) + ", "; + } + result += listValue.get(listValue.size() - 1); + targetJsonObject.put(theKey, result); + } catch (Exception e) { + LOG.trace("Error on setting key: {}, path: {}", theKey, jsonPath); + } + } + + return targetJsonObject; + + } + + /** + * To temporal reference DV. + * + * @param theProject the the project + * @param timelineJSONObject the timeline JSON object + * @return the temporal reference DV + */ + public static TemporalReferenceDV toTemporalReferenceDV(Project theProject, JSONObject timelineJSONObject) { + + TemporalReferenceDV tr = null; + + if (timelineJSONObject != null) { + tr = new TemporalReferenceDV(); + tr.setProjectID(theProject.getId()); + tr.setProfileID(theProject.getProfileID()); + tr.setJsonTimelineObject(timelineJSONObject.toString()); + String start = timelineJSONObject.getString("start"); + tr.setStart(DateUtils.toDate(start)); + String end = timelineJSONObject.getString("end"); + tr.setEnd(DateUtils.toDate(end)); + } + + return tr; + + } + } diff --git a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataViewModel.java b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataViewModel.java index 78f391f..53dbbbd 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataViewModel.java +++ b/src/main/java/org/gcube/application/geoportalcommon/ConvertToDataViewModel.java @@ -22,7 +22,7 @@ public class ConvertToDataViewModel { /** The Constant LOG. */ private static final Logger LOG = LoggerFactory.getLogger(ConvertToDataViewModel.class); - public static final String DATE_FORMAT = "dd-MM-yyyy"; + public static final String DATE_FORMAT = "yyyy-MM-dd"; public static final String HOURS_MINUTES_SEPARATOR = ":"; @@ -58,28 +58,6 @@ public class ConvertToDataViewModel { } -// /** -// * To workspace content. -// * -// * @param wContent the w content -// * @return the workspace content DV -// */ -// public static WorkspaceContentDV toWorkspaceContent(WorkspaceContent wContent) { -// LOG.debug("toWorkspaceContent called"); -// -// if (wContent == null) -// return null; -// -// WorkspaceContentDV theWSDV = new WorkspaceContentDV(); -// theWSDV.setLink(wContent.getLink()); -// theWSDV.setMimetype(wContent.getMimetype()); -// theWSDV.setStorageID(wContent.getStorageID()); -// theWSDV.setId(wContent.getId()); -// theWSDV.setName(wContent.getName()); -// -// return theWSDV; -// } - /** * To bound map. * diff --git a/src/main/java/org/gcube/application/geoportalcommon/MockDocumentConfigurationReader.java b/src/main/java/org/gcube/application/geoportalcommon/MockDocumentConfigurationReader.java deleted file mode 100644 index 314f033..0000000 --- a/src/main/java/org/gcube/application/geoportalcommon/MockDocumentConfigurationReader.java +++ /dev/null @@ -1,177 +0,0 @@ -//package org.gcube.application.geoportalcommon; -// -//import java.io.IOException; -//import java.nio.file.Files; -//import java.nio.file.Paths; -//import java.util.ArrayList; -//import java.util.LinkedHashMap; -//import java.util.List; -// -//import org.bson.Document; -//import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration; -//import org.gcube.application.geoportalcommon.geoportal.config.GcubeProfile; -//import org.gcube.application.geoportalcommon.geoportal.config.ItemField; -//import org.gcube.application.geoportalcommon.shared.geoportal.ConfigurationDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.GEOPORTAL_CONFIGURATION_TYPE; -//import org.gcube.application.geoportalcommon.shared.geoportal.GEOPORTAL_DATA_HANDLER; -//import org.gcube.application.geoportalcommon.shared.geoportal.HandlerDeclarationDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.UseCaseDescriptorDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.config.DocumentConfigDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.config.GcubeProfileDV; -//import org.gcube.application.geoportalcommon.shared.geoportal.config.ItemFieldDV; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -// -//public class MockDocumentConfigurationReader { -// private static final Logger LOG = LoggerFactory.getLogger(MockDocumentConfigurationReader.class); -// -// private List listDocumentConfigsDV = new ArrayList(); -// -// public MockDocumentConfigurationReader() { -// try { -// //loadConfigurations(); -// } catch (Exception e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } -// } -// -// private void loadConfigurations() { -// -// List listUCDDV = new ArrayList(); -// UseCaseDescriptorDV usecaseDescriptorDV = new UseCaseDescriptorDV("theId","version","listConcessioni", null); -// List handlers = new ArrayList(); -// -// -// -// HandlerDeclarationDV hdDV = new HandlerDeclarationDV(); -// hdDV.setId(handlerDeclaration.getId()); -// hdDV.setType(handlerDeclaration.getType()); -// hdDV.setItemType("MISSING ITEM TYPE IN THE SERVICE MODEL"); -// hdDV.setDataHandlerType(to_GEOPORTAL_DATA_HANDLER(handlerDeclaration.getId())); -// -//// List gcubeProfiles = new ArrayList(); -//// GcubeProfileDV profile = new GcubeProfileDV(); -//// profile.setGcubeName("GcubeName"); -//// profile.setGcubeSecondaryType("GcubeSecondaryType"); -//// gcubeProfiles.add(profile); -//// -//// ConfigurationDV> configuration = new ConfigurationDV>(gcubeProfiles); -//// HandlerDeclarationDV handler = new HandlerDeclarationDV(GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getId(), GEOPORTAL_DATA_HANDLER.geoportal_data_entry.getType(), "Concessioni", configuration,GEOPORTAL_DATA_HANDLER.geoportal_data_entry); -//// -//// handlers.add(handler); -//// usecaseDescriptorDV.setHandlers(handlers); -//// listUCDDV.add(usecaseDescriptorDV); -// -// -// try { -// GEOPORTAL_CONFIGURATION_TYPE geoportalConfigType = null; -// -// String jsonConfig = readFile( -// "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config5.json"); -// -// Document document = org.gcube.application.geoportal.client.utils.Serialization.read(jsonConfig, Document.class); -// -// LinkedHashMap configuration = (LinkedHashMap) document.get("_configuration"); -// -// -// List configurations = new ArrayList(configuration.values()); -// -// switch (geoportalConfigType) { -// case gcube_profiles: { -// -// List listGcubeProfiles = new ArrayList(configurations.size()); -// -// int i = 0; -// for (String gCubeProfile : configurations) { -// LOG.debug(i++ + ") the gCubeProfile is: " + gCubeProfile); -// GcubeProfile profile = org.gcube.application.geoportal.client.utils.Serialization.read(gCubeProfile, -// GcubeProfile.class); -// listGcubeProfiles.add(ConvertToDataValueObjectModel.toGcubeProfileDV(profile)); -// } -// -// ConfigurationDV> dDV = new ConfigurationDV>( -// listGcubeProfiles); -// dDV.setConfiguration(listGcubeProfiles); -// dDV.setConfigurationType(GEOPORTAL_CONFIGURATION_TYPE.gcube_profiles); -// hdDV.setConfiguration(dDV); -// LOG.info("returning {}", hdDV); -// return hdDV; -// } -// case item_fields: { -// -// List listItemFields = new ArrayList(configurations.size()); -// -// int i = 0; -// for (String itemField : configurations) { -// LOG.debug(i++ + ") the itemField is: " + itemField); -// ItemField profile = org.gcube.application.geoportal.client.utils.Serialization.read(itemField, -// ItemField.class); -// listItemFields.add(ConvertToDataValueObjectModel.toItemFieldDV(profile)); -// } -// -// ConfigurationDV> dDV = new ConfigurationDV>(listItemFields); -// dDV.setConfiguration(listItemFields); -// dDV.setConfigurationType(GEOPORTAL_CONFIGURATION_TYPE.item_fields); -// hdDV.setConfiguration(dDV); -// LOG.info("returning {}", hdDV); -// return hdDV; -// } -// -// default: -// break; -// } -// -// } catch (Exception e) { -// LOG.error("Error on getting " + HandlerDeclaration.class.getSimpleName(), e); -// throw e; -// } -// } -// -// //THIS IS A MOCK -// private void loadDocumentConfiguration() throws Exception { -// System.out.println("loadDocumentConfiguration called"); -// String filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config.json"; -// -// DocumentConfigDV dc = getDocumentConfigVO(filePath); -// listDocumentConfigsDV.add(dc); -// -// filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config2.json"; -// dc = getDocumentConfigVO(filePath); -// listDocumentConfigsDV.add(dc); -// -// filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config3.json"; -// dc = getDocumentConfigVO(filePath); -// listDocumentConfigsDV.add(dc); -// -// filePath = "/home/francescomangiacrapa/git/geoportal-data-common/src/test/resources/geoportal-config4.json"; -// dc = getDocumentConfigVO(filePath); -// listDocumentConfigsDV.add(dc); -// } -// -// private DocumentConfigDV getDocumentConfigVO(String filePath) throws JsonProcessingException, IOException { -// String theFile = readFile(filePath); -// System.out.println("the file is: " + theFile); -// DocumentConfig dc = org.gcube.application.geoportal.client.utils.Serialization.read(theFile, -// DocumentConfig.class); -// System.out.println(dc); -// -// return ConvertToDataValueObjectModel.toDocumentConfigDV(dc); -// } -// -// public static String readFile(String filePath) { -// String content = ""; -// -// try { -// content = new String(Files.readAllBytes(Paths.get(filePath))); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// -// return content; -// } -// -// public List getListDocumentConfig() { -// return listDocumentConfigsDV; -// } -//} diff --git a/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java b/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java deleted file mode 100644 index c4fee2d..0000000 --- a/src/main/java/org/gcube/application/geoportalcommon/MongoServiceCommon.java +++ /dev/null @@ -1,266 +0,0 @@ -//package org.gcube.application.geoportalcommon; -// -//import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.mongoConcessioni; -// -//import java.util.ArrayList; -//import java.util.Arrays; -//import java.util.Iterator; -//import java.util.List; -//import java.util.Map; -// -//import org.bson.Document; -//import org.gcube.application.geoportal.common.model.legacy.Concessione; -//import org.gcube.application.geoportal.common.model.rest.QueryRequest; -//import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest; -//import org.gcube.application.geoportal.common.model.rest.QueryRequest.OrderedRequest.Direction; -//import org.gcube.application.geoportal.common.model.rest.QueryRequest.PagedRequest; -//import org.gcube.application.geoportal.common.rest.MongoConcessioni; -//import org.gcube.application.geoportalcommon.shared.ItemFieldDV; -//import org.gcube.application.geoportalcommon.shared.ResultSetPaginatedData; -//import org.gcube.application.geoportalcommon.shared.SearchingFilter; -//import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP; -//import org.gcube.application.geoportalcommon.shared.SearchingFilter.ORDER; -//import org.gcube.application.geoportalcommon.shared.WhereClause; -//import org.gcube.application.geoportalcommon.shared.products.ConcessioneDV; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -// -//import com.mongodb.BasicDBList; -//import com.mongodb.BasicDBObject; -//import com.mongodb.BasicDBObjectBuilder; -// -///** -// * The Class MongoServiceCommon. -// * -// * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it -// * -// * Dec 3, 2021 -// */ -//public class MongoServiceCommon { -// -// private static Logger LOG = LoggerFactory.getLogger(MongoServiceCommon.class); -// -// /** -// * Gets the instance mongo concessioni. -// * -// * @return the instance mongo concessioni -// */ -// public MongoConcessioni getInstanceMongoConcessioni() { -// return mongoConcessioni().build(); -// } -// -// /** -// * Gets the list of concessioni. -// * -// * @param reloadFromService the reload from service -// * @return the list of concessioni -// * @throws Exception the exception -// */ -// public List getListOfConcessioni() throws Exception { -// LOG.info("called getListOfConcessioni"); -// -// List listOfConcessioni = new ArrayList(); -// LOG.info("Loading list of concessioni from client mongo"); -// MongoConcessioni clientMongo = getInstanceMongoConcessioni(); -// -// Iterator concessioni = clientMongo.getList(); -// if (concessioni != null) { -// while (concessioni.hasNext()) { -// Concessione concessione = (Concessione) concessioni.next(); -// listOfConcessioni.add(concessione); -// -// } -// } -// -// LOG.info("read list of concessioni with size: " + listOfConcessioni.size()); -// return listOfConcessioni; -// } -// -// /** -// * Query on mongo. -// * -// * @param offset the offset -// * @param limit the limit -// * @param filter the filter -// * @param recordType the record type -// * @return the result set paginated data -// * @throws Exception the exception -// */ -// public ResultSetPaginatedData queryOnMongo(Integer totalItems, Integer offset, Integer limit, SearchingFilter filter, String recordType) throws Exception { -// -// try { -// -// if (recordType.equalsIgnoreCase("concessione")) { -// MongoConcessioni clientMongo = getInstanceMongoConcessioni(); -// -// if(totalItems==null || totalItems < 0) { -// // TODO MUST BE REPLACED BY COUNT -// List listOfConcessioni = getListOfConcessioni(); -// int listConcessioniSize = listOfConcessioni.size(); -// totalItems = listConcessioniSize; -// } -// -// Integer offsetIndex = offset; -// Integer limitIndex = limit; -// -// if (offset == null || offset<0) { -// offsetIndex = 0; -// } -// if (limit == null || limit<0) { -// limitIndex = totalItems; -// } -// -// ResultSetPaginatedData searchedData = new ResultSetPaginatedData(offsetIndex, limitIndex, false); -// searchedData.setTotalItems(totalItems); -// -// List toReturnList = new ArrayList(); -// Direction sDirection = null; -// List orderingFields = new ArrayList(); -// -// if (filter == null) { -// LOG.info("No filter found, creating empty filter"); -// filter = new SearchingFilter(); -// } -// -// ORDER order = filter.getOrder(); -// -// if (order == null) { -// order = ORDER.ASC; -// LOG.info("No direction/order found, using default: " + order); -// } -// -// switch (order) { -// case ASC: -// sDirection = Direction.ASCENDING; -// break; -// case DESC: -// sDirection = Direction.DESCENDING; -// break; -// } -// -// List orderByFields = filter.getOrderByFields(); -// -// if(orderByFields==null) { -// orderByFields = new ArrayList(); -// } -// -// if(orderByFields.isEmpty()) { -// ItemField orderD = new ItemField("", Arrays.asList("name"), false, false, false); -// LOG.info("Order by is null, adding default: " + orderD); -// orderByFields.add(orderD); -// } -// -// for (ItemField itemField : orderByFields) { -// if (itemField.getJsonFields() != null) { -// for (String field : itemField.getJsonFields()) { -// orderingFields.add(field); -// } -// } -// -// } -// -// QueryRequest request = new QueryRequest(); -// PagedRequest paging = new PagedRequest(); -// paging.setOffset(offsetIndex); -// paging.setLimit(limitIndex); -// request.setPaging(paging); -// -// OrderedRequest ordering = new OrderedRequest(); -// ordering.setDirection(sDirection); -// ordering.setFields(orderingFields); -// -// request.setOrdering(ordering); -// -// Document query = new Document(); -// if(filter.getConditions()!=null) { -// for (WhereClause whereClause : filter.getConditions()) { -// -// LOGICAL_OP searchWithOperator = whereClause.getOperator(); -// if(searchWithOperator==null) { -// searchWithOperator = LOGICAL_OP.OR; -// } -// -// if (whereClause.getSearchInto() != null) { -// Map searchFields = whereClause.getSearchInto(); -// BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); -// for (String key : searchFields.keySet()) { -// // using regex and case-insensitive -// BasicDBObject bs = new BasicDBObject(); -// bs.append("$regex", searchFields.get(key)); -// bs.append("$options", "i"); -// builder.append(key, bs); -// -// -// } -// //Building list of Document in OR clause -// BasicDBList list = new BasicDBList(); -// Map map = builder.get().toMap(); -// for (Object key : map.keySet()) { -// -// BasicDBObject value = (BasicDBObject) map.get(key); -// Document doc = new Document((String) key, value); -// list.add(doc); -// } -// -// //query = new Document(); -// query.put(searchWithOperator.getOperator(), list); -// -//// BasicDBObject bs = new BasicDBObject(); -//// bs.append("$eq", "PASSED"); -//// query.put("report.status", bs); -// -// } -// } -// } -// -// request.setFilter(query); -// -// LOG.info("Paging offset: " + offsetIndex + ", limit: " + limitIndex); -// LOG.info("Direction: " + sDirection); -// LOG.info("Order by Fields: " + orderingFields); -// LOG.info("Search for conditions: " + filter.getConditions()); -// if (query != null) { -// LOG.info("Search query to JSON: " + query.toJson()); -// } -// -// Iterator concessioni = clientMongo.query(request); -// int i = 0; -// while (concessioni.hasNext()) { -// Concessione concessione = concessioni.next(); -// ConcessioneDV concessioneDV = ConvertToDataViewModel.toMetadataConcessione(concessione, true); -// toReturnList.add(concessioneDV); -// i++; -// LOG.trace(i+") converted: " + concessioneDV); -// } -// LOG.debug("read " + toReturnList + " project/s"); -// -// searchedData.setData(toReturnList); -// -// // TODO WORKAROUND MUST BE REMOVE AFTER THE QUERY COUNT -// // AND LIST.SIZE WILL BE AVAILABLE IN THE SERVICE -// if (filter.getConditions() != null) { -// searchedData.setTotalItems(toReturnList.size()); -// totalItems = toReturnList.size(); -// } -// -// if (totalItems == limit || totalItems == 0) { -// LOG.debug("Page completed returning " + totalItems + " items"); -// int newOffset = offsetIndex + limitIndex; -// searchedData.setServerSearchFinished(newOffset > totalItems || totalItems == 0); -// LOG.debug("is Search finished: " + searchedData.isServerSearchFinished()); -// -// } -// -// return searchedData; -// } -// -// } catch (Exception e) { -// LOG.error("Error on loading paginated and filtered list of concessioni: ", e); -// throw new Exception("Error occurred on loading list of Concessioni. Error: " + e.getMessage()); -// } -// -// return null; -// -// } -// -//} diff --git a/src/main/java/org/gcube/application/geoportalcommon/geoportal/UseCaseDescriptorCaller.java b/src/main/java/org/gcube/application/geoportalcommon/geoportal/UseCaseDescriptorCaller.java index 2dc48ba..ab57e87 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/geoportal/UseCaseDescriptorCaller.java +++ b/src/main/java/org/gcube/application/geoportalcommon/geoportal/UseCaseDescriptorCaller.java @@ -4,6 +4,7 @@ import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPl import java.util.ArrayList; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import org.bson.Document; @@ -12,6 +13,7 @@ import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDec import org.gcube.application.geoportal.common.model.useCaseDescriptor.RelationshipDefinition; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; import org.gcube.application.geoportal.common.rest.UseCaseDescriptorsI; +import org.gcube.application.geoportalcommon.shared.geoportal.ucd.GEOPORTAL_DATA_HANDLER; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,6 +31,8 @@ public class UseCaseDescriptorCaller { private static Logger LOG = LoggerFactory.getLogger(UseCaseDescriptorCaller.class); + public static final String TIMELINE_CONFIG_TJT_DOCUMENT = "tjt_document"; + /** * Use case descriptors client. * @@ -189,4 +193,37 @@ public class UseCaseDescriptorCaller { return ucd.getRelationshipDefinitions(); } + /** + * Read temporal dimension template. + * + * @param profileID the profile ID + * @return the document + * @throws Exception the exception + */ + public Document readTemporalDimensionTemplate(String profileID) throws Exception { + + UseCaseDescriptorsI client = useCaseDescriptorsClient(); + UseCaseDescriptor ucd = client.getById(profileID); + + List timelineHandlers = ucd + .getHandlersByType(GEOPORTAL_DATA_HANDLER.geoportal_timeline_json_template.getType()); + + if (timelineHandlers != null && timelineHandlers.size() > 0) { + HandlerDeclaration handler = timelineHandlers.get(0); // only one expected + Document config = handler.getConfiguration(); + try { + LinkedHashMap tjtDoc = (LinkedHashMap) config + .get(TIMELINE_CONFIG_TJT_DOCUMENT); + return new Document(tjtDoc); + } catch (Exception e) { + LOG.warn("Error on reading the handler type " + + GEOPORTAL_DATA_HANDLER.geoportal_timeline_json_template.getType() + " in the profileID: " + + profileID, e); + return null; + } + } + + return null; + } + } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/ProjectDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/ProjectDV.java index 427abc5..ab895e3 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/ProjectDV.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/ProjectDV.java @@ -28,6 +28,7 @@ public class ProjectDV implements Serializable { // Shortcut to "SPATIAL REFERENCE" containted into IdentificationReferenceDV private GeoJSON spatialReference; + private TemporalReferenceDV temporalReference; public ProjectDV() { @@ -113,6 +114,14 @@ public class ProjectDV implements Serializable { this.spatialReference = spatialReference; } + public TemporalReferenceDV getTemporalReference() { + return temporalReference; + } + + public void setTemporalReference(TemporalReferenceDV temporalReference) { + this.temporalReference = temporalReference; + } + @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -136,6 +145,8 @@ public class ProjectDV implements Serializable { builder.append(lifecycleInformationDV); builder.append(", spatialReference="); builder.append(spatialReference); + builder.append(", temporalReference="); + builder.append(temporalReference); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/TemporalReferenceDV.java b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/TemporalReferenceDV.java index f6f3af6..f5ce190 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/TemporalReferenceDV.java +++ b/src/main/java/org/gcube/application/geoportalcommon/shared/geoportal/project/TemporalReferenceDV.java @@ -1,5 +1,7 @@ package org.gcube.application.geoportalcommon.shared.geoportal.project; +import java.util.Date; + import org.gcube.application.geoportalcommon.shared.geoportal.DocumentDV; /** @@ -16,7 +18,13 @@ public class TemporalReferenceDV extends DocumentDV { * */ private static final long serialVersionUID = -7990905553022863653L; - private String field; + private String profileID; + private String projectID; + + private String jsonTimelineObject; + + private Date start; + private Date end; /** * Instantiates a new temporal reference DV. @@ -25,24 +33,59 @@ public class TemporalReferenceDV extends DocumentDV { } - public TemporalReferenceDV(String field) { - super(); - this.field = field; + public String getJsonTimelineObject() { + return jsonTimelineObject; } - public String getField() { - return field; + public void setJsonTimelineObject(String jsonTimelineObject) { + this.jsonTimelineObject = jsonTimelineObject; } - public void setField(String field) { - this.field = field; + public String getProfileID() { + return profileID; + } + + public String getProjectID() { + return projectID; + } + + public Date getStart() { + return start; + } + + public Date getEnd() { + return end; + } + + public void setProfileID(String profileID) { + this.profileID = profileID; + } + + public void setProjectID(String projectID) { + this.projectID = projectID; + } + + public void setStart(Date start) { + this.start = start; + } + + public void setEnd(Date end) { + this.end = end; } @Override public String toString() { StringBuilder builder = new StringBuilder(); - builder.append("TemporalReferenceDV [field="); - builder.append(field); + builder.append("TemporalReferenceDV [profileID="); + builder.append(profileID); + builder.append(", projectID="); + builder.append(projectID); + builder.append(", jsonTimelineObject="); + builder.append(jsonTimelineObject); + builder.append(", start="); + builder.append(start); + builder.append(", end="); + builder.append(end); builder.append("]"); return builder.toString(); } diff --git a/src/main/java/org/gcube/application/geoportalcommon/util/DateUtils.java b/src/main/java/org/gcube/application/geoportalcommon/util/DateUtils.java index be3ccc5..10206a5 100644 --- a/src/main/java/org/gcube/application/geoportalcommon/util/DateUtils.java +++ b/src/main/java/org/gcube/application/geoportalcommon/util/DateUtils.java @@ -11,7 +11,7 @@ import java.util.Date; * * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it * - * Aug 4, 2021 + * Aug 4, 2021 */ public class DateUtils { @@ -62,4 +62,26 @@ public class DateUtils { return null; return Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDateTime(); } + + public static Date toDate(String date) { + + if (date == null || date.isEmpty()) + return null; + + try { + LocalDate localDate = LocalDate.parse(date); + return asDate(localDate); + } catch (Exception e) { + // TODO: handle exception + } + + try { + LocalDateTime dateTime = LocalDateTime.parse(date); + return asDate(dateTime); + } catch (Exception e) { + // TODO: handle exception + } + + return null; + } } \ No newline at end of file