2022-03-07 12:15:48 +01:00
|
|
|
package org.gcube.application.geoportal.clients;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
import org.bson.Document;
|
2022-09-26 16:17:37 +02:00
|
|
|
import org.gcube.application.cms.tests.Tests;
|
2022-03-07 12:15:48 +01:00
|
|
|
import org.gcube.application.geoportal.client.utils.Serialization;
|
2022-05-17 11:02:49 +02:00
|
|
|
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
|
2022-03-07 12:15:48 +01:00
|
|
|
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.StorageUtils;
|
2022-05-10 18:06:39 +02:00
|
|
|
import org.junit.Test;
|
2022-03-07 12:15:48 +01:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.rmi.RemoteException;
|
|
|
|
|
2022-03-07 13:59:24 +01:00
|
|
|
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.projects;
|
2022-03-07 12:15:48 +01:00
|
|
|
|
2022-04-22 11:04:25 +02:00
|
|
|
public abstract class GenericUseCases extends BasicVreTests{
|
2022-03-07 12:15:48 +01:00
|
|
|
|
2022-04-22 11:04:25 +02:00
|
|
|
protected String getUCID(){ return "basic";}
|
|
|
|
|
|
|
|
protected Projects<Project> getClient(String profileID){
|
2022-03-07 12:29:40 +01:00
|
|
|
return projects(profileID).build();
|
2022-03-07 12:15:48 +01:00
|
|
|
}
|
|
|
|
|
2022-04-22 11:04:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
protected Projects<Project> getClient(){
|
|
|
|
return getClient(getUCID());
|
|
|
|
}
|
|
|
|
|
2022-05-10 18:06:39 +02:00
|
|
|
@Test
|
2022-05-17 11:02:49 +02:00
|
|
|
public void createNew () throws RemoteException, FileNotFoundException, JsonProcessingException, InvalidRequestException {
|
2022-10-18 18:00:44 +02:00
|
|
|
Projects<Project> client = getClient();
|
2022-03-07 12:15:48 +01:00
|
|
|
|
2022-10-18 18:00:44 +02:00
|
|
|
// Create project
|
|
|
|
Project project = client.createNew(getNewDocument());
|
2022-03-07 12:15:48 +01:00
|
|
|
|
2022-10-18 18:00:44 +02:00
|
|
|
project = prepareWithFileSet(project);
|
2022-03-07 12:15:48 +01:00
|
|
|
|
2022-10-18 18:00:44 +02:00
|
|
|
System.out.println("Resulting Project : "+project);
|
|
|
|
System.out.println("JSON Reprepsentation : "+ Serialization.write(project));
|
|
|
|
}
|
2022-03-07 12:15:48 +01:00
|
|
|
|
2022-10-18 18:00:44 +02:00
|
|
|
protected Document getNewDocument(){
|
|
|
|
Document myDocument= new Document();
|
|
|
|
myDocument.put("section",new Document("title","myTitle"));
|
|
|
|
return myDocument;
|
|
|
|
}
|
2022-03-07 12:15:48 +01:00
|
|
|
|
2022-10-18 18:00:44 +02:00
|
|
|
protected Project prepareWithFileSet(Project project) throws FileNotFoundException, InvalidRequestException, RemoteException {
|
2023-01-10 11:42:09 +01:00
|
|
|
|
|
|
|
return getClient().registerFileSet(project.getId(), prepareRequest());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected RegisterFileSetRequest prepareRequest() throws FileNotFoundException {
|
2022-05-11 15:57:53 +02:00
|
|
|
String parentPath = "$.section";
|
|
|
|
String fieldName = "fileset";
|
|
|
|
String fieldDefinition = "$.section._children[?(@.fileset)]";
|
2022-03-07 12:15:48 +01:00
|
|
|
|
|
|
|
// Prepare request
|
2023-01-10 11:42:09 +01:00
|
|
|
return FileSets.
|
2022-03-07 12:15:48 +01:00
|
|
|
prepareRequest(new StorageUtils(),
|
2022-09-29 16:33:11 +02:00
|
|
|
parentPath,fieldName,fieldDefinition, new File(Tests.FOLDER_CONCESSIONI,"pos.shp"));
|
2022-03-07 12:15:48 +01:00
|
|
|
}
|
2023-01-10 11:42:09 +01:00
|
|
|
|
2022-03-07 12:15:48 +01:00
|
|
|
}
|