mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
126581 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 124740 gjames: RA-847, RA-848 Retrieving deleted nodes git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126926 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
131
source/java/org/alfresco/rest/api/impl/DeletedNodesImpl.java
Normal file
131
source/java/org/alfresco/rest/api/impl/DeletedNodesImpl.java
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2016 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.rest.api.impl;
|
||||
|
||||
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.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.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Handles trashcan / deleted nodes
|
||||
*
|
||||
* @author Gethin James
|
||||
*/
|
||||
public class DeletedNodesImpl implements DeletedNodes
|
||||
{
|
||||
private NodeArchiveService nodeArchiveService;
|
||||
private PersonService personService;
|
||||
private NodeService nodeService;
|
||||
private Nodes nodes;
|
||||
|
||||
public void setNodeArchiveService(NodeArchiveService nodeArchiveService)
|
||||
{
|
||||
this.nodeArchiveService = nodeArchiveService;
|
||||
}
|
||||
|
||||
public void setPersonService(PersonService personService)
|
||||
{
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setNodes(Nodes nodes)
|
||||
{
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets archived information on the Node
|
||||
* @param aNode
|
||||
* @param mapUserInfo
|
||||
*/
|
||||
private void mapArchiveInfo(Node aNode, Map<String, UserInfo> mapUserInfo)
|
||||
{
|
||||
if (mapUserInfo == null) {
|
||||
mapUserInfo = new HashMap<>();
|
||||
}
|
||||
Map<QName, Serializable> nodeProps = nodeService.getProperties(aNode.getNodeRef());
|
||||
aNode.setArchivedAt((Date)nodeProps.get(ContentModel.PROP_ARCHIVED_DATE));
|
||||
aNode.setArchivedByUser(aNode.lookupUserInfo((String)nodeProps.get(ContentModel.PROP_ARCHIVED_BY), mapUserInfo, personService));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionWithPagingInfo<Node> listDeleted(Parameters parameters)
|
||||
{
|
||||
PagingRequest pagingRequest = Util.getPagingRequest(parameters.getPaging());
|
||||
NodeRef archiveStoreRootNodeRef = nodeService.getStoreArchiveNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
|
||||
|
||||
// Create canned query
|
||||
ArchivedNodesCannedQueryBuilder queryBuilder = new ArchivedNodesCannedQueryBuilder.Builder(
|
||||
archiveStoreRootNodeRef, pagingRequest).sortOrderAscending(false).build();
|
||||
|
||||
// Query the DB
|
||||
PagingResults<NodeRef> result = nodeArchiveService.listArchivedNodes(queryBuilder);
|
||||
List<Node> nodesFound = new ArrayList<Node>(result.getPage().size());
|
||||
Map mapUserInfo = new HashMap<>();
|
||||
for (NodeRef nRef:result.getPage())
|
||||
{
|
||||
Node foundNode = nodes.getFolderOrDocument(nRef, null, null, parameters.getInclude(), mapUserInfo);
|
||||
mapArchiveInfo(foundNode,mapUserInfo);
|
||||
nodesFound.add(foundNode);
|
||||
}
|
||||
return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodesFound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node getDeletedNode(String originalId, Parameters parameters)
|
||||
{
|
||||
//First check the node is valid and has been archived.
|
||||
NodeRef validatedNodeRef = nodes.validateNode(StoreRef.STORE_REF_ARCHIVE_SPACESSTORE, originalId);
|
||||
|
||||
//Now get the Node
|
||||
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, validatedNodeRef.getId());
|
||||
NodeRef archivedNodeRef = nodeArchiveService.getArchivedNode(nodeRef);
|
||||
|
||||
//Turn it into a JSON Node (FULL version)
|
||||
Node foundNode = nodes.getFolderOrDocumentFullInfo(archivedNodeRef, null, null, parameters, null);
|
||||
if (foundNode != null) mapArchiveInfo(foundNode,null);
|
||||
return foundNode;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user