ProfiledDocument REST methods

This commit is contained in:
Fabio Sinibaldi 2022-01-18 12:01:33 +01:00
parent b0e5d098c0
commit 2cdfcd2870
6 changed files with 129 additions and 7 deletions

View File

@ -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<TempFile> streams;
private Document attributes;
public void validate()throws InvalidRequestException {
Concessione.Paths.validate(destinationPath);

View File

@ -26,6 +26,7 @@ public class InterfaceConstants {
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{

View File

@ -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;
}

View File

@ -40,4 +40,5 @@ public interface MongoManagerI<T> {
public T performStep(String id, String step, Document options) throws IOException, StepException;
public T registerFileSet(String id, String destination, Document attributes, List<TempFile> files) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException;
public T deleteFileSet(String id, String destination, Boolean force) throws ConfigurationException, StorageHubException, StorageException, StepException, JsonProcessingException;
}

View File

@ -50,7 +50,7 @@ import static org.gcube.application.cms.Serialization.*;
@Slf4j
public class ProfiledMongoManager extends MongoManager implements MongoManagerI<ProfiledDocument>{
@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

View File

@ -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<ProfiledMongoManager>(){
@Override
protected ProfiledMongoManager run() throws Exception {
@ -51,7 +55,101 @@ public class ProfiledDocuments {
return new GuardedMethod<ProfiledDocument>() {
@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<ProfiledDocument>() {
@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<Boolean>() {
@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<ProfiledDocument>() {
@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<ProfiledDocument>() {
@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<ProfiledDocument>() {
@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();
}