Added and managed ignore_errors to delete method
This commit is contained in:
parent
5a4d79b7d6
commit
2453a56f19
|
@ -141,6 +141,7 @@ public interface MongoManagerI<T> {
|
|||
*
|
||||
* @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<T> {
|
|||
* @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;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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<Boolean>() {
|
||||
@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();
|
||||
|
@ -300,6 +319,7 @@ 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,
|
||||
|
|
Loading…
Reference in New Issue