mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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/HEAD/root@126581 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -488,6 +488,28 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="deletedNodes" class="org.alfresco.rest.api.impl.DeletedNodesImpl">
|
||||
<property name="nodes" ref="Nodes" />
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
<property name="nodeArchiveService" ref="nodeArchiveService"/>
|
||||
<property name="personService" ref="PersonService" />
|
||||
</bean>
|
||||
|
||||
<bean id="DeletedNodes" class="org.springframework.aop.framework.ProxyFactoryBean">
|
||||
<property name="proxyInterfaces">
|
||||
<value>org.alfresco.rest.api.DeletedNodes</value>
|
||||
</property>
|
||||
<property name="target">
|
||||
<ref bean="deletedNodes" />
|
||||
</property>
|
||||
<property name="interceptorNames">
|
||||
<list>
|
||||
<idref bean="legacyExceptionInterceptor" />
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="quickShareLinks" class="org.alfresco.rest.api.impl.QuickShareLinksImpl">
|
||||
<property name="quickShareService" ref="QuickShareService"/>
|
||||
<property name="nodes" ref="nodes"/>
|
||||
@@ -748,6 +770,11 @@
|
||||
<property name="tags" ref="Tags" />
|
||||
</bean>
|
||||
|
||||
<bean class="org.alfresco.rest.api.trashcan.TrashcanEntityResource">
|
||||
<property name="deletedNodes" ref="DeletedNodes" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean class="org.alfresco.rest.api.quicksharelinks.QuickShareLinkEntityResource">
|
||||
<property name="quickShareLinks" ref="QuickShareLinks" />
|
||||
</bean>
|
||||
|
34
source/java/org/alfresco/rest/api/DeletedNodes.java
Normal file
34
source/java/org/alfresco/rest/api/DeletedNodes.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.framework.resource.parameters.Parameters;
|
||||
|
||||
/**
|
||||
* Handles trashcan / deleted nodes
|
||||
*
|
||||
* @author Gethin James
|
||||
*/
|
||||
public interface DeletedNodes
|
||||
{
|
||||
CollectionWithPagingInfo<Node> listDeleted(Parameters parameters);
|
||||
Node getDeletedNode(String originalId, Parameters parameters);
|
||||
}
|
@@ -19,11 +19,14 @@
|
||||
package org.alfresco.rest.api;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.rest.api.model.Document;
|
||||
import org.alfresco.rest.api.model.Folder;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.api.model.UserInfo;
|
||||
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
|
||||
import org.alfresco.rest.framework.resource.content.BinaryResource;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
@@ -78,6 +81,20 @@ public interface Nodes
|
||||
*/
|
||||
Node getFolderOrDocument(String nodeId, Parameters parameters);
|
||||
|
||||
Node getFolderOrDocumentFullInfo(NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, Parameters parameters, Map<String, UserInfo> mapUserInfo);
|
||||
|
||||
/**
|
||||
* Get the folder or document representation (as appropriate) for the given node.
|
||||
*
|
||||
* @param nodeRef A real Node
|
||||
* @param parentNodeRef
|
||||
* @param nodeTypeQName
|
||||
* @param includeParam
|
||||
* @param mapUserInfo
|
||||
* @return
|
||||
*/
|
||||
Node getFolderOrDocument(NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, List<String> includeParam, Map<String, UserInfo> mapUserInfo);
|
||||
|
||||
/**
|
||||
* Get list of children of a parent folder.
|
||||
*
|
||||
|
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;
|
||||
}
|
||||
}
|
@@ -767,7 +767,8 @@ public class NodesImpl implements Nodes
|
||||
return getFolderOrDocumentFullInfo(nodeRef, parentNodeRef, nodeTypeQName, parameters, null);
|
||||
}
|
||||
|
||||
private Node getFolderOrDocumentFullInfo(NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, Parameters parameters, Map<String,UserInfo> mapUserInfo)
|
||||
@Override
|
||||
public Node getFolderOrDocumentFullInfo(NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, Parameters parameters, Map<String,UserInfo> mapUserInfo)
|
||||
{
|
||||
List<String> includeParam = new ArrayList<>();
|
||||
if (parameters != null)
|
||||
@@ -782,7 +783,8 @@ public class NodesImpl implements Nodes
|
||||
return getFolderOrDocument(nodeRef, parentNodeRef, nodeTypeQName, includeParam, mapUserInfo);
|
||||
}
|
||||
|
||||
private Node getFolderOrDocument(final NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, List<String> includeParam, Map<String,UserInfo> mapUserInfo)
|
||||
@Override
|
||||
public Node getFolderOrDocument(final NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, List<String> includeParam, Map<String, UserInfo> mapUserInfo)
|
||||
{
|
||||
if (mapUserInfo == null)
|
||||
{
|
||||
|
@@ -56,6 +56,10 @@ public class Node implements Comparable<Node>
|
||||
protected UserInfo createdByUser;
|
||||
protected UserInfo modifiedByUser;
|
||||
|
||||
//Archived info, explicitly setting to NULL because NULLS don't get shown in the JSON.
|
||||
protected Date archivedAt = null;
|
||||
protected UserInfo archivedByUser = null;
|
||||
|
||||
protected Boolean isFolder;
|
||||
protected Boolean isFile;
|
||||
protected Boolean isLink;
|
||||
@@ -303,6 +307,26 @@ public class Node implements Comparable<Node>
|
||||
this.relativePath = relativePath;
|
||||
}
|
||||
|
||||
public Date getArchivedAt()
|
||||
{
|
||||
return archivedAt;
|
||||
}
|
||||
|
||||
public void setArchivedAt(Date archivedAt)
|
||||
{
|
||||
this.archivedAt = archivedAt;
|
||||
}
|
||||
|
||||
public UserInfo getArchivedByUser()
|
||||
{
|
||||
return archivedByUser;
|
||||
}
|
||||
|
||||
public void setArchivedByUser(UserInfo archivedByUser)
|
||||
{
|
||||
this.archivedByUser = archivedByUser;
|
||||
}
|
||||
|
||||
public boolean equals(Object other)
|
||||
{
|
||||
if(this == other)
|
||||
@@ -339,6 +363,14 @@ public class Node implements Comparable<Node>
|
||||
sb.append(", modifiedByUser=").append(getModifiedByUser());
|
||||
sb.append(", createdAt=").append(getCreatedAt());
|
||||
sb.append(", createdByUser=").append(getCreatedByUser());
|
||||
if (getArchivedAt() != null)
|
||||
{
|
||||
sb.append(", archivedAt=").append(getArchivedAt());
|
||||
}
|
||||
if (getArchivedByUser() != null)
|
||||
{
|
||||
sb.append(", archivedByUser=").append(getArchivedByUser());
|
||||
}
|
||||
if (getIsLink() != null)
|
||||
{
|
||||
sb.append(", isLink=").append(getIsLink()); // note: symbolic link (not shared link)
|
||||
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.trashcan;
|
||||
|
||||
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.node.archive.ArchivedNodesCannedQueryBuilder;
|
||||
import org.alfresco.repo.node.archive.NodeArchiveService;
|
||||
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.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.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An implementation of an Entity Resource for handling archived content
|
||||
*
|
||||
* @author Gethin James
|
||||
*/
|
||||
@EntityResource(name="deleted-nodes", title = "Deleted Nodes")
|
||||
public class TrashcanEntityResource implements
|
||||
EntityResourceAction.ReadById<Node>, EntityResourceAction.Read<Node>
|
||||
{
|
||||
private DeletedNodes deletedNodes;
|
||||
|
||||
public void setDeletedNodes(DeletedNodes deletedNodes)
|
||||
{
|
||||
this.deletedNodes = deletedNodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CollectionWithPagingInfo<Node> readAll(Parameters params)
|
||||
{
|
||||
return deletedNodes.listDeleted(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node readById(String id, Parameters parameters) throws EntityNotFoundException
|
||||
{
|
||||
return deletedNodes.getDeletedNode(id, parameters);
|
||||
}
|
||||
}
|
@@ -0,0 +1,4 @@
|
||||
@WebApi(name="alfresco", scope=Api.SCOPE.PUBLIC, version=1)
|
||||
package org.alfresco.rest.api.trashcan;
|
||||
import org.alfresco.rest.framework.Api;
|
||||
import org.alfresco.rest.framework.WebApi;
|
@@ -0,0 +1,95 @@
|
||||
package org.alfresco.rest;
|
||||
|
||||
import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.rest.api.tests.AbstractBaseApiTest;
|
||||
import org.alfresco.rest.api.tests.RepoService;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.data.ContentInfo;
|
||||
import org.alfresco.rest.api.tests.client.data.Document;
|
||||
import org.alfresco.rest.api.tests.client.data.Folder;
|
||||
import org.alfresco.rest.api.tests.util.JacksonUtil;
|
||||
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
/**
|
||||
* Created by gethin on 31/03/16.
|
||||
*/
|
||||
public class AbstractSingleNetworkSiteTest extends AbstractBaseApiTest
|
||||
{
|
||||
protected MutableAuthenticationService authenticationService;
|
||||
protected PersonService personService;
|
||||
|
||||
protected RepoService.TestNetwork networkOne;
|
||||
protected RepoService.TestPerson u1;
|
||||
protected RepoService.TestSite tSite;
|
||||
protected NodeRef docLibNodeRef;
|
||||
|
||||
protected JacksonUtil jacksonUtil;
|
||||
|
||||
@Override
|
||||
public String getScope()
|
||||
{
|
||||
return "public";
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
|
||||
personService = applicationContext.getBean("personService", PersonService.class);
|
||||
|
||||
jacksonUtil = new JacksonUtil(applicationContext.getBean("jsonHelper", JacksonHelper.class));
|
||||
|
||||
networkOne = getTestFixture().getRandomNetwork();
|
||||
u1 = networkOne.createUser();
|
||||
tSite = createSite(networkOne, u1, SiteVisibility.PRIVATE);
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(u1.getId());
|
||||
docLibNodeRef = tSite.getContainerNodeRef("documentLibrary");
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
if (personService.personExists(u1.getId()))
|
||||
{
|
||||
authenticationService.deleteAuthentication(u1.getId());
|
||||
personService.deletePerson(u1.getId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
|
||||
protected Document createDocument(Folder parentFolder, String docName) throws Exception
|
||||
{
|
||||
Document d1 = new Document();
|
||||
d1.setName(docName);
|
||||
d1.setNodeType("cm:content");
|
||||
ContentInfo ci = new ContentInfo();
|
||||
ci.setMimeType("text/plain");
|
||||
d1.setContent(ci);
|
||||
|
||||
// create empty file
|
||||
HttpResponse response = post(getNodeChildrenUrl(parentFolder.getId()), u1.getId(), toJsonAsStringNonNull(d1), 201);
|
||||
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
}
|
||||
}
|
114
source/test-java/org/alfresco/rest/DeletedNodesTest.java
Normal file
114
source/test-java/org/alfresco/rest/DeletedNodesTest.java
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.tests.AbstractBaseApiTest;
|
||||
import org.alfresco.rest.api.tests.RepoService;
|
||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||
import org.alfresco.rest.api.tests.client.data.Document;
|
||||
import org.alfresco.rest.api.tests.client.data.Folder;
|
||||
import org.alfresco.rest.api.tests.client.data.Node;
|
||||
import org.alfresco.rest.api.tests.util.JacksonUtil;
|
||||
import org.alfresco.rest.api.tests.util.RestApiUtil;
|
||||
import org.alfresco.rest.framework.jacksonextensions.JacksonHelper;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests Deleting nodes and recovering
|
||||
*
|
||||
* @author gethin
|
||||
*/
|
||||
public class DeletedNodesTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
|
||||
protected static final String URL_DELETED_NODES = "deleted-nodes";
|
||||
|
||||
@Test
|
||||
public void testCreateAndDelete() throws Exception
|
||||
{
|
||||
publicApiClient.setRequestContext(new RequestContext(u1.getId()));
|
||||
Date now = new Date();
|
||||
String folder1 = "folder" + now.getTime() + "_1";
|
||||
Folder createdFolder = createFolder(u1.getId(), docLibNodeRef.getId(), folder1, null);
|
||||
assertNotNull(createdFolder);
|
||||
|
||||
//Create a folder outside a site
|
||||
Folder createdFolderNonSite = createFolder(u1.getId(), Nodes.PATH_MY, folder1, null);
|
||||
assertNotNull(createdFolderNonSite);
|
||||
|
||||
Document document = createDocument(createdFolder, "d1.txt");
|
||||
Document documentNotDeleted = createDocument(createdFolder, "notdeleted1.txt");
|
||||
|
||||
PublicApiClient.Paging paging = getPaging(0, 100);
|
||||
//First get any deleted nodes
|
||||
HttpResponse response = getAll(URL_DELETED_NODES, u1.getId(), paging, 200);
|
||||
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertNotNull(nodes);
|
||||
int numOfNodes = nodes.size();
|
||||
|
||||
delete(URL_NODES, u1.getId(), document.getId(), 204);
|
||||
delete(URL_NODES, u1.getId(), createdFolder.getId(), 204);
|
||||
delete(URL_NODES, u1.getId(), createdFolderNonSite.getId(), 204);
|
||||
|
||||
response = getAll(URL_DELETED_NODES, u1.getId(), paging, 200);
|
||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||
assertNotNull(nodes);
|
||||
assertEquals(numOfNodes+3,nodes.size());
|
||||
|
||||
response = getSingle(URL_DELETED_NODES, u1.getId(), document.getId(), 200);
|
||||
Document node = jacksonUtil.parseEntry(response.getJsonResponse(), Document.class);
|
||||
assertNotNull(node);
|
||||
assertEquals(u1.getId(), node.getArchivedByUser().getId());
|
||||
assertTrue(node.getArchivedAt().after(now));
|
||||
|
||||
response = getSingle(URL_DELETED_NODES, u1.getId(), createdFolder.getId(), 200);
|
||||
Folder fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class);
|
||||
assertNotNull(fNode);
|
||||
assertEquals(u1.getId(), fNode.getArchivedByUser().getId());
|
||||
assertTrue(fNode.getArchivedAt().after(now));
|
||||
|
||||
response = getSingle(URL_DELETED_NODES, u1.getId(), createdFolderNonSite.getId(), 200);
|
||||
fNode = jacksonUtil.parseEntry(response.getJsonResponse(), Folder.class);
|
||||
assertNotNull(fNode);
|
||||
assertEquals(u1.getId(), fNode.getArchivedByUser().getId());
|
||||
assertTrue(fNode.getArchivedAt().after(now));
|
||||
|
||||
//Invalid node ref
|
||||
response = getSingle(URL_DELETED_NODES, u1.getId(), "iddontexist", 404);
|
||||
}
|
||||
|
||||
}
|
@@ -6,6 +6,7 @@ import static org.junit.Assert.*;
|
||||
import org.alfresco.repo.activities.ActivityType;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.rest.AbstractSingleNetworkSiteTest;
|
||||
import org.alfresco.rest.api.Activities;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.nodes.NodesEntityResource;
|
||||
@@ -37,57 +38,8 @@ import java.util.Map;
|
||||
*
|
||||
* @author gethin
|
||||
*/
|
||||
public class ActivitiesPostingTest extends AbstractBaseApiTest
|
||||
public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest
|
||||
{
|
||||
protected MutableAuthenticationService authenticationService;
|
||||
protected PersonService personService;
|
||||
|
||||
RepoService.TestNetwork networkOne;
|
||||
RepoService.TestPerson u1;
|
||||
RepoService.TestSite tSite;
|
||||
NodeRef docLibNodeRef;
|
||||
|
||||
@Override
|
||||
public String getScope()
|
||||
{
|
||||
return "public";
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception
|
||||
{
|
||||
authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
|
||||
personService = applicationContext.getBean("personService", PersonService.class);
|
||||
|
||||
networkOne = getTestFixture().getRandomNetwork();
|
||||
u1 = networkOne.createUser();
|
||||
tSite = createSite(networkOne, u1, SiteVisibility.PRIVATE);
|
||||
|
||||
AuthenticationUtil.setFullyAuthenticatedUser(u1.getId());
|
||||
docLibNodeRef = tSite.getContainerNodeRef("documentLibrary");
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception
|
||||
{
|
||||
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
|
||||
transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
|
||||
{
|
||||
@Override
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
if (personService.personExists(u1.getId()))
|
||||
{
|
||||
authenticationService.deleteAuthentication(u1.getId());
|
||||
personService.deletePerson(u1.getId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
AuthenticationUtil.clearCurrentSecurityContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateUpdate() throws Exception
|
||||
@@ -183,19 +135,6 @@ public class ActivitiesPostingTest extends AbstractBaseApiTest
|
||||
return publicApiClient.people().getActivities(u1.getId(), meParams).getList();
|
||||
}
|
||||
|
||||
private Document createDocument(Folder parentFolder, String docName) throws Exception
|
||||
{
|
||||
Document d1 = new Document();
|
||||
d1.setName(docName);
|
||||
d1.setNodeType("cm:content");
|
||||
ContentInfo ci = new ContentInfo();
|
||||
ci.setMimeType("text/plain");
|
||||
d1.setContent(ci);
|
||||
|
||||
// create empty file
|
||||
HttpResponse response = post(getNodeChildrenUrl(parentFolder.getId()), u1.getId(), toJsonAsStringNonNull(d1), 201);
|
||||
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
}
|
||||
|
||||
private Activity matchActivity(List<Activity> list, String type, String user, String siteId, String parentId, String title)
|
||||
{
|
||||
|
@@ -44,6 +44,9 @@ public class Node
|
||||
protected UserInfo createdByUser;
|
||||
protected UserInfo modifiedByUser;
|
||||
|
||||
protected Date archivedAt;
|
||||
protected UserInfo archivedByUser;
|
||||
|
||||
protected Boolean isFolder;
|
||||
protected Boolean isFile;
|
||||
protected Boolean isLink;
|
||||
@@ -116,6 +119,26 @@ public class Node
|
||||
this.modifiedByUser = modifiedByUser;
|
||||
}
|
||||
|
||||
public Date getArchivedAt()
|
||||
{
|
||||
return archivedAt;
|
||||
}
|
||||
|
||||
public void setArchivedAt(Date archivedAt)
|
||||
{
|
||||
this.archivedAt = archivedAt;
|
||||
}
|
||||
|
||||
public UserInfo getArchivedByUser()
|
||||
{
|
||||
return archivedByUser;
|
||||
}
|
||||
|
||||
public void setArchivedByUser(UserInfo archivedByUser)
|
||||
{
|
||||
this.archivedByUser = archivedByUser;
|
||||
}
|
||||
|
||||
public Boolean getIsFolder()
|
||||
{
|
||||
return isFolder;
|
||||
|
Reference in New Issue
Block a user