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)
124563 gjames: RA-884: Posting activities for file/folder deleted git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126566 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -94,6 +94,7 @@ import org.alfresco.service.ServiceRegistry;
|
|||||||
import org.alfresco.service.cmr.action.Action;
|
import org.alfresco.service.cmr.action.Action;
|
||||||
import org.alfresco.service.cmr.action.ActionDefinition;
|
import org.alfresco.service.cmr.action.ActionDefinition;
|
||||||
import org.alfresco.service.cmr.action.ActionService;
|
import org.alfresco.service.cmr.action.ActionService;
|
||||||
|
import org.alfresco.service.cmr.activities.ActivityInfo;
|
||||||
import org.alfresco.service.cmr.activities.ActivityPoster;
|
import org.alfresco.service.cmr.activities.ActivityPoster;
|
||||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||||
@@ -121,6 +122,8 @@ import org.alfresco.service.cmr.security.AuthorityService;
|
|||||||
import org.alfresco.service.cmr.security.OwnableService;
|
import org.alfresco.service.cmr.security.OwnableService;
|
||||||
import org.alfresco.service.cmr.security.PermissionService;
|
import org.alfresco.service.cmr.security.PermissionService;
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
|
import org.alfresco.service.cmr.site.SiteInfo;
|
||||||
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
|
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
|
||||||
import org.alfresco.service.cmr.usage.ContentQuotaException;
|
import org.alfresco.service.cmr.usage.ContentQuotaException;
|
||||||
import org.alfresco.service.cmr.version.VersionService;
|
import org.alfresco.service.cmr.version.VersionService;
|
||||||
@@ -178,8 +181,14 @@ public class NodesImpl implements Nodes
|
|||||||
private OwnableService ownableService;
|
private OwnableService ownableService;
|
||||||
private AuthorityService authorityService;
|
private AuthorityService authorityService;
|
||||||
private ThumbnailService thumbnailService;
|
private ThumbnailService thumbnailService;
|
||||||
|
private SiteService siteService;
|
||||||
private ActivityPoster poster;
|
private ActivityPoster poster;
|
||||||
|
|
||||||
|
private enum Activity_Type
|
||||||
|
{
|
||||||
|
ADDED, UPDATED, DELETED, DOWNLOADED
|
||||||
|
}
|
||||||
|
|
||||||
private BehaviourFilter behaviourFilter;
|
private BehaviourFilter behaviourFilter;
|
||||||
|
|
||||||
// note: circular - Nodes/QuickShareLinks currently use each other (albeit for different methods)
|
// note: circular - Nodes/QuickShareLinks currently use each other (albeit for different methods)
|
||||||
@@ -216,6 +225,7 @@ public class NodesImpl implements Nodes
|
|||||||
this.ownableService = sr.getOwnableService();
|
this.ownableService = sr.getOwnableService();
|
||||||
this.authorityService = sr.getAuthorityService();
|
this.authorityService = sr.getAuthorityService();
|
||||||
this.thumbnailService = sr.getThumbnailService();
|
this.thumbnailService = sr.getThumbnailService();
|
||||||
|
this.siteService = sr.getSiteService();
|
||||||
|
|
||||||
if (defaultIgnoreTypesAndAspects != null)
|
if (defaultIgnoreTypesAndAspects != null)
|
||||||
{
|
{
|
||||||
@@ -1352,7 +1362,11 @@ public class NodesImpl implements Nodes
|
|||||||
nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
|
nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
|
||||||
|
|
||||||
fileFolderService.delete(nodeRef);
|
fileFolderService.delete(nodeRef);
|
||||||
|
|
||||||
|
postActivity(Activity_Type.DELETED, activityInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1505,18 +1519,70 @@ public class NodesImpl implements Nodes
|
|||||||
throw new ConstraintViolatedException(dcne.getMessage());
|
throw new ConstraintViolatedException(dcne.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isFolder = isSubClass(nodeTypeQName, ContentModel.TYPE_FOLDER);
|
ActivityInfo activityInfo = getActivityInfo(parentNodeRef, newNode);
|
||||||
boolean isContent = isSubClass(nodeTypeQName, ContentModel.TYPE_CONTENT);
|
postActivity(Activity_Type.ADDED, activityInfo);
|
||||||
|
|
||||||
if (isFolder || isContent)
|
|
||||||
{
|
|
||||||
FileInfo fileInfo = fileFolderService.getFileInfo(newNode);
|
|
||||||
poster.postSiteAwareFileFolderActivity(isFolder?ActivityType.FOLDER_ADDED:ActivityType.FILE_ADDED, null, TenantUtil.getCurrentDomain(),
|
|
||||||
null, parentNodeRef, newNode, nodeName, APP_TOOL, Client.asType(Client.ClientType.script), fileInfo);
|
|
||||||
}
|
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void postActivity(Activity_Type activity_type, ActivityInfo activityInfo)
|
||||||
|
{
|
||||||
|
if (activityInfo == null) return; //Nothing to do.
|
||||||
|
|
||||||
|
String activityType = determineActivityType(activity_type, activityInfo.getFileInfo().isFolder());
|
||||||
|
if (activityType != null)
|
||||||
|
{
|
||||||
|
poster.postFileFolderActivity(activityType, null, TenantUtil.getCurrentDomain(),
|
||||||
|
activityInfo.getSiteId(), activityInfo.getParentNodeRef(), activityInfo.getNodeRef(),
|
||||||
|
activityInfo.getFileName(), APP_TOOL, Client.asType(Client.ClientType.script),
|
||||||
|
activityInfo.getFileInfo());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ActivityInfo getActivityInfo(NodeRef parentNodeRef, NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
SiteInfo siteInfo = siteService.getSite(nodeRef);
|
||||||
|
String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
|
||||||
|
if(siteId != null && !siteId.equals(""))
|
||||||
|
{
|
||||||
|
FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
|
||||||
|
if (fileInfo != null)
|
||||||
|
{
|
||||||
|
boolean isContent = isSubClass(fileInfo.getType(), ContentModel.TYPE_CONTENT);
|
||||||
|
|
||||||
|
if (fileInfo.isFolder() || isContent)
|
||||||
|
{
|
||||||
|
return new ActivityInfo(null, parentNodeRef, siteId, fileInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
logger.debug("Non-site activity, so ignored " + nodeRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String determineActivityType(Activity_Type activity_type, boolean isFolder)
|
||||||
|
{
|
||||||
|
switch (activity_type)
|
||||||
|
{
|
||||||
|
case DELETED:
|
||||||
|
return isFolder ? ActivityType.FOLDER_DELETED:ActivityType.FILE_DELETED;
|
||||||
|
case ADDED:
|
||||||
|
return isFolder ? ActivityType.FOLDER_ADDED:ActivityType.FILE_ADDED;
|
||||||
|
case UPDATED:
|
||||||
|
if (!isFolder) return ActivityType.FILE_UPDATED;
|
||||||
|
break;
|
||||||
|
case DOWNLOADED:
|
||||||
|
if (!isFolder) return ActivityPoster.DOWNLOADED;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// check cm:cmobject (but *not* cm:systemfolder)
|
// check cm:cmobject (but *not* cm:systemfolder)
|
||||||
private void validateCmObject(QName nodeTypeQName)
|
private void validateCmObject(QName nodeTypeQName)
|
||||||
{
|
{
|
||||||
@@ -1730,16 +1796,10 @@ public class NodesImpl implements Nodes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Node updatedNode = getFolderOrDocument(nodeRef.getId(), parameters);
|
ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
|
||||||
boolean isContent = isSubClass(nodeTypeQName, ContentModel.TYPE_CONTENT);
|
postActivity(Activity_Type.UPDATED, activityInfo);
|
||||||
|
|
||||||
if (isContent)
|
return getFolderOrDocument(nodeRef.getId(), parameters);
|
||||||
{
|
|
||||||
FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
|
|
||||||
poster.postSiteAwareFileFolderActivity(ActivityType.FILE_UPDATED, null, TenantUtil.getCurrentDomain(),
|
|
||||||
null, updatedNode.getParentId(), updatedNode.getNodeRef(), updatedNode.getName(), APP_TOOL, Client.asType(Client.ClientType.script), fileInfo);
|
|
||||||
}
|
|
||||||
return updatedNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1903,8 +1963,8 @@ public class NodesImpl implements Nodes
|
|||||||
createVersion(nodeRef, isVersioned, versionType, versionComment);
|
createVersion(nodeRef, isVersioned, versionType, versionComment);
|
||||||
}
|
}
|
||||||
|
|
||||||
poster.postSiteAwareFileFolderActivity(ActivityType.FILE_UPDATED, null, TenantUtil.getCurrentDomain(),
|
ActivityInfo activityInfo = getActivityInfo(parentNodeRef, nodeRef);
|
||||||
null, parentNodeRef, nodeRef, fileName, APP_TOOL, Client.asType(Client.ClientType.script), fileInfo);
|
postActivity(Activity_Type.UPDATED, activityInfo);
|
||||||
|
|
||||||
extractMetadata(nodeRef);
|
extractMetadata(nodeRef);
|
||||||
}
|
}
|
||||||
|
@@ -5,11 +5,13 @@ import static org.junit.Assert.*;
|
|||||||
|
|
||||||
import org.alfresco.repo.activities.ActivityType;
|
import org.alfresco.repo.activities.ActivityType;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.tenant.TenantUtil;
|
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||||
import org.alfresco.rest.api.Activities;
|
import org.alfresco.rest.api.Activities;
|
||||||
|
import org.alfresco.rest.api.Nodes;
|
||||||
import org.alfresco.rest.api.tests.client.HttpResponse;
|
import org.alfresco.rest.api.tests.client.HttpResponse;
|
||||||
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
import org.alfresco.rest.api.tests.client.PublicApiClient;
|
||||||
|
import org.alfresco.rest.api.tests.client.PublicApiException;
|
||||||
|
import org.alfresco.rest.api.tests.client.RequestContext;
|
||||||
import org.alfresco.rest.api.tests.client.data.Activity;
|
import org.alfresco.rest.api.tests.client.data.Activity;
|
||||||
import org.alfresco.rest.api.tests.client.data.ContentInfo;
|
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.Document;
|
||||||
@@ -19,13 +21,10 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
|||||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||||
import org.alfresco.service.cmr.security.PersonService;
|
import org.alfresco.service.cmr.security.PersonService;
|
||||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -92,39 +91,84 @@ public class ActivitiesPostingTest extends AbstractBaseApiTest
|
|||||||
Folder createdFolder = createFolder(u1.getId(), docLibNodeRef.getId(), folder1, null);
|
Folder createdFolder = createFolder(u1.getId(), docLibNodeRef.getId(), folder1, null);
|
||||||
assertNotNull(createdFolder);
|
assertNotNull(createdFolder);
|
||||||
|
|
||||||
|
String docName = "d1.txt";
|
||||||
|
Document documentResp = createDocument(createdFolder, docName);
|
||||||
|
|
||||||
|
//Update the file
|
||||||
|
Document dUpdate = new Document();
|
||||||
|
dUpdate.setName("d1b.txt");
|
||||||
|
HttpResponse response = put(URL_NODES, u1.getId(), documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200);
|
||||||
|
|
||||||
|
delete(URL_NODES, u1.getId(), documentResp.getId(), 204);
|
||||||
|
delete(URL_NODES, u1.getId(), createdFolder.getId(), 204);
|
||||||
|
|
||||||
|
List<Activity> activities = getMyActivites();
|
||||||
|
assertEquals(activities.size(),5);
|
||||||
|
Activity act = matchActivity(activities, ActivityType.FOLDER_ADDED, u1.getId(), tSite.getSiteId(), docLibNodeRef.getId(), folder1);
|
||||||
|
assertNotNull(act);
|
||||||
|
|
||||||
|
act = matchActivity(activities, ActivityType.FILE_ADDED, u1.getId(), tSite.getSiteId(), createdFolder.getId(), docName);
|
||||||
|
assertNotNull(act);
|
||||||
|
|
||||||
|
act = matchActivity(activities, ActivityType.FILE_UPDATED, u1.getId(), tSite.getSiteId(), createdFolder.getId(), dUpdate.getName());
|
||||||
|
assertNotNull(act);
|
||||||
|
|
||||||
|
act = matchActivity(activities, ActivityType.FOLDER_DELETED, u1.getId(), tSite.getSiteId(), docLibNodeRef.getId(), folder1);
|
||||||
|
assertNotNull(act);
|
||||||
|
|
||||||
|
act = matchActivity(activities, ActivityType.FILE_DELETED, u1.getId(), tSite.getSiteId(), createdFolder.getId(), dUpdate.getName());
|
||||||
|
assertNotNull(act);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNonSite() throws Exception
|
||||||
|
{
|
||||||
|
List<Activity> activities = getMyActivites();
|
||||||
|
String folder1 = "nonSitefolder" + System.currentTimeMillis() + "_1";
|
||||||
|
//Create a folder outside a site
|
||||||
|
Folder createdFolder = createFolder(u1.getId(), Nodes.PATH_MY, folder1, null);
|
||||||
|
assertNotNull(createdFolder);
|
||||||
|
|
||||||
|
String docName = "nonsite_d1.txt";
|
||||||
|
Document documentResp = createDocument(createdFolder, docName);
|
||||||
|
assertNotNull(documentResp);
|
||||||
|
|
||||||
|
//Update the file
|
||||||
|
Document dUpdate = new Document();
|
||||||
|
dUpdate.setName("nonsite_d2.txt");
|
||||||
|
HttpResponse response = put(URL_NODES, u1.getId(), documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200);
|
||||||
|
|
||||||
|
List<Activity> activitiesAgain = getMyActivites();
|
||||||
|
assertEquals("No activites should be created for non-site nodes", activities, activitiesAgain);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Activity> getMyActivites() throws Exception
|
||||||
|
{
|
||||||
|
repoService.generateFeed();
|
||||||
|
|
||||||
|
publicApiClient.setRequestContext(new RequestContext(u1.getId()));
|
||||||
|
Map<String, String> meParams = new HashMap<>();
|
||||||
|
meParams.put("who", String.valueOf(Activities.ActivityWho.me));
|
||||||
|
return publicApiClient.people().getActivities(u1.getId(), meParams).getList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Document createDocument(Folder parentFolder, String docName) throws Exception
|
||||||
|
{
|
||||||
Document d1 = new Document();
|
Document d1 = new Document();
|
||||||
d1.setName("d1.txt");
|
d1.setName(docName);
|
||||||
d1.setNodeType("cm:content");
|
d1.setNodeType("cm:content");
|
||||||
ContentInfo ci = new ContentInfo();
|
ContentInfo ci = new ContentInfo();
|
||||||
ci.setMimeType("text/plain");
|
ci.setMimeType("text/plain");
|
||||||
d1.setContent(ci);
|
d1.setContent(ci);
|
||||||
|
|
||||||
// create empty file
|
// create empty file
|
||||||
HttpResponse response = post(getNodeChildrenUrl(createdFolder.getId()), u1.getId(), toJsonAsStringNonNull(d1), 201);
|
HttpResponse response = post(getNodeChildrenUrl(parentFolder.getId()), u1.getId(), toJsonAsStringNonNull(d1), 201);
|
||||||
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||||
|
|
||||||
//Update the file
|
|
||||||
Document dUpdate = new Document();
|
|
||||||
dUpdate.setName("d1b.txt");
|
|
||||||
response = put(URL_NODES, u1.getId(), documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200);
|
|
||||||
|
|
||||||
repoService.generateFeed();
|
|
||||||
|
|
||||||
Map<String, String> meParams = new HashMap<>();
|
|
||||||
meParams.put("who", String.valueOf(Activities.ActivityWho.me));
|
|
||||||
PublicApiClient.ListResponse<Activity> activities = publicApiClient.people().getActivities(u1.getId(), meParams);
|
|
||||||
assertEquals(activities.getList().size(),3);
|
|
||||||
Activity act = matchActivity(activities.getList(), ActivityType.FOLDER_ADDED, u1.getId(), tSite.getSiteId(), docLibNodeRef.getId(), folder1);
|
|
||||||
assertNotNull(act);
|
|
||||||
|
|
||||||
act = matchActivity(activities.getList(), ActivityType.FILE_ADDED, u1.getId(), tSite.getSiteId(), createdFolder.getId(), d1.getName());
|
|
||||||
assertNotNull(act);
|
|
||||||
|
|
||||||
act = matchActivity(activities.getList(), ActivityType.FILE_UPDATED, u1.getId(), tSite.getSiteId(), createdFolder.getId(), dUpdate.getName());
|
|
||||||
assertNotNull(act);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Test non-site and non-file activities.
|
||||||
|
|
||||||
private Activity matchActivity(List<Activity> list, String type, String user, String siteId, String parentId, String title)
|
private Activity matchActivity(List<Activity> list, String type, String user, String siteId, String parentId, String title)
|
||||||
{
|
{
|
||||||
for (Activity act:list)
|
for (Activity act:list)
|
||||||
|
Reference in New Issue
Block a user