diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 761b5fd..189641d 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -161,9 +161,6 @@ - - uses - diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java index 116f092..82d602c 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/GeoportalDataViewerServiceImpl.java @@ -23,6 +23,7 @@ import org.gcube.application.geoportal.common.model.document.identification.Iden import org.gcube.application.geoportal.common.model.document.relationships.Relationship; import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject; import org.gcube.application.geoportal.common.model.rest.QueryRequest; +import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; import org.gcube.application.geoportal.common.rest.Projects; import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; @@ -97,6 +98,8 @@ import com.jayway.jsonpath.Option; @SuppressWarnings("serial") public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet implements GeoportalDataViewerService { + private static final String TIMELINE_CONFIG_TJT_DOCUMENT = "tjt_document"; + private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerServiceImpl.class); private static final String CACHE_IMAGE_PREVIEW_FOR_CONCESSIONE = "MAP_IMAGE_PREVIEW_FOR_CONCESSIONE"; @@ -986,7 +989,14 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme LOG.info("Trying to get project for id " + profileID); new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); - UseCaseDescriptor ucd = GeoportalClientCaller.useCaseDescriptors().getUCDForId(profileID); + + UseCaseDescriptor ucd = SessionUtil.getUCDForId(this.getThreadLocalRequest(), profileID); + + if (ucd == null) { + ucd = GeoportalClientCaller.useCaseDescriptors().getUCDForId(profileID); + SessionUtil.setUCDForId(this.getThreadLocalRequest(), profileID, ucd); + } + Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); @@ -1173,6 +1183,8 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme ProjectDV projectDV = new ProjectDV(); try { + new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); + useCaseDescriptors().build().query(request).forEachRemaining(u -> { try { LOG.debug("UCD for id" + u.getId() + " returend name: " + u.getName()); @@ -1197,7 +1209,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme LOG.warn("Error on getting minimalProjectDV of projectID: ", e); } - LOG.debug("minimalProjectDV returning: "+projectDV); + LOG.debug("minimalProjectDV returning: " + projectDV); return projectDV; } @@ -1211,7 +1223,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme private GeoJSON spatialReference(String profileID, String projectID) { LOG.trace("spatialReference for profileID: " + profileID + ", projectID: " + projectID + "called"); try { - + new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); List listIR = projects(profileID).build().getById(projectID) .getIdentificationReferenceByType(IdentificationReferencesTYPE.SPATIAL_REFERENCE.getType()); if (listIR != null && !listIR.isEmpty()) { @@ -1241,13 +1253,16 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme LinkedHashMap documentAsMap = new LinkedHashMap(limit); try { - Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID); + new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); + + Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID); + try { Iterator> entrySetsIt = theProject.getTheDocument().entrySet().iterator(); int i = 0; while (entrySetsIt.hasNext()) { - if (i+1 > limit) + if (i + 1 > limit) break; Entry entry = entrySetsIt.next(); @@ -1259,29 +1274,24 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme throw e; } - /*QueryRequest request = new QueryRequest(); - request.setFilter(Document.parse("{\"" + Project.ID + "\" : " + "{\"$eq\" : \"" + projectID + "\"}}")); - request.setProjection(Document.parse("{\"" + Project.THE_DOCUMENT + "\" : " + "1}")); - // should be one - projects(profileID).build().query(request).forEachRemaining(p -> { - try { - Iterator> entrySetsIt = p.getTheDocument().entrySet().iterator(); - int i = 0; - while (entrySetsIt.hasNext()) { - if (i > limit) - break; + /* + * QueryRequest request = new QueryRequest(); + * request.setFilter(Document.parse("{\"" + Project.ID + "\" : " + + * "{\"$eq\" : \"" + projectID + "\"}}")); + * request.setProjection(Document.parse("{\"" + Project.THE_DOCUMENT + "\" : " + + * "1}")); // should be one + * projects(profileID).build().query(request).forEachRemaining(p -> { try { + * Iterator> entrySetsIt = + * p.getTheDocument().entrySet().iterator(); int i = 0; while + * (entrySetsIt.hasNext()) { if (i > limit) break; + * + * Entry entry = entrySetsIt.next(); + * documentAsMap.put(entry.getKey(), entry.getValue()); i++; } + * + * } catch (Exception e) { throw e; } }); + */ - Entry entry = entrySetsIt.next(); - documentAsMap.put(entry.getKey(), entry.getValue()); - i++; - } - - } catch (Exception e) { - throw e; - } - });*/ - - LOG.debug("getEntrySetsDocumentForProjectID returning map: "+documentAsMap); + LOG.debug("getEntrySetsDocumentForProjectID returning map: " + documentAsMap); return documentAsMap; } catch (Exception e) { @@ -1301,58 +1311,88 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme try { LOG.info("Trying to getRelationshipsForTimeline for id " + profileID); + new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); List listJSON = new ArrayList(); - + String template = null; try { - String template = "{\"content\": \"$.nome\"," + "\"title\": \"$.nome\"," - + "\"start\" : \"$.dataInizioProgetto\"," + "\"end\" : \"$.dataFineProgetto\"}"; - JSONObject sourceJsonTemplate = new JSONObject(template); - com.jayway.jsonpath.Configuration conf = com.jayway.jsonpath.Configuration.defaultConfiguration(); - com.jayway.jsonpath.Configuration conf2 = conf.addOptions(Option.ALWAYS_RETURN_LIST); + template = SessionUtil.getJSONTimelineTemplate(this.getThreadLocalRequest(), profileID); - Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID); - List relationships = theProject.getRelationships(); + try { - if (relationships == null || relationships.size() == 0) - return new ArrayList(); + if (template == null) { - // Adding the input document - DocumentContext targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson()); + List timelineHandlers = useCaseDescriptors().build().getById(profileID) + .getHandlersByType(GEOPORTAL_DATA_HANDLER.geoportal_timeline_json_template.getType()); - JSONObject targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate, profileID, projectID, - null); - - targetJsonObject.put("selected", "from here"); - String theJSONResult = targetJsonObject.toString(); - LOG.debug("Base jsonObject " + theJSONResult); - listJSON.add(theJSONResult); - - // Adding the relationships - for (Relationship relationship : relationships) { - - // Adding the first level of the related project - theProject = GeoportalClientCaller.projects().getProjectByID(relationship.getTargetUCD(), - relationship.getTargetID()); - targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson()); - targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate, relationship.getTargetUCD(), - relationship.getTargetID(), relationship.getRelationshipName()); - theJSONResult = targetJsonObject.toString(); - listJSON.add(theJSONResult); - - LOG.debug("\n\ngetRelationshipsChain for " + relationship); - Iterator iterator = GeoportalClientCaller.projects() - .getRelationshipChain(relationship.getTargetUCD(), relationship.getTargetID(), - relationship.getRelationshipName(), true); - // Adding deep > 1 - while (iterator.hasNext()) { - RelationshipNavigationObject nav = (RelationshipNavigationObject) iterator.next(); - listJSON = visitRelationshipsChain(nav, relationship.getRelationshipName(), listJSON, conf2, - sourceJsonTemplate); + if (timelineHandlers != null && timelineHandlers.size() > 0) { + HandlerDeclaration handler = timelineHandlers.get(0); // only one expected + Document config = handler.getConfiguration(); + LinkedHashMap tjtDoc = (LinkedHashMap) config + .get(TIMELINE_CONFIG_TJT_DOCUMENT); + template = new Document(tjtDoc).toJson(); + LOG.info(TIMELINE_CONFIG_TJT_DOCUMENT + " read is: " + template); + SessionUtil.setJSONTimelineTemplate(this.getThreadLocalRequest(), profileID, template); + } } - LOG.debug("Finally list of jsonObject " + listJSON); + } catch (Exception e) { + LOG.warn(GEOPORTAL_DATA_HANDLER.geoportal_timeline_json_template.getType() + + " not found!!! Timeline cannot be available"); + } +// String template = "{\"content\": \"$.nome\"," + "\"title\": \"$.nome\"," +// + "\"start\" : \"$.dataInizioProgetto\"," + "\"end\" : \"$.dataFineProgetto\"}"; + if (template != null) { + + JSONObject sourceJsonTemplate = new JSONObject(template); + com.jayway.jsonpath.Configuration conf = com.jayway.jsonpath.Configuration.defaultConfiguration(); + com.jayway.jsonpath.Configuration conf2 = conf.addOptions(Option.ALWAYS_RETURN_LIST); + + Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID); + List relationships = theProject.getRelationships(); + + if (relationships == null || relationships.size() == 0) + return new ArrayList(); + + // Adding the input document + DocumentContext targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson()); + + JSONObject targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate, profileID, + projectID, null); + + targetJsonObject.put("selected", "from here"); + String theJSONResult = targetJsonObject.toString(); + LOG.debug("Base jsonObject " + theJSONResult); + listJSON.add(theJSONResult); + + // Adding the relationships + for (Relationship relationship : relationships) { + + // Adding the first level of the related project + theProject = GeoportalClientCaller.projects().getProjectByID(relationship.getTargetUCD(), + relationship.getTargetID()); + targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson()); + targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate, + relationship.getTargetUCD(), relationship.getTargetID(), + relationship.getRelationshipName()); + theJSONResult = targetJsonObject.toString(); + listJSON.add(theJSONResult); + + LOG.debug("\n\ngetRelationshipsChain for " + relationship); + Iterator iterator = GeoportalClientCaller.projects() + .getRelationshipChain(relationship.getTargetUCD(), relationship.getTargetID(), + relationship.getRelationshipName(), true); + // Adding deep > 1 + while (iterator.hasNext()) { + RelationshipNavigationObject nav = (RelationshipNavigationObject) iterator.next(); + listJSON = visitRelationshipsChain(nav, relationship.getRelationshipName(), listJSON, conf2, + sourceJsonTemplate); + } + + LOG.debug("Finally list of jsonObject " + listJSON); + + } } } catch (Exception e) { String erroMsg = "Error occurred on reading relatioships for id: " + projectID; diff --git a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java index 7dd1a0d..795659e 100644 --- a/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/geoportaldataviewer/server/util/SessionUtil.java @@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.gcube.application.geoportal.common.model.legacy.Concessione; +import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; import org.gcube.application.geoportalcommon.shared.GNADataViewerConfigProfile; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.portal.PortalContext; @@ -35,7 +36,7 @@ import com.liferay.portal.service.UserLocalServiceUtil; * Oct 20, 2020 */ public class SessionUtil { - + private static final String MAP_UCD_ID_TO_GCUBE_PROFILES = "MAP_UCD_ID_TO_GCUBE_PROFILES"; /** The log. */ @@ -43,9 +44,11 @@ public class SessionUtil { private static final String URL_SHORTENER_SERVICE = "URL_SHORTENER_SERVICE"; private static final String LIST_BASE_MAPS_LAYERS = "LIST_BASE_MAPS_LAYERS"; + private static final String TIMELINE_JSON_TEMPLATE = "TIMELINE_JSON_TEMPLATE"; + private static final String USE_CASE_DESCRIPTOR = "USE_CASE_DESCRIPTOR"; private static final String LIST_OF_CONCESSIONI = "LIST_OF_CONCESSIONI_DATA_VIEWER"; private static final String GNA_DATAVIEWER_CONFIG_PROFILE = "GNA_DATAVIEWER_CONFIG_PROFILE"; - + private static final String COUNT_DOCS_FOR_PROFILE_ID = "GNA_DATAVIEWER_COUNT_DOCS_FOR_PROFILE_ID"; /** @@ -181,7 +184,7 @@ public class SessionUtil { return shortener; } - + /** * Gets the GNA base maps. * @@ -206,6 +209,55 @@ public class SessionUtil { return lstBML; } + /** + * Gets the JSON timeline template. + * + * @param httpServletRequest the http servlet request + * @param profileID the profile ID + * @return the JSON timeline template + */ + public static String getJSONTimelineTemplate(HttpServletRequest httpServletRequest, String profileID) { + HttpSession session = httpServletRequest.getSession(); + return (String) session.getAttribute(TIMELINE_JSON_TEMPLATE + profileID); + } + + /** + * Sets the JSON timeline template. + * + * @param httpServletRequest the http servlet request + * @param profileID the profile ID + * @param jsonTimelineTemplate the json timeline template + */ + public static void setJSONTimelineTemplate(HttpServletRequest httpServletRequest, String profileID, + String jsonTimelineTemplate) { + HttpSession session = httpServletRequest.getSession(); + session.setAttribute(TIMELINE_JSON_TEMPLATE + profileID, jsonTimelineTemplate); + } + + /** + * Gets the UCD for id. + * + * @param httpServletRequest the http servlet request + * @param profileID the profile ID + * @return the UCD for id + */ + public static UseCaseDescriptor getUCDForId(HttpServletRequest httpServletRequest, String profileID) { + HttpSession session = httpServletRequest.getSession(); + return (UseCaseDescriptor) session.getAttribute(USE_CASE_DESCRIPTOR + profileID); + } + + /** + * Sets the UCD for id. + * + * @param httpServletRequest the http servlet request + * @param profileID the profile ID + * @param ucd the ucd + */ + public static void setUCDForId(HttpServletRequest httpServletRequest, String profileID, UseCaseDescriptor ucd) { + HttpSession session = httpServletRequest.getSession(); + session.setAttribute(USE_CASE_DESCRIPTOR + profileID, ucd); + } + /** * Gets the list of concessioni. * @@ -220,36 +272,32 @@ public class SessionUtil { List listOfConcessioni = (List) session.getAttribute(LIST_OF_CONCESSIONI); throw new Exception("getListConcessioni must be revisited!!!!"); /* - // setting null to force reloading from service - if (reloadFromService) - listOfConcessioni = null; - - if (listOfConcessioni == null) { - listOfConcessioni = new ArrayList(); - LOG.info("Loading list of concessione from client mongo"); - SessionUtil.getCurrentContext(httpServletRequest, true); - MongoServiceCommon serviceUtil = new MongoServiceCommon(); - MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); - - Iterator concessioni = clientMongo.getList(); - if (concessioni != null) { - while (concessioni.hasNext()) { - Concessione concessione = (Concessione) concessioni.next(); - listOfConcessioni.add(concessione); - - } - } - // LOG.debug("Got list of concessioni from client mongo: " + listOfConcessioni); - session.setAttribute(LIST_OF_CONCESSIONI, listOfConcessioni); - LOG.info("Saved in session list of concessioni from client mongo with size: " + listOfConcessioni.size()); - - } else - LOG.info("list of concessioni presents in session, using it"); - - LOG.info("read list of concessioni with size: " + listOfConcessioni.size()); - return listOfConcessioni; - - */ + * // setting null to force reloading from service if (reloadFromService) + * listOfConcessioni = null; + * + * if (listOfConcessioni == null) { listOfConcessioni = new + * ArrayList(); + * LOG.info("Loading list of concessione from client mongo"); + * SessionUtil.getCurrentContext(httpServletRequest, true); MongoServiceCommon + * serviceUtil = new MongoServiceCommon(); MongoConcessioni clientMongo = + * serviceUtil.getInstanceMongoConcessioni(); + * + * Iterator concessioni = clientMongo.getList(); if (concessioni != + * null) { while (concessioni.hasNext()) { Concessione concessione = + * (Concessione) concessioni.next(); listOfConcessioni.add(concessione); + * + * } } // LOG.debug("Got list of concessioni from client mongo: " + + * listOfConcessioni); session.setAttribute(LIST_OF_CONCESSIONI, + * listOfConcessioni); + * LOG.info("Saved in session list of concessioni from client mongo with size: " + * + listOfConcessioni.size()); + * + * } else LOG.info("list of concessioni presents in session, using it"); + * + * LOG.info("read list of concessioni with size: " + listOfConcessioni.size()); + * return listOfConcessioni; + * + */ } /** @@ -274,8 +322,7 @@ public class SessionUtil { HttpSession session = httpServletRequest.getSession(); session.setAttribute(GNA_DATAVIEWER_CONFIG_PROFILE, gNADVConfigProfile); } - - + /** * Gets the total document for profile ID. * @@ -302,4 +349,5 @@ public class SessionUtil { session.setAttribute(COUNT_DOCS_FOR_PROFILE_ID + theProfileID, countForProfileId); } + }