From f7101e98a40fdc638814f61fb864aa01f9c57155 Mon Sep 17 00:00:00 2001 From: Fabio Sinibaldi Date: Tue, 18 Oct 2022 18:00:44 +0200 Subject: [PATCH] Testing --- .../geoportal/clients/GenericUseCases.java | 27 +- .../clients/ProfiledConcessioniTest.java | 88 ++- .../basicConcessioneDocument.json | 65 ++ .../profiles/Concessioni.json | 561 +++++++++++------- 4 files changed, 497 insertions(+), 244 deletions(-) create mode 100644 test-data/profiledDocuments/basicConcessioneDocument.json 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 index 7e0a779..0a23f67 100644 --- 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 @@ -34,17 +34,24 @@ public abstract class GenericUseCases extends BasicVreTests{ @Test public void createNew () throws RemoteException, FileNotFoundException, JsonProcessingException, InvalidRequestException { - String profileID=getUCID(); - - Document myDocument= new Document(); - myDocument.put("section",new Document("title","myTitle")); - - Projects client = getClient(profileID); + Projects client = getClient(); // Create project - Project project = client.createNew(myDocument); + Project project = client.createNew(getNewDocument()); + project = prepareWithFileSet(project); + System.out.println("Resulting Project : "+project); + System.out.println("JSON Reprepsentation : "+ Serialization.write(project)); + } + + protected Document getNewDocument(){ + Document myDocument= new Document(); + myDocument.put("section",new Document("title","myTitle")); + return myDocument; + } + + protected Project prepareWithFileSet(Project project) throws FileNotFoundException, InvalidRequestException, RemoteException { String parentPath = "$.section"; String fieldName = "fileset"; String fieldDefinition = "$.section._children[?(@.fileset)]"; @@ -55,10 +62,6 @@ public abstract class GenericUseCases extends BasicVreTests{ parentPath,fieldName,fieldDefinition, new File(Tests.FOLDER_CONCESSIONI,"pos.shp")); - project = client.registerFileSet(project.getId(),fsRequest); - - System.out.println("Resulting Project : "+project); - System.out.println("JSON Reprepsentation : "+ Serialization.write(project)); + return getClient().registerFileSet(project.getId(),fsRequest); } - } diff --git a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledConcessioniTest.java b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledConcessioniTest.java index 61ed417..8af8aae 100644 --- a/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledConcessioniTest.java +++ b/geoportal-client/src/test/java/org/gcube/application/geoportal/clients/ProfiledConcessioniTest.java @@ -3,13 +3,26 @@ 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{ @@ -36,12 +49,81 @@ public class ProfiledConcessioniTest extends ProfiledDocumentsTest{ } @Test - public void performSubmit() throws RemoteException, JsonProcessingException { - String id="630f912755e2947b0278c1be"; + public void performSubmit() throws RemoteException, JsonProcessingException, FileNotFoundException, InvalidRequestException { - Project p = getClient().performStep(id,new StepExecutionRequest("SUBMIT-FOR-REVIEW",new Document())); + 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()); + } } diff --git a/test-data/profiledDocuments/basicConcessioneDocument.json b/test-data/profiledDocuments/basicConcessioneDocument.json new file mode 100644 index 0000000..c405641 --- /dev/null +++ b/test-data/profiledDocuments/basicConcessioneDocument.json @@ -0,0 +1,65 @@ +{ + "nome": "TEST Castello di Ceparano", + "introduzione": "Scavi archeologici nel castello di Ceparano, situato su una collina posta ai margini della vallata del Marzeno, nel territorio del comune di Brisighella, conosciuto dalla metà del X secolo e abbandonato nel XVI secolo. Il progetto ha l’obiettivo di definire se si tratti di un sito di nuova fondazione o se si tratta di un sito rurale altomedievale, trasformato in villaggio fortificato in un periodo successivo. Si intende inoltre chiarire la sua reale di estensione e funzione nel corso del tempo e verificare la presenza di strutture/insediamenti età precedente. ", + "descrizioneContenuto": "Relazione di fine scavo e relativo abstract; selezione di immagini rappresentative; posizionamento topografico dell'area indagata, pianta di fine scavo.", + "authors": [ + "Enrico Cirelli (Disci, Alma Mater Studiorum - Università di Bologna)" + ], + "contributore": "Enrico Cirelli", + "titolari": [ + "Enrico Cirelli" + ], + "responsabile": "Enrico Cirelli", + "editore": "Enrico Cirelli", + "fontiFinanziamento": [ + "Alma Mater Studiorum - Università di Bologna" + ], + "soggetto": [ + "Research Excavation" + ], + "risorseCorrelate": [ + "E. Cirelli, Scavi archeologici nel castello di Ceparano, in 'Cristalli', 1-2019, pp. 20-29. https://www.academia.edu/36107675/SCAVI_NEL_CASTELLO_DI_CEPARANO" + ], + "dataInizioProgetto": "2019-07-29T00:00:00", + "dataFineProgetto": "2019-08-30T00:00:00", + "titolareLicenza": [ + "Enrico Cirelli" + ], + "titolareCopyright": [ + "Enrico Cirelli" + ], + "paroleChiaveLibere": [ + "Castello", + "Chiesa castrale", + "Pieve", + "Ossario", + "Sepolture" + ], + "paroleChiaveICCD": [ + "VI-VII", + "X-XVI" + ], + "relazioneScavo": { + "titolo": "Castello di Ceparano relazione di scavo", + "responsabili": [ + "Enrico Cirelli" + ], + "soggetto": [ + "Research Excavation" + ] + }, + "abstractRelazione": { + "titolo": "Castello di Ceparano abstract relazione di scavo" + }, + "posizionamentoScavo": { + "titolo": "Posizionamento scavo" + }, + "pianteFineScavo": [ + {"titolo": "Pianta 1"}, + {"titolo": "Pianta 2"} + ], + "immaginiRappresentative": [ + {"titolo": "Img 1"}, + {"titolo": "Img 2"} + ] +} \ No newline at end of file diff --git a/test-data/profiledDocuments/profiles/Concessioni.json b/test-data/profiledDocuments/profiles/Concessioni.json index 7b7c232..9d2931f 100644 --- a/test-data/profiledDocuments/profiles/Concessioni.json +++ b/test-data/profiledDocuments/profiles/Concessioni.json @@ -1,100 +1,207 @@ { - "_id" : "profiledConcessioni", - "_version" : "1.0.0", - "_name" : "Concessione", - - "_schema" : { - "abstractRelazione" : { "_min" : 1, - "_children" : [ - {"filesetIta" :{"_type" : "RegisteredFileSet", "_min": 1}}, - {"filesetEng" :{"_type" : "RegisteredFileSet"}}, - {"title" : {"_min" : 1}} + "_id": "profiledConcessioni", + "_version": "1.0.0", + "_name": "Concessione", + "_schema": { + "abstractRelazione": { + "_min": 1, + "_children": [ + { + "filesetIta": { + "_type": "RegisteredFileSet", + "_min": 1 + } + }, + { + "filesetEng": { + "_type": "RegisteredFileSet" + } + }, + { + "title": { + "_min": 1 + } + } ] }, - "relazioneScavo" : { "_max" : 1, "_min" : 1, - "_children" : [ - {"fileset" :{"_type" : "RegisteredFileSet", "_min": 1}}, - {"title" : {"_min" : 1}} + "relazioneScavo": { + "_max": 1, + "_min": 1, + "_children": [ + { + "fileset": { + "_type": "RegisteredFileSet", + "_min": 1 + } + }, + { + "title": { + "_min": 1 + } + } ] }, - "immaginiRappresentative" : { - "_max" : 8, - "_children" : [ - {"fileset" :{"_type" : "RegisteredFileSet","_min": 1}}, - {"title" : {"_min" : 1}} + "immaginiRappresentative": { + "_max": 8, + "_children": [ + { + "fileset": { + "_type": "RegisteredFileSet", + "_min": 1 + } + }, + { + "title": { + "_min": 1 + } + } ] }, - "posizionamentoScavo" : { "_max" : 1, "_min" : 1, - "_children" : [ - {"fileset" :{"_type" : "RegisteredFileSet","_min": 1}}, - {"title" : {"_min" : 1}} + "posizionamentoScavo": { + "_max": 1, + "_min": 1, + "_children": [ + { + "fileset": { + "_type": "RegisteredFileSet", + "_min": 1 + } + }, + { + "title": { + "_min": 1 + } + } ] }, - "pianteFineScavo" : { "_max" : -1, - "_children" : [ - {"fileset" :{"_type" : "RegisteredFileSet","_min": 1}}, - {"title" : {"_min" : 1}} + "pianteFineScavo": { + "_max": -1, + "_children": [ + { + "fileset": { + "_type": "RegisteredFileSet", + "_min": 1 + } + }, + { + "title": { + "_min": 1 + } + } ] } }, - - - "_description" : "Embedded profile for concessioni [mibac] management", + "_description": "Embedded profile for concessioni [mibac] management", "_creationInfo": { - "_user" : { + "_user": { "_username": "fabio.sinibaldi" } }, - - "_dataAccessPolicies" : [ - {"_policy" : {"_read" : "any", "_write" : "any"}, "_roles":[]}, - {"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Guest"], - "_enforcer": {"_filter" : "{\"_lifecycleInformation._phase\" : {\"$eq\" : \"Published\"}}"}}, - {"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Admin"]}, - {"_policy" : {"_read" : "any", "_write" : "any"}, "_roles":["Data-Manager"]} + "_dataAccessPolicies": [ + { + "_policy": { + "_read": "any", + "_write": "any" + }, + "_roles": [] + }, + { + "_policy": { + "_read": "any", + "_write": "none" + }, + "_roles": [ + "Guest" + ], + "_enforcer": { + "_filter": "{\"_lifecycleInformation._phase\" : {\"$eq\" : \"Published\"}}" + } + }, + { + "_policy": { + "_read": "any", + "_write": "none" + }, + "_roles": [ + "Admin" + ] + }, + { + "_policy": { + "_read": "any", + "_write": "any" + }, + "_roles": [ + "Data-Manager" + ] + } ], - - "_handlers" : [ + "_handlers": [ { - "_id" : "GNA-CONCESSIONI-LC", - "_type" : "LifecycleManagement", - "_configuration" : { - "step_access" : [ - {"STEP" : "SUBMIT-FOR-REVIEW", "roles" :[]}, - {"STEP" : "REJECT-DRAFT", "roles" :["Data-Manager"]}, - {"STEP" : "APPROVE-SUBMITTED", "roles" :["Data-Manager"]} + "_id": "GNA-CONCESSIONI-LC", + "_type": "LifecycleManagement", + "_configuration": { + "step_access": [ + { + "STEP": "SUBMIT-FOR-REVIEW", + "roles": [] + }, + { + "STEP": "REJECT-DRAFT", + "roles": [ + "Data-Manager" + ] + }, + { + "STEP": "APPROVE-SUBMITTED", + "roles": [ + "Data-Manager" + ] + } ] } }, - { - "_id" : "SDI-Default-Materializer", - "_type" : "Materializer", - "_configuration" : { - "registeredFileSetPaths" : [ - {"schemaField" : "pianteFineScavo","documentPath" : "pianteFineScavo[*].fileset"}, - {"schemaField" : "posizionamentoScavo","documentPath" : "posizionamentoScavo.fileset"} + "_id": "SDI-Default-Materializer", + "_type": "Materializer", + "_configuration": { + "registeredFileSetPaths": [ + { + "schemaField": "pianteFineScavo", + "documentPath": "pianteFineScavo[*].fileset" + }, + { + "schemaField": "posizionamentoScavo", + "documentPath": "posizionamentoScavo.fileset" + } ] } }, - - - { - "_id" : "SDI-Indexer-Plugin", - "_type" : "Indexer", - "_configuration" : { - "bboxEvaluation" : ["$..posizionamentoScavo.._bbox"], - "explicitFieldMapping" : [ - {"name" : "titolo", "path" : "$._theDocument.title", "type" : "TEXT"} + "_id": "SDI-Indexer-Plugin", + "_type": "Indexer", + "_configuration": { + "bboxEvaluation": [ + "$..posizionamentoScavo.._bbox" ], - "jslt" : {}, - "additionalLayers" : [ - {"source" : {"url" : "..."},"toSetTitle":""} + "explicitFieldMapping": [ + { + "name": "titolo", + "path": "$._theDocument.title", + "type": "TEXT" + } + ], + "jslt": {}, + "additionalLayers": [ + { + "source": { + "url": "..." + }, + "toSetTitle": "" + } ] } }, - { "_id": "org.gcube.portlets.user.geoportal-data-entry-app", "_type": "DATA_ENTRY_GUI", @@ -190,168 +297,164 @@ "saveStep": "SUBMIT-FOR-REVIEW" } }, - - { - "_id": "org.gcube.portlets.user.geoportal-data-list", - "_type": "DATA_LIST_GUI", - "_configuration": { - "itemFields": [ - { - "label": "Name", - "paths": [ - "_theDocument.nome" - ], - "operator": "$and", - "searchable": true, - "sortable": true, - "asResult": true - }, - { - "label": "Introduction", - "paths": [ - "_theDocument.introduzione" - ], - "operator": "$and", - "searchable": true, - "sortable": false, - "asResult": true - }, - { - "label": "Author/s", - "paths": [ - "_theDocument.authors" - ], - "operator": "$and", - "searchable": false, - "sortable": true, - "asResult": true - }, - { - "label": "Project Start", - "paths": [ - "_theDocument.dataInizioProgetto" - ], - "operator": "$and", - "searchable": false, - "sortable": true, - "asResult": true - }, - { - "label": "Director/Staff", - "paths": [ - "_theDocument.authors", - "_theDocument.contributore", - "_theDocument.titolari", - "_theDocument.editore", - "_theDocument.responsabile" - ], - "operator": "$or", - "searchable": true, - "sortable": false, - "asResult": true - }, - { - "label": "Keywords", - "paths": [ - "_theDocument.paroleChiaveLibere", - "_theDocument.paroleChiaveICCD" - ], - "operator": "$or", - "searchable": true, - "sortable": false, - "asResult": true - }, - { - "label": "Creator", - "paths": [ - "_info._creationInfo._user._username" - ], - "operator": "$or", - "searchable": true, - "sortable": false, - "asResult": false - }, - { - "label": "Phase", - "paths": [ - "_lifecycleInformation._phase" - ], - "operator": "$or", - "searchable": true, - "sortable": true, - "asResult": false - }, - { - "label": "Status", - "paths": [ - "_lifecycleInformation._lastOperationStatus" - ], - "operator": "$or", - "searchable": true, - "sortable": true, - "asResult": false - } - ], - "actionsDefinition": [ - { - "id": "submit_for_review", - "title": "Submit for Review", - "call_STEPS": [ - "SUBMIT-FOR-REVIEW" - ], - "description": "Submit the Project (for review)", - "display_on_phase": [ - "REJECTED", - "DRAFT" - ] - }, - { - "id": "reject", - "title": "Reject", - "call_STEPS": [ - "REJECT-DRAFT" - ], - "description": "Reject the Project", - "display_on_phase": [ - "DRAFT" - ] - }, - { - "id": "approve", - "title": "Approve", - "call_STEPS": [ - "APPROVE-SUBMITTED" - ], - "description": "Approve the Project", - "display_on_phase": [ - "DRAFT" - ] - }, - { - "id": "publish", - "title": "Publish", - "call_STEPS": [ - "PUBLISH" - ], - "description": "Publish the Project", - "display_on_phase": [ - "DRAFT", - "APPROVED" - ] - }, - { - "id": "unpublish", - "title": "Unpublish", - "call_STEPS": [ - "UNPUBLISH" - ], - "description": "Unpublish the Project", - "display_on_phase": [ - "PUBLISHED" + { + "_id": "org.gcube.portlets.user.geoportal-data-list", + "_type": "DATA_LIST_GUI", + "_configuration": { + "itemFields": [ + { + "label": "Name", + "paths": [ + "_theDocument.nome" + ], + "operator": "$and", + "searchable": true, + "sortable": true, + "asResult": true + }, + { + "label": "Introduction", + "paths": [ + "_theDocument.introduzione" + ], + "operator": "$and", + "searchable": true, + "sortable": false, + "asResult": true + }, + { + "label": "Author/s", + "paths": [ + "_theDocument.authors" + ], + "operator": "$and", + "searchable": false, + "sortable": true, + "asResult": true + }, + { + "label": "Project Start", + "paths": [ + "_theDocument.dataInizioProgetto" + ], + "operator": "$and", + "searchable": false, + "sortable": true, + "asResult": true + }, + { + "label": "Director/Staff", + "paths": [ + "_theDocument.authors", + "_theDocument.contributore", + "_theDocument.titolari", + "_theDocument.editore", + "_theDocument.responsabile" + ], + "operator": "$or", + "searchable": true, + "sortable": false, + "asResult": true + }, + { + "label": "Keywords", + "paths": [ + "_theDocument.paroleChiaveLibere", + "_theDocument.paroleChiaveICCD" + ], + "operator": "$or", + "searchable": true, + "sortable": false, + "asResult": true + }, + { + "label": "Creator", + "paths": [ + "_info._creationInfo._user._username" + ], + "operator": "$or", + "searchable": true, + "sortable": false, + "asResult": false + }, + { + "label": "Phase", + "paths": [ + "_lifecycleInformation._phase" + ], + "operator": "$or", + "searchable": true, + "sortable": true, + "asResult": false + }, + { + "label": "Status", + "paths": [ + "_lifecycleInformation._lastOperationStatus" + ], + "operator": "$or", + "searchable": true, + "sortable": true, + "asResult": false + } ] } - ] - } -} + }, + { + "_id": "org.gcube.portlets.user.geoportal-workflow-action-list", + "_type": "WORKFLOW_ACTION_LIST_GUI", + "_configuration": { + "actionsDefinition": [ + { + "id": "post_creation_action", + "title": "Post Creation Action", + "call_STEPS": [ + "SUBMIT-FOR-REVIEW" + ], + "description": "Action fired after the Project creation", + "display_on_phase": [] + }, + { + "id": "submit_for_review", + "title": "Submit for Review", + "call_STEPS": [ + "SUBMIT-FOR-REVIEW" + ], + "description": "Submit the Project (for review)", + "display_on_phase": [ + "DRAFT" + ] + }, + { + "id": "reject", + "title": "Reject", + "call_STEPS": [ + "REJECT-DRAFT" + ], + "description": "Reject the Project", + "display_on_phase": [ + "Pending Approval" + ] + }, + { + "id": "approve", + "title": "Approve", + "call_STEPS": [ + "APPROVE-SUBMITTED" + ], + "description": "Approve the Project", + "display_on_phase": [ + "Pending Approval" + ] + } + ] + } + } + ], + "_relationshipDefinitions" : [ + {"_id": "precedes", "_label" : "Precede", + "_reverseRelationId" : "follows"}, + {"_id": "follows", "_label" : "Segue", + "_reverseRelationId" : "precedes"} ] -} \ No newline at end of file +}