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 id the id
|
||||||
* @param force the force
|
* @param force the force
|
||||||
|
* @param ignoreErrors the ignore errors
|
||||||
* @throws DeletionException the deletion exception
|
* @throws DeletionException the deletion exception
|
||||||
* @throws InvalidUserRoleException the invalid user role exception
|
* @throws InvalidUserRoleException the invalid user role exception
|
||||||
* @throws ProjectLockedException the project locked exception
|
* @throws ProjectLockedException the project locked exception
|
||||||
|
@ -149,7 +150,7 @@ public interface MongoManagerI<T> {
|
||||||
* @throws JsonProcessingException the json processing exception
|
* @throws JsonProcessingException the json processing exception
|
||||||
* @throws InvalidLockException the invalid lock 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,
|
throws DeletionException, InvalidUserRoleException, ProjectLockedException, ProjectNotFoundException,
|
||||||
UnauthorizedAccess, JsonProcessingException, InvalidLockException;
|
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.HandlerDeclaration;
|
||||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.RelationshipDefinition;
|
import org.gcube.application.geoportal.common.model.useCaseDescriptor.RelationshipDefinition;
|
||||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
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.common.utils.StorageUtils;
|
||||||
import org.gcube.application.geoportal.service.engine.providers.PluginManager;
|
import org.gcube.application.geoportal.service.engine.providers.PluginManager;
|
||||||
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
||||||
|
@ -704,6 +705,7 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
*
|
*
|
||||||
* @param id the id
|
* @param id the id
|
||||||
* @param force the force
|
* @param force the force
|
||||||
|
* @param ignoreErrors the ignore errors
|
||||||
* @throws DeletionException the deletion exception
|
* @throws DeletionException the deletion exception
|
||||||
* @throws InvalidUserRoleException the invalid user role exception
|
* @throws InvalidUserRoleException the invalid user role exception
|
||||||
* @throws ProjectLockedException the project locked exception
|
* @throws ProjectLockedException the project locked exception
|
||||||
|
@ -711,12 +713,14 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
* @throws UnauthorizedAccess the unauthorized access
|
* @throws UnauthorizedAccess the unauthorized access
|
||||||
* @throws JsonProcessingException the json processing exception
|
* @throws JsonProcessingException the json processing exception
|
||||||
* @throws InvalidLockException the invalid lock exception
|
* @throws InvalidLockException the invalid lock exception
|
||||||
|
*
|
||||||
|
* Updated by Francesco Mangiacrapa
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void delete(String id, boolean force)
|
public void delete(String id, boolean force, Boolean ignoreErrors)
|
||||||
throws DeletionException, InvalidUserRoleException, ProjectLockedException, ProjectNotFoundException,
|
throws DeletionException, InvalidUserRoleException, ProjectLockedException, ProjectNotFoundException,
|
||||||
UnauthorizedAccess, JsonProcessingException, InvalidLockException {
|
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 + "}");
|
Project doc = lock(id, "Deletion { force : " + force + "}");
|
||||||
boolean deleted = false;
|
boolean deleted = false;
|
||||||
try {
|
try {
|
||||||
|
@ -728,7 +732,10 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
||||||
if (!policy.canWrite(doc, u))
|
if (!policy.canWrite(doc, u))
|
||||||
throw new UnauthorizedAccess("No edit rights on project " + id);
|
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
|
// Only continue deleting if event was ok
|
||||||
if (doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) {
|
if (doc.getLifecycleInformation().getLastOperationStatus().equals(LifecycleInformation.Status.OK)) {
|
||||||
try {
|
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.engine.providers.ProjectAccessImpl;
|
||||||
import org.gcube.application.geoportal.service.http.PATCH;
|
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.RequestHeader;
|
||||||
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
import com.webcohesion.enunciate.metadata.rs.RequestHeaders;
|
||||||
|
|
||||||
|
@ -234,6 +235,24 @@ public class ProfiledDocuments {
|
||||||
@Path("{" + InterfaceConstants.Parameters.PROJECT_ID + "}")
|
@Path("{" + InterfaceConstants.Parameters.PROJECT_ID + "}")
|
||||||
public Boolean delete(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,
|
public Boolean delete(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,
|
||||||
@DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force) {
|
@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,
|
String path = CalledMethodHandler.buildCalledResource(HttpMethod.DELETE,
|
||||||
"/" + InterfaceConstants.Methods.PROJECTS + "/" + manager.getUseCaseDescriptor().getId());
|
"/" + InterfaceConstants.Methods.PROJECTS + "/" + manager.getUseCaseDescriptor().getId());
|
||||||
|
@ -242,9 +261,9 @@ public class ProfiledDocuments {
|
||||||
Boolean deleted = new GuardedMethod<Boolean>() {
|
Boolean deleted = new GuardedMethod<Boolean>() {
|
||||||
@Override
|
@Override
|
||||||
protected Boolean run() throws Exception, WebApplicationException {
|
protected Boolean run() throws Exception, WebApplicationException {
|
||||||
log.info("Deleting Project ({}, ID {}). Force is {}", manager.getUseCaseDescriptor().getId(), id,
|
log.info("Deleting Project ({}, ID {}). Force is {}, Ignore_Errors is {}", manager.getUseCaseDescriptor().getId(), id,
|
||||||
force);
|
force, ignoreErrors);
|
||||||
manager.delete(id, force);
|
manager.delete(id, force, ignoreErrors);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}.execute().getResult();
|
}.execute().getResult();
|
||||||
|
@ -300,6 +319,7 @@ public class ProfiledDocuments {
|
||||||
}.execute().getResult();
|
}.execute().getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete file set. the Authorization must be a VRE token
|
* Delete file set. the Authorization must be a VRE token
|
||||||
*
|
*
|
||||||
|
@ -315,6 +335,31 @@ public class ProfiledDocuments {
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Path("/" + InterfaceConstants.Methods.DELETE_FILES_PATH + "/{" + InterfaceConstants.Parameters.PROJECT_ID + "}")
|
@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,
|
public Project deleteFileSet(@PathParam(InterfaceConstants.Parameters.PROJECT_ID) String id,
|
||||||
@DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force,
|
@DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.FORCE) Boolean force,
|
||||||
@DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.IGNORE_ERRORS) Boolean ignore_errors,
|
@DefaultValue("false") @QueryParam(InterfaceConstants.Parameters.IGNORE_ERRORS) Boolean ignore_errors,
|
||||||
|
|
Loading…
Reference in New Issue