This commit is contained in:
Fabio Sinibaldi 2023-01-10 11:42:09 +01:00
parent 56bac71bb2
commit 5055c548d1
9 changed files with 101 additions and 15 deletions

View File

@ -10,7 +10,7 @@ import java.nio.charset.Charset;
import java.util.HashMap;
public class TestDocuments {
public static File BASE_FOLDER =new File("test-data/profiledDocuments");
public static File BASE_FOLDER =new File("../test-data/profiledDocuments");
public static final HashMap<String, Project> documentMap =new HashMap<>();
static{

View File

@ -52,16 +52,19 @@ public abstract class GenericUseCases extends BasicVreTests{
}
protected Project prepareWithFileSet(Project project) throws FileNotFoundException, InvalidRequestException, RemoteException {
return getClient().registerFileSet(project.getId(), prepareRequest());
}
protected RegisterFileSetRequest prepareRequest() throws FileNotFoundException {
String parentPath = "$.section";
String fieldName = "fileset";
String fieldDefinition = "$.section._children[?(@.fileset)]";
// Prepare request
RegisterFileSetRequest fsRequest = FileSets.
return FileSets.
prepareRequest(new StorageUtils(),
parentPath,fieldName,fieldDefinition, new File(Tests.FOLDER_CONCESSIONI,"pos.shp"));
return getClient().registerFileSet(project.getId(),fsRequest);
}
}

View File

@ -2,12 +2,17 @@ package org.gcube.application.geoportal.clients;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
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.JSONPathWrapper;
import org.gcube.application.geoportal.common.model.document.Project;
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.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field;
@ -25,6 +30,9 @@ import java.io.IOException;
import java.nio.charset.Charset;
import java.rmi.RemoteException;
import static org.junit.Assert.assertEquals;
@Slf4j
public class ProfiledConcessioniTest extends ProfiledDocumentsTest{
@Data
@ -78,11 +86,28 @@ public class ProfiledConcessioniTest extends ProfiledDocumentsTest{
// Set relazione
client.registerFileSet(project.getId(), FileSets.
Access toSetAccess = new Access();
toSetAccess.setPolicy(AccessPolicy.RESTRICTED);
toSetAccess.setLicense("CC0-1.0");
RegisterFileSetRequest request=FileSets.
prepareRequest(new StorageUtils(),
"$.relazioneScavo","fileset",
"$.relazioneScavo."+Field.CHILDREN+"[?(@.fileset)]",
new File(Tests.FOLDER_CONCESSIONI,"relazione.pdf")));
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()).get(0),RegisteredFileSet.class);
assertEquals(Serialization.convert(f.getAccess(),Access.class).getPolicy(),toSetAccess.getPolicy());
assertEquals(Serialization.convert(f.getAccess(),Access.class).getLicense(),toSetAccess.getLicense());
// Set Abstract

View File

@ -3,22 +3,35 @@ package org.gcube.application.geoportal.clients;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.bson.Document;
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.JSONPathWrapper;
import org.gcube.application.geoportal.common.model.configuration.Configuration;
import org.gcube.application.geoportal.common.model.document.Project;
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;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
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;
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
import org.junit.Test;
import java.io.File;
import java.io.FileNotFoundException;
import java.rmi.RemoteException;
import java.time.LocalDateTime;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicLong;
import static org.gcube.application.geoportal.client.utils.Serialization.write;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
@ -33,7 +46,7 @@ public class ProfiledDocumentsTest<M extends Project,C extends Projects<M>> exte
@Test
public void registerNew() throws RemoteException, JsonProcessingException {
public void registerNew() throws RemoteException, JsonProcessingException, FileNotFoundException, InvalidRequestException {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
Projects<M> client = (Projects<M>) getClient();
@ -46,6 +59,38 @@ public class ProfiledDocumentsTest<M extends Project,C extends Projects<M>> exte
Project p =client.createNew(theDoc);
log.debug("Registered project (AS JSON) : {}", write(p));
}
@Test
public void testAccess() throws FileNotFoundException, RemoteException, InvalidRequestException, JsonProcessingException {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
Projects<M> client = (Projects<M>) getClient();
Document theDoc= Document.parse("{\n" +
"\"posizionamentoScavo\" :{\n" +
"\t\"titolo\" : \"mio titolo\"}}");
theDoc.put("startTime", LocalDateTime.now());
Project p =client.createNew(theDoc);
RegisterFileSetRequest fsRequest = prepareRequest();
Access access = new Access();
access.setLicense("CC0-1.0");
access.setPolicy(AccessPolicy.RESTRICTED);
fsRequest.setToSetAccess(access);
p=client.registerFileSet(p.getId(),fsRequest);
log.info("Registered fileset. Result is {}", Serialization.write(p));
RegisteredFileSet f= Serialization.convert(new JSONPathWrapper(p.getTheDocument().toJson()).getByPath(fsRequest.getParentPath()).get(0),RegisteredFileSet.class);
assertEquals(Serialization.convert(f.getAccess(),Access.class).getPolicy(),AccessPolicy.RESTRICTED);
}
@Test

View File

@ -953,7 +953,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
private static final RegisteredFileSet prepareRegisteredFileSet(Access toSetAccess,String docID, String profileID,
Document attributes,List<TempFile> files, StorageUtils storage,WorkspaceManager ws) throws StorageHubException, StorageException {
log.debug("Preparing Registered FileSet..");
log.debug("Preparing Registered FileSet {}");
RegisteredFileSet toReturn = new RegisteredFileSet();
if(attributes!=null) toReturn.putAll(attributes);
String uuid = UUID.randomUUID().toString();

View File

@ -9,6 +9,7 @@ import org.gcube.application.cms.tests.TokenSetter;
import org.gcube.application.cms.tests.model.BasicTests;
import org.gcube.application.geoportal.common.model.configuration.Configuration;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.access.Access;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
@ -29,6 +30,7 @@ import javax.ws.rs.core.MediaType;
import java.io.File;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
@ -158,9 +160,12 @@ public abstract class AbstractProfiledDocumentsTests extends BasicServiceTestUni
String fieldDefinitionPath,
Document attributes,
RegisterFileSetRequest.ClashOptions clashPolicy,
Access access,
String ...files) throws Exception {
FileSets.RequestBuilder builder = FileSets.build(parentPath,fieldName,fieldDefinitionPath);
builder.setAccess(access);
builder.setClashPolicy(clashPolicy).setAttributes(attributes);
for(String file:files)
@ -169,6 +174,7 @@ public abstract class AbstractProfiledDocumentsTests extends BasicServiceTestUni
Project doc = check(baseTarget().path(InterfaceConstants.Methods.REGISTER_FILES_PATH).path(id).request(MediaType.APPLICATION_JSON).
post(Entity.entity(Serialization.write(builder.getTheRequest()),
MediaType.APPLICATION_JSON)), Project.class);
BasicTests.validate(doc);
return doc;
}

View File

@ -4,6 +4,8 @@ import org.bson.Document;
import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
import org.gcube.application.geoportal.common.model.document.Project;
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.Relationship;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
@ -89,7 +91,7 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{
fieldDefinition,
new Document("customField","customFieldValue"),
RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING,
filename);
new Access(),filename);
wrapper = new JSONPathWrapper(doc.getTheDocument().toJson());
assertTrue("Relazione exists",wrapper.getMatchingPaths("section").size()==1);
@ -127,8 +129,9 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{
Project doc = createNew(baseDoc);
Access access =new Access();
access.setLicense("test-license");
access.setPolicy(AccessPolicy.RESTRICTED);
// INSERT ONE, MERGE INFO (NB default values already exist)
doc = upload(
@ -138,7 +141,7 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{
fieldDefinition,
new Document("customField","customFieldValue"),
RegisterFileSetRequest.ClashOptions.REPLACE_EXISTING,
filename);
access,filename);
return doc;
}

View File

@ -8,6 +8,7 @@ import org.gcube.application.cms.serialization.Serialization;
import org.gcube.application.cms.tests.model.BasicTests;
import org.gcube.application.geoportal.common.model.JSONPathWrapper;
import org.gcube.application.geoportal.common.model.document.Project;
import org.gcube.application.geoportal.common.model.document.access.Access;
import org.gcube.application.geoportal.common.model.document.identification.SpatialReference;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
@ -70,7 +71,7 @@ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
"fileset",
"$.posizionamentoScavo."+ Field.CHILDREN+"[?(@.fileset)]",
null,
RegisterFileSetRequest.ClashOptions.MERGE_EXISTING,
RegisterFileSetRequest.ClashOptions.MERGE_EXISTING,new Access(),
"concessioni/pos.SHP");

View File

@ -250,6 +250,9 @@ public class ExportConcessioniAsProjects {
+ "[?(@.fileset)]");
req.addAll(convertFiles(content));
req.setAccess(getAccess(rel));
project = client.registerFileSet(project.getId(),req.getTheRequest());
}
// upload fileset