package org.gcube.application.geoportal.clients; import com.fasterxml.jackson.core.JsonProcessingException; import lombok.Data; import org.bson.Document; import org.gcube.application.cms.tests.TestDocuments; import org.gcube.application.cms.tests.Tests; import org.gcube.application.geoportal.client.utils.Serialization; import org.gcube.application.geoportal.common.faults.InvalidRequestException; import org.gcube.application.geoportal.common.model.document.Project; import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest; import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest; import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field; import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; 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 org.junit.Test; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.nio.charset.Charset; import java.rmi.RemoteException; public class ProfiledConcessioniTest extends ProfiledDocumentsTest{ @Data private static class MyClass { private String field; } @Override protected String getUCID() { return "profiledConcessioni"; } public void test(){ UseCaseDescriptor p=null; HandlerDeclaration h = p.getHandlersMapByID().get("MyID").get(0); Document doc = h.getConfiguration(); System.out.println(Serialization.convert(doc, MyClass.class)); } @Test public void performSubmit() throws RemoteException, JsonProcessingException, FileNotFoundException, InvalidRequestException { Projects client = getClient(); Project p=client.createNew(getNewDocument()); p=prepareWithFileSet(p); p = getClient().performStep(p.getId(), new StepExecutionRequest("SUBMIT-FOR-REVIEW",new Document())); System.out.println("Result is "+Serialization.write(p)); } @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 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()); } }