This commit is contained in:
Fabio Sinibaldi 2022-02-14 17:06:32 +01:00
parent 85ceecda12
commit aac6bdf49f
13 changed files with 203 additions and 89 deletions

View File

@ -58,17 +58,18 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
public StepExecutionReport performStep(StepExecutionRequest request) throws StepException { public StepExecutionReport performStep(StepExecutionRequest request) throws StepException {
log.info("Serving Request {}",request); log.info("Serving Request {}",request);
StepExecutionReport report=new StepExecutionReport(); StepExecutionReport report=new StepExecutionReport();
LifecycleInformation info=new LifecycleInformation(); LifecycleInformation info=request.getDocument().getLifecycleInformation();
info.setPhase(request.getStep());
info.setLastOperationStatus(LifecycleInformation.Status.OK); info.setLastOperationStatus(LifecycleInformation.Status.OK);
info.setLastInvokedStep(request.getStep());
report.setRequest(request); report.setRequest(request);
report.setResult(request.getDocument()); report.setResult(request.getDocument());
try { try {
switch (request.getStep()) { switch (request.getStep()) {
case "SUBMIT-FOR-REVIEW" :{ case "SUBMIT-FOR-REVIEW" :{
//TODO Checks //TODO Checks
if(!request.getDocument().getLifecycleInformation().getPhase().equals("Draft"))
throw new StepException("Document is not in Draft phase");
//Materialize layers //Materialize layers
MaterializationRequest matReq = new MaterializationRequest(); MaterializationRequest matReq = new MaterializationRequest();
matReq.setDocument(request.getDocument()); matReq.setDocument(request.getDocument());
@ -77,6 +78,7 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
String workspace = request.getProfile().getId() + request.getContext().getId(); String workspace = request.getProfile().getId() + request.getContext().getId();
params.put("workspace", Files.fixFilename(workspace)); params.put("workspace", Files.fixFilename(workspace));
matReq.setParameters(params); matReq.setParameters(params);
MaterializationReport matRep = new SDIMaterializerPlugin().materialize(matReq); MaterializationReport matRep = new SDIMaterializerPlugin().materialize(matReq);
@ -85,6 +87,8 @@ public class ConcessioniLifeCycleManager implements LifecycleManager {
for(String msg : matRep.getMessages()) for(String msg : matRep.getMessages())
info.addErrorMessage(msg); info.addErrorMessage(msg);
} }
info.setPhase("Pending Approval");
//TODO Index-confidential //TODO Index-confidential
//TODO Notifications //TODO Notifications

View File

@ -95,6 +95,8 @@ public class SDIMaterializerPlugin implements MaterializationPlugin {
configuration.putIfAbsent("documentID",profiledDocument.get_id()); configuration.putIfAbsent("documentID",profiledDocument.get_id());
if(configuration.containsKey("titleField")) if(configuration.containsKey("titleField"))
configuration.putIfAbsent("layerTitle",fs.getString(configuration.getString("titleField"))); configuration.putIfAbsent("layerTitle",fs.getString(configuration.getString("titleField")));
else configuration.putIfAbsent("layerTitle",fs.getUUID());
RegisteredFileSet obtained = sdiManager.materializeLayer(fs,configuration); RegisteredFileSet obtained = sdiManager.materializeLayer(fs,configuration);
log.debug("Obtained {} ",obtained); log.debug("Obtained {} ",obtained);
documentNavigator.set("$..[?(@.uuid == "+fs.getUUID()+")]",obtained); documentNavigator.set("$..[?(@.uuid == "+fs.getUUID()+")]",obtained);

View File

@ -1,10 +1,7 @@
package org.gcube.application.geoportal.common.model.document.filesets; package org.gcube.application.geoportal.common.model.document.filesets;
import com.sun.xml.internal.ws.message.PayloadElementSniffer;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.NonNull;
import java.util.List; import java.util.List;

View File

@ -1,17 +0,0 @@
package org.gcube.application.geoportal.common.model.document.filesets;
import lombok.Data;
import lombok.ToString;
import org.bson.Document;
import sun.jvm.hotspot.utilities.PlatformInfo;
import java.util.List;
@Data
public class SDILayer extends Materialization{
private
private List<Document> ogcLinks;
private List<PlatformInfo>
}

View File

@ -1,11 +1,9 @@
package org.gcube.application.geoportal.common.model.rest; package org.gcube.application.geoportal.common.model.rest;
import com.sun.tools.jdeps.Archive;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.bson.Document; import org.bson.Document;
import org.gcube.application.geoportal.common.model.configuration.Index;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -17,6 +15,14 @@ import java.util.List;
@NoArgsConstructor @NoArgsConstructor
public class Configuration{ public class Configuration{
public class Index extends Document {
}
public class Archive extends Document {
}
public static String PROFILE_ID="profile_id"; public static String PROFILE_ID="profile_id";
public static String CONTEXT = "context"; public static String CONTEXT = "context";
public static String LAST_UPDATED_TIME = ""; public static String LAST_UPDATED_TIME = "";

View File

@ -2,14 +2,19 @@ package org.gcube.application.geoportal.service.engine.handlers;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.plugins.LifecycleManager; import org.gcube.application.cms.plugins.LifecycleManager;
import org.gcube.application.cms.plugins.faults.EventException;
import org.gcube.application.cms.plugins.faults.InitializationException; import org.gcube.application.cms.plugins.faults.InitializationException;
import org.gcube.application.cms.plugins.faults.ShutDownException; import org.gcube.application.cms.plugins.faults.ShutDownException;
import org.gcube.application.cms.plugins.faults.StepException; import org.gcube.application.cms.plugins.faults.StepException;
import org.gcube.application.cms.plugins.model.PluginDescriptor; import org.gcube.application.cms.plugins.model.PluginDescriptor;
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
import org.gcube.application.cms.plugins.reports.StepExecutionReport; import org.gcube.application.cms.plugins.reports.StepExecutionReport;
import org.gcube.application.cms.plugins.reports.InitializationReport; import org.gcube.application.cms.plugins.reports.InitializationReport;
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest; import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.model.document.ComparableVersion; import org.gcube.application.geoportal.common.model.document.ComparableVersion;
import org.gcube.application.geoportal.common.model.rest.Configuration;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
@Slf4j @Slf4j
public class SimpleLifeCycleManager implements LifecycleManager { public class SimpleLifeCycleManager implements LifecycleManager {
@ -41,32 +46,22 @@ public class SimpleLifeCycleManager implements LifecycleManager {
log.info("Received Request "); log.info("Received Request ");
switch(request.getStep()){ switch(request.getStep()){
case StepExecutionRequest.Steps.ON_INIT_DOCUMENT:{
break;
}
case StepExecutionRequest.Steps.ON_MATERIALIZE_DOCUMENT:{
break;
}
case StepExecutionRequest.Steps.ON_DEMATERIALIZE_DOCUMENT:{
break;
}
case StepExecutionRequest.Steps.ON_DEINDEX_DOCUMENT:{
break;
}
case StepExecutionRequest.Steps.ON_INDEX_DOCUMENT:{
break;
}
case StepExecutionRequest.Steps.ON_DELETE_DOCUMENT:{
break;
}
default : throw new StepException("Invalid Step "+request.getStep()); default : throw new StepException("Invalid Step "+request.getStep());
} }
throw new StepException("Still to implement"); //throw new StepException("Still to implement");
} }
@Override
public Configuration getCurrentConfiguration() throws ConfigurationException {
return null;
}
@Override
public EventExecutionReport onEvent(EventExecutionRequest request) throws EventException {
return null;
}
@Override @Override

View File

@ -2,6 +2,7 @@ package org.gcube.application.geoportal.service.engine.mongo;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
import org.bson.Document; import org.bson.Document;
import org.gcube.application.cms.plugins.faults.EventException;
import org.gcube.application.cms.plugins.faults.StepException; import org.gcube.application.cms.plugins.faults.StepException;
import org.gcube.application.geoportal.common.faults.StorageException; import org.gcube.application.geoportal.common.faults.StorageException;
import org.gcube.application.geoportal.common.model.rest.Configuration; import org.gcube.application.geoportal.common.model.rest.Configuration;
@ -18,10 +19,10 @@ public interface MongoManagerI<T> {
// create // create
public T registerNew(Document toRegister) throws IOException, StepException; public T registerNew(Document toRegister) throws IOException, StepException, EventException;
// update // update
public T update(String id,Document toSetDocument) throws IOException, StepException; public T update(String id,Document toSetDocument) throws IOException, StepException, EventException;
// delete // delete
@ -38,8 +39,8 @@ public interface MongoManagerI<T> {
public T performStep(String id, String step, Document options) throws IOException, StepException; public T performStep(String id, String step, Document options) throws IOException, StepException;
public T registerFileSet(String id, RegisterFileSetRequest request) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException, DeletionException; public T registerFileSet(String id, RegisterFileSetRequest request) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException, DeletionException, EventException;
public T deleteFileSet(String id, String destination, Boolean force) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException, DeletionException; public T deleteFileSet(String id, String destination, Boolean force) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException, DeletionException, EventException;
public Configuration getConfiguration()throws ConfigurationException; public Configuration getConfiguration()throws ConfigurationException;
} }

View File

@ -9,17 +9,22 @@ import org.apache.commons.io.IOUtils;
import org.bson.Document; import org.bson.Document;
import org.bson.types.ObjectId; import org.bson.types.ObjectId;
import org.gcube.application.cms.plugins.LifecycleManager; import org.gcube.application.cms.plugins.LifecycleManager;
import org.gcube.application.cms.plugins.faults.EventException;
import org.gcube.application.cms.plugins.faults.StepException; import org.gcube.application.cms.plugins.faults.StepException;
import org.gcube.application.cms.plugins.model.PluginDescriptor; import org.gcube.application.cms.plugins.model.PluginDescriptor;
import org.gcube.application.cms.plugins.reports.EventExecutionReport;
import org.gcube.application.cms.plugins.reports.StepExecutionReport; import org.gcube.application.cms.plugins.reports.StepExecutionReport;
import org.gcube.application.cms.plugins.requests.EventExecutionRequest;
import org.gcube.application.cms.plugins.requests.StepExecutionRequest; import org.gcube.application.cms.plugins.requests.StepExecutionRequest;
import org.gcube.application.geoportal.common.faults.StorageException; import org.gcube.application.geoportal.common.faults.StorageException;
import org.gcube.application.geoportal.common.model.document.*; import org.gcube.application.geoportal.common.model.document.*;
import org.gcube.application.geoportal.common.model.document.access.Access; 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.access.AccessPolicy;
import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo;
import org.gcube.application.geoportal.common.model.document.accounting.PublicationInfo; import org.gcube.application.geoportal.common.model.document.accounting.PublicationInfo;
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFile; import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFile;
import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet; import org.gcube.application.geoportal.common.model.document.filesets.RegisteredFileSet;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.model.legacy.Concessione;
import org.gcube.application.geoportal.common.model.profile.Field; import org.gcube.application.geoportal.common.model.profile.Field;
import org.gcube.application.geoportal.common.model.profile.HandlerDeclaration; import org.gcube.application.geoportal.common.model.profile.HandlerDeclaration;
@ -86,7 +91,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
} }
@Getter(lazy = true) @Getter(lazy = true)
private final LifecycleManager manager=getLCManager(); private final LifecycleManager manager=getLCManager();
private LifecycleManager getLCManager() { private LifecycleManager getLCManager() {
try{ try{
@ -122,7 +127,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
} }
@Override @Override
public ProfiledDocument registerNew(Document toRegisterDoc) throws IOException, StepException { public ProfiledDocument registerNew(Document toRegisterDoc) throws IOException, StepException, EventException {
log.info("Registering new document in {} ",profile.getId()); log.info("Registering new document in {} ",profile.getId());
log.debug("Going to register {}",toRegisterDoc.toJson()); log.debug("Going to register {}",toRegisterDoc.toJson());
@ -145,9 +150,14 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
toRegister.setProfileVersion(profile.getVersion()); toRegister.setProfileVersion(profile.getVersion());
toRegister.setVersion(new Semver("1.0.0")); toRegister.setVersion(new Semver("1.0.0"));
// Apply Lifecycle
toRegister=step(toRegister,StepExecutionRequest.Steps.ON_INIT_DOCUMENT,null).getResult(); LifecycleInformation draftInfo=new LifecycleInformation();
draftInfo.setPhase("DRAFT");
toRegister.setLifecycleInformation(draftInfo);
// Apply Lifecycle
toRegister = triggerEvent(toRegister,EventExecutionRequest.Events.ON_INIT_DOCUMENT,null).getResult();
log.debug("Going to register {} ",toRegister); log.debug("Going to register {} ",toRegister);
@ -159,7 +169,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
} }
@Override @Override
public ProfiledDocument update(String id, Document toSet) throws IOException, StepException { public ProfiledDocument update(String id, Document toSet) throws IOException, EventException {
log.trace("Replacing {} ",toSet); log.trace("Replacing {} ",toSet);
ProfiledDocument toUpdate=getByID(id); ProfiledDocument toUpdate=getByID(id);
toUpdate.setTheDocument(toSet); toUpdate.setTheDocument(toSet);
@ -171,12 +181,11 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
} }
private ProfiledDocument onUpdate(ProfiledDocument toUpdate) throws StepException { private ProfiledDocument onUpdate(ProfiledDocument toUpdate) throws EventException {
UserUtils.AuthenticatedUser u = UserUtils.getCurrent(); UserUtils.AuthenticatedUser u = UserUtils.getCurrent();
toUpdate.getInfo().setLastEditInfo(u.asInfo()); toUpdate.getInfo().setLastEditInfo(u.asInfo());
toUpdate.setVersion(toUpdate.getVersion().withIncPatch()); toUpdate.setVersion(toUpdate.getVersion().withIncPatch());
return triggerEvent(toUpdate,EventExecutionRequest.Events.ON_INIT_DOCUMENT,null).getResult();
return step(toUpdate,StepExecutionRequest.Steps.ON_UPDATE_DOCUMENT,null).getResult();
} }
@Override @Override
@ -209,7 +218,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
} }
@Override @Override
public ProfiledDocument getByID(String id){ public ProfiledDocument getByID(String id) throws WebApplicationException{
Document doc=super.getById(asId(id),getCollectionName()); Document doc=super.getById(asId(id),getCollectionName());
if(doc==null) throw new WebApplicationException("No document with ID "+id); if(doc==null) throw new WebApplicationException("No document with ID "+id);
return convert(doc,ProfiledDocument.class); return convert(doc,ProfiledDocument.class);
@ -242,8 +251,21 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
@Override @Override
public ProfiledDocument performStep(String id, String step, Document options) throws StepException, JsonProcessingException { public ProfiledDocument performStep(String id, String step, Document options) throws StepException, JsonProcessingException {
StepExecutionReport report = step(getByID(id), step, options); ProfiledDocument document = getByID(id);
return convert(replace(asDocumentWithId(report.getResult()),new ObjectId(id),getCollectionName()),ProfiledDocument.class); try{
StepExecutionReport report = step(document, step, options);
document = report.getResult();
} catch(Throwable t){
log.error("[Profile {} ] ERROR Invoking Step {} on document {}" ,profile.getId(),step,id,t);
LifecycleInformation info = new LifecycleInformation();
info.setPhase(document.getLifecycleInformation().getPhase());
info.setLastOperationStatus(LifecycleInformation.Status.ERROR);
info.addErrorMessage(t.getMessage());
info.setLastInvokedStep(step);
document.setLifecycleInformation(info);
}finally{
return convert(replace(asDocumentWithId(document),new ObjectId(id),getCollectionName()),ProfiledDocument.class);
}
} }
@ -261,7 +283,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
* *
*/ */
@Override @Override
public ProfiledDocument registerFileSet(String id,RegisterFileSetRequest request) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException, DeletionException { public ProfiledDocument registerFileSet(String id,RegisterFileSetRequest request) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException, DeletionException, EventException {
List<TempFile> files=request.getStreams(); List<TempFile> files=request.getStreams();
Document attributes =request.getAttributes(); Document attributes =request.getAttributes();
@ -339,7 +361,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
} }
@Override @Override
public ProfiledDocument deleteFileSet(String id, String destination, Boolean force) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException, DeletionException { public ProfiledDocument deleteFileSet(String id, String destination, Boolean force) throws ConfigurationException, StorageHubException, JsonProcessingException, DeletionException, EventException {
ProfiledDocument doc = getByID(id); ProfiledDocument doc = getByID(id);
doc=deleteFileSetRoutine(doc,destination,force,new WorkspaceManager()); doc=deleteFileSetRoutine(doc,destination,force,new WorkspaceManager());
doc=onUpdate(doc); doc=onUpdate(doc);
@ -349,7 +371,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
@Override @Override
public Configuration getConfiguration() throws ConfigurationException { public Configuration getConfiguration() throws ConfigurationException {
log.debug("Asking configuration for {} in {} ",profile.getId(), UserUtils.getCurrent().getContext()); log.debug("Asking configuration for {} in {} ",profile.getId(), UserUtils.getCurrent().getContext());
Configuration toReturn= manager.getCurrentConfiguration(); Configuration toReturn= getManager().getCurrentConfiguration();
log.debug("Returning current configuration {}",toReturn); log.debug("Returning current configuration {}",toReturn);
return toReturn; return toReturn;
} }
@ -362,14 +384,28 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
request.setDocument(theDocument); request.setDocument(theDocument);
request.setProfile(profile); request.setProfile(profile);
request.setStep(step); request.setStep(step);
AccountingInfo user= UserUtils.getCurrent().asInfo();
request.setUser(user.getUser());
request.setContext(user.getContext());
log.debug("Requesting Step Execution {} ",request); log.debug("Requesting Step Execution {} ",request);
StepExecutionReport report= getManager().performStep(request);
log.debug("Report is {}",report); StepExecutionReport report= getManager().performStep(request);
if(report.getResult()==null) throw new StepException("Report result is null"); log.debug("Report is {}",report);
if(report.getResult()==null) throw new StepException("Report result is null");
return report; return report;
} }
private EventExecutionReport triggerEvent(ProfiledDocument theDocument, String event, Document parameters) throws EventException {
log.info("[Profile {} ] triggering event {} on {}" ,profile.getId(),event,getManager().getDescriptor());
EventExecutionRequest request= new EventExecutionRequest();
request.setEvent(event);
request.setProfile(profile);
request.setCallParameters(parameters);
request.setDocument(theDocument);
log.debug("Triggering {} ",request);
return getManager().onEvent(request);
}
private static final RegisteredFileSet prepareRegisteredFileSet(ProfiledDocument doc, Profile profile,String destination, private static final RegisteredFileSet prepareRegisteredFileSet(ProfiledDocument doc, Profile profile,String destination,

View File

@ -30,7 +30,7 @@ public class ConcessioniOverMongo {
@Override @Override
protected Configuration run() throws Exception, WebApplicationException { protected Configuration run() throws Exception, WebApplicationException {
Configuration toReturn = new Configuration(); Configuration toReturn = new Configuration();
toReturn.setIndex(new PostgisIndex().getInfo()); //toReturn.setIndex(new PostgisIndex().getInfo());
log.info("Returning configuration {} ",toReturn); log.info("Returning configuration {} ",toReturn);
return toReturn; return toReturn;
} }

View File

@ -4,13 +4,25 @@
"name" : "Concessione", "name" : "Concessione",
"schema" : { "schema" : {
"relazioneScavo" : { "relazioneScavo" : { "_max" : 1, "_min" : 1,
"_type" : "RegisteredFileSet", "children" : [
"_max" : 1, {"fileset" :{"_type" : "RegisteredFileSet"}},
"_min" : 1}, {"title" : {"_max" : 1, "_min" : 1}}
]
},
"imgs" : { "imgs" : {
"_type" : "RegisteredFileSet", "_max" : -1,
"_max" : -1} "children" : [
{"fileset" :{"_type" : "RegisteredFileSet"}},
{"title" : {"_max" : 1, "_min" : 1}}
]
},
"posizionamentoScavo" : { "_max" : 1, "_min" : 1,
"children" : [
{"fileset" :{"_type" : "RegisteredFileSet"}},
{"title" : {"_max" : 1, "_min" : 1}}
]
}
}, },
@ -44,8 +56,8 @@
"type" : "Materializer", "type" : "Materializer",
"configuration" : { "configuration" : {
"registeredFileSetPaths" : [ "registeredFileSetPaths" : [
{"pianteFineScavo" : "pianteFineScavo"}, {"schemaField" : "pianteFineScavo","documentPath" : "pianteFineScavo[*]"},
{"posizionamentoScavo" : "posizionamentoScavo"} {"schemaField" : "posizionamentoScavo","documentPath" : "posizionamentoScavo"}
] ]
} }
}, },

View File

@ -0,0 +1,25 @@
package org.gcube.application.geoportal.service;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.junit.Test;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import static org.junit.Assert.assertEquals;
public class InexistentProfileTests extends ProfiledDocumentsTests {
@Override
protected WebTarget baseTarget() {
String testProfileId="profiledConcessioni";
return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId);
}
// GET
@Test
public void testMissingProfile(){
Response resp = target(InterfaceConstants.Methods.PROJECTS)
.path("non-existent-profile").request().get();
assertEquals(404,resp.getStatus());
}
}

View File

@ -0,0 +1,49 @@
package org.gcube.application.geoportal.service;
import org.bson.Document;
import org.gcube.application.cms.tests.model.concessioni.TestConcessioniModel;
import org.gcube.application.geoportal.common.model.document.ProfiledDocument;
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest;
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.junit.Test;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ProfiledConcessioniTests extends ProfiledDocumentsTests{
@Override
protected WebTarget baseTarget() {
String testProfileId="profiledConcessioni";
return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId);
}
@Test
public void testSDI() throws Exception {
// Create new
ProfiledDocument doc = createNew();
// register filesets
doc = upload(
new StorageUtils(),
doc.get_id(),
"posizionamentoScavo.fileset",
"posizionamentoScavo.children[?(@.fileset)]",
Document.parse("{\"titolo\" : \"mio titolo\",\"some\" : \"something\" }"),
RegisterFileSetRequest.ClashOptions.MERGE_EXISTING,
"pos.shp");
// invoke step SUBMIT-FOR-REVIEW
StepExecutionRequest req=new StepExecutionRequest();
req.setStepID("SUBMIT-FOR-REVIEW");
doc=step(doc.get_id(),req);
System.out.println(doc);
assertTrue(doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK));
}
}

View File

@ -11,6 +11,7 @@ import org.gcube.application.geoportal.common.model.document.filesets.Registered
import org.gcube.application.geoportal.common.model.rest.Configuration; import org.gcube.application.geoportal.common.model.rest.Configuration;
import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.model.rest.QueryRequest;
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest; import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest;
import org.gcube.application.geoportal.common.rest.InterfaceConstants; import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.utils.FileSets; import org.gcube.application.geoportal.common.utils.FileSets;
import org.gcube.application.geoportal.common.utils.StorageUtils; import org.gcube.application.geoportal.common.utils.StorageUtils;
@ -29,9 +30,9 @@ import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class ProfiledDocumentsTests extends BasicServiceTestUnit{ public abstract class ProfiledDocumentsTests extends BasicServiceTestUnit{
String testProfileId="profiledConcessioni";
@Before @Before
public void setContext(){ public void setContext(){
@ -39,16 +40,8 @@ public class ProfiledDocumentsTests extends BasicServiceTestUnit{
} }
protected WebTarget baseTarget(){ protected abstract WebTarget baseTarget();
return target(InterfaceConstants.Methods.PROJECTS).path(testProfileId);
}
// GET
@Test
public void testMissingProfile(){
Response resp = target(InterfaceConstants.Methods.PROJECTS)
.path("non-existent-profile").request().get();
assertEquals(404,resp.getStatus());
}
@Test @Test
@ -182,13 +175,13 @@ public class ProfiledDocumentsTests extends BasicServiceTestUnit{
// @@@@@@@@@@@@@@@ Routines // @@@@@@@@@@@@@@@ Routines
private ProfiledDocument createNew() throws Exception { protected ProfiledDocument createNew() throws Exception {
Document document =new Document(Collections.singletonMap("dumbKey","dumbValue")); Document document =new Document(Collections.singletonMap("dumbKey","dumbValue"));
return check(baseTarget().request(MediaType.APPLICATION_JSON). return check(baseTarget().request(MediaType.APPLICATION_JSON).
post(Entity.entity(document, MediaType.APPLICATION_JSON)),ProfiledDocument.class); post(Entity.entity(document, MediaType.APPLICATION_JSON)),ProfiledDocument.class);
} }
private ProfiledDocument upload(StorageUtils storage, protected ProfiledDocument upload(StorageUtils storage,
String id, String id,
String path, String path,
String fieldDefinitionPath, String fieldDefinitionPath,
@ -206,4 +199,15 @@ public class ProfiledDocumentsTests extends BasicServiceTestUnit{
post(Entity.entity(Serialization.write(builder.getTheRequest()), post(Entity.entity(Serialization.write(builder.getTheRequest()),
MediaType.APPLICATION_JSON)),ProfiledDocument.class); MediaType.APPLICATION_JSON)),ProfiledDocument.class);
} }
protected ProfiledDocument step(String id, StepExecutionRequest request) throws Exception {
ProfiledDocument toReturn= check(baseTarget().
path(InterfaceConstants.Methods.STEP).path(id).request(MediaType.APPLICATION_JSON).
post(Entity.entity(Serialization.write(request),
MediaType.APPLICATION_JSON)),ProfiledDocument.class);
assertTrue(toReturn.getLifecycleInformation().getLastInvokedStep().equals(request.getStepID()));
return toReturn;
}
} }