diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/rest/AddSectionToConcessioneRequest.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/rest/AddSectionToConcessioneRequest.java index ae9774a..4606c34 100644 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/rest/AddSectionToConcessioneRequest.java +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/model/rest/AddSectionToConcessioneRequest.java @@ -7,6 +7,7 @@ import javax.xml.bind.annotation.XmlRootElement; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import org.bson.Document; import org.gcube.application.geoportal.common.faults.InvalidRequestException; import org.gcube.application.geoportal.common.model.legacy.Concessione; import org.gcube.application.geoportal.common.rest.TempFile; @@ -19,7 +20,7 @@ public class AddSectionToConcessioneRequest { private String destinationPath; private List streams; - + private Document attributes; public void validate()throws InvalidRequestException { Concessione.Paths.validate(destinationPath); diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/InterfaceConstants.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/InterfaceConstants.java index 1dac42a..276b288 100644 --- a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/InterfaceConstants.java +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/InterfaceConstants.java @@ -25,7 +25,8 @@ public class InterfaceConstants { public static final String CONFIGURATION_PATH="configuration"; public static final String SEARCH_PATH="search"; public static final String QUERY_PATH="query"; - + + public static final String STEP="step"; } public static final class Parameters{ diff --git a/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/StepExecutionRequest.java b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/StepExecutionRequest.java new file mode 100644 index 0000000..4790186 --- /dev/null +++ b/geoportal-common/src/main/java/org/gcube/application/geoportal/common/rest/StepExecutionRequest.java @@ -0,0 +1,19 @@ +package org.gcube.application.geoportal.common.rest; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.bson.Document; + + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +@Data +@AllArgsConstructor +@NoArgsConstructor +public class StepExecutionRequest { + + private String stepID; + private Document options; +} diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManagerI.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManagerI.java index a0242f9..0469c2a 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManagerI.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManagerI.java @@ -40,4 +40,5 @@ public interface MongoManagerI { public T performStep(String id, String step, Document options) throws IOException, StepException; public T registerFileSet(String id, String destination, Document attributes, List files) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException; + public T deleteFileSet(String id, String destination, Boolean force) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException; } diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java index 4e7303b..9f419cc 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java @@ -50,7 +50,7 @@ import static org.gcube.application.cms.Serialization.*; @Slf4j public class ProfiledMongoManager extends MongoManager implements MongoManagerI{ - + @Getter Profile profile; MongoDatabase db=null; @@ -292,8 +292,10 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI< return convert(replace(asDocument(doc),getCollectionName()),ProfiledDocument.class); } - - + @Override + public ProfiledDocument deleteFileSet(String id, String destination, Boolean force) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException { + throw new RuntimeException("Implement this"); + } // @Override diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java index 1c53501..bf7fa59 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java @@ -3,9 +3,13 @@ package org.gcube.application.geoportal.service.rest; import lombok.extern.slf4j.Slf4j; import org.bson.Document; import org.gcube.application.geoportal.common.model.document.ProfiledDocument; +import org.gcube.application.geoportal.common.model.legacy.Concessione; +import org.gcube.application.geoportal.common.model.rest.AddSectionToConcessioneRequest; import org.gcube.application.geoportal.common.model.rest.Configuration; import org.gcube.application.geoportal.common.model.rest.QueryRequest; import org.gcube.application.geoportal.common.rest.InterfaceConstants; +import org.gcube.application.geoportal.common.rest.StepExecutionRequest; +import org.gcube.application.geoportal.service.engine.mongo.ConcessioniMongoManager; import org.gcube.application.geoportal.service.engine.mongo.ProfiledMongoManager; import org.gcube.application.geoportal.service.model.internal.faults.ConfigurationException; import org.gcube.application.cms.Serialization; @@ -20,7 +24,7 @@ public class ProfiledDocuments { private ProfiledMongoManager manager; public ProfiledDocuments(@PathParam(InterfaceConstants.Parameters.PROFILE_ID) String profileID) throws ConfigurationException { - log.debug("Accessing profiles "+profileID); + log.info("Accessing profiles "+profileID); manager=new GuardedMethod(){ @Override protected ProfiledMongoManager run() throws Exception { @@ -51,7 +55,101 @@ public class ProfiledDocuments { return new GuardedMethod() { @Override protected ProfiledDocument run() throws Exception, WebApplicationException { - return manager.registerNew(d); + log.info("Creating new ProfiledDocument ({})",manager.getProfile().getId()); + ProfiledDocument toReturn= manager.registerNew(d); + log.info("Created new ProfiledDocument ({}, ID {})",manager.getProfile().getId(),toReturn.get_id()); + return toReturn; + } + }.execute().getResult(); + } + + + @PUT + @Path("{"+InterfaceConstants.Parameters.PROJECT_ID+"}") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public ProfiledDocument update(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String documentId, Document d) { + return new GuardedMethod() { + @Override + protected ProfiledDocument run() throws Exception, WebApplicationException { + log.info("Updating ProfiledDocument ({}, ID {})",manager.getProfile().getId(),documentId); + return manager.update(documentId,d); + } + }.execute().getResult(); + } + + + @DELETE + @Produces(MediaType.APPLICATION_JSON) + @Path("{"+InterfaceConstants.Parameters.PROJECT_ID+"}") + public Boolean delete(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, + @DefaultValue("false") + @QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force) { + return new GuardedMethod() { + @Override + protected Boolean run() throws Exception, WebApplicationException { + log.info("Deleting ProfiledDocument ({}, ID {}). Force is {}",manager.getProfile().getId(),id,force); + manager.delete(id,force); + return true; + } + }.execute().getResult(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/"+InterfaceConstants.Methods.REGISTER_FILES_PATH+"/{"+InterfaceConstants.Parameters.PROJECT_ID+"}") + public ProfiledDocument registerFileSet(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, + AddSectionToConcessioneRequest request) { + return new GuardedMethod() { + @Override + protected ProfiledDocument run() throws Exception, WebApplicationException { + log.info("Registering {} file(s) for ProfiledDocument ({}, ID {}) at path {}", + request.getStreams().size(), + manager.getProfile().getId(), + id,request.getDestinationPath()); + request.validate(); + return manager.registerFileSet(id,request.getDestinationPath(),request.getAttributes(),request.getStreams()); + } + }.execute().getResult(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/"+InterfaceConstants.Methods.DELETE_FILES_PATH+"/{"+InterfaceConstants.Parameters.PROJECT_ID+"}") + public ProfiledDocument deleteFileSet( + @PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, + @DefaultValue("false") + @QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force, + String path) { + return new GuardedMethod() { + @Override + protected ProfiledDocument run() throws Exception, WebApplicationException { + log.info("Deleting FileSet of ProfiledDocument ({}, ID {}) at path {}. Force is {}", + manager.getProfile().getId(), + id,path,force); + return manager.deleteFileSet(id,path,force); + } + }.execute().getResult(); + } + + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Path("/"+InterfaceConstants.Methods.STEP+"/{"+InterfaceConstants.Parameters.PROJECT_ID+"}") + public ProfiledDocument performStep( + @PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, + StepExecutionRequest request) { + return new GuardedMethod() { + @Override + protected ProfiledDocument run() throws Exception, WebApplicationException { + log.info("Executing step {} on ProfiledDocument ({},ID,{}) with options {}", + request.getStepID(), + manager.getProfile().getId(), + id,request.getOptions()); + return manager.performStep(id,request.getStepID(),request.getOptions()); } }.execute().getResult(); }