Integrated with timeline config

This commit is contained in:
Francesco Mangiacrapa 2022-11-08 17:56:36 +01:00
parent fec3f26c0a
commit 62dc1bad6c
3 changed files with 192 additions and 107 deletions

View File

@ -161,9 +161,6 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="geoportal-data-common-2.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common">
<dependency-type>uses</dependency-type>
</dependent-module>

View File

@ -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.Relationship;
import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject; 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.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.model.useCaseDescriptor.UseCaseDescriptor;
import org.gcube.application.geoportal.common.rest.Projects; import org.gcube.application.geoportal.common.rest.Projects;
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel; import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
@ -97,6 +98,8 @@ import com.jayway.jsonpath.Option;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet implements GeoportalDataViewerService { 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 Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerServiceImpl.class);
private static final String CACHE_IMAGE_PREVIEW_FOR_CONCESSIONE = "MAP_IMAGE_PREVIEW_FOR_CONCESSIONE"; 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); LOG.info("Trying to get project for id " + profileID);
new GeoportalServiceIdentityProxy(this.getThreadLocalRequest()); 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); Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID);
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true); ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
@ -1173,6 +1183,8 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
ProjectDV projectDV = new ProjectDV(); ProjectDV projectDV = new ProjectDV();
try { try {
new GeoportalServiceIdentityProxy(this.getThreadLocalRequest());
useCaseDescriptors().build().query(request).forEachRemaining(u -> { useCaseDescriptors().build().query(request).forEachRemaining(u -> {
try { try {
LOG.debug("UCD for id" + u.getId() + " returend name: " + u.getName()); LOG.debug("UCD for id" + u.getId() + " returend name: " + u.getName());
@ -1211,7 +1223,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
private GeoJSON spatialReference(String profileID, String projectID) { private GeoJSON spatialReference(String profileID, String projectID) {
LOG.trace("spatialReference for profileID: " + profileID + ", projectID: " + projectID + "called"); LOG.trace("spatialReference for profileID: " + profileID + ", projectID: " + projectID + "called");
try { try {
new GeoportalServiceIdentityProxy(this.getThreadLocalRequest());
List<IdentificationReference> listIR = projects(profileID).build().getById(projectID) List<IdentificationReference> listIR = projects(profileID).build().getById(projectID)
.getIdentificationReferenceByType(IdentificationReferencesTYPE.SPATIAL_REFERENCE.getType()); .getIdentificationReferenceByType(IdentificationReferencesTYPE.SPATIAL_REFERENCE.getType());
if (listIR != null && !listIR.isEmpty()) { if (listIR != null && !listIR.isEmpty()) {
@ -1241,6 +1253,9 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(limit); LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(limit);
try { try {
new GeoportalServiceIdentityProxy(this.getThreadLocalRequest());
Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID); Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID);
try { try {
@ -1259,27 +1274,22 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
throw e; throw e;
} }
/*QueryRequest request = new QueryRequest(); /*
request.setFilter(Document.parse("{\"" + Project.ID + "\" : " + "{\"$eq\" : \"" + projectID + "\"}}")); * QueryRequest request = new QueryRequest();
request.setProjection(Document.parse("{\"" + Project.THE_DOCUMENT + "\" : " + "1}")); * request.setFilter(Document.parse("{\"" + Project.ID + "\" : " +
// should be one * "{\"$eq\" : \"" + projectID + "\"}}"));
projects(profileID).build().query(request).forEachRemaining(p -> { * request.setProjection(Document.parse("{\"" + Project.THE_DOCUMENT + "\" : " +
try { * "1}")); // should be one
Iterator<Entry<String, Object>> entrySetsIt = p.getTheDocument().entrySet().iterator(); * projects(profileID).build().query(request).forEachRemaining(p -> { try {
int i = 0; * Iterator<Entry<String, Object>> entrySetsIt =
while (entrySetsIt.hasNext()) { * p.getTheDocument().entrySet().iterator(); int i = 0; while
if (i > limit) * (entrySetsIt.hasNext()) { if (i > limit) break;
break; *
* Entry<String, Object> entry = entrySetsIt.next();
Entry<String, Object> entry = entrySetsIt.next(); * documentAsMap.put(entry.getKey(), entry.getValue()); i++; }
documentAsMap.put(entry.getKey(), entry.getValue()); *
i++; * } catch (Exception e) { throw e; } });
} */
} catch (Exception e) {
throw e;
}
});*/
LOG.debug("getEntrySetsDocumentForProjectID returning map: " + documentAsMap); LOG.debug("getEntrySetsDocumentForProjectID returning map: " + documentAsMap);
return documentAsMap; return documentAsMap;
@ -1301,11 +1311,39 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
try { try {
LOG.info("Trying to getRelationshipsForTimeline for id " + profileID); LOG.info("Trying to getRelationshipsForTimeline for id " + profileID);
new GeoportalServiceIdentityProxy(this.getThreadLocalRequest());
List<String> listJSON = new ArrayList<String>(); List<String> listJSON = new ArrayList<String>();
String template = null;
try {
template = SessionUtil.getJSONTimelineTemplate(this.getThreadLocalRequest(), profileID);
try { try {
String template = "{\"content\": \"$.nome\"," + "\"title\": \"$.nome\","
+ "\"start\" : \"$.dataInizioProgetto\"," + "\"end\" : \"$.dataFineProgetto\"}"; if (template == null) {
List<HandlerDeclaration> timelineHandlers = useCaseDescriptors().build().getById(profileID)
.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();
LinkedHashMap<String, Object> tjtDoc = (LinkedHashMap<String, Object>) 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);
}
}
} 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); JSONObject sourceJsonTemplate = new JSONObject(template);
com.jayway.jsonpath.Configuration conf = com.jayway.jsonpath.Configuration.defaultConfiguration(); com.jayway.jsonpath.Configuration conf = com.jayway.jsonpath.Configuration.defaultConfiguration();
@ -1320,8 +1358,8 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
// Adding the input document // Adding the input document
DocumentContext targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson()); DocumentContext targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson());
JSONObject targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate, profileID, projectID, JSONObject targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate, profileID,
null); projectID, null);
targetJsonObject.put("selected", "from here"); targetJsonObject.put("selected", "from here");
String theJSONResult = targetJsonObject.toString(); String theJSONResult = targetJsonObject.toString();
@ -1335,8 +1373,9 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
theProject = GeoportalClientCaller.projects().getProjectByID(relationship.getTargetUCD(), theProject = GeoportalClientCaller.projects().getProjectByID(relationship.getTargetUCD(),
relationship.getTargetID()); relationship.getTargetID());
targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson()); targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson());
targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate, relationship.getTargetUCD(), targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate,
relationship.getTargetID(), relationship.getRelationshipName()); relationship.getTargetUCD(), relationship.getTargetID(),
relationship.getRelationshipName());
theJSONResult = targetJsonObject.toString(); theJSONResult = targetJsonObject.toString();
listJSON.add(theJSONResult); listJSON.add(theJSONResult);
@ -1354,6 +1393,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
LOG.debug("Finally list of jsonObject " + listJSON); LOG.debug("Finally list of jsonObject " + listJSON);
} }
}
} catch (Exception e) { } catch (Exception e) {
String erroMsg = "Error occurred on reading relatioships for id: " + projectID; String erroMsg = "Error occurred on reading relatioships for id: " + projectID;
LOG.error(erroMsg, e); LOG.error(erroMsg, e);

View File

@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.gcube.application.geoportal.common.model.legacy.Concessione; 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.application.geoportalcommon.shared.GNADataViewerConfigProfile;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.portal.PortalContext; import org.gcube.common.portal.PortalContext;
@ -43,6 +44,8 @@ public class SessionUtil {
private static final String URL_SHORTENER_SERVICE = "URL_SHORTENER_SERVICE"; 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 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 LIST_OF_CONCESSIONI = "LIST_OF_CONCESSIONI_DATA_VIEWER";
private static final String GNA_DATAVIEWER_CONFIG_PROFILE = "GNA_DATAVIEWER_CONFIG_PROFILE"; private static final String GNA_DATAVIEWER_CONFIG_PROFILE = "GNA_DATAVIEWER_CONFIG_PROFILE";
@ -206,6 +209,55 @@ public class SessionUtil {
return lstBML; 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. * Gets the list of concessioni.
* *
@ -220,35 +272,31 @@ public class SessionUtil {
List<Concessione> listOfConcessioni = (List<Concessione>) session.getAttribute(LIST_OF_CONCESSIONI); List<Concessione> listOfConcessioni = (List<Concessione>) session.getAttribute(LIST_OF_CONCESSIONI);
throw new Exception("getListConcessioni must be revisited!!!!"); throw new Exception("getListConcessioni must be revisited!!!!");
/* /*
// setting null to force reloading from service * // setting null to force reloading from service if (reloadFromService)
if (reloadFromService) * listOfConcessioni = null;
listOfConcessioni = null; *
* if (listOfConcessioni == null) { listOfConcessioni = new
if (listOfConcessioni == null) { * ArrayList<Concessione>();
listOfConcessioni = new ArrayList<Concessione>(); * LOG.info("Loading list of concessione from client mongo");
LOG.info("Loading list of concessione from client mongo"); * SessionUtil.getCurrentContext(httpServletRequest, true); MongoServiceCommon
SessionUtil.getCurrentContext(httpServletRequest, true); * serviceUtil = new MongoServiceCommon(); MongoConcessioni clientMongo =
MongoServiceCommon serviceUtil = new MongoServiceCommon(); * serviceUtil.getInstanceMongoConcessioni();
MongoConcessioni clientMongo = serviceUtil.getInstanceMongoConcessioni(); *
* Iterator<Concessione> concessioni = clientMongo.getList(); if (concessioni !=
Iterator<Concessione> concessioni = clientMongo.getList(); * null) { while (concessioni.hasNext()) { Concessione concessione =
if (concessioni != null) { * (Concessione) concessioni.next(); listOfConcessioni.add(concessione);
while (concessioni.hasNext()) { *
Concessione concessione = (Concessione) concessioni.next(); * } } // LOG.debug("Got list of concessioni from client mongo: " +
listOfConcessioni.add(concessione); * listOfConcessioni); session.setAttribute(LIST_OF_CONCESSIONI,
* listOfConcessioni);
} * LOG.info("Saved in session list of concessioni from client mongo with size: "
} * + listOfConcessioni.size());
// LOG.debug("Got list of concessioni from client mongo: " + listOfConcessioni); *
session.setAttribute(LIST_OF_CONCESSIONI, listOfConcessioni); * } else LOG.info("list of concessioni presents in session, using it");
LOG.info("Saved in session list of concessioni from client mongo with size: " + listOfConcessioni.size()); *
* LOG.info("read list of concessioni with size: " + listOfConcessioni.size());
} else * return listOfConcessioni;
LOG.info("list of concessioni presents in session, using it"); *
LOG.info("read list of concessioni with size: " + listOfConcessioni.size());
return listOfConcessioni;
*/ */
} }
@ -275,7 +323,6 @@ public class SessionUtil {
session.setAttribute(GNA_DATAVIEWER_CONFIG_PROFILE, gNADVConfigProfile); session.setAttribute(GNA_DATAVIEWER_CONFIG_PROFILE, gNADVConfigProfile);
} }
/** /**
* Gets the total document for profile ID. * Gets the total document for profile ID.
* *
@ -302,4 +349,5 @@ public class SessionUtil {
session.setAttribute(COUNT_DOCS_FOR_PROFILE_ID + theProfileID, countForProfileId); session.setAttribute(COUNT_DOCS_FOR_PROFILE_ID + theProfileID, countForProfileId);
} }
} }