2022-10-13 16:53:33 +02:00
|
|
|
package org.gcube.portlets.user.geoportaldataviewer;
|
|
|
|
|
2022-10-25 11:35:03 +02:00
|
|
|
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors;
|
|
|
|
|
2022-11-28 09:49:46 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedHashMap;
|
2022-10-18 14:17:41 +02:00
|
|
|
import java.util.List;
|
2022-11-28 09:49:46 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
import java.util.stream.StreamSupport;
|
2022-10-18 14:17:41 +02:00
|
|
|
|
2022-10-25 11:35:03 +02:00
|
|
|
import org.bson.Document;
|
2022-10-13 16:53:33 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.document.Project;
|
2022-10-27 15:09:07 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.document.identification.IdentificationReference;
|
2022-10-25 11:35:03 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
|
|
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
2022-10-13 16:53:33 +02:00
|
|
|
import org.gcube.application.geoportalcommon.ConvertToDataValueObjectModel;
|
|
|
|
import org.gcube.application.geoportalcommon.ProjectDVBuilder;
|
|
|
|
import org.gcube.application.geoportalcommon.geoportal.GeoportalClientCaller;
|
|
|
|
import org.gcube.application.geoportalcommon.geoportal.ProjectsCaller;
|
|
|
|
import org.gcube.application.geoportalcommon.geoportal.UseCaseDescriptorCaller;
|
2022-10-27 15:09:07 +02:00
|
|
|
import org.gcube.application.geoportalcommon.geoportal.util.GisUtil;
|
2022-11-28 09:49:46 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.WhereClause;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.SearchingFilter.LOGICAL_OP;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.ResultDocumentDV;
|
2022-10-27 15:09:07 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.geojson.Crs;
|
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.geojson.GeoJSON;
|
2022-10-18 14:17:41 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV;
|
2022-10-19 17:51:13 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.innerobject.PayloadDV;
|
2022-10-13 16:53:33 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
|
2022-11-16 16:42:12 +01:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.TemporalReferenceDV;
|
2022-10-13 16:53:33 +02:00
|
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView;
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
2022-10-14 15:31:32 +02:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.Geoportal_JSON_Mapper;
|
2022-11-16 16:42:12 +01:00
|
|
|
import org.gcube.portlets.user.geoportaldataviewer.shared.ProjectEdit;
|
2022-10-27 15:09:07 +02:00
|
|
|
import org.json.JSONObject;
|
2022-11-16 16:42:12 +01:00
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
2022-10-13 16:53:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Class GeoportalViewer_Tests.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
|
|
|
*
|
|
|
|
* Sep 9, 2022
|
|
|
|
*/
|
|
|
|
public class GeoportalViewer_Tests {
|
|
|
|
|
|
|
|
private UseCaseDescriptorCaller clientUCD;
|
|
|
|
|
|
|
|
private ProjectsCaller clientProjects;
|
|
|
|
|
2022-11-28 09:49:46 +01:00
|
|
|
private static String CONTEXT = "/pred4s/preprod/preVRE";
|
|
|
|
private static String TOKEN = "5c3c7551-870d-4259-bd77-a7e603fe4949-980114272"; //preVRE
|
2022-10-13 16:53:33 +02:00
|
|
|
|
2022-11-28 09:49:46 +01:00
|
|
|
//private static String CONTEXT = "/gcube/devsec/devVRE";
|
|
|
|
//private static String TOKEN = ""; // devVRE
|
2022-10-13 16:53:33 +02:00
|
|
|
|
|
|
|
private static String PROFILE_ID = "profiledConcessioni";
|
2022-11-28 09:49:46 +01:00
|
|
|
private static String PROJECT_ID = "637ceb4d21dd0d6fb9f24706";
|
2022-10-18 14:17:41 +02:00
|
|
|
|
2022-10-13 16:53:33 +02:00
|
|
|
private static String USERNAME = "francesco.mangiacrapa";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the client.
|
|
|
|
*
|
|
|
|
* @return the client
|
|
|
|
*/
|
2022-11-28 09:49:46 +01:00
|
|
|
@Before
|
2022-10-13 16:53:33 +02:00
|
|
|
public void getClient() {
|
|
|
|
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
|
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
clientUCD = GeoportalClientCaller.useCaseDescriptors();
|
|
|
|
clientProjects = GeoportalClientCaller.projects();
|
|
|
|
}
|
|
|
|
|
2022-10-19 17:51:13 +02:00
|
|
|
// @Test
|
2022-10-14 15:31:32 +02:00
|
|
|
public void getProjectViewForID() {
|
2022-10-13 16:53:33 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
Project project = clientProjects.getProjectByID(PROFILE_ID, PROJECT_ID);
|
|
|
|
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
|
|
|
ProjectDV projectDV = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
|
2022-10-18 14:17:41 +02:00
|
|
|
|
2022-10-13 16:53:33 +02:00
|
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
2022-10-14 15:31:32 +02:00
|
|
|
ProjectView projectView = Geoportal_JSON_Mapper.loadProjectView(projectDV, CONTEXT, USERNAME);
|
2022-10-14 17:19:40 +02:00
|
|
|
Geoportal_JSON_Mapper.prettyPrintProjectView(projectView);
|
2022-10-13 16:53:33 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-19 17:51:13 +02:00
|
|
|
// @Test
|
2022-10-18 14:17:41 +02:00
|
|
|
public void getLayersForId() {
|
|
|
|
System.out.println("getLayersForId [profileID: " + PROFILE_ID + ", projectID: " + PROJECT_ID + "] called");
|
|
|
|
|
|
|
|
List<GCubeSDIViewerLayerDV> listLayers = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
Project project = clientProjects.getProjectByID(PROFILE_ID, PROJECT_ID);
|
|
|
|
String jsonDocument = project.getTheDocument().toJson();
|
|
|
|
System.out.println("JSON Project is: " + jsonDocument);
|
|
|
|
|
|
|
|
String materializationParentJSONPath = String.format("%s..%s", Geoportal_JSON_Mapper.JSON_$_POINTER,
|
|
|
|
Geoportal_JSON_Mapper.FILESET);
|
|
|
|
|
2022-10-19 17:51:13 +02:00
|
|
|
listLayers = Geoportal_JSON_Mapper.readGcubeSDILayersForFileset(materializationParentJSONPath,
|
|
|
|
jsonDocument);
|
2022-10-18 14:17:41 +02:00
|
|
|
|
|
|
|
listLayers.stream().forEach(s -> System.out.println(s));
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
String erroMsg = "Layers are not available for profileID " + PROFILE_ID + " with projectID " + PROJECT_ID;
|
|
|
|
System.out.println(erroMsg);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-16 16:42:12 +01:00
|
|
|
// @Test
|
2022-10-27 15:09:07 +02:00
|
|
|
public void getSpatialReference() {
|
|
|
|
System.out.println("getSpatialReference [profileID: " + PROFILE_ID + ", projectID: " + PROJECT_ID + "] called");
|
|
|
|
try {
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
Project project = clientProjects.getProjectByID(PROFILE_ID, PROJECT_ID);
|
|
|
|
|
|
|
|
List<IdentificationReference> itentificationReference = project.getIdentificationReferences();
|
|
|
|
|
|
|
|
for (IdentificationReference identificationReference : itentificationReference) {
|
|
|
|
String geoJSON = identificationReference.get("geoJSON").toString();
|
|
|
|
JSONObject jsonObject = new JSONObject(geoJSON);
|
|
|
|
|
|
|
|
GeoJSON geoJson = new GeoJSON();
|
|
|
|
geoJson.setType(jsonObject.getString("type"));
|
|
|
|
geoJson.setBbox(GisUtil.fromJSONArray(jsonObject.getJSONArray("bbox")));
|
|
|
|
Crs crs = org.gcube.application.geoportal.client.utils.Serialization
|
|
|
|
.convert(jsonObject.getJSONObject("crs").toString(), Crs.class);
|
|
|
|
geoJson.setCrs(crs);
|
|
|
|
geoJson.setGeoJSON(geoJSON);
|
|
|
|
|
|
|
|
System.out.println(geoJson);
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
String erroMsg = "getSpatialReference not available for profileID " + PROFILE_ID + " with projectID "
|
|
|
|
+ PROJECT_ID;
|
|
|
|
System.out.println(erroMsg);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// @Test
|
2022-10-19 17:51:13 +02:00
|
|
|
public void getImagesForId() {
|
|
|
|
System.out.println("getImagesForId [profileID: " + PROFILE_ID + ", projectID: " + PROJECT_ID + "] called");
|
|
|
|
|
|
|
|
List<PayloadDV> listImages = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
Project project = clientProjects.getProjectByID(PROFILE_ID, PROJECT_ID);
|
|
|
|
String jsonDocument = project.getTheDocument().toJson();
|
|
|
|
System.out.println("JSON Project is: " + jsonDocument);
|
2022-10-25 11:35:03 +02:00
|
|
|
|
|
|
|
String filesetJSONPath = String.format("%s..%s", Geoportal_JSON_Mapper.JSON_$_POINTER,
|
|
|
|
Geoportal_JSON_Mapper.FILESET);
|
|
|
|
listImages = Geoportal_JSON_Mapper.readImagesForFileset(filesetJSONPath, jsonDocument, true);
|
2022-10-19 17:51:13 +02:00
|
|
|
|
|
|
|
listImages.stream().forEach(s -> System.out.println("Image: " + s));
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
String erroMsg = "Images are not available for profileID " + PROFILE_ID + " with projectID " + PROJECT_ID;
|
|
|
|
System.out.println(erroMsg);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-10-27 15:09:07 +02:00
|
|
|
|
|
|
|
// @Test
|
2022-10-25 11:35:03 +02:00
|
|
|
public void testUCDQuery() {
|
|
|
|
QueryRequest request = new QueryRequest();
|
|
|
|
request.setFilter(
|
|
|
|
Document.parse("{\"" + UseCaseDescriptor.ID + "\" : " + "{\"$eq\" : \"" + PROFILE_ID + "\"}}"));
|
|
|
|
request.setProjection(Document.parse("{\"" + UseCaseDescriptor.NAME + "\" : " + "1}"));
|
|
|
|
|
|
|
|
try {
|
|
|
|
useCaseDescriptors().build().query(request).forEachRemaining(u -> {
|
|
|
|
try {
|
|
|
|
System.out.println("UCD for id" + u.getId() + " returend name: " + u.getName());
|
|
|
|
ProjectDV projectDV = new ProjectDV();
|
|
|
|
projectDV.setId(PROJECT_ID);
|
|
|
|
projectDV.setProfileName(u.getName());
|
|
|
|
projectDV.setProfileID(u.getId());
|
|
|
|
System.out.println(projectDV);
|
|
|
|
} catch (Exception e) {
|
|
|
|
System.out.println("Invalid UCD, UCID : " + u.getId());
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (Exception e) {
|
|
|
|
// silent
|
|
|
|
}
|
|
|
|
}
|
2022-10-19 17:51:13 +02:00
|
|
|
|
2022-11-28 09:49:46 +01:00
|
|
|
@Test
|
2022-11-16 16:42:12 +01:00
|
|
|
public void testReadProjectEdit() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
Project theProject = clientProjects.getProjectByID(PROFILE_ID, PROJECT_ID);
|
|
|
|
ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
|
|
|
|
projectBuilder.relationships(true);
|
|
|
|
ProjectDV theProjectDV = ConvertToDataValueObjectModel.toProjectDV(theProject, projectBuilder);
|
2022-11-28 09:49:46 +01:00
|
|
|
Geoportal_JSON_Mapper geojsonM = new Geoportal_JSON_Mapper();
|
2022-11-16 16:42:12 +01:00
|
|
|
ProjectEdit projectEdit = Geoportal_JSON_Mapper.loadProjectEdit(theProjectDV, CONTEXT, USERNAME);
|
|
|
|
Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectEdit);
|
|
|
|
|
|
|
|
// ProjectView projectView = Geoportal_JSON_Mapper.loadProjectView(theProjectDV, CONTEXT, USERNAME);
|
|
|
|
// Geoportal_JSON_Mapper.prettyPrintProjectView(projectView);
|
2022-11-28 09:49:46 +01:00
|
|
|
System.out.println("testReadProjectEdit terminated");
|
2022-11-16 16:42:12 +01:00
|
|
|
} catch (Exception e) {
|
2022-11-28 09:49:46 +01:00
|
|
|
System.err.println("Error");
|
2022-11-16 16:42:12 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void testTemporalReference() {
|
|
|
|
try {
|
|
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
|
|
Project theProject = clientProjects.getProjectByID(PROFILE_ID, PROJECT_ID);
|
|
|
|
Document temporalJsonTemplate = GeoportalClientCaller.useCaseDescriptors()
|
|
|
|
.readTemporalDimensionTemplate(theProject.getProfileID());
|
|
|
|
|
|
|
|
// String template = "{\"content\": \"$.nome\"," + "\"title\": \"$.nome\","
|
|
|
|
// + "\"start\" : \"$.dataInizioProgetto\"," + "\"end\" : \"$.dataFineProgetto\"}";
|
|
|
|
|
|
|
|
if (temporalJsonTemplate != null) {
|
|
|
|
|
|
|
|
JSONObject sourceJsonTemplate = new JSONObject(temporalJsonTemplate);
|
|
|
|
|
|
|
|
JSONObject targetJsonObject = ConvertToDataValueObjectModel.toTimelineJSONModel(theProject,
|
|
|
|
sourceJsonTemplate, theProject.getProfileID(), theProject.getId(), null);
|
|
|
|
|
|
|
|
TemporalReferenceDV temporalDV = ConvertToDataValueObjectModel.toTemporalReferenceDV(theProject,
|
|
|
|
targetJsonObject);
|
|
|
|
System.out.println(temporalDV);
|
|
|
|
// ProjectView projectView = Geoportal_JSON_Mapper.loadProjectView(theProjectDV, CONTEXT, USERNAME);
|
|
|
|
// Geoportal_JSON_Mapper.prettyPrintProjectView(projectView);
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2022-11-28 09:49:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getResultsWithSize() throws Exception {
|
|
|
|
// List<Project> listOfProjects = client.getListForProfileID(PROFILE_ID);
|
|
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
System.out.println("start at: "+start);
|
|
|
|
SearchingFilter filter = new SearchingFilter();
|
|
|
|
|
|
|
|
// Where Clause
|
|
|
|
List<WhereClause> conditions = new ArrayList<WhereClause>();
|
|
|
|
Map<String, Object> searchInto = new HashMap<String, Object>();
|
|
|
|
searchInto.put("_theDocument.dataInizioProgetto", "2021");
|
|
|
|
WhereClause whereClause = new WhereClause(LOGICAL_OP.OR, searchInto);
|
|
|
|
|
|
|
|
conditions.add(whereClause);
|
|
|
|
filter.setConditions(conditions);
|
|
|
|
|
|
|
|
//NEED TO GET projections
|
|
|
|
|
|
|
|
//SETTING PROJECTION ONLY FOR PROEJCT ID
|
|
|
|
LinkedHashMap<String, Object> projectionForIDs = new LinkedHashMap<String, Object>();
|
|
|
|
projectionForIDs.put(Project.ID, 1);
|
|
|
|
filter.setProjection(projectionForIDs);
|
|
|
|
|
|
|
|
//LIMIT IS NULL MEANS THAT IT IS EQUAL TO NUMBER TOTAL OF DOCUMENTS
|
|
|
|
Integer totalDocs = clientProjects.getTotalDocument(PROFILE_ID);
|
|
|
|
Iterator<Project> projects = clientProjects.queryOnMongo(PROFILE_ID, totalDocs, 0, null, filter);
|
|
|
|
|
|
|
|
//CALCULATING SIZE OF THE ITERATOR OF PROJECT IDs
|
|
|
|
Iterable<Project> itP = () -> projects;
|
|
|
|
Stream<Project> targetStream = StreamSupport.stream(itP.spliterator(), false);
|
|
|
|
List<String> listProjectIDs = targetStream.map(Project::getId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
System.out.println("Total Ids are: "+listProjectIDs.size());
|
|
|
|
//listProjectIDs.stream().forEach(p -> System.out.println(p));
|
|
|
|
|
|
|
|
long end = System.currentTimeMillis();
|
|
|
|
System.out.println("IDS returned in ms: "+(end-start));
|
|
|
|
|
|
|
|
//RESETTIG FILTER AND PROJECT TO CLIENT QUERY
|
|
|
|
LinkedHashMap<String, Object> projection = new LinkedHashMap<String, Object>();
|
|
|
|
// default
|
|
|
|
//PROJECTION
|
|
|
|
projection.put(Project.ID, 1);
|
|
|
|
projection.put("_theDocument.nome", 1);
|
|
|
|
projection.put("_profileID", 1);
|
|
|
|
projection.put("_profileVersion", 1);
|
|
|
|
projection.put("_version", 1);
|
|
|
|
projection.put("_theDocument", 1);
|
|
|
|
|
|
|
|
projection.put("_theDocument.paroleChiaveLibere", 1);
|
|
|
|
projection.put("_theDocument.editore", 1);
|
|
|
|
projection.put("_theDocument.paroleChiaveICCD", 1);
|
|
|
|
projection.put("_theDocument.responsabile", 1);
|
|
|
|
|
|
|
|
projection.put("_theDocument.introduzione", 1);
|
|
|
|
projection.put("_theDocument.authors", 1);
|
|
|
|
projection.put("_theDocument.dataInizioProgetto", 1);
|
|
|
|
filter.setProjection(projection);
|
|
|
|
|
|
|
|
|
|
|
|
//Integer totalDocs = client.getTotalDocument(PROFILE_ID);
|
|
|
|
Iterator<Project> itProjects = clientProjects.queryOnMongo(PROFILE_ID, totalDocs, 0, 50, filter);
|
|
|
|
|
|
|
|
List<ResultDocumentDV> results = ConvertToDataValueObjectModel.toListResultDocument(itProjects);
|
|
|
|
int i = 0;
|
|
|
|
for (ResultDocumentDV projectDV : results) {
|
|
|
|
System.out.println(++i + ") " + projectDV.getId() + " dataInizioProgetto: "+projectDV.getDocumentAsMap().get("dataInizioProgetto"));
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("Result listed has size: "+results.size());
|
|
|
|
|
|
|
|
end = System.currentTimeMillis();
|
|
|
|
System.out.println("Result listed in ms: "+(end-start));
|
|
|
|
|
|
|
|
}
|
2022-11-16 16:42:12 +01:00
|
|
|
|
2022-10-13 16:53:33 +02:00
|
|
|
}
|