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;
|
2023-01-18 17:43:44 +01:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2022-03-04 11:29:14 +01:00
|
|
|
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;
|
2023-01-18 17:43:44 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
|
2022-09-14 11:27:45 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.document.Project;
|
2023-01-18 17:43:44 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.document.access.Access;
|
|
|
|
import org.gcube.application.geoportal.common.model.document.access.AccessPolicy;
|
|
|
|
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
|
|
|
|
import org.gcube.application.geoportal.common.model.document.relationships.RelationshipNavigationObject;
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.CreateRelationshipRequest;
|
|
|
|
import org.gcube.application.geoportal.common.model.rest.DeleteRelationshipRequest;
|
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;
|
2023-01-18 17:43:44 +01:00
|
|
|
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
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;
|
2023-01-18 17:43:44 +01:00
|
|
|
import java.util.Iterator;
|
2022-09-14 11:27:45 +02:00
|
|
|
|
2023-01-18 17:43:44 +01:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import static org.junit.Assume.assumeTrue;
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
public class ProfiledConcessioniTest <M extends Project,C extends Projects<M>> extends GenericUseCases{
|
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
|
|
|
|
|
2023-01-18 17:43:44 +01:00
|
|
|
|
|
|
|
Access toSetAccess = new Access();
|
|
|
|
toSetAccess.setPolicy(AccessPolicy.RESTRICTED);
|
|
|
|
toSetAccess.setLicense("CC0-1.0");
|
|
|
|
|
|
|
|
RegisterFileSetRequest request=FileSets.
|
2022-10-18 18:00:44 +02:00
|
|
|
prepareRequest(new StorageUtils(),
|
|
|
|
"$.relazioneScavo","fileset",
|
|
|
|
"$.relazioneScavo."+Field.CHILDREN+"[?(@.fileset)]",
|
2023-01-18 17:43:44 +01:00
|
|
|
new File(Tests.FOLDER_CONCESSIONI,"relazione.pdf"));
|
|
|
|
request.setToSetAccess(toSetAccess);
|
|
|
|
|
|
|
|
project=client.registerFileSet(project.getId(), request);
|
|
|
|
|
|
|
|
String jsonDoc=project.getTheDocument().toJson();
|
|
|
|
log.info("Registered fileset. Result is {}", jsonDoc);
|
|
|
|
RegisteredFileSet f= Serialization.convert(new JSONPathWrapper(jsonDoc).getByPath(
|
|
|
|
request.getParentPath()+"."+request.getFieldName()).get(0),RegisteredFileSet.class);
|
|
|
|
|
|
|
|
assertEquals(Serialization.convert(f.getAccess(),Access.class).getPolicy(),toSetAccess.getPolicy());
|
|
|
|
assertEquals(Serialization.convert(f.getAccess(),Access.class).getLicense(),toSetAccess.getLicense());
|
|
|
|
|
2022-10-18 18:00:44 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2023-01-24 17:36:42 +01:00
|
|
|
RegisterFileSetRequest req = FileSets.
|
2022-10-18 18:00:44 +02:00
|
|
|
prepareRequest(new StorageUtils(),
|
|
|
|
"$.posizionamentoScavo","fileset",
|
|
|
|
"$.posizionamentoScavo."+Field.CHILDREN+"[?(@.fileset)]",
|
2023-01-24 17:36:42 +01:00
|
|
|
new File(Tests.FOLDER_CONCESSIONI,"pos.shx"),
|
|
|
|
new File(Tests.FOLDER_CONCESSIONI,"pos.shp"));
|
|
|
|
|
|
|
|
String toTestStrangeName = "e. gna_topografia_timponedellamotta";
|
|
|
|
//String toTestStrangeName = "1. my: Strange name *pos";
|
|
|
|
|
|
|
|
req.getStreams().forEach(t ->t.setFilename(t.getFilename().replace("pos",toTestStrangeName)));
|
|
|
|
|
|
|
|
client.registerFileSet(project.getId(), req);
|
2022-10-18 18:00:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
}
|
2023-01-18 17:43:44 +01:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testRelationships() throws Exception{
|
|
|
|
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
|
|
|
Projects<M> client = (Projects<M>) getClient();
|
|
|
|
Project source = client.createNew(new Document().append("field","value"));
|
|
|
|
Project target = client.createNew(new Document().append("field2","value"));
|
|
|
|
|
|
|
|
String relId="follows";
|
|
|
|
|
|
|
|
|
|
|
|
Project linkedSource = client.setRelation(
|
|
|
|
new CreateRelationshipRequest(source.getId(),relId,
|
|
|
|
target.getId(), null));
|
|
|
|
|
|
|
|
assertTrue(linkedSource.getRelationships()!=null);
|
|
|
|
assertTrue(!linkedSource.getRelationships().isEmpty());
|
|
|
|
assertTrue(linkedSource.getRelationships().get(0).getRelationshipName().equals(relId));
|
|
|
|
assertTrue(linkedSource.getRelationships().get(0).getTargetID().equals(target.getId()));
|
|
|
|
assertTrue(linkedSource.getRelationships().get(0).getTargetUCD().equals(target.getProfileID()));
|
|
|
|
|
|
|
|
Iterator<RelationshipNavigationObject> it = client.getRelationshipChain(source.getId(),relId,true);
|
|
|
|
System.out.println("Scanning rel ..");
|
|
|
|
it.forEachRemaining(r -> {
|
|
|
|
System.out.println(r.getTarget().getId());
|
|
|
|
System.out.println("Children size : "+r.getChildren().size());
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
Project unLinkedSource = client.deleteRelation(
|
|
|
|
new DeleteRelationshipRequest(source.getId(),relId,
|
|
|
|
target.getId(),null));
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(unLinkedSource.getRelationships()==null || unLinkedSource.getRelationships().isEmpty());
|
|
|
|
|
|
|
|
}
|
2022-03-04 11:29:14 +01:00
|
|
|
}
|