gcube-cms-suite/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledConcessioniTest.java

130 lines
4.8 KiB
Java
Raw Normal View History

2022-03-04 11:29:14 +01:00
package org.gcube.application.geoportal.clients;
2022-09-14 11:27:45 +02:00
import com.fasterxml.jackson.core.JsonProcessingException;
2022-03-04 11:29:14 +01:00
import lombok.Data;
import org.bson.Document;
2022-10-18 18:00:44 +02:00
import org.gcube.application.cms.tests.TestDocuments;
import org.gcube.application.cms.tests.Tests;
2022-03-16 12:11:05 +01:00
import org.gcube.application.geoportal.client.utils.Serialization;
2022-10-18 18:00:44 +02:00
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
2022-09-14 11:27:45 +02:00
import org.gcube.application.geoportal.common.model.document.Project;
2022-10-18 18:00:44 +02:00
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
2022-09-14 11:27:45 +02:00
import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest;
2022-10-18 18:00:44 +02:00
import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field;
2022-03-04 14:23:20 +01:00
import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
2022-10-18 18:00:44 +02:00
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;
2022-09-14 11:27:45 +02:00
import org.junit.Test;
2022-03-04 11:29:14 +01:00
2022-10-18 18:00:44 +02:00
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;
2022-09-14 11:27:45 +02:00
import java.rmi.RemoteException;
public class ProfiledConcessioniTest extends ProfiledDocumentsTest{
2022-03-04 11:29:14 +01:00
@Data
private static class MyClass {
private String field;
}
2022-09-14 11:27:45 +02:00
@Override
protected String getUCID() {
return "profiledConcessioni";
}
2022-03-04 11:29:14 +01:00
public void test(){
2022-03-04 14:23:20 +01:00
UseCaseDescriptor p=null;
2022-03-04 11:29:14 +01:00
HandlerDeclaration h = p.getHandlersMapByID().get("MyID").get(0);
Document doc = h.getConfiguration();
System.out.println(Serialization.convert(doc, MyClass.class));
}
2022-09-14 11:27:45 +02:00
@Test
2022-10-18 18:00:44 +02:00
public void performSubmit() throws RemoteException, JsonProcessingException, FileNotFoundException, InvalidRequestException {
2022-09-14 11:27:45 +02:00
2022-10-18 18:00:44 +02:00
Projects<Project> client = getClient();
Project p=client.createNew(getNewDocument());
p=prepareWithFileSet(p);
p = getClient().performStep(p.getId(), new StepExecutionRequest("SUBMIT-FOR-REVIEW",new Document()));
2022-09-14 11:27:45 +02:00
System.out.println("Result is "+Serialization.write(p));
}
2022-10-18 18:00:44 +02:00
@Override
protected Document getNewDocument() {
try {
String json = Files.readFileAsString(TestDocuments.BASE_FOLDER + "/basicConcessioneDocument.json", Charset.defaultCharset());
return Document.parse(json);
}catch (Throwable t){
throw new RuntimeException(t);
}
}
@Override
protected Project prepareWithFileSet(Project project) throws FileNotFoundException, InvalidRequestException, RemoteException {
Projects<Project> client = getClient();
// Set relazione
client.registerFileSet(project.getId(), FileSets.
prepareRequest(new StorageUtils(),
"$.relazioneScavo","fileset",
"$.relazioneScavo."+Field.CHILDREN+"[?(@.fileset)]",
new File(Tests.FOLDER_CONCESSIONI,"relazione.pdf")));
// Set Abstract
client.registerFileSet(project.getId(), FileSets.
prepareRequest(new StorageUtils(),
"$.abstractRelazione","filesetIta",
"$.abstractRelazione."+Field.CHILDREN+"[?(@.filesetIta)]",
new File(Tests.FOLDER_CONCESSIONI,"relazione.pdf")));
// Set pos
client.registerFileSet(project.getId(), FileSets.
prepareRequest(new StorageUtils(),
"$.posizionamentoScavo","fileset",
"$.posizionamentoScavo."+Field.CHILDREN+"[?(@.fileset)]",
new File(Tests.FOLDER_CONCESSIONI,"pos.shp"),
new File(Tests.FOLDER_CONCESSIONI,"pos.shx")));
// Add 2 imgs
for(int i=0;i<2;i++){
client.registerFileSet(project.getId(), FileSets.
prepareRequest(new StorageUtils(),
"$.immaginiRappresentative["+i+"]","fileset",
"$.immaginiRappresentative."+Field.CHILDREN+"[?(@.fileset)]",
new File(Tests.FOLDER_CONCESSIONI,"immagine"+(i+1)+".png")));
}
// Add 2 piante
for(int i=0;i<2;i++){
client.registerFileSet(project.getId(), FileSets.
prepareRequest(new StorageUtils(),
"$.pianteFineScavo["+i+"]","fileset",
"$.pianteFineScavo."+Field.CHILDREN+"[?(@.fileset)]",
new File(Tests.FOLDER_CONCESSIONI,"pianta.shp"),
new File(Tests.FOLDER_CONCESSIONI,"pianta.shx")));
}
return client.getById(project.getId());
}
2022-03-04 11:29:14 +01:00
}