Updated deleteFileSet

This commit is contained in:
Francesco Mangiacrapa 2023-04-26 12:34:50 +02:00
parent e871d0135e
commit 7eef6d1441
4 changed files with 804 additions and 443 deletions

View File

@ -19,6 +19,9 @@
<sis.version>1.0</sis.version>
<enunciate.version>2.14.0</enunciate.version>
<webappDirectory>${project.basedir}${file.separator}${project.artifactId}${file.separator}src${file.separator}main${file.separator}webapp${file.separator}WEB-INF</webappDirectory>
<!-- Enabled them for testing with JAVA 8 -->
<!-- <maven.compiler.source>1.8</maven.compiler.source> -->
<!-- <maven.compiler.target>1.8</maven.compiler.target> -->
</properties>
<scm>
@ -143,6 +146,37 @@
<scope>test</scope>
</dependency>
<!-- TEST with JDK1.8
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<scope>test</scope>
</dependency>
-->
<!-- Plugins related tests -->
<dependency>

View File

@ -236,9 +236,10 @@ public interface MongoManagerI<T> {
/**
* Delete file set.
*
* @param id the id
* @param destination the destination
* @param force the force
* @param id the id
* @param destination the destination
* @param force the force
* @param ignore_errors the ignore errors
* @return the t
* @throws ConfigurationException the configuration exception
* @throws StorageHubException the storage hub exception
@ -253,9 +254,8 @@ public interface MongoManagerI<T> {
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
*/
public T deleteFileSet(String id, String destination, Boolean force)
throws ConfigurationException, StorageHubException, StorageException, StepException,
JsonProcessingException, DeletionException, EventException, ProjectLockedException,
public T deleteFileSet(String id, String path, Boolean force, Boolean ignore_errors) throws ConfigurationException,
StorageHubException, JsonProcessingException, DeletionException, EventException, ProjectLockedException,
ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess;
/**

View File

@ -86,17 +86,41 @@ import com.vdurmont.semver4j.Semver;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
/**
* The Class ProfiledMongoManager.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 26, 2023
*/
@Slf4j
public class ProfiledMongoManager extends MongoManager implements MongoManagerI<Project> {
/**
* Gets the use case descriptor.
*
* @return the use case descriptor
*/
@Getter
UseCaseDescriptor useCaseDescriptor;
/**
* Mongo ID field name.
*
* @return the string
*/
@Override
protected String mongoIDFieldName() {
return ID;
}
/**
* Instantiates a new profiled mongo manager.
*
* @param profileId the profile id
* @throws ConfigurationException the configuration exception
* @throws RegistrationException the registration exception
*/
public ProfiledMongoManager(String profileId) throws ConfigurationException, RegistrationException {
// Check UseCaseDescriptor ID
log.info("Loading useCaseDescriptor ID {} ", profileId);
@ -112,11 +136,28 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
/**
* Gets the to use collection name.
*
* @return the to use collection name
*/
private String getToUseCollectionName() {
// TODO collection name in UCD
return useCaseDescriptor.getId();
}
/**
* Lock.
*
* @param id the id
* @param op the op
* @return the project
* @throws ProjectNotFoundException the project not found exception
* @throws ProjectLockedException the project locked exception
* @throws JsonProcessingException the json processing exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
*/
protected Project lock(String id, String op) throws ProjectNotFoundException, ProjectLockedException,
JsonProcessingException, InvalidUserRoleException, UnauthorizedAccess {
log.trace("Locking {} cause {} ", id, op);
@ -154,6 +195,17 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
return Serialization.convert(obj, Project.class);
}
/**
* Unlock and update.
*
* @param proj the proj
* @return the project
* @throws InvalidLockException the invalid lock exception
* @throws ProjectNotFoundException the project not found exception
* @throws JsonProcessingException the json processing exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
*/
protected Project unlockAndUpdate(Project proj) throws InvalidLockException, ProjectNotFoundException,
JsonProcessingException, InvalidUserRoleException, UnauthorizedAccess {
log.info("Unlocking for update {} lock is {} ", proj.getId(), proj.getLock());
@ -163,7 +215,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
Document filter = new Document(mongoIDFieldName(), asId(proj.getId())).append(Project.LOCK + "." + Lock.ID,
oldLock.getId());
log.info("Filter document is {} ", filter.toJson());
Object obj = getCollection().findOneAndReplace(
@ -181,19 +233,30 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
return Serialization.convert(obj, Project.class);
}
/**
* Unlock and patch.
*
* @param proj the proj
* @return the project
* @throws InvalidLockException the invalid lock exception
* @throws ProjectNotFoundException the project not found exception
* @throws JsonProcessingException the json processing exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
*/
protected Project unlockAndPatch(Project proj) throws InvalidLockException, ProjectNotFoundException,
JsonProcessingException, InvalidUserRoleException, UnauthorizedAccess {
log.info("Unlocking for patching {} lock is {} ", proj.getId(), proj.getLock());
// find one and update
Lock oldLock = proj.getLock();
Document filter = new Document(mongoIDFieldName(), asId(proj.getId())).append(Project.LOCK + "." + Lock.ID,
oldLock.getId());
String documentValueAsJson = proj.getTheDocument().toJson();
String updatedDocumentAsJson = new Document(Project.THE_DOCUMENT,documentValueAsJson).toJson();
String updatedDocumentAsJson = new Document(Project.THE_DOCUMENT, documentValueAsJson).toJson();
Document setUpdatedDocument = new Document("$set", updatedDocumentAsJson);
log.info("Filter document is {} ", filter.toJson());
log.info("$set is {} ", setUpdatedDocument);
@ -201,22 +264,32 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
// filter by id and missing lock
filter,
// update lock info
setUpdatedDocument,
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER));
setUpdatedDocument, new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER));
if (obj == null) {
// can-t unlock, check cause
throw new InvalidLockException(
"Found lock for " + proj.getId() + " is " + proj.getLock() + ", expected is " + oldLock);
}
//I could use Serialization.convert(obj, Project.class), but to be sure I'm reading again the project by
// I could use Serialization.convert(obj, Project.class), but to be sure I'm
// reading again the project by
proj = getByID(proj.getId());
proj = unlock(proj);
return proj;
}
/**
* Unlock.
*
* @param proj the proj
* @return the project
* @throws InvalidLockException the invalid lock exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws ProjectNotFoundException the project not found exception
* @throws UnauthorizedAccess the unauthorized access
*/
protected Project unlock(Project proj)
throws InvalidLockException, InvalidUserRoleException, ProjectNotFoundException, UnauthorizedAccess {
log.trace("Unlocking for update {} lock is {} ", proj.getId(), proj.getLock());
@ -241,9 +314,19 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
return Serialization.convert(obj, Project.class);
}
/**
* Gets the manager.
*
* @return the manager
*/
@Getter(lazy = true)
private final LifecycleManager manager = getLCManager();
/**
* Gets the LC manager.
*
* @return the LC manager
*/
private LifecycleManager getLCManager() {
try {
LifecycleManager toReturn = null;
@ -274,6 +357,14 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* Register new.
*
* @param toRegisterDoc the to register doc
* @return the project
* @throws IOException Signals that an I/O exception has occurred.
* @throws InvalidUserRoleException the invalid user role exception
*/
@Override
public Project registerNew(Document toRegisterDoc) throws IOException, InvalidUserRoleException {
log.info("Registering new document in {} ", useCaseDescriptor.getId());
@ -329,6 +420,20 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* Update.
*
* @param id the id
* @param toSet the to set
* @return the project
* @throws IOException Signals that an I/O exception has occurred.
* @throws EventException the event exception
* @throws ProjectLockedException the project locked exception
* @throws ProjectNotFoundException the project not found exception
* @throws InvalidLockException the invalid lock exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
*/
@Override
public Project update(String id, Document toSet) throws IOException, EventException, ProjectLockedException,
ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess {
@ -359,6 +464,20 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* Patch.
*
* @param id the id
* @param toSet the to set
* @return the project
* @throws IOException Signals that an I/O exception has occurred.
* @throws EventException the event exception
* @throws ProjectLockedException the project locked exception
* @throws ProjectNotFoundException the project not found exception
* @throws InvalidLockException the invalid lock exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
*/
@Override
public Project patch(String id, Document toSet) throws IOException, EventException, ProjectLockedException,
ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess {
@ -389,6 +508,24 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* Sets the relation.
*
* @param id the id
* @param relation the relation
* @param targetUCD the target UCD
* @param targetId the target id
* @return the project
* @throws IOException Signals that an I/O exception has occurred.
* @throws EventException the event exception
* @throws ProjectLockedException the project locked exception
* @throws ProjectNotFoundException the project not found exception
* @throws InvalidLockException the invalid lock exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
* @throws RegistrationException the registration exception
* @throws ConfigurationException the configuration exception
*/
@Override
public Project setRelation(String id, String relation, String targetUCD, String targetId)
throws IOException, EventException, ProjectLockedException, ProjectNotFoundException, InvalidLockException,
@ -451,6 +588,24 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* Delete relation.
*
* @param id the id
* @param relation the relation
* @param targetUCD the target UCD
* @param targetId the target id
* @return the project
* @throws IOException Signals that an I/O exception has occurred.
* @throws EventException the event exception
* @throws ProjectLockedException the project locked exception
* @throws ProjectNotFoundException the project not found exception
* @throws InvalidLockException the invalid lock exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
* @throws RegistrationException the registration exception
* @throws ConfigurationException the configuration exception
*/
@Override
public Project deleteRelation(String id, String relation, String targetUCD, String targetId)
throws IOException, EventException, ProjectLockedException, ProjectNotFoundException, InvalidLockException,
@ -523,6 +678,13 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* On update.
*
* @param toUpdate the to update
* @return the project
* @throws EventException the event exception
*/
private Project onUpdate(Project toUpdate) throws EventException {
UserUtils.AuthenticatedUser u = UserUtils.getCurrent();
toUpdate.getInfo().setLastEditInfo(u.asInfo());
@ -537,6 +699,19 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
// return triggerEvent(toUpdate, EventExecutionRequest.Events.ON_UPDATE_DOCUMENT, null);
// }
/**
* Delete.
*
* @param id the id
* @param force the force
* @throws DeletionException the deletion exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws ProjectLockedException the project locked exception
* @throws ProjectNotFoundException the project not found exception
* @throws UnauthorizedAccess the unauthorized access
* @throws JsonProcessingException the json processing exception
* @throws InvalidLockException the invalid lock exception
*/
@Override
public void delete(String id, boolean force)
throws DeletionException, InvalidUserRoleException, ProjectLockedException, ProjectNotFoundException,
@ -580,6 +755,15 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* Gets the by ID.
*
* @param id the id
* @return the by ID
* @throws ProjectNotFoundException the project not found exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
*/
@Override
public Project getByID(String id) throws ProjectNotFoundException, InvalidUserRoleException, UnauthorizedAccess {
User u = UserUtils.getCurrent().asInfo().getUser();
@ -602,6 +786,13 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
return p;
}
/**
* Query.
*
* @param queryRequest the query request
* @return the iterable
* @throws InvalidUserRoleException the invalid user role exception
*/
@Override
public Iterable<Document> query(QueryRequest queryRequest) throws InvalidUserRoleException {
LinkedBlockingQueue queue = new LinkedBlockingQueue<Project>();
@ -642,6 +833,13 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
return queue;
}
/**
* Filter.
*
* @param queryRequest the query request
* @return the iterable
* @throws InvalidUserRoleException the invalid user role exception
*/
@Override
public Iterable<Project> filter(QueryRequest queryRequest) throws InvalidUserRoleException {
LinkedBlockingQueue queue = new LinkedBlockingQueue<Project>();
@ -682,6 +880,23 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
return queue;
}
/**
* Perform step.
*
* @param id the id
* @param step the step
* @param options the options
* @return the project
* @throws StepException the step exception
* @throws JsonProcessingException the json processing exception
* @throws ProjectLockedException the project locked exception
* @throws ProjectNotFoundException the project not found exception
* @throws InvalidLockException the invalid lock exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
* @throws ConfigurationException the configuration exception
* @throws InsufficientPrivileges the insufficient privileges
*/
@Override
public Project performStep(String id, String step, Document options) throws StepException, JsonProcessingException,
ProjectLockedException, ProjectNotFoundException, InvalidLockException, InvalidUserRoleException,
@ -723,11 +938,22 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
/**
* NB Put at path :
*
*
* Path Examples artifact images images[1] layers[?(@.name = 'myName')].fileset
*
*
*
* @param id the id
* @param request the request
* @return the project
* @throws ConfigurationException the configuration exception
* @throws StorageHubException the storage hub exception
* @throws StorageException the storage exception
* @throws JsonProcessingException the json processing exception
* @throws EventException the event exception
* @throws ProjectLockedException the project locked exception
* @throws ProjectNotFoundException the project not found exception
* @throws InvalidLockException the invalid lock exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
*/
@Override
public Project registerFileSet(String id, RegisterFileSetRequest request) throws ConfigurationException,
@ -810,7 +1036,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
RegisteredFileSet.class);
if (!(toDelete == null) && !(toDelete.isEmpty())) {
String path = parentMatchingPath + "." + request.getFieldName();
deleteFileSetRoutine(doc, false, path);
deleteFileSetRoutine(doc, false, false, path);
}
RegisteredFileSet fs = prepareRegisteredFileSet(toSetAccess, doc.getId(), useCaseDescriptor.getId(),
@ -872,12 +1098,32 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* Delete file set.
*
* @param id the id
* @param path the path
* @param force the force
* @param ignore_errors the ignore errors
* @return the project
* @throws ConfigurationException the configuration exception
* @throws StorageHubException the storage hub exception
* @throws JsonProcessingException the json processing exception
* @throws DeletionException the deletion exception
* @throws EventException the event exception
* @throws ProjectLockedException the project locked exception
* @throws ProjectNotFoundException the project not found exception
* @throws InvalidLockException the invalid lock exception
* @throws InvalidUserRoleException the invalid user role exception
* @throws UnauthorizedAccess the unauthorized access
*/
@Override
public Project deleteFileSet(String id, String path, Boolean force) throws ConfigurationException,
StorageHubException, JsonProcessingException, DeletionException, EventException, ProjectLockedException,
ProjectNotFoundException, InvalidLockException, InvalidUserRoleException, UnauthorizedAccess {
log.info("Deleting Fileset for {} [useCaseDescriptor ID {}], at {} [force {} ]", id, useCaseDescriptor.getId(),
path, force);
public Project deleteFileSet(String id, String path, Boolean force, Boolean ignore_errors)
throws ConfigurationException, StorageHubException, JsonProcessingException, DeletionException,
EventException, ProjectLockedException, ProjectNotFoundException, InvalidLockException,
InvalidUserRoleException, UnauthorizedAccess {
log.info("Deleting Fileset for {} [useCaseDescriptor ID {}], at {} [force {} and ignore_errors {}]", id,
useCaseDescriptor.getId(), path, force, ignore_errors);
Project doc = lock(id, "Fileset Deletion");
try {
User u = UserUtils.getCurrent().asInfo().getUser();
@ -895,7 +1141,10 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
doc.getLifecycleInformation().cleanState();
doc.getLifecycleInformation().cleanState().setLastOperationStatus(LifecycleInformation.Status.OK);
doc = deleteFileSetRoutine(doc, force, path);
if (ignore_errors == null)
ignore_errors = false;
doc = deleteFileSetRoutine(doc, force, ignore_errors, path);
return unlockAndUpdate(doc);
} catch (Throwable t) {
log.warn("Unexpected Exception while trying to delete fileset on {}.", id, t);
@ -904,6 +1153,17 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* Force unlock.
*
* @param id the id
* @return the project
* @throws InvalidUserRoleException the invalid user role exception
* @throws ProjectNotFoundException the project not found exception
* @throws UnauthorizedAccess the unauthorized access
* @throws JsonProcessingException the json processing exception
* @throws InvalidLockException the invalid lock exception
*/
@Override
public Project forceUnlock(String id) throws InvalidUserRoleException, ProjectNotFoundException, UnauthorizedAccess,
JsonProcessingException, InvalidLockException {
@ -922,6 +1182,20 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* Sets the access policy.
*
* @param id the id
* @param access the access
* @return the project
* @throws InvalidUserRoleException the invalid user role exception
* @throws ProjectLockedException the project locked exception
* @throws ProjectNotFoundException the project not found exception
* @throws UnauthorizedAccess the unauthorized access
* @throws JsonProcessingException the json processing exception
* @throws InvalidLockException the invalid lock exception
* @throws EventException the event exception
*/
@Override
public Project setAccessPolicy(String id, Access access)
throws InvalidUserRoleException, ProjectLockedException, ProjectNotFoundException, UnauthorizedAccess,
@ -951,16 +1225,41 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
private Project deleteFileSetRoutine(Project doc, Boolean force, String path)
/**
* Delete file set routine. updated by Francesco
*
* @param doc the doc
* @param force the force
* @param ignore_errors the ignore errors
* @param path the path
* @return the project
* @throws ConfigurationException the configuration exception
* @throws StorageHubException the storage hub exception
*/
private Project deleteFileSetRoutine(Project doc, Boolean force, Boolean ignore_errors, String path)
throws ConfigurationException, StorageHubException {
log.info("Delete[force : {}] FS at {} for {}:{}", force, path, doc.getProfileID(), doc.getId());
log.info("Delete[force : {}, ignore_errors: {}] FS at {} for {}:{}", force, ignore_errors, path,
doc.getProfileID(), doc.getId());
JSONPathWrapper wrapper = new JSONPathWrapper(doc.getTheDocument().toJson());
List<String> matchingPaths = wrapper.getMatchingPaths(path);
if (matchingPaths.isEmpty())
throw new WebApplicationException("No Registered FileSet found at " + path, Response.Status.BAD_REQUEST);
if (matchingPaths.size() > 1)
throw new WebApplicationException("Multiple Fileset (" + matchingPaths.size() + ") matching " + path,
Response.Status.BAD_REQUEST);
String error = null;
if (matchingPaths.isEmpty()) {
error = "No Registered FileSet found at " + path;
if (!ignore_errors) {
throw new WebApplicationException(error, Response.Status.BAD_REQUEST);
}
}
if (matchingPaths.size() > 1 && !ignore_errors) {
error = "Multiple Fileset (" + matchingPaths.size() + ") matching " + path;
if (!ignore_errors)
throw new WebApplicationException(error, Response.Status.BAD_REQUEST);
}
if (error != null && ignore_errors) {
log.info("Error detected {}. Ignoring it and returning input doc", error);
return doc;
}
RegisteredFileSet fs = Serialization.convert(wrapper.getByPath(path).get(0), RegisteredFileSet.class);
log.debug("Going to delete {}", fs);
@ -1000,6 +1299,12 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
return doc;
}
/**
* Gets the configuration.
*
* @return the configuration
* @throws ConfigurationException the configuration exception
*/
@Override
public Configuration getConfiguration() throws ConfigurationException {
String context = UserUtils.getCurrent().getContext();
@ -1072,6 +1377,17 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
return toReturn;
}
/**
* Step.
*
* @param theDocument the the document
* @param step the step
* @param callParameters the call parameters
* @return the project
* @throws InsufficientPrivileges the insufficient privileges
* @throws ConfigurationException the configuration exception
* @throws StepException the step exception
*/
private Project step(Project theDocument, String step, Document callParameters)
throws InsufficientPrivileges, ConfigurationException, StepException {
try {
@ -1120,6 +1436,14 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* Trigger event.
*
* @param project the project
* @param event the event
* @param parameters the parameters
* @return the project
*/
private Project triggerEvent(Project project, String event, Document parameters) {
try {
log.info("[UseCaseDescriptor {}] triggering event {} on {}", useCaseDescriptor.getId(), event,
@ -1140,6 +1464,20 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
}
}
/**
* Prepare registered file set.
*
* @param toSetAccess the to set access
* @param docID the doc ID
* @param profileID the profile ID
* @param attributes the attributes
* @param files the files
* @param storage the storage
* @param ws the ws
* @return the registered file set
* @throws StorageHubException the storage hub exception
* @throws StorageException the storage exception
*/
private static final RegisteredFileSet prepareRegisteredFileSet(Access toSetAccess, String docID, String profileID,
Document attributes, List<TempFile> files, StorageUtils storage, WorkspaceManager ws)
throws StorageHubException, StorageException {
@ -1203,6 +1541,14 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
return toReturn;
}
/**
* Gets the field definition.
*
* @param useCaseDescriptor the use case descriptor
* @param fieldPath the field path
* @return the field definition
* @throws WebApplicationException the web application exception
*/
private static Field getFieldDefinition(UseCaseDescriptor useCaseDescriptor, String fieldPath)
throws WebApplicationException {
JSONPathWrapper schemaWrapper = new JSONPathWrapper(useCaseDescriptor.getSchema().toJson());

View File

@ -36,444 +36,425 @@ import lombok.extern.slf4j.Slf4j;
/**
* The Class ProfiledDocuments.
* @author created by Fabio Sinibaldi
* @author maintainer - Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Apr 18, 2023
* @author created by Fabio Sinibaldi
* @author new manager/developer and mantainer - Francesco Mangiacrapa at ISTI-CNR
* francesco.mangiacrapa@isti.cnr.it
*
* Apr 18, 2023
*/
@Path(InterfaceConstants.Methods.PROJECTS+"/{"+InterfaceConstants.Parameters.UCID +"}")
@Path(InterfaceConstants.Methods.PROJECTS + "/{" + InterfaceConstants.Parameters.UCID + "}")
@Slf4j
@RequestHeaders({
@RequestHeader( name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
@RequestHeader( name = "Content-Type", description = "application/json")
})
@RequestHeader(name = "Authorization", description = "Bearer token, see https://dev.d4science.org/how-to-access-resources"),
@RequestHeader(name = "Content-Type", description = "application/json") })
public class ProfiledDocuments {
private ProfiledMongoManager manager;
private ProfiledMongoManager manager;
/**
* 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();
}
/**
* 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>(){
/**
* 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();
}
@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) {
return new GuardedMethod<Project>() {
@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();
}
/**
* Creates the new.
*
* @param d the d
* @return the project
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Project createNew(Document d) {
return new GuardedMethod<Project>() {
@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();
}
/**
* 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) {
return new GuardedMethod<Project>() {
@Override
protected Project run() throws Exception, WebApplicationException {
log.info("Updating Project ({}, ID {})", manager.getUseCaseDescriptor().getId(), documentId);
return manager.update(documentId, d);
}
}.execute().getResult();
}
/**
* 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();
}
/**
* 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) {
return new GuardedMethod<Project>() {
@Override
protected Project run() throws Exception, WebApplicationException {
log.info("Updating Project ({}, ID {})",manager.getUseCaseDescriptor().getId(),documentId);
return manager.update(documentId,d);
}
}.execute().getResult();
}
/**
* 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);
}
}.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) {
return new GuardedMethod<Boolean>() {
@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();
}
/**
* 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.
*
* @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) {
return new GuardedMethod<Boolean>() {
@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();
}
/**
* 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,
@DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.IGNORE_ERRORS) Boolean ignore_errors, String path) {
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();
}
/**
* 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();
}
/**
* 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,
StepExecutionRequest request) {
return new GuardedMethod<Project>() {
@Override
protected Project run() throws Exception, WebApplicationException {
log.info("Executing step {} on Project ({},ID,{}) with options {}", request.getStepID(),
manager.getUseCaseDescriptor().getId(), id, request.getOptions());
return manager.performStep(id, request.getStepID(), request.getOptions());
}
}.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,
String path) {
return new GuardedMethod<Project>() {
@Override
protected Project run() throws Exception, WebApplicationException {
log.info("Deleting FileSet of Project ({}, ID {}) at path {}. Force is {}",
manager.getUseCaseDescriptor().getId(),
id,path,force);
return manager.deleteFileSet(id,path,force);
}
}.execute().getResult();
}
/**
* 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();
}
/**
* 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,
StepExecutionRequest request) {
return new GuardedMethod<Project>() {
@Override
protected Project run() throws Exception, WebApplicationException {
log.info("Executing step {} on Project ({},ID,{}) with options {}",
request.getStepID(),
manager.getUseCaseDescriptor().getId(),
id,request.getOptions());
return manager.performStep(id,request.getStepID(),request.getOptions());
}
}.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>() {
/**
* 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 {}, setting Policy {} Project ID {}", manager.getUseCaseDescriptor().getId(), toSet, id);
return manager.setAccessPolicy(id, toSet);
}
}.execute().getResult();
}
@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();
}
// ********************************** READ
/**
* 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>(){
/**
* 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();
}
@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();
}
/**
* 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();
}
//********************************** READ
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
/**
* 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();
}
// 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();
}
}