From c166849c87802e148687572711cce5db4a7fa23c Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Tue, 22 Jul 2014 12:15:29 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud) 75134: Merged BRANCHES/DEV/KEVINR3 to BRANCHES/DEV/HEAD-BUG-FIX 71905: Merged BRANCHES/DEV/KEVINR2 to BRANCHES/DEV/KEVINR3 71779: Activities prototype - PDF Previewer link to original PDF correction 71776: Activities prototype - Slingshot download urls for Image Preview dashlet and PDF Previewer components. 71752: Activities prototype - Added activity feed items for Preview and Download actions 71913: Activities prototype - styling and UX 72000: Activities prototype - improved CSS 73462: Activities prototype - CSS tweaks 75128: Activities prototype - CSS tweaks git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@77438 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/public-rest-context.xml | 2 + .../documentlibrary/activity.post.json.js | 2 + .../alfresco/slingshot/download.get.desc.xml | 12 ++ .../web-scripts-application-context.xml | 6 + .../web/scripts/SlingshotContentGet.java | 109 ++++++++++++++++++ 5 files changed, 131 insertions(+) create mode 100644 config/alfresco/templates/webscripts/org/alfresco/slingshot/download.get.desc.xml create mode 100644 source/java/org/alfresco/slingshot/web/scripts/SlingshotContentGet.java diff --git a/config/alfresco/public-rest-context.xml b/config/alfresco/public-rest-context.xml index 5878c4fd8e..df5faa069a 100644 --- a/config/alfresco/public-rest-context.xml +++ b/config/alfresco/public-rest-context.xml @@ -258,6 +258,8 @@ org.alfresco.documentlibrary.file-created org.alfresco.documentlibrary.file-deleted org.alfresco.documentlibrary.file-liked + org.alfresco.documentlibrary.file-previewed + org.alfresco.documentlibrary.file-downloaded org.alfresco.documentlibrary.inline-edit org.alfresco.documentlibrary.folder-liked org.alfresco.documentlibrary.folder-added diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/activity.post.json.js b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/activity.post.json.js index 658236a63d..3bf6f0b63b 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/activity.post.json.js +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/activity.post.json.js @@ -82,6 +82,8 @@ function postActivity() case "file-added": case "file-updated": case "file-liked": + case "file-previewed": + case "file-downloaded": case "folder-liked": case "google-docs-checkout": case "google-docs-checkin": diff --git a/config/alfresco/templates/webscripts/org/alfresco/slingshot/download.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/slingshot/download.get.desc.xml new file mode 100644 index 0000000000..92a58f7f4e --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/slingshot/download.get.desc.xml @@ -0,0 +1,12 @@ + + DownloadContent + Slingshot download content webscript - posts an activity for Site content download then delegates to standard ContentGet implementation + /slingshot/node/content{property}/{store_type}/{store_id}/{id}?a={attach?} + /slingshot/node/content{property}/{store_type}/{store_id}/{id}/{filename}?a={attach?} + /slingshot/node/{store_type}/{store_id}/{id}/content{property}?a={attach?} + /slingshot/node/{store_type}/{store_id}/{id}/content{property}/{filename}?a={attach?} + argument + user + required + internal + \ No newline at end of file diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml index 0b76195beb..5229341c30 100644 --- a/config/alfresco/web-scripts-application-context.xml +++ b/config/alfresco/web-scripts-application-context.xml @@ -2060,4 +2060,10 @@ + + + + + + diff --git a/source/java/org/alfresco/slingshot/web/scripts/SlingshotContentGet.java b/source/java/org/alfresco/slingshot/web/scripts/SlingshotContentGet.java new file mode 100644 index 0000000000..819db53e79 --- /dev/null +++ b/source/java/org/alfresco/slingshot/web/scripts/SlingshotContentGet.java @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2005-2014 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.slingshot.web.scripts; + +import java.io.IOException; +import java.util.Map; + +import org.alfresco.model.ContentModel; +import org.alfresco.repo.web.scripts.content.ContentGet; +import org.alfresco.service.cmr.activities.ActivityService; +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. + *

+ * Checks to see if: + * a) the request is an explicit download (attachment) + * b) the requested NodeRef within the context of a Share Site + *

+ * If both tests are true then generates an Activity feed item to record the Download request. + * All other requests and any further processing is performed by the super class. + * + * @author Kevin Roast + */ +public class SlingshotContentGet extends ContentGet +{ + protected SiteService siteService; + protected ActivityService activityService; + + public void setSiteService(SiteService siteService) + { + this.siteService = siteService; + } + + public void setActivityService(ActivityService activityService) + { + this.activityService = activityService; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.web.scripts.content.ContentGet#execute(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.WebScriptResponse) + */ + @Override + public void execute(final WebScriptRequest req, final WebScriptResponse res) throws IOException + { + // are we downloading content as an attachment? + if (Boolean.valueOf(req.getParameter("a"))) + { + // is this node part of a Site context? + Map templateVars = req.getServiceMatch().getTemplateVars(); + String storeType = templateVars.get("store_type"); + String storeId = templateVars.get("store_id"); + String nodeId = templateVars.get("id"); + + // create the NodeRef and ensure it is valid + if (storeType != null && storeId != null && nodeId != null) + { + final NodeRef nodeRef = new NodeRef(storeType, storeId, nodeId); + final SiteInfo site = this.siteService.getSite(nodeRef); + if (site != null) + { + // found a valid parent Site - gather the details to post an Activity + String filename = templateVars.get("filename"); + if (filename == null || filename.length() == 0) + { + 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()); + } + } + } + super.execute(req, res); + } +} \ No newline at end of file