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