diff --git a/config/alfresco/activities/activities-feed-context.xml b/config/alfresco/activities/activities-feed-context.xml
index 039ffe0626..eb7a2d3bb8 100644
--- a/config/alfresco/activities/activities-feed-context.xml
+++ b/config/alfresco/activities/activities-feed-context.xml
@@ -24,5 +24,18 @@
-
+
+
+
+
+
+
+ ffActivitiesPoster
+
+
+
+ org.alfresco.service.cmr.activities.ActivityPoster
+
+
+
diff --git a/config/alfresco/opencmis-context.xml b/config/alfresco/opencmis-context.xml
index daa6454308..6a854934ba 100644
--- a/config/alfresco/opencmis-context.xml
+++ b/config/alfresco/opencmis-context.xml
@@ -115,7 +115,7 @@
-
+
diff --git a/config/alfresco/subsystems/ActivitiesFeed/default/activities-feed-context.xml b/config/alfresco/subsystems/ActivitiesFeed/default/activities-feed-context.xml
index 5e47d6b773..2ecc34bb01 100644
--- a/config/alfresco/subsystems/ActivitiesFeed/default/activities-feed-context.xml
+++ b/config/alfresco/subsystems/ActivitiesFeed/default/activities-feed-context.xml
@@ -26,6 +26,10 @@
+
+
+
+
diff --git a/source/java/org/alfresco/opencmis/ActivityPosterImpl.java b/source/java/org/alfresco/opencmis/ActivityPosterImpl.java
index 4376fc19f6..bed24d54d3 100644
--- a/source/java/org/alfresco/opencmis/ActivityPosterImpl.java
+++ b/source/java/org/alfresco/opencmis/ActivityPosterImpl.java
@@ -20,14 +20,13 @@ package org.alfresco.opencmis;
import java.util.List;
-import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.Client;
import org.alfresco.repo.Client.ClientType;
import org.alfresco.repo.activities.ActivityType;
import org.alfresco.repo.model.filefolder.HiddenAspect;
import org.alfresco.repo.tenant.TenantService;
-import org.alfresco.service.cmr.activities.ActivityService;
+import org.alfresco.service.cmr.activities.ActivityPoster;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileFolderServiceType;
import org.alfresco.service.cmr.model.FileInfo;
@@ -40,26 +39,23 @@ import org.alfresco.service.namespace.QName;
import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.json.JSONException;
-import org.json.JSONObject;
import org.springframework.beans.factory.InitializingBean;
/**
* OpenCMIS methods may use an instance of this class to post activity data.
*
- * @see ActivityPoster
+ * @see CmisActivityPoster
* @author sglover
*/
-// TODO consolidate with ActivityPost for WebDAV
-public class ActivityPosterImpl implements ActivityPoster, InitializingBean
+public class ActivityPosterImpl implements CmisActivityPoster, InitializingBean
{
private static final String APP_TOOL = "CMIS";
public static final char PathSeperatorChar = '/';
// Logging
- private static Log logger = LogFactory.getLog(ActivityPoster.class);
+ private static Log logger = LogFactory.getLog(CmisActivityPoster.class);
- private ActivityService activityService;
+ private ActivityPoster poster;
private SiteService siteService;
private TenantService tenantService;
private NodeService nodeService;
@@ -68,48 +64,48 @@ public class ActivityPosterImpl implements ActivityPoster, InitializingBean
private boolean activitiesEnabled = true;
- /**
+ /**
* Constructor
*/
public ActivityPosterImpl()
{
}
- public void setHiddenAspect(HiddenAspect hiddenAspect)
- {
- this.hiddenAspect = hiddenAspect;
- }
-
- public void setFileFolderService(FileFolderService fileFolderService)
+ public void setHiddenAspect(HiddenAspect hiddenAspect)
{
- this.fileFolderService = fileFolderService;
- }
+ this.hiddenAspect = hiddenAspect;
+ }
- public void setTenantService(TenantService tenantService)
- {
- this.tenantService = tenantService;
- }
-
- public void setSiteService(SiteService siteService)
+ public void setFileFolderService(FileFolderService fileFolderService)
{
- this.siteService = siteService;
- }
+ this.fileFolderService = fileFolderService;
+ }
- public void setNodeService(NodeService nodeService)
- {
- this.nodeService = nodeService;
- }
-
- public void setActivityService(ActivityService activityService)
+ public void setTenantService(TenantService tenantService)
{
- this.activityService = activityService;
- }
+ this.tenantService = tenantService;
+ }
- public void setActivitiesEnabled(boolean activitiesEnabled)
- {
- this.activitiesEnabled = activitiesEnabled;
- }
+ public void setSiteService(SiteService siteService)
+ {
+ this.siteService = siteService;
+ }
+ public void setNodeService(NodeService nodeService)
+ {
+ this.nodeService = nodeService;
+ }
+
+ public void setActivitiesEnabled(boolean activitiesEnabled)
+ {
+ this.activitiesEnabled = activitiesEnabled;
+ }
+
+ public void setPoster(ActivityPoster poster)
+ {
+ this.poster = poster;
+ }
+
private final String getPathFromNode(NodeRef rootNodeRef, NodeRef nodeRef) throws FileNotFoundException
{
// Check if the nodes are valid, or equal
@@ -147,12 +143,12 @@ public class ActivityPosterImpl implements ActivityPoster, InitializingBean
*/
public void afterPropertiesSet() throws Exception
{
- PropertyCheck.mandatory(this, "activityService", activityService);
+ PropertyCheck.mandatory(this, "poster", poster);
PropertyCheck.mandatory(this, "siteService", siteService);
PropertyCheck.mandatory(this, "tenantService", tenantService);
PropertyCheck.mandatory(this, "nodeService", nodeService);
PropertyCheck.mandatory(this, "fileFolderService", fileFolderService);
- }
+ }
private String getCurrentTenantDomain()
{
@@ -166,10 +162,10 @@ public class ActivityPosterImpl implements ActivityPoster, InitializingBean
private boolean isFolder(NodeRef nodeRef)
{
- QName typeQName = nodeService.getType(nodeRef);
- FileFolderServiceType type = fileFolderService.getType(typeQName);
- boolean isFolder = type.equals(FileFolderServiceType.FOLDER);
- return isFolder;
+ QName typeQName = nodeService.getType(nodeRef);
+ FileFolderServiceType type = fileFolderService.getType(typeQName);
+ boolean isFolder = type.equals(FileFolderServiceType.FOLDER);
+ return isFolder;
}
/**
@@ -178,40 +174,42 @@ public class ActivityPosterImpl implements ActivityPoster, InitializingBean
@Override
public void postFileFolderAdded(NodeRef nodeRef)
{
- if(activitiesEnabled && !hiddenAspect.hasHiddenAspect(nodeRef))
- {
- SiteInfo siteInfo = siteService.getSite(nodeRef);
- String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
-
- if(siteId != null && !siteId.equals(""))
- {
- // post only for nodes within sites
- NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
+ if(activitiesEnabled && !hiddenAspect.hasHiddenAspect(nodeRef))
+ {
+ SiteInfo siteInfo = siteService.getSite(nodeRef);
+ String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
+
+ if(siteId != null && !siteId.equals(""))
+ {
+ // post only for nodes within sites
+ NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
- String path = null;
- boolean isFolder = isFolder(nodeRef);
- String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
+ String path = null;
+ boolean isFolder = isFolder(nodeRef);
+ String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
- if(isFolder)
- {
- NodeRef documentLibrary = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
- path = "/";
- try
- {
- path = getPathFromNode(documentLibrary, nodeRef);
- }
- catch (FileNotFoundException error)
- {
- if (logger.isDebugEnabled())
- {
- logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found.");
- }
- }
- }
- FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
- postFileFolderActivity((isFolder ? ActivityType.FOLDER_ADDED : ActivityType.FILE_ADDED), path, parentNodeRef, nodeRef, siteId, name, fileInfo);
- }
- }
+ if(isFolder)
+ {
+ NodeRef documentLibrary = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
+ path = "/";
+ try
+ {
+ path = getPathFromNode(documentLibrary, nodeRef);
+ }
+ catch (FileNotFoundException error)
+ {
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found.");
+ }
+ }
+ }
+ FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
+ poster.postFileFolderActivity((isFolder ? ActivityType.FOLDER_ADDED : ActivityType.FILE_ADDED), path, getCurrentTenantDomain(),
+ siteId, parentNodeRef, nodeRef, name, APP_TOOL, Client.asType(ClientType.cmis), fileInfo);
+
+ }
+ }
}
/**
@@ -220,22 +218,23 @@ public class ActivityPosterImpl implements ActivityPoster, InitializingBean
@Override
public void postFileFolderUpdated(boolean isFolder, NodeRef nodeRef)
{
- if(activitiesEnabled && !hiddenAspect.hasHiddenAspect(nodeRef))
- {
- SiteInfo siteInfo = siteService.getSite(nodeRef);
- String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
- if(siteId != null && !siteId.equals(""))
- {
- // post only for nodes within sites
- String fileName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
-
- if (!isFolder)
- {
- FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
- postFileFolderActivity(ActivityType.FILE_UPDATED, null, null, nodeRef, siteId, fileName, fileInfo);
- }
- }
- }
+ if(activitiesEnabled && !hiddenAspect.hasHiddenAspect(nodeRef))
+ {
+ SiteInfo siteInfo = siteService.getSite(nodeRef);
+ String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
+ if(siteId != null && !siteId.equals(""))
+ {
+ // post only for nodes within sites
+ String fileName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
+
+ if (!isFolder)
+ {
+ FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
+ poster.postFileFolderActivity(ActivityType.FILE_UPDATED, null, getCurrentTenantDomain(),
+ siteId, null, nodeRef, fileName, APP_TOOL, Client.asType(ClientType.cmis), fileInfo);
+ }
+ }
+ }
}
/**
@@ -244,167 +243,92 @@ public class ActivityPosterImpl implements ActivityPoster, InitializingBean
@Override
public void postFileFolderDeleted(ActivityInfo activityInfo)
{
- if(activitiesEnabled && activityInfo.getSiteId() != null)
- {
- // post only for nodes within sites
- postFileFolderActivity((activityInfo.isFolder() ? ActivityType.FOLDER_DELETED : ActivityType.FILE_DELETED), activityInfo.getParentPath(), activityInfo.getParentNodeRef(), activityInfo.getNodeRef(),
- activityInfo.getSiteId(), activityInfo.getFileName(), null);
- }
+ if(activitiesEnabled && activityInfo.getSiteId() != null)
+ {
+ poster.postFileFolderActivity((activityInfo.isFolder() ? ActivityType.FOLDER_DELETED : ActivityType.FILE_DELETED), activityInfo.getParentPath(), getCurrentTenantDomain(),
+ activityInfo.getSiteId(), activityInfo.getParentNodeRef(), activityInfo.getNodeRef(), activityInfo.getFileName(), APP_TOOL, Client.asType(ClientType.cmis), null);
+ }
}
public ActivityInfo getActivityInfo(NodeRef nodeRef)
{
SiteInfo siteInfo = siteService.getSite(nodeRef);
String siteId = (siteInfo != null ? siteInfo.getShortName() : null);
- if(siteId != null && !siteId.equals(""))
- {
- NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
- FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
- String name = fileInfo.getName();
- boolean isFolder = fileInfo.isFolder();
-
- NodeRef documentLibrary = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
- String parentPath = "/";
- try
- {
- parentPath = getPathFromNode(documentLibrary, parentNodeRef);
- }
- catch (FileNotFoundException error)
- {
- if (logger.isDebugEnabled())
- {
- logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found.");
- }
- }
-
- return new ActivityInfo(nodeRef, parentPath, parentNodeRef, siteId, name, isFolder);
- }
- else
- {
- return null;
- }
- }
-
- private void postFileFolderActivity(
- String activityType,
- String path,
- NodeRef parentNodeRef,
- NodeRef nodeRef,
- String siteId,
- String name,
- FileInfo fileInfo)
- {
- JSONObject json = createActivityJSON(getCurrentTenantDomain(), path, parentNodeRef, nodeRef, name);
-
- activityService.postActivity(
- activityType,
- siteId,
- APP_TOOL,
- json.toString(),
- Client.asType(ClientType.cmis),
- fileInfo);
- }
-
- /**
- * Create JSON suitable for create, modify or delete activity posts. Returns a new JSONObject
- * containing appropriate key/value pairs.
- *
- * @param tenantDomain
- * @param nodeRef
- * @param fileName
- * @throws WebDAVServerException
- * @return JSONObject
- */
- private JSONObject createActivityJSON(
- String tenantDomain,
- String path,
- NodeRef parentNodeRef,
- NodeRef nodeRef,
- String fileName)
- {
- JSONObject json = new JSONObject();
- try
+ if(siteId != null && !siteId.equals(""))
{
- json.put("nodeRef", nodeRef);
-
- if (parentNodeRef != null)
+ NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef();
+ FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef);
+ String name = fileInfo.getName();
+ boolean isFolder = fileInfo.isFolder();
+
+ NodeRef documentLibrary = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
+ String parentPath = "/";
+ try
{
- // Used for deleted files.
- json.put("parentNodeRef", parentNodeRef);
+ parentPath = getPathFromNode(documentLibrary, parentNodeRef);
+ }
+ catch (FileNotFoundException error)
+ {
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found.");
+ }
}
- if (path != null)
- {
- // Used for deleted files and folders (added or deleted)
- json.put("page", "documentlibrary?path=" + path);
- }
- else
- {
- // Used for added or modified files.
- json.put("page", "document-details?nodeRef=" + nodeRef);
- }
- json.put("title", fileName);
-
- if (!tenantDomain.equals(TenantService.DEFAULT_DOMAIN))
- {
- // Only used in multi-tenant setups.
- json.put("tenantDomain", tenantDomain);
- }
+ return new ActivityInfo(nodeRef, parentPath, parentNodeRef, siteId, name, isFolder);
}
- catch (JSONException error)
+ else
{
- throw new AlfrescoRuntimeException("", error);
+ return null;
}
-
- return json;
}
public static class ActivityInfo
{
- private NodeRef nodeRef;
+ private NodeRef nodeRef;
private String parentPath;
private NodeRef parentNodeRef;
private String siteId;
private String fileName;
private boolean isFolder;
- public ActivityInfo(NodeRef nodeRef, String parentPath, NodeRef parentNodeRef,
- String siteId, String fileName, boolean isFolder)
- {
- super();
- this.nodeRef = nodeRef;
- this.parentPath = parentPath;
- this.parentNodeRef = parentNodeRef;
- this.siteId = siteId;
- this.fileName = fileName;
- this.isFolder = isFolder;
- }
-
- public NodeRef getNodeRef()
- {
- return nodeRef;
- }
+ public ActivityInfo(NodeRef nodeRef, String parentPath, NodeRef parentNodeRef,
+ String siteId, String fileName, boolean isFolder)
+ {
+ super();
+ this.nodeRef = nodeRef;
+ this.parentPath = parentPath;
+ this.parentNodeRef = parentNodeRef;
+ this.siteId = siteId;
+ this.fileName = fileName;
+ this.isFolder = isFolder;
+ }
+
+ public NodeRef getNodeRef()
+ {
+ return nodeRef;
+ }
- public String getParentPath()
- {
- return parentPath;
- }
+ public String getParentPath()
+ {
+ return parentPath;
+ }
- public NodeRef getParentNodeRef()
- {
- return parentNodeRef;
- }
+ public NodeRef getParentNodeRef()
+ {
+ return parentNodeRef;
+ }
- public String getSiteId()
- {
- return siteId;
- }
-
- public String getFileName()
- {
- return fileName;
- }
-
+ public String getSiteId()
+ {
+ return siteId;
+ }
+
+ public String getFileName()
+ {
+ return fileName;
+ }
+
public boolean isFolder()
{
return isFolder;
diff --git a/source/java/org/alfresco/opencmis/CMISConnector.java b/source/java/org/alfresco/opencmis/CMISConnector.java
index b9a635ffb4..a9a119a825 100644
--- a/source/java/org/alfresco/opencmis/CMISConnector.java
+++ b/source/java/org/alfresco/opencmis/CMISConnector.java
@@ -321,7 +321,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
private ServiceRegistry serviceRegistry;
private EventPublisher eventPublisher;
- private ActivityPoster activityPoster;
+ private CmisActivityPoster activityPoster;
private BehaviourFilter behaviourFilter;
@@ -376,12 +376,12 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
this.siteService = siteService;
}
- public void setActivityPoster(ActivityPoster activityPoster)
+ public void setActivityPoster(CmisActivityPoster activityPoster)
{
this.activityPoster = activityPoster;
}
- public ActivityPoster getActivityPoster()
+ public CmisActivityPoster getActivityPoster()
{
return activityPoster;
}
diff --git a/source/java/org/alfresco/opencmis/ActivityPoster.java b/source/java/org/alfresco/opencmis/CmisActivityPoster.java
similarity index 93%
rename from source/java/org/alfresco/opencmis/ActivityPoster.java
rename to source/java/org/alfresco/opencmis/CmisActivityPoster.java
index 783066b709..83ab491aad 100644
--- a/source/java/org/alfresco/opencmis/ActivityPoster.java
+++ b/source/java/org/alfresco/opencmis/CmisActivityPoster.java
@@ -26,8 +26,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
*
* @author sglover
*/
-// TODO consolidate with ActivityPost for WebDAV
-public interface ActivityPoster
+public interface CmisActivityPoster
{
void postFileFolderAdded(NodeRef nodeRef);
diff --git a/source/java/org/alfresco/service/cmr/activities/ActivityPoster.java b/source/java/org/alfresco/service/cmr/activities/ActivityPoster.java
new file mode 100644
index 0000000000..8f08568da1
--- /dev/null
+++ b/source/java/org/alfresco/service/cmr/activities/ActivityPoster.java
@@ -0,0 +1,33 @@
+package org.alfresco.service.cmr.activities;
+
+import org.alfresco.repo.Client;
+import org.alfresco.service.cmr.model.FileInfo;
+import org.alfresco.service.cmr.repository.NodeRef;
+
+/**
+ * A consolidated services for posting file folder activities.
+ *
+ * @author Gethin James
+ */
+public interface ActivityPoster
+{
+
+ public static final String DOWNLOADED = "org.alfresco.documentlibrary.file-downloaded";
+ /**
+ * Posts file folder activity.
+ * @param activityType required
+ * @param path optional
+ * @param tenantDomain optional
+ * @param siteId required
+ * @param parentNodeRef optional
+ * @param nodeRef required
+ * @param fileName required
+ * @param appTool required
+ * @param client required
+ * @param fileInfo optional
+ */
+ void postFileFolderActivity(String activityType, String path, String tenantDomain,
+ String siteId, NodeRef parentNodeRef, NodeRef nodeRef, String fileName,
+ String appTool, Client client, FileInfo fileInfo);
+
+}
diff --git a/source/java/org/alfresco/service/cmr/activities/FileFolderActivityPosterImpl.java b/source/java/org/alfresco/service/cmr/activities/FileFolderActivityPosterImpl.java
new file mode 100644
index 0000000000..063cd57c25
--- /dev/null
+++ b/source/java/org/alfresco/service/cmr/activities/FileFolderActivityPosterImpl.java
@@ -0,0 +1,108 @@
+package org.alfresco.service.cmr.activities;
+
+import org.alfresco.error.AlfrescoRuntimeException;
+import org.alfresco.repo.Client;
+import org.alfresco.repo.tenant.TenantService;
+import org.alfresco.service.cmr.model.FileInfo;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * A consolidated services for posting file folder activities.
+ * Some code was moved from webdav.ActivityPosterImpl and
+ * opencmis.ActivityPosterImpl.
+ *
+ * @author Gethin James
+ */
+public class FileFolderActivityPosterImpl implements ActivityPoster
+{
+ private ActivityService activityService;
+
+ @Override
+ public void postFileFolderActivity(
+ String activityType,
+ String path,
+ String tenantDomain,
+ String siteId,
+ NodeRef parentNodeRef,
+ NodeRef nodeRef,
+ String fileName,
+ String appTool,
+ Client client,
+ FileInfo fileInfo)
+ {
+
+ JSONObject json;
+ try
+ {
+ json = createActivityJSON(tenantDomain, path, parentNodeRef, nodeRef, fileName);
+ }
+ catch (JSONException jsonError)
+ {
+ throw new AlfrescoRuntimeException("Unabled to create activities json", jsonError);
+ }
+
+ activityService.postActivity(
+ activityType,
+ siteId,
+ appTool,
+ json.toString(),
+ client,
+ fileInfo);
+ }
+
+ /**
+ * Create JSON suitable for create, modify or delete activity posts.
+ *
+ * @param tenantDomain
+ * @param path
+ * @param parentNodeRef
+ * @param nodeRef
+ * @param fileName
+ * @throws JSONException
+ * @return JSONObject
+ */
+ protected JSONObject createActivityJSON(
+ String tenantDomain,
+ String path,
+ NodeRef parentNodeRef,
+ NodeRef nodeRef,
+ String fileName) throws JSONException
+ {
+ JSONObject json = new JSONObject();
+
+ json.put("nodeRef", nodeRef);
+
+ if (parentNodeRef != null)
+ {
+ // Used for deleted files.
+ json.put("parentNodeRef", parentNodeRef);
+ }
+
+ if (path != null)
+ {
+ // Used for deleted files and folders (added or deleted)
+ json.put("page", "documentlibrary?path=" + path);
+ }
+ else
+ {
+ // Used for added or modified files.
+ json.put("page", "document-details?nodeRef=" + nodeRef);
+ }
+ json.put("title", fileName);
+
+ if (tenantDomain!= null && !tenantDomain.equals(TenantService.DEFAULT_DOMAIN))
+ {
+ // Only used in multi-tenant setups.
+ json.put("tenantDomain", tenantDomain);
+ }
+
+ return json;
+ }
+
+ public void setActivityService(ActivityService activityService)
+ {
+ this.activityService = activityService;
+ }
+}