mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged BRANCHES/DEV/CLOUD1-BUG-FIX to HEAD:
42884: ALF-1059 / CLOUD-469: Post activities for folder(s) add + delete git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@42891 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -25,19 +25,21 @@ import org.alfresco.service.cmr.model.FileInfo;
|
||||
*
|
||||
* @author Matt Ward
|
||||
*/
|
||||
// TODO consolidate with ActivityPost for OpenCMIS
|
||||
public interface ActivityPoster
|
||||
{
|
||||
void postFileAdded(
|
||||
void postFileFolderAdded(
|
||||
String siteId,
|
||||
String tenantDomain,
|
||||
FileInfo contentNodeInfo) throws WebDAVServerException;
|
||||
String path,
|
||||
FileInfo nodeInfo) throws WebDAVServerException;
|
||||
|
||||
void postFileUpdated(
|
||||
void postFileFolderUpdated(
|
||||
String siteId,
|
||||
String tenantDomain,
|
||||
FileInfo contentNodeInfo) throws WebDAVServerException;
|
||||
FileInfo nodeInfo) throws WebDAVServerException;
|
||||
|
||||
void postFileDeleted(
|
||||
void postFileFolderDeleted(
|
||||
String siteId,
|
||||
String tenantDomain,
|
||||
String parentPath,
|
||||
|
@@ -34,6 +34,7 @@ import org.json.JSONObject;
|
||||
* @see ActivityPoster
|
||||
* @author Matt Ward
|
||||
*/
|
||||
// TODO consolidate with ActivityPost for OpenCMIS
|
||||
public class ActivityPosterImpl implements ActivityPoster
|
||||
{
|
||||
private String appTool;
|
||||
@@ -66,53 +67,57 @@ public class ActivityPosterImpl implements ActivityPoster
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void postFileAdded(
|
||||
public void postFileFolderAdded(
|
||||
String siteId,
|
||||
String tenantDomain,
|
||||
FileInfo contentNodeInfo) throws WebDAVServerException
|
||||
String path,
|
||||
FileInfo nodeInfo) throws WebDAVServerException
|
||||
{
|
||||
postFileActivity(ActivityType.FILE_ADDED, siteId, tenantDomain, null, null, contentNodeInfo);
|
||||
postFileFolderActivity(nodeInfo.isFolder() ? ActivityType.FOLDER_ADDED : ActivityType.FILE_ADDED, siteId, tenantDomain, path, null, nodeInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void postFileUpdated(
|
||||
public void postFileFolderUpdated(
|
||||
String siteId,
|
||||
String tenantDomain,
|
||||
FileInfo contentNodeInfo) throws WebDAVServerException
|
||||
FileInfo nodeInfo) throws WebDAVServerException
|
||||
{
|
||||
postFileActivity(ActivityType.FILE_UPDATED, siteId, tenantDomain, null, null, contentNodeInfo);
|
||||
if (! nodeInfo.isFolder())
|
||||
{
|
||||
postFileFolderActivity(ActivityType.FILE_UPDATED, siteId, tenantDomain, null, null, nodeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void postFileDeleted(
|
||||
public void postFileFolderDeleted(
|
||||
String siteId,
|
||||
String tenantDomain,
|
||||
String parentPath,
|
||||
FileInfo parentNodeInfo,
|
||||
FileInfo contentNodeInfo) throws WebDAVServerException
|
||||
FileInfo nodeInfo) throws WebDAVServerException
|
||||
{
|
||||
postFileActivity(ActivityType.FILE_DELETED, siteId, tenantDomain, parentPath, parentNodeInfo.getNodeRef(), contentNodeInfo);
|
||||
postFileFolderActivity(nodeInfo.isFolder() ? ActivityType.FOLDER_DELETED : ActivityType.FILE_DELETED, siteId, tenantDomain, parentPath, parentNodeInfo.getNodeRef(), nodeInfo);
|
||||
}
|
||||
|
||||
|
||||
private void postFileActivity(
|
||||
private void postFileFolderActivity(
|
||||
String activityType,
|
||||
String siteId,
|
||||
String tenantDomain,
|
||||
String parentPath,
|
||||
String path,
|
||||
NodeRef parentNodeRef,
|
||||
FileInfo contentNodeInfo) throws WebDAVServerException
|
||||
{
|
||||
String fileName = contentNodeInfo.getName();
|
||||
NodeRef nodeRef = contentNodeInfo.getNodeRef();
|
||||
|
||||
JSONObject json = createActivityJSON(tenantDomain, parentPath, parentNodeRef, nodeRef, fileName);
|
||||
JSONObject json = createActivityJSON(tenantDomain, path, parentNodeRef, nodeRef, fileName);
|
||||
|
||||
activityService.postActivity(
|
||||
activityType,
|
||||
@@ -133,7 +138,7 @@ public class ActivityPosterImpl implements ActivityPoster
|
||||
*/
|
||||
private JSONObject createActivityJSON(
|
||||
String tenantDomain,
|
||||
String parentPath,
|
||||
String path,
|
||||
NodeRef parentNodeRef,
|
||||
NodeRef nodeRef,
|
||||
String fileName) throws WebDAVServerException
|
||||
@@ -149,10 +154,10 @@ public class ActivityPosterImpl implements ActivityPoster
|
||||
json.put("parentNodeRef", parentNodeRef);
|
||||
}
|
||||
|
||||
if (parentPath != null)
|
||||
if (path != null)
|
||||
{
|
||||
// Used for deleted files.
|
||||
json.put("page", "documentlibrary?path=" + parentPath);
|
||||
// Used for deleted files and folders (added or deleted)
|
||||
json.put("page", "documentlibrary?path=" + path);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -108,14 +108,14 @@ public class DeleteMethod extends WebDAVMethod implements ActivityPostProducer
|
||||
String siteId = getSiteId();
|
||||
NodeRef deletedNodeRef = fileInfo.getNodeRef();
|
||||
FileInfo parentFile = getDAVHelper().getParentNodeForPath(getRootNodeRef(), getPath(), getServletPath());
|
||||
boolean hidden = getNodeService().hasAspect(deletedNodeRef, ContentModel.ASPECT_HIDDEN);
|
||||
boolean hidden = fileInfo.isHidden();
|
||||
// Delete it
|
||||
fileFolderService.delete(deletedNodeRef);
|
||||
// Don't post activity data for hidden files, resource forks etc.
|
||||
if (!hidden)
|
||||
{
|
||||
postActivity(parentFile, fileInfo, siteId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class DeleteMethod extends WebDAVMethod implements ActivityPostProducer
|
||||
}
|
||||
}
|
||||
|
||||
activityPoster.postFileDeleted(siteId, tenantDomain, parentPath, parent, deletedFile);
|
||||
activityPoster.postFileFolderDeleted(siteId, tenantDomain, parentPath, parent, deletedFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
||||
* Copyright (C) 2005-2012 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
@@ -25,14 +25,18 @@ import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.cmr.webdav.WebDavService;
|
||||
|
||||
/**
|
||||
* Implements the WebDAV MKCOL method
|
||||
*
|
||||
* @author gavinc
|
||||
*/
|
||||
public class MkcolMethod extends WebDAVMethod
|
||||
public class MkcolMethod extends WebDAVMethod implements ActivityPostProducer
|
||||
{
|
||||
private ActivityPoster activityPoster;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
@@ -124,9 +128,60 @@ public class MkcolMethod extends WebDAVMethod
|
||||
String folderName = getPath().substring(lastPos + 1);
|
||||
|
||||
// Create the new folder node
|
||||
fileFolderService.create(parentNodeRef, folderName, ContentModel.TYPE_FOLDER);
|
||||
|
||||
FileInfo fileInfo = fileFolderService.create(parentNodeRef, folderName, ContentModel.TYPE_FOLDER);
|
||||
|
||||
// Don't post activity data for hidden folder
|
||||
if (!fileInfo.isHidden())
|
||||
{
|
||||
postActivity(fileInfo);
|
||||
}
|
||||
|
||||
// Return a success status
|
||||
m_response.setStatus(HttpServletResponse.SC_CREATED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a folder added activity post.
|
||||
*
|
||||
* @throws WebDAVServerException
|
||||
*/
|
||||
private void postActivity(FileInfo fileInfo) throws WebDAVServerException
|
||||
{
|
||||
WebDavService davService = getDAVHelper().getServiceRegistry().getWebDavService();
|
||||
if (!davService.activitiesEnabled())
|
||||
{
|
||||
// Don't post activities if this behaviour is disabled.
|
||||
return;
|
||||
}
|
||||
|
||||
String siteId = getSiteId();
|
||||
String tenantDomain = getTenantDomain();
|
||||
|
||||
// Check there is enough information to publish site activity.
|
||||
if (!siteId.equals(WebDAVHelper.EMPTY_SITE_ID))
|
||||
{
|
||||
SiteService siteService = getServiceRegistry().getSiteService();
|
||||
NodeRef documentLibrary = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY);
|
||||
String path = "/";
|
||||
try
|
||||
{
|
||||
path = getDAVHelper().getPathFromNode(documentLibrary, fileInfo.getNodeRef());
|
||||
}
|
||||
catch (FileNotFoundException error)
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found.");
|
||||
}
|
||||
}
|
||||
|
||||
activityPoster.postFileFolderAdded(siteId, tenantDomain, path, fileInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivityPoster(ActivityPoster activityPoster)
|
||||
{
|
||||
this.activityPoster = activityPoster;
|
||||
}
|
||||
}
|
||||
|
@@ -363,12 +363,14 @@ public class PutMethod extends WebDAVMethod implements ActivityPostProducer
|
||||
if (!getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_HIDDEN))
|
||||
{
|
||||
if (isCreated())
|
||||
{
|
||||
activityPoster.postFileAdded(siteId, tenantDomain, contentNodeInfo);
|
||||
{
|
||||
// file added
|
||||
activityPoster.postFileFolderAdded(siteId, tenantDomain, null, contentNodeInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
activityPoster.postFileUpdated(siteId, tenantDomain, contentNodeInfo);
|
||||
{
|
||||
// file updated
|
||||
activityPoster.postFileFolderUpdated(siteId, tenantDomain, contentNodeInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user