From 2453a56f195325be44ef0e7f6cd4d6007c2800a1 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Fri, 10 May 2024 10:54:03 +0200 Subject: [PATCH] Added and managed ignore_errors to delete method --- .../service/engine/mongo/MongoManagerI.java | 3 +- .../engine/mongo/ProfiledMongoManager.java | 13 ++++- .../service/rest/ProfiledDocuments.java | 55 +++++++++++++++++-- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManagerI.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManagerI.java index 97f0734..f8b0924 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManagerI.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/MongoManagerI.java @@ -141,6 +141,7 @@ public interface MongoManagerI { * * @param id the id * @param force the force + * @param ignoreErrors the ignore errors * @throws DeletionException the deletion exception * @throws InvalidUserRoleException the invalid user role exception * @throws ProjectLockedException the project locked exception @@ -149,7 +150,7 @@ public interface MongoManagerI { * @throws JsonProcessingException the json processing exception * @throws InvalidLockException the invalid lock exception */ - public void delete(String id, boolean force) + public void delete(String id, boolean force, Boolean ignoreErrors) throws DeletionException, InvalidUserRoleException, ProjectLockedException, ProjectNotFoundException, UnauthorizedAccess, JsonProcessingException, InvalidLockException; diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java index a7b3f69..2cde1bc 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/engine/mongo/ProfiledMongoManager.java @@ -71,6 +71,7 @@ import org.gcube.application.geoportal.common.model.useCaseDescriptor.Field; import org.gcube.application.geoportal.common.model.useCaseDescriptor.HandlerDeclaration; import org.gcube.application.geoportal.common.model.useCaseDescriptor.RelationshipDefinition; import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor; +import org.gcube.application.geoportal.common.rest.InterfaceConstants; import org.gcube.application.geoportal.common.utils.StorageUtils; import org.gcube.application.geoportal.service.engine.providers.PluginManager; import org.gcube.common.storagehub.client.dsl.FolderContainer; @@ -704,6 +705,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI< * * @param id the id * @param force the force + * @param ignoreErrors the ignore errors * @throws DeletionException the deletion exception * @throws InvalidUserRoleException the invalid user role exception * @throws ProjectLockedException the project locked exception @@ -711,12 +713,14 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI< * @throws UnauthorizedAccess the unauthorized access * @throws JsonProcessingException the json processing exception * @throws InvalidLockException the invalid lock exception + * + * Updated by Francesco Mangiacrapa */ @Override - public void delete(String id, boolean force) + public void delete(String id, boolean force, Boolean ignoreErrors) throws DeletionException, InvalidUserRoleException, ProjectLockedException, ProjectNotFoundException, UnauthorizedAccess, JsonProcessingException, InvalidLockException { - log.info("Deleting by ID {}, force {}", id, force); + log.info("Deleting by ID {}, force {} ignoreErrors {}", id, force, ignoreErrors); Project doc = lock(id, "Deletion { force : " + force + "}"); boolean deleted = false; try { @@ -728,7 +732,10 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI< if (!policy.canWrite(doc, u)) throw new UnauthorizedAccess("No edit rights on project " + id); - doc = triggerEvent(doc, EventExecutionRequest.Events.ON_DELETE_DOCUMENT, new Document("force", force)); + Document parameters = new Document(); + parameters.append(InterfaceConstants.Parameters.FORCE, force); + parameters.append(InterfaceConstants.Parameters.IGNORE_ERRORS, ignoreErrors); + doc = triggerEvent(doc, EventExecutionRequest.Events.ON_DELETE_DOCUMENT, parameters); // Only continue deleting if event was ok if (doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) { try { diff --git a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java index ed23674..8c2726a 100644 --- a/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java +++ b/geoportal-service/src/main/java/org/gcube/application/geoportal/service/rest/ProfiledDocuments.java @@ -39,6 +39,7 @@ import org.gcube.application.geoportal.service.engine.providers.ConfigurationCac import org.gcube.application.geoportal.service.engine.providers.ProjectAccessImpl; import org.gcube.application.geoportal.service.http.PATCH; +import com.webcohesion.enunciate.metadata.Ignore; import com.webcohesion.enunciate.metadata.rs.RequestHeader; import com.webcohesion.enunciate.metadata.rs.RequestHeaders; @@ -221,7 +222,7 @@ public class ProfiledDocuments { } }.execute().getResult(); } - + /** * Delete. * @@ -234,6 +235,24 @@ public class ProfiledDocuments { @Path("{" + InterfaceConstants.Parameters.PROJECT_ID + "}") public Boolean delete(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, @DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force) { + return delete(id, force, false); + } + + /** + * Delete. + * + * @param id the id + * @param force the force + * @return the boolean + * + * @Ignore means excluded by API doc + */ + @DELETE + @Produces(MediaType.APPLICATION_JSON) + @Path("{" + InterfaceConstants.Parameters.PROJECT_ID + "}") + @Ignore + public Boolean delete(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id, + @DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force, @QueryParam(InterfaceConstants.Parameters.IGNORE_ERRORS) Boolean ignoreErrors) { String path = CalledMethodHandler.buildCalledResource(HttpMethod.DELETE, "/" + InterfaceConstants.Methods.PROJECTS + "/" + manager.getUseCaseDescriptor().getId()); @@ -242,9 +261,9 @@ public class ProfiledDocuments { Boolean deleted = new GuardedMethod() { @Override protected Boolean run() throws Exception, WebApplicationException { - log.info("Deleting Project ({}, ID {}). Force is {}", manager.getUseCaseDescriptor().getId(), id, - force); - manager.delete(id, force); + log.info("Deleting Project ({}, ID {}). Force is {}, Ignore_Errors is {}", manager.getUseCaseDescriptor().getId(), id, + force, ignoreErrors); + manager.delete(id, force, ignoreErrors); return true; } }.execute().getResult(); @@ -299,7 +318,8 @@ public class ProfiledDocuments { } }.execute().getResult(); } - + + /** * Delete file set. the Authorization must be a VRE token * @@ -315,6 +335,31 @@ public class ProfiledDocuments { @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 deleteFileSet(id, force, false, path); + } + + + /** + * 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 + * + * @Ignore means that is excluded by API doc + */ + @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 + "}") + @Ignore 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,