Provide example use case for insertion #22883

This commit is contained in:
Fabio Sinibaldi 2022-03-07 12:15:48 +01:00
parent 9a8705183a
commit 696031974c
2 changed files with 55 additions and 2 deletions

View File

@ -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<Project> 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<Project> 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));
}
}

View File

@ -63,6 +63,4 @@ public class ProfiledDocumentsTest<M extends Project,C extends Projects<M>> exte
}
}