2021-09-20 16:47:35 +02:00
|
|
|
package org.gcube.application.geoportal.service.rest;
|
|
|
|
|
2024-04-12 15:49:29 +02:00
|
|
|
import java.lang.reflect.Field;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2023-04-18 10:35:23 +02:00
|
|
|
import javax.ws.rs.Consumes;
|
|
|
|
import javax.ws.rs.DELETE;
|
|
|
|
import javax.ws.rs.DefaultValue;
|
|
|
|
import javax.ws.rs.GET;
|
|
|
|
import javax.ws.rs.POST;
|
|
|
|
import javax.ws.rs.PUT;
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
import javax.ws.rs.PathParam;
|
|
|
|
import javax.ws.rs.Produces;
|
|
|
|
import javax.ws.rs.QueryParam;
|
|
|
|
import javax.ws.rs.WebApplicationException;
|
|
|
|
import javax.ws.rs.core.MediaType;
|
|
|
|
|
2021-09-20 16:47:35 +02:00
|
|
|
import org.bson.Document;
|
2022-03-10 18:15:10 +01:00
|
|
|
import org.gcube.application.cms.implementations.ImplementationProvider;
|
2023-12-21 10:49:37 +01:00
|
|
|
import org.gcube.application.cms.implementations.utils.UserUtils;
|
|
|
|
import org.gcube.application.cms.plugins.events.EventManager;
|
|
|
|
import org.gcube.application.cms.plugins.events.EventManager.Event;
|
|
|
|
import org.gcube.application.cms.plugins.events.ItemObserved;
|
2024-04-17 15:53:45 +02:00
|
|
|
import org.gcube.application.cms.plugins.events.ItemObserved.OPTIONAL_FIELD;
|
2022-09-26 16:11:20 +02:00
|
|
|
import org.gcube.application.cms.serialization.Serialization;
|
2022-03-10 18:15:10 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
2022-09-26 16:11:20 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.document.Project;
|
2022-05-17 14:35:06 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.document.access.Access;
|
2023-12-21 10:49:37 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.document.accounting.AccountingInfo;
|
2024-03-22 16:22:22 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation;
|
|
|
|
import org.gcube.application.geoportal.common.model.document.lifecycle.LifecycleInformation.Status;
|
2022-09-26 16:11:20 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
|
2021-12-07 11:16:26 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
2022-01-27 15:02:53 +01:00
|
|
|
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
|
2024-04-15 12:27:52 +02:00
|
|
|
import org.gcube.application.geoportal.common.model.rest.PerformStepRequest;
|
2022-09-26 16:11:20 +02:00
|
|
|
import org.gcube.application.geoportal.common.rest.InterfaceConstants;
|
2021-12-07 11:16:26 +01:00
|
|
|
import org.gcube.application.geoportal.service.engine.mongo.ProfiledMongoManager;
|
2022-03-10 18:15:10 +01:00
|
|
|
import org.gcube.application.geoportal.service.engine.providers.ConfigurationCache;
|
2022-10-27 16:03:38 +02:00
|
|
|
import org.gcube.application.geoportal.service.engine.providers.ProjectAccessImpl;
|
2023-04-18 10:35:23 +02:00
|
|
|
import org.gcube.application.geoportal.service.http.PATCH;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
2023-04-18 10:35:23 +02:00
|
|
|
import com.webcohesion.enunciate.metadata.rs.RequestHeader;
|
|
|
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2021-09-20 16:47:35 +02:00
|
|
|
|
2023-04-18 11:21:24 +02:00
|
|
|
/**
|
|
|
|
* The Class ProfiledDocuments.
|
2023-04-26 12:34:50 +02:00
|
|
|
*
|
2023-04-18 11:21:24 +02:00
|
|
|
* @author created by Fabio Sinibaldi
|
2023-12-21 10:49:37 +01:00
|
|
|
* @author new manager/developer and mantainer - Francesco Mangiacrapa at
|
|
|
|
* ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
2023-04-18 11:21:24 +02:00
|
|
|
*
|
2023-04-26 12:34:50 +02:00
|
|
|
* Apr 18, 2023
|
2023-04-18 11:21:24 +02:00
|
|
|
*/
|
2023-04-26 12:34:50 +02:00
|
|
|
@Path(InterfaceConstants.Methods.PROJECTS + "/{" + InterfaceConstants.Parameters.UCID + "}")
|
2021-09-20 16:47:35 +02:00
|
|
|
@Slf4j
|
2022-06-08 16:32:01 +02:00
|
|
|
@RequestHeaders({
|
2023-04-26 12:34:50 +02:00
|
|
|
@RequestHeader(name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
|
|
|
@RequestHeader(name = "Content-Type", description = "application/json") })
|
2021-12-15 19:10:19 +01:00
|
|
|
public class ProfiledDocuments {
|
2021-09-20 16:47:35 +02:00
|
|
|
|
2023-04-26 12:34:50 +02:00
|
|
|
private ProfiledMongoManager manager;
|
2023-12-21 10:49:37 +01:00
|
|
|
private EventManager eventManager = EventManager.getInstance(); // as singleton
|
2023-04-26 12:34:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Instantiates a new profiled documents.
|
|
|
|
*
|
|
|
|
* @param profileID the profile ID
|
|
|
|
* @throws ConfigurationException the configuration exception
|
|
|
|
*/
|
|
|
|
public ProfiledDocuments(@PathParam(InterfaceConstants.Parameters.UCID) String profileID)
|
|
|
|
throws ConfigurationException {
|
|
|
|
log.info("Accessing profile " + profileID);
|
|
|
|
manager = new GuardedMethod<ProfiledMongoManager>() {
|
|
|
|
@Override
|
|
|
|
protected ProfiledMongoManager run() throws Exception {
|
|
|
|
return new ProfiledMongoManager(profileID);
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the configuration.
|
|
|
|
*
|
|
|
|
* @param profileID the profile ID
|
|
|
|
* @return the configuration
|
|
|
|
*/
|
|
|
|
@GET
|
|
|
|
@Path(InterfaceConstants.Methods.CONFIGURATION_PATH)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
public Configuration getConfiguration(@PathParam(InterfaceConstants.Parameters.UCID) String profileID) {
|
|
|
|
return new GuardedMethod<Configuration>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Configuration run() throws Exception, WebApplicationException {
|
|
|
|
return ImplementationProvider.get().getProvidedObjectByClass(ConfigurationCache.ConfigurationMap.class)
|
|
|
|
.get(profileID);
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates the new.
|
|
|
|
*
|
|
|
|
* @param d the d
|
|
|
|
* @return the project
|
|
|
|
*/
|
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
public Project createNew(Document d) {
|
2023-12-21 10:49:37 +01:00
|
|
|
Project theNewProject = new GuardedMethod<Project>() {
|
2023-04-26 12:34:50 +02:00
|
|
|
@Override
|
|
|
|
protected Project run() throws Exception, WebApplicationException {
|
|
|
|
log.info("Creating new Project ({})", manager.getUseCaseDescriptor().getId());
|
|
|
|
Project toReturn = manager.registerNew(d);
|
|
|
|
log.info("Created new Project ({}, ID {})", manager.getUseCaseDescriptor().getId(), toReturn.getId());
|
|
|
|
return toReturn;
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
2023-12-21 10:49:37 +01:00
|
|
|
|
2024-03-22 16:22:22 +01:00
|
|
|
Status status = theNewProject.getLifecycleInformation().getLastOperationStatus();
|
2024-04-16 10:54:16 +02:00
|
|
|
// If latest operation status is not ERROR, notify PROJECT_CREATED event
|
2024-03-22 16:22:22 +01:00
|
|
|
if (status != null && !status.equals(LifecycleInformation.Status.ERROR)) {
|
|
|
|
// notifying the Event.PROJECT_CREATED;
|
|
|
|
ItemObserved<Project> item = new ItemObserved<Project>();
|
|
|
|
EventManager.Event event = Event.PROJECT_CREATED;
|
|
|
|
AccountingInfo user = UserUtils.getCurrent().asInfo();
|
|
|
|
item.setUserCaller(user.getUser());
|
|
|
|
item.setContext(user.getContext());
|
2024-04-17 15:53:45 +02:00
|
|
|
item.setOptional(null);
|
2024-03-22 16:22:22 +01:00
|
|
|
item.setEvent(event);
|
|
|
|
item.setProject(theNewProject);
|
2024-04-15 11:28:51 +02:00
|
|
|
item.setUseCaseDescriptor(manager.getUseCaseDescriptor());
|
2024-03-22 16:22:22 +01:00
|
|
|
log.info("By notifying event ({}, ID {})", event, item.getProjectId());
|
|
|
|
eventManager.notify(event, item);
|
|
|
|
}
|
2023-12-21 10:49:37 +01:00
|
|
|
|
|
|
|
return theNewProject;
|
2023-04-26 12:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update.
|
|
|
|
*
|
|
|
|
* @param documentId the document id
|
|
|
|
* @param d the d
|
|
|
|
* @return the project
|
|
|
|
*/
|
|
|
|
@PUT
|
|
|
|
@Path("{" + InterfaceConstants.Parameters.PROJECT_ID + "}")
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
public Project update(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String documentId, Document d) {
|
2023-12-21 10:49:37 +01:00
|
|
|
Project theUpdatedProject = new GuardedMethod<Project>() {
|
2023-04-26 12:34:50 +02:00
|
|
|
@Override
|
|
|
|
protected Project run() throws Exception, WebApplicationException {
|
|
|
|
log.info("Updating Project ({}, ID {})", manager.getUseCaseDescriptor().getId(), documentId);
|
|
|
|
return manager.update(documentId, d);
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
2023-12-21 10:49:37 +01:00
|
|
|
|
2024-03-22 16:22:22 +01:00
|
|
|
Status status = theUpdatedProject.getLifecycleInformation().getLastOperationStatus();
|
2024-04-16 10:54:16 +02:00
|
|
|
// If latest operation status is not ERROR, notify PROJECT_UPDATED event
|
2024-03-22 16:22:22 +01:00
|
|
|
if (status != null && !status.equals(LifecycleInformation.Status.ERROR)) {
|
|
|
|
|
|
|
|
ItemObserved<Project> item = new ItemObserved<Project>();
|
|
|
|
EventManager.Event event = Event.PROJECT_UPDATED;
|
|
|
|
AccountingInfo user = UserUtils.getCurrent().asInfo();
|
|
|
|
item.setUserCaller(user.getUser());
|
|
|
|
item.setContext(user.getContext());
|
2024-04-17 15:53:45 +02:00
|
|
|
item.setOptional(null);
|
2024-03-22 16:22:22 +01:00
|
|
|
item.setEvent(event);
|
|
|
|
item.setProject(theUpdatedProject);
|
2024-04-15 11:28:51 +02:00
|
|
|
item.setUseCaseDescriptor(manager.getUseCaseDescriptor());
|
2024-03-22 16:22:22 +01:00
|
|
|
log.info("By notifying event ({}, ID {})", event, item.getProjectId());
|
|
|
|
eventManager.notify(event, item);
|
|
|
|
}
|
2023-12-21 10:49:37 +01:00
|
|
|
|
|
|
|
return theUpdatedProject;
|
2023-04-26 12:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Patch.
|
|
|
|
*
|
|
|
|
* @param documentId the document id
|
|
|
|
* @param d the d
|
|
|
|
* @return the project
|
|
|
|
*/
|
|
|
|
@PATCH
|
|
|
|
@Path("{" + InterfaceConstants.Parameters.PROJECT_ID + "}")
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
public Project patch(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String documentId, Document d) {
|
|
|
|
return new GuardedMethod<Project>() {
|
|
|
|
@Override
|
|
|
|
protected Project run() throws Exception, WebApplicationException {
|
|
|
|
log.info("Patching Project ({}, ID {})", manager.getUseCaseDescriptor().getId(), documentId);
|
|
|
|
// return manager.patch(documentId,d);
|
|
|
|
throw new WebApplicationException("This method has not yet been implemented!");
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @param force the force
|
|
|
|
* @return the boolean
|
|
|
|
*/
|
|
|
|
@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) {
|
2023-12-21 10:49:37 +01:00
|
|
|
Boolean deleted = new GuardedMethod<Boolean>() {
|
2023-04-26 12:34:50 +02:00
|
|
|
@Override
|
|
|
|
protected Boolean run() throws Exception, WebApplicationException {
|
|
|
|
log.info("Deleting Project ({}, ID {}). Force is {}", manager.getUseCaseDescriptor().getId(), id,
|
|
|
|
force);
|
|
|
|
manager.delete(id, force);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
2023-12-21 10:49:37 +01:00
|
|
|
|
2024-04-16 10:54:16 +02:00
|
|
|
// If deleted, notify PROJECT_DELETED event
|
2024-03-22 16:22:22 +01:00
|
|
|
if (deleted) {
|
|
|
|
ItemObserved<Project> item = new ItemObserved<Project>();
|
|
|
|
EventManager.Event event = Event.PROJECT_DELETED;
|
|
|
|
AccountingInfo user = UserUtils.getCurrent().asInfo();
|
|
|
|
item.setUserCaller(user.getUser());
|
|
|
|
item.setContext(user.getContext());
|
|
|
|
item.setEvent(event);
|
2024-04-15 11:28:51 +02:00
|
|
|
item.setUseCaseDescriptor(manager.getUseCaseDescriptor());
|
2024-03-22 16:22:22 +01:00
|
|
|
// Referencing delete project
|
|
|
|
Project deletedProject = new Project();
|
|
|
|
deletedProject.setId(id);
|
|
|
|
deletedProject.setProfileID(manager.getUseCaseDescriptor().getId());
|
|
|
|
item.setProject(deletedProject);
|
|
|
|
log.info("By notifying event ({}, ID {})", event, item.getProjectId());
|
|
|
|
eventManager.notify(event, item);
|
|
|
|
}
|
2023-12-21 10:49:37 +01:00
|
|
|
|
|
|
|
return deleted;
|
2023-04-26 12:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register file set.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @param request the request
|
|
|
|
* @return the project
|
|
|
|
*/
|
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("/" + InterfaceConstants.Methods.REGISTER_FILES_PATH + "/{" + InterfaceConstants.Parameters.PROJECT_ID + "}")
|
|
|
|
public Project registerFileSet(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,
|
|
|
|
RegisterFileSetRequest request) {
|
|
|
|
return new GuardedMethod<Project>() {
|
|
|
|
@Override
|
|
|
|
protected Project run() throws Exception, WebApplicationException {
|
|
|
|
log.info("UCD {} : Project {} Registering Fileset. Request is {}",
|
|
|
|
manager.getUseCaseDescriptor().getId(), id, request);
|
|
|
|
request.validate();
|
|
|
|
return manager.registerFileSet(id, request);
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete file set. the Authorization must be a VRE token
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @param force the force
|
|
|
|
* @param path the path must be passed as text in the body
|
|
|
|
* @return the project
|
|
|
|
*/
|
|
|
|
@RequestHeaders({
|
|
|
|
@RequestHeader(name = "Authorization", description = "VRE Bearer token, see https://dev.d4science.org/how-to-access-resources"),
|
|
|
|
@RequestHeader(name = "Content-Type", description = "application/json") })
|
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("/" + InterfaceConstants.Methods.DELETE_FILES_PATH + "/{" + InterfaceConstants.Parameters.PROJECT_ID + "}")
|
|
|
|
public Project deleteFileSet(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,
|
|
|
|
@DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force,
|
2023-12-21 10:49:37 +01:00
|
|
|
@DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.IGNORE_ERRORS) Boolean ignore_errors,
|
|
|
|
String path) {
|
2023-04-26 12:34:50 +02:00
|
|
|
return new GuardedMethod<Project>() {
|
|
|
|
@Override
|
|
|
|
protected Project run() throws Exception, WebApplicationException {
|
|
|
|
log.info("Deleting FileSet of Project ({}, ID {}) at path {}. Force is {}. Ignore_errors is {}",
|
|
|
|
manager.getUseCaseDescriptor().getId(), id, path, force, ignore_errors);
|
|
|
|
return manager.deleteFileSet(id, path, force, ignore_errors);
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Perform step.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @param request the request
|
|
|
|
* @return the project
|
|
|
|
*/
|
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("/" + InterfaceConstants.Methods.STEP + "/{" + InterfaceConstants.Parameters.PROJECT_ID + "}")
|
|
|
|
public Project performStep(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,
|
2024-04-15 12:27:52 +02:00
|
|
|
PerformStepRequest performStepRequest) {
|
2023-12-21 10:49:37 +01:00
|
|
|
Project theProject = new GuardedMethod<Project>() {
|
2023-04-26 12:34:50 +02:00
|
|
|
@Override
|
|
|
|
protected Project run() throws Exception, WebApplicationException {
|
2024-04-15 12:27:52 +02:00
|
|
|
log.info("Executing step {} on Project ({},ID,{}) with options {}", performStepRequest.getStepID(),
|
|
|
|
manager.getUseCaseDescriptor().getId(), id, performStepRequest.getOptions());
|
|
|
|
return manager.performStep(id, performStepRequest.getStepID(), performStepRequest.getOptions());
|
2023-04-26 12:34:50 +02:00
|
|
|
}
|
|
|
|
}.execute().getResult();
|
2023-12-21 10:49:37 +01:00
|
|
|
|
2024-03-22 16:22:22 +01:00
|
|
|
Status status = theProject.getLifecycleInformation().getLastOperationStatus();
|
2024-04-16 10:54:16 +02:00
|
|
|
// If latest operation status is not ERROR, notify LIFECYCLE_STEP_PERFORMED
|
|
|
|
// event
|
2024-03-22 16:22:22 +01:00
|
|
|
if (status != null && !status.equals(LifecycleInformation.Status.ERROR)) {
|
|
|
|
ItemObserved<Project> item = new ItemObserved<Project>();
|
|
|
|
EventManager.Event event = Event.LIFECYCLE_STEP_PERFORMED;
|
|
|
|
AccountingInfo user = UserUtils.getCurrent().asInfo();
|
|
|
|
item.setUserCaller(user.getUser());
|
|
|
|
item.setContext(user.getContext());
|
|
|
|
item.setEvent(event);
|
2024-04-17 15:53:45 +02:00
|
|
|
item.setOptional(OPTIONAL_FIELD.message, performStepRequest.getMessage());
|
2024-04-15 11:28:51 +02:00
|
|
|
item.setUseCaseDescriptor(manager.getUseCaseDescriptor());
|
2024-03-22 16:22:22 +01:00
|
|
|
item.setProject(theProject);
|
|
|
|
log.info("By notifying event ({}, ID {})", event, item.getProjectId());
|
|
|
|
eventManager.notify(event, item);
|
|
|
|
}
|
2023-12-21 10:49:37 +01:00
|
|
|
|
|
|
|
return theProject;
|
2023-04-26 12:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Force unlock.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @return the project
|
|
|
|
*/
|
|
|
|
@PUT
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("/" + InterfaceConstants.Methods.FORCE_UNLOCK + "/{" + InterfaceConstants.Parameters.PROJECT_ID + "}")
|
|
|
|
public Project forceUnlock(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) {
|
|
|
|
return new GuardedMethod<Project>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Project run() throws Exception, WebApplicationException {
|
|
|
|
log.warn("UCD {}, forcing unlock for Project ID {}", manager.getUseCaseDescriptor().getId(), id);
|
|
|
|
return manager.forceUnlock(id);
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the access policy.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @param toSet the to set
|
|
|
|
* @return the project
|
|
|
|
*/
|
|
|
|
@PUT
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("/" + InterfaceConstants.Methods.SET_PROJECT_ACCESS_POLICY + "/{" + InterfaceConstants.Parameters.PROJECT_ID
|
|
|
|
+ "}")
|
|
|
|
public Project setAccessPolicy(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, Access toSet) {
|
|
|
|
return new GuardedMethod<Project>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Project run() throws Exception, WebApplicationException {
|
|
|
|
log.warn("UCD {}, setting Policy {} Project ID {}", manager.getUseCaseDescriptor().getId(), toSet, id);
|
|
|
|
return manager.setAccessPolicy(id, toSet);
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ********************************** READ
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List.
|
|
|
|
*
|
|
|
|
* @return the iterable
|
|
|
|
*/
|
|
|
|
@GET
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
public Iterable<?> list() {
|
|
|
|
return new GuardedMethod<Iterable<?>>() {
|
|
|
|
protected Iterable<?> run() throws Exception, WebApplicationException {
|
|
|
|
return manager.query(new QueryRequest());
|
|
|
|
};
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the by id.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @return the by id
|
|
|
|
*/
|
|
|
|
// BY ID
|
|
|
|
@GET
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("{" + InterfaceConstants.Parameters.PROJECT_ID + "}")
|
|
|
|
public Project getById(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id) {
|
|
|
|
return new GuardedMethod<Project>() {
|
|
|
|
@Override
|
|
|
|
protected Project run() throws Exception, WebApplicationException {
|
|
|
|
return manager.getByID(id);
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Search.
|
|
|
|
*
|
|
|
|
* @param filter the filter
|
|
|
|
* @return the string
|
|
|
|
*/
|
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("/" + InterfaceConstants.Methods.SEARCH_PATH)
|
|
|
|
public String search(String filter) {
|
|
|
|
return new GuardedMethod<String>() {
|
|
|
|
@Override
|
|
|
|
protected String run() throws Exception, WebApplicationException {
|
|
|
|
QueryRequest req = new QueryRequest();
|
|
|
|
req.setFilter(Document.parse(filter));
|
|
|
|
return Serialization.write(manager.query(req));
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Query.
|
|
|
|
*
|
|
|
|
* @param queryString the query string
|
|
|
|
* @return the iterable
|
|
|
|
*/
|
|
|
|
@POST
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("/" + InterfaceConstants.Methods.QUERY_PATH)
|
|
|
|
public Iterable<?> query(String queryString) {
|
|
|
|
return new GuardedMethod<Iterable<?>>() {
|
|
|
|
@Override
|
|
|
|
protected Iterable<?> run() throws Exception, WebApplicationException {
|
|
|
|
return manager.query(Serialization.parseQuery(queryString));
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Relationships
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the relationship chain.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @param relationshipId the relationship id
|
|
|
|
* @param deep the deep
|
|
|
|
* @return the relationship chain
|
|
|
|
*/
|
|
|
|
@GET
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("{" + InterfaceConstants.Methods.RELATIONSHIP + "}/{" + InterfaceConstants.Parameters.PROJECT_ID + "}" + "/{"
|
|
|
|
+ InterfaceConstants.Parameters.RELATIONSHIP_ID + "}")
|
|
|
|
public String getRelationshipChain(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,
|
|
|
|
@PathParam(InterfaceConstants.Parameters.RELATIONSHIP_ID) String relationshipId,
|
|
|
|
@DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.DEEP) Boolean deep) {
|
|
|
|
return new GuardedMethod<String>() {
|
|
|
|
@Override
|
|
|
|
protected String run() throws Exception, WebApplicationException {
|
|
|
|
return Serialization.write(ProjectAccessImpl
|
|
|
|
.getRelationshipChain(manager.getUseCaseDescriptor().getId(), id, relationshipId, deep));
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the relation.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @param relationshipId the relationship id
|
|
|
|
* @param targetId the target id
|
|
|
|
* @param targetUCD the target UCD
|
|
|
|
* @return the project
|
|
|
|
*/
|
|
|
|
@PUT
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("{" + InterfaceConstants.Methods.RELATIONSHIP + "}/{" + InterfaceConstants.Parameters.PROJECT_ID + "}" + "/{"
|
|
|
|
+ InterfaceConstants.Parameters.RELATIONSHIP_ID + "}")
|
|
|
|
public Project setRelation(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,
|
|
|
|
@PathParam(InterfaceConstants.Parameters.RELATIONSHIP_ID) String relationshipId,
|
|
|
|
@QueryParam(InterfaceConstants.Parameters.TARGET_ID) String targetId,
|
|
|
|
@QueryParam(InterfaceConstants.Parameters.TARGET_UCD) String targetUCD) {
|
|
|
|
return new GuardedMethod<Project>() {
|
|
|
|
@Override
|
|
|
|
protected Project run() throws Exception, WebApplicationException {
|
|
|
|
log.info("Set relation from Project ({} : {}) [{}]-> ({} : {})",
|
|
|
|
manager.getUseCaseDescriptor().getId(), id, relationshipId, targetUCD, targetId);
|
|
|
|
String toUseTargetUCD = targetUCD;
|
|
|
|
if (toUseTargetUCD == null || toUseTargetUCD.isEmpty()) {
|
|
|
|
log.debug("Target UCD is null, forcing same UCD () as source ",
|
|
|
|
manager.getUseCaseDescriptor().getId());
|
|
|
|
toUseTargetUCD = manager.getUseCaseDescriptor().getId();
|
|
|
|
}
|
|
|
|
return manager.setRelation(id, relationshipId, toUseTargetUCD, targetId);
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete relation.
|
|
|
|
*
|
|
|
|
* @param id the id
|
|
|
|
* @param relationshipId the relationship id
|
|
|
|
* @param targetId the target id
|
|
|
|
* @param targetUCD the target UCD
|
|
|
|
* @return the project
|
|
|
|
*/
|
|
|
|
@DELETE
|
|
|
|
@Produces(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("{" + InterfaceConstants.Methods.RELATIONSHIP + "}/{" + InterfaceConstants.Parameters.PROJECT_ID + "}" + "/{"
|
|
|
|
+ InterfaceConstants.Parameters.RELATIONSHIP_ID + "}")
|
|
|
|
public Project deleteRelation(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,
|
|
|
|
@PathParam(InterfaceConstants.Parameters.RELATIONSHIP_ID) String relationshipId,
|
|
|
|
@QueryParam(InterfaceConstants.Parameters.TARGET_ID) String targetId,
|
|
|
|
@QueryParam(InterfaceConstants.Parameters.TARGET_UCD) String targetUCD) {
|
|
|
|
return new GuardedMethod<Project>() {
|
|
|
|
@Override
|
|
|
|
protected Project run() throws Exception, WebApplicationException {
|
|
|
|
log.info("Deleting relation from Project ({} : {}) [{}]-> ({} : {})",
|
|
|
|
manager.getUseCaseDescriptor().getId(), id, relationshipId, targetUCD, targetId);
|
|
|
|
return manager.deleteRelation(id, relationshipId, targetUCD, targetId);
|
|
|
|
}
|
|
|
|
}.execute().getResult();
|
|
|
|
}
|
2022-10-27 16:03:38 +02:00
|
|
|
|
2023-12-21 10:49:37 +01:00
|
|
|
}
|