108 lines
3.8 KiB
Java
108 lines
3.8 KiB
Java
package org.gcube.portlets.user.geoportaldataviewer;
|
|
|
|
import java.util.List;
|
|
|
|
import org.gcube.application.geoportal.common.model.document.Project;
|
|
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;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDIViewerLayerDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.project.ProjectDV;
|
|
import org.gcube.application.geoportalcommon.shared.geoportal.view.ProjectView;
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
import org.gcube.portlets.user.geoportaldataviewer.server.Geoportal_JSON_Mapper;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
/**
|
|
* 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";
|
|
private static String TOKEN = "c41a00c0-7897-48d2-a67a-05190d6ce5e6-98187548"; // devVRE
|
|
|
|
private static String PROFILE_ID = "profiledConcessioni";
|
|
private static String PROJECT_ID = "6311d408900dde90e44d9265";
|
|
|
|
private static String USERNAME = "francesco.mangiacrapa";
|
|
|
|
/**
|
|
* Gets the client.
|
|
*
|
|
* @return the client
|
|
*/
|
|
@Before
|
|
public void getClient() {
|
|
// assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
clientUCD = GeoportalClientCaller.useCaseDescriptors();
|
|
clientProjects = GeoportalClientCaller.projects();
|
|
}
|
|
|
|
//@Test
|
|
public void getProjectViewForID() {
|
|
|
|
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);
|
|
|
|
ScopeProvider.instance.set(CONTEXT);
|
|
SecurityTokenProvider.instance.set(TOKEN);
|
|
ProjectView projectView = Geoportal_JSON_Mapper.loadProjectView(projectDV, CONTEXT, USERNAME);
|
|
Geoportal_JSON_Mapper.prettyPrintProjectView(projectView);
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
@Test
|
|
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);
|
|
|
|
listLayers = Geoportal_JSON_Mapper.readGcubeSDILayersForFileset(materializationParentJSONPath, jsonDocument);
|
|
|
|
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();
|
|
}
|
|
|
|
}
|
|
|
|
}
|