mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)
82375: Merged WAT2 (5.0/Cloud) to HEAD-BUG-FIX (5.0/Cloud) 76480: Re-worked download activity posting following Kev's changes git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@83218 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1816,7 +1816,7 @@
|
||||
<!-- Share Content Download - post of an Activity before performing a Site download action -->
|
||||
<bean id="webscript.org.alfresco.slingshot.download.get" class="org.alfresco.slingshot.web.scripts.SlingshotContentGet" parent="webscript.org.alfresco.content.content.get">
|
||||
<property name="siteService" ref="SiteService" />
|
||||
<property name="activityService" ref="activityService" />
|
||||
<property name="poster" ref="activitiesPoster" />
|
||||
</bean>
|
||||
|
||||
<!-- Get/Post/Put/Delete Solr FacetConfig -->
|
||||
|
@@ -28,5 +28,5 @@ package org.alfresco.repo.webdav;
|
||||
*/
|
||||
public interface ActivityPostProducer
|
||||
{
|
||||
void setActivityPoster(ActivityPoster activityPoster);
|
||||
void setActivityPoster(WebDAVActivityPoster activityPoster);
|
||||
}
|
||||
|
@@ -20,28 +20,29 @@ package org.alfresco.repo.webdav;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.repo.Client;
|
||||
import org.alfresco.repo.Client.ClientType;
|
||||
import org.alfresco.repo.activities.ActivityType;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.service.cmr.activities.ActivityPoster;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* WebDAV methods may use an instance of this class to post activity data.
|
||||
*
|
||||
* @see ActivityPoster
|
||||
* @see WebDAVActivityPoster
|
||||
* @author Matt Ward
|
||||
*/
|
||||
// TODO consolidate with ActivityPost for OpenCMIS
|
||||
public class ActivityPosterImpl implements ActivityPoster
|
||||
public class ActivityPosterImpl implements WebDAVActivityPoster
|
||||
{
|
||||
private String appTool;
|
||||
private ActivityService activityService;
|
||||
private ActivityPoster poster;
|
||||
|
||||
protected static Log logger = LogFactory.getLog("org.alfresco.webdav.protocol.activity");
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
@@ -61,7 +62,6 @@ public class ActivityPosterImpl implements ActivityPoster
|
||||
public ActivityPosterImpl(String appTool, ActivityService activityService)
|
||||
{
|
||||
this.appTool = appTool;
|
||||
this.activityService = activityService;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,78 +119,27 @@ public class ActivityPosterImpl implements ActivityPoster
|
||||
String fileName = contentNodeInfo.getName();
|
||||
NodeRef nodeRef = contentNodeInfo.getNodeRef();
|
||||
|
||||
JSONObject json = createActivityJSON(tenantDomain, path, parentNodeRef, nodeRef, fileName);
|
||||
|
||||
activityService.postActivity(
|
||||
activityType,
|
||||
siteId,
|
||||
appTool,
|
||||
json.toString(),
|
||||
Client.asType(ClientType.webdav),
|
||||
contentNodeInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) throws WebDAVServerException
|
||||
{
|
||||
JSONObject json = new JSONObject();
|
||||
try
|
||||
{
|
||||
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.equals(TenantService.DEFAULT_DOMAIN))
|
||||
{
|
||||
// Only used in multi-tenant setups.
|
||||
json.put("tenantDomain", tenantDomain);
|
||||
}
|
||||
poster.postFileFolderActivity(activityType, path, tenantDomain, siteId,
|
||||
parentNodeRef, nodeRef, fileName,
|
||||
appTool, Client.asType(ClientType.webdav),contentNodeInfo);
|
||||
}
|
||||
catch (JSONException error)
|
||||
catch (AlfrescoRuntimeException are)
|
||||
{
|
||||
logger.error("Failed to post activity.", are);
|
||||
throw new WebDAVServerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
public void setAppTool(String appTool)
|
||||
{
|
||||
this.appTool = appTool;
|
||||
}
|
||||
|
||||
public void setActivityService(ActivityService activityService)
|
||||
public void setPoster(ActivityPoster poster)
|
||||
{
|
||||
this.activityService = activityService;
|
||||
this.poster = poster;
|
||||
}
|
||||
}
|
||||
|
@@ -45,7 +45,7 @@ import org.alfresco.util.FileFilterMode;
|
||||
*/
|
||||
public class DeleteMethod extends WebDAVMethod implements ActivityPostProducer
|
||||
{
|
||||
private ActivityPoster activityPoster;
|
||||
private WebDAVActivityPoster activityPoster;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
@@ -248,7 +248,7 @@ public class DeleteMethod extends WebDAVMethod implements ActivityPostProducer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivityPoster(ActivityPoster activityPoster)
|
||||
public void setActivityPoster(WebDAVActivityPoster activityPoster)
|
||||
{
|
||||
this.activityPoster = activityPoster;
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ import org.alfresco.service.cmr.webdav.WebDavService;
|
||||
*/
|
||||
public class MkcolMethod extends WebDAVMethod implements ActivityPostProducer
|
||||
{
|
||||
private ActivityPoster activityPoster;
|
||||
private WebDAVActivityPoster activityPoster;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
@@ -180,7 +180,7 @@ public class MkcolMethod extends WebDAVMethod implements ActivityPostProducer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivityPoster(ActivityPoster activityPoster)
|
||||
public void setActivityPoster(WebDAVActivityPoster activityPoster)
|
||||
{
|
||||
this.activityPoster = activityPoster;
|
||||
}
|
||||
|
@@ -52,7 +52,7 @@ public class PutMethod extends WebDAVMethod implements ActivityPostProducer
|
||||
// Try to delete the node if the PUT fails
|
||||
private boolean noContent = false;
|
||||
private boolean created = false;
|
||||
private ActivityPoster activityPoster;
|
||||
private WebDAVActivityPoster activityPoster;
|
||||
private FileInfo contentNodeInfo;
|
||||
private long fileSize;
|
||||
|
||||
@@ -411,7 +411,7 @@ public class PutMethod extends WebDAVMethod implements ActivityPostProducer
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActivityPoster(ActivityPoster activityPoster)
|
||||
public void setActivityPoster(WebDAVActivityPoster activityPoster)
|
||||
{
|
||||
this.activityPoster = activityPoster;
|
||||
}
|
||||
|
@@ -25,8 +25,7 @@ import org.alfresco.service.cmr.model.FileInfo;
|
||||
*
|
||||
* @author Matt Ward
|
||||
*/
|
||||
// TODO consolidate with ActivityPost for OpenCMIS
|
||||
public interface ActivityPoster
|
||||
public interface WebDAVActivityPoster
|
||||
{
|
||||
void postFileFolderAdded(
|
||||
String siteId,
|
@@ -32,15 +32,10 @@ import java.util.regex.Pattern;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.events.types.ContentEvent;
|
||||
import org.alfresco.events.types.ContentEventImpl;
|
||||
import org.alfresco.events.types.ContentReadRangeEvent;
|
||||
import org.alfresco.events.types.Event;
|
||||
import org.alfresco.jlan.util.IPAddress;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.Client;
|
||||
import org.alfresco.repo.Client.ClientType;
|
||||
import org.alfresco.repo.events.EventPreparator;
|
||||
import org.alfresco.repo.events.EventPublisher;
|
||||
import org.alfresco.repo.lock.LockUtils;
|
||||
import org.alfresco.repo.model.filefolder.HiddenAspect;
|
||||
@@ -48,6 +43,7 @@ import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.action.ActionService;
|
||||
import org.alfresco.service.cmr.activities.ActivityPoster;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.lock.LockService;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
@@ -112,6 +108,7 @@ public class WebDAVHelper
|
||||
private TenantService m_tenantService;
|
||||
private HiddenAspect m_hiddenAspect;
|
||||
private EventPublisher eventPublisher;
|
||||
private ActivityPoster poster;
|
||||
|
||||
// pattern is tested against full path after it has been lower cased.
|
||||
private Pattern m_renameShufflePattern = Pattern.compile("(.*/\\..*)|(.*[a-f0-9]{8}+$)|(.*\\.tmp$)|(.*\\.wbk$)|(.*\\.bak$)|(.*\\~$)|(.*backup.*\\.do[ct]{1}[x]?[m]?$)|(.*\\.sb\\-\\w{8}\\-\\w{6}$)");
|
||||
@@ -335,6 +332,15 @@ public class WebDAVHelper
|
||||
this.eventPublisher = eventPublisher;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param poster
|
||||
*/
|
||||
public void setPoster(ActivityPoster poster)
|
||||
{
|
||||
this.poster = poster;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dictionaryService the dictionary service
|
||||
*/
|
||||
@@ -1091,25 +1097,30 @@ public class WebDAVHelper
|
||||
protected void publishReadEvent(final FileInfo realNodeInfo, final String mimetype, final Long size, final String contentEncoding, final String range)
|
||||
{
|
||||
|
||||
eventPublisher.publishEvent(new EventPreparator(){
|
||||
@Override
|
||||
public Event prepareEvent(String user, String networkId, String transactionId)
|
||||
{
|
||||
// SiteService siteService = getServiceRegistry().getSiteService();
|
||||
// final String siteId = siteService.getSiteShortName(realNodeInfo.getNodeRef());
|
||||
|
||||
if (StringUtils.hasText(range))
|
||||
{
|
||||
return new ContentReadRangeEvent(user, networkId, transactionId, realNodeInfo.getNodeRef().getId(),
|
||||
null, realNodeInfo.getType().toString(), Client.asType(ClientType.webdav), realNodeInfo.getName(), mimetype, size, contentEncoding, range);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ContentEventImpl(ContentEvent.DOWNLOAD, user, networkId, transactionId, realNodeInfo.getNodeRef().getId(),
|
||||
null, realNodeInfo.getType().toString(), Client.asType(ClientType.webdav), realNodeInfo.getName(), mimetype, size, contentEncoding);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!StringUtils.hasText(range))
|
||||
{
|
||||
//Its not a range request
|
||||
SiteService siteService = getServiceRegistry().getSiteService();
|
||||
final String siteId = siteService.getSiteShortName(realNodeInfo.getNodeRef());
|
||||
|
||||
poster.postFileFolderActivity(ActivityPoster.DOWNLOADED, null, m_tenantService.getCurrentUserDomain(),
|
||||
siteId, null, realNodeInfo.getNodeRef(), realNodeInfo.getName(),
|
||||
"webdav", Client.asType(ClientType.webdav), null);
|
||||
}
|
||||
|
||||
// eventPublisher.publishEvent(new EventPreparator(){
|
||||
// @Override
|
||||
// public Event prepareEvent(String user, String networkId, String transactionId)
|
||||
// {
|
||||
//
|
||||
//
|
||||
// if (StringUtils.hasText(range))
|
||||
// {
|
||||
// return new ContentReadRangeEvent(user, networkId, transactionId, realNodeInfo.getNodeRef().getId(),
|
||||
// siteId, realNodeInfo.getType().toString(), Client.asType(ClientType.webdav), realNodeInfo.getName(), mimetype, size, contentEncoding, range);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
|
@@ -92,7 +92,7 @@ public class WebDAVServlet extends HttpServlet
|
||||
|
||||
// WebDAV helper class
|
||||
private WebDAVHelper m_davHelper;
|
||||
private ActivityPoster activityPoster;
|
||||
private WebDAVActivityPoster activityPoster;
|
||||
|
||||
/**
|
||||
* @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
|
||||
|
@@ -22,15 +22,15 @@ import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.Client;
|
||||
import org.alfresco.repo.Client.ClientType;
|
||||
import org.alfresco.repo.web.scripts.content.ContentGet;
|
||||
import org.alfresco.service.cmr.activities.ActivityService;
|
||||
import org.alfresco.service.cmr.activities.ActivityPoster;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.springframework.extensions.surf.util.StringBuilderWriter;
|
||||
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||
import org.springframework.extensions.webscripts.json.JSONWriter;
|
||||
|
||||
/**
|
||||
* Share specific ContentGet implementation.
|
||||
@@ -47,16 +47,16 @@ import org.springframework.extensions.webscripts.json.JSONWriter;
|
||||
public class SlingshotContentGet extends ContentGet
|
||||
{
|
||||
protected SiteService siteService;
|
||||
protected ActivityService activityService;
|
||||
private ActivityPoster poster;
|
||||
|
||||
public void setSiteService(SiteService siteService)
|
||||
{
|
||||
this.siteService = siteService;
|
||||
}
|
||||
|
||||
public void setActivityService(ActivityService activityService)
|
||||
public void setPoster(ActivityPoster poster)
|
||||
{
|
||||
this.activityService = activityService;
|
||||
this.poster = poster;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -68,7 +68,7 @@ public class SlingshotContentGet extends ContentGet
|
||||
// are we downloading content as an attachment?
|
||||
if (Boolean.valueOf(req.getParameter("a")))
|
||||
{
|
||||
// is this node part of a Site context?
|
||||
// is this private ActivityPoster poster; node part of a Site context?
|
||||
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
|
||||
String storeType = templateVars.get("store_type");
|
||||
String storeId = templateVars.get("store_id");
|
||||
@@ -87,20 +87,9 @@ public class SlingshotContentGet extends ContentGet
|
||||
{
|
||||
filename = (String)this.nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
|
||||
}
|
||||
StringBuilderWriter out = new StringBuilderWriter(256);
|
||||
final JSONWriter json = new JSONWriter(out);
|
||||
json.startObject();
|
||||
json.writeValue("title", filename);
|
||||
json.writeValue("nodeRef", nodeRef.toString());
|
||||
json.writeValue("page", "document-details?nodeRef=" + nodeRef.toString());
|
||||
json.endObject();
|
||||
|
||||
// post an activity - mirror the mechanism as if from the Share application
|
||||
this.activityService.postActivity(
|
||||
"org.alfresco.documentlibrary.file-downloaded",
|
||||
site.getShortName(),
|
||||
"documentlibrary",
|
||||
out.toString());
|
||||
poster.postFileFolderActivity(ActivityPoster.DOWNLOADED, null, null,
|
||||
site.getShortName(), null, nodeRef, filename, "documentlibrary", Client.asType(ClientType.webclient), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -133,27 +133,4 @@ public class WebDAVHelperIntegrationTest
|
||||
FileInfo found = webDAVHelper.getNodeForPath(rootFolder, "/");
|
||||
assertEquals(rootFolder, found.getNodeRef());
|
||||
}
|
||||
/*
|
||||
@Test
|
||||
public void testPublishEvent()
|
||||
{
|
||||
FileInfo folderInfo = fileFolderService.create(rootFolder, "my_folder", ContentModel.TYPE_FOLDER);
|
||||
FileInfo fileInfo = fileFolderService.create(folderInfo.getNodeRef(), "my_file.txt", ContentModel.TYPE_CONTENT);
|
||||
webDAVHelper.publishReadEvent(fileInfo, "text", 2l, "UTF-8", null);
|
||||
|
||||
List<ContentReadEvent> readEvents = eventPublisher.getQueueByType(ContentReadEvent.class);
|
||||
boolean found = false;
|
||||
for (ContentReadEvent event : readEvents)
|
||||
{
|
||||
if (fileInfo.getNodeRef().getId().equals(event.getNodeId()))
|
||||
{
|
||||
assertEquals(event.getMimeType(),("text"));
|
||||
assertEquals(event.getClient(),Client.webdav);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertTrue(found);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user