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-10-18 14:17:41 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
|
|
|
// private static String CONTEXT = "/pred4s/preprod/preVRE";
|
|
|
|
// private static String TOKEN = ""; //preVRE
|
|
|
|
|
|
|
|
private static String CONTEXT = "/gcube/devsec/devVRE";
|
2022-11-08 12:15:11 +01:00
|
|
|
private static String TOKEN = ""; // devVRE
|
2022-10-13 16:53:33 +02:00
|
|
|
|
|
|
|
private static String PROFILE_ID = "profiledConcessioni";
|
2022-11-16 16:42:12 +01:00
|
|
|
private static String PROJECT_ID = "6372470aa7b910781daaa8bc";
|
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-08 12:15:11 +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-16 16:42:12 +01:00
|
|
|
// @Test
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
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-10-13 16:53:33 +02:00
|
|
|
}
|