in progress timeline

This commit is contained in:
Francesco Mangiacrapa 2022-11-07 17:58:06 +01:00
parent ed93c13434
commit b9f73817f8
5 changed files with 162 additions and 120 deletions

View File

@ -6,6 +6,7 @@ package org.gcube.portlets.user.geoportaldataviewer.client;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -588,15 +589,15 @@ public class LayerManager {
}
public void removeIndexLayer(IndexLayerDV layer) {
String wmsLink = layer.getLayer().getOgcLinks().get("wms");
GWT.log("index layer wmsLink: " + wmsLink);
String layerNameKey = URLUtil.getValueOfParameter("layers", wmsLink);
olMap.removeWMSLayer(layerNameKey);
mapIndexLayerObjects.remove(layerNameKey);
GWT.log("New INDEX_LAYER mapIndexLayerObjects is: " + mapIndexLayerObjects);
}
/**
@ -894,7 +895,8 @@ public class LayerManager {
public void showPopupInfoForCentroidLayer(GeoNaSpatialQueryResult geoNaDataObject, FeatureRow feature,
Coordinate onFailureCenterTo) {
GWT.log("showPopupInfoForCentroidLayer must be revisited");
GWT.log("showPopupInfoForCentroidLayer showing feature: " + feature);
GWT.log("showPopupInfoForCentroidLayer showing layerObject: " + geoNaDataObject.getSourceLayerObject());
FlexTable flex = new FlexTable();
flex.setCellPadding(1);
@ -909,37 +911,33 @@ public class LayerManager {
return;
}
// Showing properties belonging to concessioni centroid layer
Map<String, List<String>> entries = feature.getMapProperties();
ProjectDV projectDV = geoNaDataObject.getSourceLayerObject().getProjectDV();
String nome = "";
String descrizione = "";
String date = "";
for (String key : entries.keySet()) {
String theValue = entries.get(key).get(0);
if (key.equalsIgnoreCase("nome")) {
nome = theValue != null ? theValue : "";
} else if (key.equalsIgnoreCase("descrizione")) {
descrizione = theValue != null ? theValue : "";
} else if (key.equalsIgnoreCase("date_scavo")) {
date = theValue != null ? theValue : "";
if (projectDV != null && projectDV.getTheDocument() != null) {
LinkedHashMap<String, Object> map = projectDV.getTheDocument().getDocumentAsMap();
// my-html-table
FlexTable intFlex = new FlexTable();
intFlex.setCellPadding(1);
intFlex.setCellSpacing(1);
//intFlex.getElement().addClassName("my-html-table");
//int i = 0;
for (String key : map.keySet()) {
try {
Object theValue = map.get(key);
String toStringValue = theValue + "";
//intFlex.setHTML(i, 0, key);
intFlex.setHTML(intFlex.getRowCount() + 1, 0, "<span>"+StringUtil.ellipsize(toStringValue, 100)+"</span>");
//i++;
} catch (Exception e) {
// TODO: handle exception
}
}
flex.setHTML(flex.getRowCount() + 1, 0, intFlex.getElement().getString());
}
// GeoportalDataViewerConstants.print("0: "+nome);
flex.setHTML(0, 0, new HTML(nome).toString());
try {
descrizione = StringUtil.ellipsize(descrizione, 100);
GWT.log("reduced: " + descrizione);
} catch (Exception e) {
GWT.log("error: " + e.getMessage());
}
// GeoportalDataViewerConstants.print("1: "+descrizione);
flex.setText(1, 0, descrizione);
// GeoportalDataViewerConstants.print("2: "+date);
date = StringUtil.formatDate(date);
flex.setHTML(2, 0, new HTML("<code>" + date + "</code>").toString());
// Showing properties belonging to centroid layer, ignoring this
// Map<String, List<String>> entries = feature.getMapProperties();
if (geoNaDataObject.getMapImages() != null) {
for (String key : geoNaDataObject.getMapImages().keySet()) {
@ -1085,6 +1083,4 @@ public class LayerManager {
return overlayLayerManager;
}
}

View File

@ -106,6 +106,9 @@ public class TimelineRelationPanel extends Composite {
private void setSelectedProject(String projectID) {
this.selectedProjectID = projectID;
GWT.log("selectedProjectID: " + selectedProjectID);
if(selectedProjectID == null || selectedProjectID.isEmpty())
return;
String[] references = this.selectedProjectID.split(",");

View File

@ -21,6 +21,7 @@ import org.gcube.application.geoportal.common.model.configuration.Index;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.identification.IdentificationReference;
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.UseCaseDescriptor;
import org.gcube.application.geoportal.common.rest.Projects;
@ -1065,6 +1066,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
List<PayloadDV> images;
// Loading images for profileID and projectID
try {
images = getImagesForId(profileID, projectID, true);
Map<String, List<PayloadDV>> mapImages = new LinkedHashMap<String, List<PayloadDV>>();
@ -1077,8 +1079,9 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
}
// Sets only profileID and profileName into ProjectDV
if (layerObject.getProjectDV() == null) {
ProjectDV projectDV = minimalProjectDV(profileID, projectID);
if (layerObject.getProjectDV() == null
|| layerObject.getProjectDV().getTheDocument() == null) {
ProjectDV projectDV = minimalProjectDV(profileID, projectID, true, 2);
layerObject.setProjectDV(projectDV);
}
}
@ -1102,7 +1105,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
// Mininal set of info for displaying into popup
if (layerObject.getProjectDV() == null) {
ProjectDV projectDV = minimalProjectDV(layerObject.getProfileID(),
layerObject.getProjectID());
layerObject.getProjectID(), false, 0);
layerObject.setProjectDV(projectDV);
}
@ -1158,8 +1161,10 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
* @param projectID the project ID
* @return the project DV
*/
private ProjectDV minimalProjectDV(String profileID, String projectID) {
LOG.trace("minimalProjectDV for profileID: " + profileID + ", projectID: " + projectID + "called");
private ProjectDV minimalProjectDV(String profileID, String projectID, boolean loadDocument,
int limitDocumentEntries) {
LOG.debug("called minimalProjectDV for profileID: " + profileID + ", projectID: " + projectID
+ ", loadDocument: " + loadDocument + ", limitDocumentEntries: " + limitDocumentEntries);
QueryRequest request = new QueryRequest();
request.setFilter(
@ -1179,10 +1184,20 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
LOG.warn("Invalid UCD, UCID : " + u.getId());
}
});
if (loadDocument) {
LinkedHashMap<String, Object> theDocument = getEntrySetsDocumentForProjectID(profileID, projectID,
limitDocumentEntries);
DocumentDV docDV = new DocumentDV();
docDV.setDocumentAsMap(theDocument);
projectDV.setTheDocument(docDV);
}
} catch (Exception e) {
// silent
LOG.warn("Error on getting minimalProjectDV of projectID: ", e);
}
LOG.debug("minimalProjectDV returning: "+projectDV);
return projectDV;
}
@ -1221,17 +1236,18 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
@Override
public LinkedHashMap<String, Object> getEntrySetsDocumentForProjectID(String profileID, String projectID,
int limit) {
LOG.debug("called getEntrySetsDocumentForProjectID for profileID: " + profileID + ", projectID: " + projectID);
LinkedHashMap<String, Object> documentAsMap = new LinkedHashMap<String, Object>(limit);
try {
Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID);
try {
Iterator<Entry<String, Object>> entrySetsIt = theProject.getTheDocument().entrySet().iterator();
int i = 0;
while (entrySetsIt.hasNext()) {
if (i > limit)
if (i+1 > limit)
break;
Entry<String, Object> entry = entrySetsIt.next();
@ -1243,6 +1259,29 @@ 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<Entry<String, Object>> entrySetsIt = p.getTheDocument().entrySet().iterator();
int i = 0;
while (entrySetsIt.hasNext()) {
if (i > limit)
break;
Entry<String, Object> entry = entrySetsIt.next();
documentAsMap.put(entry.getKey(), entry.getValue());
i++;
}
} catch (Exception e) {
throw e;
}
});*/
LOG.debug("getEntrySetsDocumentForProjectID returning map: "+documentAsMap);
return documentAsMap;
} catch (Exception e) {
@ -1274,68 +1313,45 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
Project theProject = GeoportalClientCaller.projects().getProjectByID(profileID, projectID);
List<Relationship> relationships = theProject.getRelationships();
if(relationships==null || relationships.size()==0)
if (relationships == null || relationships.size() == 0)
return new ArrayList<String>();
//Adding the input document
// Adding the input document
DocumentContext targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson());
JSONObject targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate,
profileID,projectID, null);
JSONObject targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate, profileID, projectID,
null);
targetJsonObject.put("selected", "from here");
String theJSONResult = targetJsonObject.toString();
LOG.debug("Built jsonObject " + theJSONResult);
LOG.debug("Base jsonObject " + theJSONResult);
listJSON.add(theJSONResult);
for (Relationship relationship : relationships) {
Project targetProject = GeoportalClientCaller.projects().getProjectByID(relationship.getTargetUCD(),
// 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(targetProject.getTheDocument().toJson());
targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate,
relationship.getTargetUCD(), relationship.getTargetID(), null);
targetDoc = JsonPath.using(conf2).parse(theProject.getTheDocument().toJson());
targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate, relationship.getTargetUCD(),
relationship.getTargetID(), relationship.getRelationshipName());
theJSONResult = targetJsonObject.toString();
LOG.debug("Built jsonObject " + theJSONResult);
listJSON.add(theJSONResult);
// GeoportalClientCaller.projects().getRelationshipChain(profileID, projectID, relationship.getRelationshipName());
// relationship.getRelationshipName();
LOG.debug("\n\ngetRelationshipsChain for " + relationship);
Iterator<RelationshipNavigationObject> 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);
}
// targetJsonObject.put("id", relationship.getTargetUCD() + "," + relationship.getTargetID());
// targetJsonObject.put("relationship_name", relationship.getRelationshipName());
//
// LOG.debug("targetDoc is: " + targetDoc.jsonString());
// LOG.debug("sourceJsonTemplate is: " + sourceJsonTemplate.toString());
//
// for (Object key : sourceJsonTemplate.keySet()) {
// String theKey = key + "";
// LOG.debug("Searching key: " + theKey);
// String jsonPath = sourceJsonTemplate.getString(theKey);
// LOG.debug("with key: " + theKey + " read JSON path: " + jsonPath);
//
// // Works fine
//
// List<String> 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);
// }
//
// List<PayloadDV> images = getImagesForId(relationship.getTargetUCD(), relationship.getTargetID(),
// true);
// if (images.size() > 0) {
// images.get(0).getLink();
// targetJsonObject.put("image_url", images.get(0).getLink());
// }
// String theJSONResult = targetJsonObject.toString();
// LOG.debug("Built jsonObject " + theJSONResult);
// listJSON.add(theJSONResult);
LOG.debug("Finally list of jsonObject " + listJSON);
}
} catch (Exception e) {
@ -1343,24 +1359,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
LOG.error(erroMsg, e);
}
// TODO LOAD AND APPLT TEMPLATING OF KIND
//
// for (int i = 0; i < 5; i++) {
//
// JSONObject jsonObject = new JSONObject();
// jsonObject.put("id", "UCD"+i+",ID"+i);
// jsonObject.put("content",
// "title moooooooooooooolto lungoooooooooooooooooooooooooooooooooooooooooooooooooo" + i);
// jsonObject.put("start", "201" + i + "-04-1");
// jsonObject.put("end", "201" + i + "-09-1");
// jsonObject.put("relationship_name", "follows");
// if (i < 3)
// jsonObject.put("image_url",
// "https://data-pre.d4science.org/shub/E_ck5hN0hBcGljR3oySm5KOWJxOUMyRkRaWkZ4WnhmWXJjWVlLeWxGcW9FMWQraitOWStmQXREQklNUlMydzNFTw==");
//
// listJSON.add(jsonObject.toString());
// }
LOG.debug("returning list of relantionships having size: " + listJSON.size());
return listJSON;
} catch (Exception e) {
String erroMsg = "Error occurred on reading relatioships for id: " + projectID;
@ -1369,6 +1368,45 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
}
}
// recursive visit of the Relationships
public List<String> visitRelationshipsChain(RelationshipNavigationObject nav, String relationshipName,
List<String> listJSONTimelineModel, com.jayway.jsonpath.Configuration conf2,
JSONObject sourceJsonTemplate) {
if (nav == null)
return listJSONTimelineModel;
LOG.debug("visitRelationshipsChain of target: " + nav.getTarget().getId() + ", relationshipName: "
+ relationshipName);
if (LOG.isDebugEnabled()) {
LOG.debug("visitRelationshipsChain target doc: " + nav.getTarget().getTheDocument());
LOG.debug("visitRelationshipsChain children " + nav.getChildren());
}
try {
Project targetProject = nav.getTarget();
DocumentContext targetDoc = JsonPath.using(conf2).parse(targetProject.getTheDocument().toJson());
JSONObject targetJsonObject = toTimelineJSONModel(targetDoc, sourceJsonTemplate,
nav.getTarget().getProfileID(), nav.getTarget().getId(), relationshipName);
String theJSONResult = targetJsonObject.toString();
listJSONTimelineModel.add(theJSONResult);
LOG.debug("Built jsonObject " + theJSONResult);
} catch (Exception e) {
LOG.warn("Skipping " + nav.getTarget().getId() + " translate relationshipName: " + relationshipName);
}
if (nav.getChildren() != null) {
LOG.debug("visiting children...");
for (RelationshipNavigationObject relationship : nav.getChildren()) {
listJSONTimelineModel = visitRelationshipsChain(relationship, relationshipName, listJSONTimelineModel,
conf2, sourceJsonTemplate);
}
}
return listJSONTimelineModel;
}
private JSONObject toTimelineJSONModel(DocumentContext targetDoc, JSONObject sourceJsonTemplate, String targetUCD,
String targetProjectID, String relationName) {
JSONObject targetJsonObject = new JSONObject();

View File

@ -74,6 +74,7 @@ body {
.ol-popup-closer:after {
content: "✖";
font-size: 14px;
}
.data-click-img {
@ -84,6 +85,14 @@ body {
font-weight: bold;
}
.popup-table table {
font-size: 12px;
}
.popup-table table tr:nth-child(2) {
font-weight: bold;
}
#page-view-details {
margin: 10px;
text-rendering: optimizelegibility;
@ -575,7 +584,7 @@ body {
width: 800px;
position: absolute;
bottom: 2px;
z-index: 10000;
z-index: 1000;
background: white;
opacity: 0.9;
margin: 0;
@ -584,8 +593,9 @@ body {
}
@media all and (max-width: 1024px) {
#timeline-data{
left: 730px;
width: 250px;
}
#timeline-data {
width: 250px;
left: 125px;
bottom: 50px
}
}

View File

@ -44,11 +44,6 @@
<span id="relation-style">{{selected}}</span>
</tr></td>
{{/if}}
{{#if relationship_name}}
<tr><td>
<span id="relation-style">{{relationship_name}}</span>
</tr></td>
{{/if}}
{{#if image_url}}
<tr><td>
<img src="{{image_url}}"></img>