diff --git a/source/java/org/alfresco/rest/api/Nodes.java b/source/java/org/alfresco/rest/api/Nodes.java index 8027254a7b..43da2c6db0 100644 --- a/source/java/org/alfresco/rest/api/Nodes.java +++ b/source/java/org/alfresco/rest/api/Nodes.java @@ -159,9 +159,10 @@ public interface Nodes * * @param fileNodeId * @param parameters + * @param recordActivity true, if an activity post is required. * @return */ - BinaryResource getContent(String fileNodeId, Parameters parameters); + BinaryResource getContent(String fileNodeId, Parameters parameters, boolean recordActivity); /** * Uploads file content (updates existing node with new content). diff --git a/source/java/org/alfresco/rest/api/impl/NodesImpl.java b/source/java/org/alfresco/rest/api/impl/NodesImpl.java index e16783298b..8fed152b1b 100644 --- a/source/java/org/alfresco/rest/api/impl/NodesImpl.java +++ b/source/java/org/alfresco/rest/api/impl/NodesImpl.java @@ -25,29 +25,11 @@ */ package org.alfresco.rest.api.impl; -import java.io.InputStream; -import java.io.Serializable; -import java.math.BigInteger; -import java.util.AbstractList; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.concurrent.ConcurrentHashMap; - import org.alfresco.model.ApplicationModel; import org.alfresco.model.ContentModel; import org.alfresco.model.QuickShareModel; import org.alfresco.query.PagingRequest; import org.alfresco.query.PagingResults; -import org.alfresco.repo.Client; import org.alfresco.repo.action.executer.ContentMetadataExtracter; import org.alfresco.repo.activities.ActivityType; import org.alfresco.repo.content.ContentLimitViolationException; @@ -58,7 +40,6 @@ import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery; import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; -import org.alfresco.repo.security.authentication.HashPasswordTransactionListener; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.site.SiteModel; import org.alfresco.repo.tenant.TenantUtil; @@ -153,6 +134,23 @@ import org.springframework.extensions.webscripts.servlet.FormData; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; +import java.io.InputStream; +import java.io.Serializable; +import java.math.BigInteger; +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.concurrent.ConcurrentHashMap; + /** * Centralises access to file/folder/node services and maps between representations. * @@ -1950,7 +1948,7 @@ public class NodesImpl implements Nodes } @Override - public BinaryResource getContent(String fileNodeId, Parameters parameters) + public BinaryResource getContent(String fileNodeId, Parameters parameters, boolean recordActivity) { final NodeRef nodeRef = validateNode(fileNodeId); @@ -1991,8 +1989,11 @@ public class NodesImpl implements Nodes } String attachFileName = (attach ? name : null); - final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef); - postActivity(Activity_Type.DOWNLOADED, activityInfo, true); + if (recordActivity) + { + final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef); + postActivity(Activity_Type.DOWNLOADED, activityInfo, true); + } return new NodeBinaryResource(nodeRef, ContentModel.PROP_CONTENT, ci, attachFileName); } diff --git a/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java b/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java index 85942c0954..e0391fd2d5 100644 --- a/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java +++ b/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java @@ -235,7 +235,7 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean } else { - return nodes.getContent(nodeId, parameters); + return nodes.getContent(nodeId, parameters, false); } } }, networkTenantDomain); diff --git a/source/java/org/alfresco/rest/api/nodes/NodesEntityResource.java b/source/java/org/alfresco/rest/api/nodes/NodesEntityResource.java index 0ecb8f2891..2e42ab4abb 100644 --- a/source/java/org/alfresco/rest/api/nodes/NodesEntityResource.java +++ b/source/java/org/alfresco/rest/api/nodes/NodesEntityResource.java @@ -91,7 +91,7 @@ public class NodesEntityResource implements @BinaryProperties({"content"}) public BinaryResource readProperty(String fileNodeId, Parameters parameters) throws EntityNotFoundException { - return nodes.getContent(fileNodeId, parameters); + return nodes.getContent(fileNodeId, parameters, true); } @Override diff --git a/source/test-java/org/alfresco/rest/api/tests/ActivitiesPostingTest.java b/source/test-java/org/alfresco/rest/api/tests/ActivitiesPostingTest.java index 507a4fd929..933f192637 100644 --- a/source/test-java/org/alfresco/rest/api/tests/ActivitiesPostingTest.java +++ b/source/test-java/org/alfresco/rest/api/tests/ActivitiesPostingTest.java @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2005-2016 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.rest.api.tests; import static org.alfresco.rest.api.tests.util.RestApiUtil.toJsonAsStringNonNull; @@ -41,6 +59,9 @@ import java.util.Map; public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest { + /** + * Tests the main activites, added, updated, deleted, downloaded + */ @Test public void testCreateUpdate() throws Exception { @@ -54,10 +75,10 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest //Update the file Document dUpdate = new Document(); dUpdate.setName("d1b.txt"); - HttpResponse response = put(URL_NODES, u1.getId(), documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200); + put(URL_NODES, u1.getId(), documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200); //Now download it - response = getSingle(NodesEntityResource.class, u1.getId(), documentResp.getId()+"/content", null, 200); + HttpResponse response = getSingle(NodesEntityResource.class, u1.getId(), documentResp.getId()+"/content", null, 200); String textContent = response.getResponse(); assertNotNull(textContent); @@ -85,6 +106,9 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest assertNotNull(act); } + /** + * Tests non-file activites. So no events. + */ @Test public void testNonFileActivities() throws Exception { @@ -103,6 +127,9 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest assertEquals("No activites should be created for non-file activities", activities, activitiesAgain); } + /** + * Tests non-site file activites. So no events. + */ @Test public void testNonSite() throws Exception { @@ -119,12 +146,17 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest //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); + put(URL_NODES, u1.getId(), documentResp.getId(), toJsonAsStringNonNull(dUpdate), null, 200); List activitiesAgain = getMyActivites(); assertEquals("No activites should be created for non-site nodes", activities, activitiesAgain); } + /** + * Generate the feed an get the activities for user1 + * @return + * @throws Exception + */ private List getMyActivites() throws Exception { repoService.generateFeed(); @@ -136,6 +168,16 @@ public class ActivitiesPostingTest extends AbstractSingleNetworkSiteTest } + /** + * Match an exact activity by a combination of the parameters + * @param list + * @param type + * @param user + * @param siteId + * @param parentId + * @param title + * @return + */ private Activity matchActivity(List list, String type, String user, String siteId, String parentId, String title) { for (Activity act:list)