Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)

124825 gjames: RA-849: Restore Deleted Node


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126592 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2016-05-10 11:43:34 +00:00
parent a0a32ef095
commit 3e05671735
4 changed files with 88 additions and 0 deletions

View File

@@ -18,9 +18,11 @@
*/
package org.alfresco.rest.api;
import org.alfresco.repo.node.archive.RestoreNodeReport;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Handles trashcan / deleted nodes
@@ -31,4 +33,5 @@ public interface DeletedNodes
{
CollectionWithPagingInfo<Node> listDeleted(Parameters parameters);
Node getDeletedNode(String originalId, Parameters parameters);
Node restoreArchivedNode(String archivedId);
}

View File

@@ -22,11 +22,18 @@ import org.alfresco.model.ContentModel;
import org.alfresco.query.PagingRequest;
import org.alfresco.query.PagingResults;
import org.alfresco.repo.node.archive.ArchivedNodesCannedQueryBuilder;
import org.alfresco.repo.node.archive.RestoreNodeReport;
import org.alfresco.repo.node.integrity.IntegrityException;
import org.alfresco.rest.api.model.Node;
import org.alfresco.repo.node.archive.NodeArchiveService;
import org.alfresco.rest.api.DeletedNodes;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.model.UserInfo;
import org.alfresco.rest.framework.core.exceptions.ApiException;
import org.alfresco.rest.framework.core.exceptions.ConstraintViolatedException;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.core.exceptions.NotFoundException;
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.service.ServiceRegistry;
@@ -128,4 +135,29 @@ public class DeletedNodesImpl implements DeletedNodes
if (foundNode != null) mapArchiveInfo(foundNode,null);
return foundNode;
}
@Override
public Node restoreArchivedNode(String archivedId)
{
//First check the node is valid and has been archived.
NodeRef validatedNodeRef = nodes.validateNode(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, archivedId);
RestoreNodeReport restored = nodeArchiveService.restoreArchivedNode(validatedNodeRef);
switch (restored.getStatus())
{
case SUCCESS:
return nodes.getFolderOrDocumentFullInfo(restored.getRestoredNodeRef(), null, null, null, null);
case FAILURE_PERMISSION:
throw new PermissionDeniedException();
case FAILURE_INTEGRITY:
throw new IntegrityException("Restore failed due to an integrity error", null);
case FAILURE_DUPLICATE_CHILD_NODE_NAME:
throw new ConstraintViolatedException("Name already exists in target");
case FAILURE_INVALID_ARCHIVE_NODE:
throw new EntityNotFoundException(archivedId);
case FAILURE_INVALID_PARENT:
throw new NotFoundException("Invalid parent id "+restored.getTargetParentNodeRef());
default:
throw new ApiException("Unable to restore node "+archivedId);
}
}
}

View File

@@ -27,11 +27,15 @@ import org.alfresco.rest.api.DeletedNodes;
import org.alfresco.rest.api.Nodes;
import org.alfresco.rest.api.impl.Util;
import org.alfresco.rest.api.model.Node;
import org.alfresco.rest.api.model.NodeTarget;
import org.alfresco.rest.framework.Operation;
import org.alfresco.rest.framework.WebApiDescription;
import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException;
import org.alfresco.rest.framework.resource.EntityResource;
import org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction;
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
import org.alfresco.rest.framework.resource.parameters.Parameters;
import org.alfresco.rest.framework.webscripts.WithResponse;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
@@ -66,4 +70,11 @@ public class TrashcanEntityResource implements
{
return deletedNodes.getDeletedNode(id, parameters);
}
@Operation("restore")
@WebApiDescription(title = "Restore deleted Node", description="Restores an archived node")
public Node restoreDeletedNode(String nodeId, Void ignored, Parameters parameters, WithResponse withResponse)
{
return deletedNodes.restoreArchivedNode(nodeId);
}
}