From 696031974c4c1221060dfdf084398cfe8eda4043 Mon Sep 17 00:00:00 2001 From: Fabio Sinibaldi Date: Mon, 7 Mar 2022 12:15:48 +0100 Subject: [PATCH] Provide example use case for insertion #22883 --- .../geoportal/clients/GenericUseCases.java | 55 +++++++++++++++++++ .../clients/ProfiledDocumentsTest.java | 2 - 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 geoportal-client/src/test/java/org/gcube/application/geoportal/clients/GenericUseCases.java diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/GenericUseCases.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/GenericUseCases.java new file mode 100644 index 0000000..002c846 --- /dev/null +++ b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/GenericUseCases.java @@ -0,0 +1,55 @@ +package org.gcube.application.geoportal.clients; + +import com.fasterxml.jackson.core.JsonProcessingException; +import org.bson.Document; +import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel; +import org.gcube.application.geoportal.client.DefaultProfiledDocumentsClient; +import org.gcube.application.geoportal.client.utils.Serialization; +import org.gcube.application.geoportal.common.model.document.Project; +import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest; +import org.gcube.application.geoportal.common.rest.Projects; +import org.gcube.application.geoportal.common.utils.FileSets; +import org.gcube.application.geoportal.common.utils.Files; +import org.gcube.application.geoportal.common.utils.StorageUtils; + +import java.io.File; +import java.io.FileNotFoundException; +import java.rmi.RemoteException; + +import static org.gcube.application.geoportal.client.GeoportalAbstractPlugin.profiledModel; + +public class GenericUseCases { + + public Projects getClient(String profileID){ + return profiledModel(profileID, Project.class, DefaultProfiledDocumentsClient.class).build(); + } + + public void createNew () throws RemoteException, FileNotFoundException, JsonProcessingException { + String profileID=null; + + String myJSON=null; + Document myDocument = Document.parse(myJSON); + + Projects client = getClient(profileID); + + // Create project + Project project = client.createNew(myDocument); + + + String parentPath = ""; + String fieldName = ""; + String fieldDefinition = ""; + + // Prepare request + RegisterFileSetRequest fsRequest = FileSets. + prepareRequest(new StorageUtils(), + parentPath,fieldName,fieldDefinition, new File(TestConcessioniModel.getBaseFolder(),"pos.shp")); + + + project = client.registerFileSet(project.getId(),fsRequest); + + System.out.println("Resulting Project : "+project); + System.out.println("JSON Reprepsentation : "+ Serialization.write(project)); + } + +} diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java index e2b65a2..bfc0b03 100644 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java +++ b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledDocumentsTest.java @@ -63,6 +63,4 @@ public class ProfiledDocumentsTest> exte } - - }