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)
126566 jkaabimofrad: 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/BRANCHES/DEV/5.2.N/root@126912 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -101,6 +101,7 @@ import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.Action;
|
||||
import org.alfresco.service.cmr.action.ActionDefinition;
|
||||
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.dictionary.AspectDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
||||
@@ -128,6 +129,8 @@ import org.alfresco.service.cmr.security.AuthorityService;
|
||||
import org.alfresco.service.cmr.security.OwnableService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
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.usage.ContentQuotaException;
|
||||
import org.alfresco.service.cmr.version.VersionService;
|
||||
@@ -185,8 +188,14 @@ public class NodesImpl implements Nodes
|
||||
private OwnableService ownableService;
|
||||
private AuthorityService authorityService;
|
||||
private ThumbnailService thumbnailService;
|
||||
private SiteService siteService;
|
||||
private ActivityPoster poster;
|
||||
|
||||
private enum Activity_Type
|
||||
{
|
||||
ADDED, UPDATED, DELETED, DOWNLOADED
|
||||
}
|
||||
|
||||
private BehaviourFilter behaviourFilter;
|
||||
|
||||
// note: circular - Nodes/QuickShareLinks currently use each other (albeit for different methods)
|
||||
@@ -223,6 +232,7 @@ public class NodesImpl implements Nodes
|
||||
this.ownableService = sr.getOwnableService();
|
||||
this.authorityService = sr.getAuthorityService();
|
||||
this.thumbnailService = sr.getThumbnailService();
|
||||
this.siteService = sr.getSiteService();
|
||||
|
||||
if (defaultIgnoreTypesAndAspects != null)
|
||||
{
|
||||
@@ -1359,7 +1369,11 @@ public class NodesImpl implements Nodes
|
||||
nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
|
||||
}
|
||||
|
||||
final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
|
||||
|
||||
fileFolderService.delete(nodeRef);
|
||||
|
||||
postActivity(Activity_Type.DELETED, activityInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1512,18 +1526,70 @@ public class NodesImpl implements Nodes
|
||||
throw new ConstraintViolatedException(dcne.getMessage());
|
||||
}
|
||||
|
||||
boolean isFolder = isSubClass(nodeTypeQName, ContentModel.TYPE_FOLDER);
|
||||
boolean isContent = isSubClass(nodeTypeQName, ContentModel.TYPE_CONTENT);
|
||||
|
||||
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);
|
||||
}
|
||||
ActivityInfo activityInfo = getActivityInfo(parentNodeRef, newNode);
|
||||
postActivity(Activity_Type.ADDED, activityInfo);
|
||||
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)
|
||||
private void validateCmObject(QName nodeTypeQName)
|
||||
{
|
||||
@@ -1737,16 +1803,10 @@ public class NodesImpl implements Nodes
|
||||
}
|
||||
}
|
||||
|
||||
Node updatedNode = getFolderOrDocument(nodeRef.getId(), parameters);
|
||||
boolean isContent = isSubClass(nodeTypeQName, ContentModel.TYPE_CONTENT);
|
||||
ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
|
||||
postActivity(Activity_Type.UPDATED, activityInfo);
|
||||
|
||||
if (isContent)
|
||||
{
|
||||
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;
|
||||
return getFolderOrDocument(nodeRef.getId(), parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1910,8 +1970,8 @@ public class NodesImpl implements Nodes
|
||||
createVersion(nodeRef, isVersioned, versionType, versionComment);
|
||||
}
|
||||
|
||||
poster.postSiteAwareFileFolderActivity(ActivityType.FILE_UPDATED, null, TenantUtil.getCurrentDomain(),
|
||||
null, parentNodeRef, nodeRef, fileName, APP_TOOL, Client.asType(Client.ClientType.script), fileInfo);
|
||||
ActivityInfo activityInfo = getActivityInfo(parentNodeRef, nodeRef);
|
||||
postActivity(Activity_Type.UPDATED, activityInfo);
|
||||
|
||||
extractMetadata(nodeRef);
|
||||
}
|
||||
|
@@ -5,11 +5,13 @@ import static org.junit.Assert.*;
|
||||
|
||||
import org.alfresco.repo.activities.ActivityType;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
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.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.ContentInfo;
|
||||
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.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -92,39 +91,84 @@ public class ActivitiesPostingTest extends AbstractBaseApiTest
|
||||
Folder createdFolder = createFolder(u1.getId(), docLibNodeRef.getId(), folder1, null);
|
||||
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();
|
||||
d1.setName("d1.txt");
|
||||
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(createdFolder.getId()), u1.getId(), toJsonAsStringNonNull(d1), 201);
|
||||
Document documentResp = 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);
|
||||
|
||||
HttpResponse response = post(getNodeChildrenUrl(parentFolder.getId()), u1.getId(), toJsonAsStringNonNull(d1), 201);
|
||||
return RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
}
|
||||
|
||||
//TODO: Test non-site and non-file activities.
|
||||
|
||||
private Activity matchActivity(List<Activity> list, String type, String user, String siteId, String parentId, String title)
|
||||
{
|
||||
for (Activity act:list)
|
||||
|
Reference in New Issue
Block a user