mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged BRANCHES/DEV/HEAD_QUICK_SHARE_TMP to HEAD:
41724: Merged BRANCHES/DEV/CLOUD1-BUG-FIX to BRANCHES/DEV/HEAD_QUICK_SHARE_TMP: 41211: CLOUD-593: Prevent copying of QuickShare properties on node copy. 41725: QuickShare: minor - rename unit test 41727: Refactored quickshare components to match new webscript boilerplate format in Share 41733: QuickShare: fix ShareContentGet NPE git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@41742 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||
{
|
||||
"sharedId" : "${sharedId}"
|
||||
"sharedId": "${sharedDTO.id}"
|
||||
}
|
||||
</#escape>
|
@@ -1853,8 +1853,7 @@
|
||||
<property name="dictionaryService" ref="DictionaryService" />
|
||||
<property name="mimetypeService" ref="MimetypeService" />
|
||||
<property name="CMISRenditionService" ref="CMISRenditionService" />
|
||||
<property name="attributeService" ref="AttributeService" />
|
||||
<property name="tenantService" ref="tenantService" />
|
||||
<property name="quickShareService" ref="QuickShareService"/>
|
||||
<property name="enabled" value="${system.quickshare.enabled}" />
|
||||
</bean>
|
||||
|
||||
@@ -1866,22 +1865,15 @@
|
||||
</bean>
|
||||
|
||||
<bean id="org.alfresco.repository.quickshare.abstract" class="org.alfresco.repo.web.scripts.quickshare.AbstractQuickShareContent" abstract="true">
|
||||
<property name="nodeService" ref="NodeService" />
|
||||
<property name="attributeService" ref="AttributeService" />
|
||||
<property name="tenantService" ref="tenantService" />
|
||||
<property name="enabled" value="${system.quickshare.enabled}" />
|
||||
<property name="quickShareService" ref="QuickShareService" />
|
||||
</bean>
|
||||
|
||||
<!-- unauthenticated (note: equivalent to authenticated "metadata.get" (limited version with thumbnail data - see below) -->
|
||||
<bean id="webscript.org.alfresco.repository.quickshare.metadata-noauth.get" class="org.alfresco.repo.web.scripts.quickshare.QuickShareMetaDataGet" parent="org.alfresco.repository.quickshare.abstract">
|
||||
<property name="personService" ref="PersonService" />
|
||||
<property name="thumbnailService" ref="ThumbnailService" />
|
||||
</bean>
|
||||
|
||||
<!-- authenticated -->
|
||||
<bean id="webscript.org.alfresco.repository.quickshare.metadata.get" class="org.alfresco.repo.web.scripts.quickshare.MetaDataGet" parent="org.alfresco.repository.quickshare.abstract">
|
||||
<property name="personService" ref="PersonService" />
|
||||
<property name="thumbnailService" ref="ThumbnailService" />
|
||||
</bean>
|
||||
|
||||
<!-- authenticated -->
|
||||
@@ -1894,8 +1886,7 @@
|
||||
</bean>
|
||||
|
||||
<!-- authenticated -->
|
||||
<bean id="webscript.org.alfresco.repository.quickshare.unshare.delete" class="org.alfresco.repo.web.scripts.quickshare.UnshareContentDelete" parent="org.alfresco.repository.quickshare.abstract" init-method="init">
|
||||
<property name="policyComponent" ref="policyComponent" />
|
||||
<bean id="webscript.org.alfresco.repository.quickshare.unshare.delete" class="org.alfresco.repo.web.scripts.quickshare.UnshareContentDelete" parent="org.alfresco.repository.quickshare.abstract">
|
||||
</bean>
|
||||
|
||||
<!-- END: QuickShare (aka PublicView) -->
|
||||
|
@@ -18,45 +18,25 @@
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.quickshare;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.service.cmr.quickshare.QuickShareService;
|
||||
import org.springframework.extensions.webscripts.DeclarativeWebScript;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
|
||||
|
||||
/**
|
||||
* QuickShare/PublicView
|
||||
*
|
||||
* @author janv
|
||||
* @since Cloud/4.2
|
||||
*/
|
||||
public abstract class AbstractQuickShareContent extends DeclarativeWebScript
|
||||
{
|
||||
protected NodeService nodeService;
|
||||
protected AttributeService attributeService;
|
||||
protected TenantService tenantService;
|
||||
protected QuickShareService quickShareService;
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
public void setQuickShareService(QuickShareService quickShareService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public void setAttributeService(AttributeService attributeService)
|
||||
{
|
||||
this.attributeService = attributeService;
|
||||
}
|
||||
|
||||
public void setTenantService(TenantService tenantService)
|
||||
{
|
||||
this.tenantService = tenantService;
|
||||
this.quickShareService = quickShareService;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled)
|
||||
@@ -68,31 +48,4 @@ public abstract class AbstractQuickShareContent extends DeclarativeWebScript
|
||||
{
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
|
||||
protected Pair<String, NodeRef> getTenantNodeRefFromSharedId(final String sharedId)
|
||||
{
|
||||
return getTenantNodeRefFromSharedId(attributeService, tenantService, sharedId);
|
||||
}
|
||||
|
||||
/* package */ static Pair<String, NodeRef> getTenantNodeRefFromSharedId(final AttributeService attributeService, final TenantService tenantService, final String sharedId)
|
||||
{
|
||||
final NodeRef nodeRef = TenantUtil.runAsDefaultTenant(new TenantRunAsWork<NodeRef>()
|
||||
{
|
||||
public NodeRef doWork() throws Exception
|
||||
{
|
||||
return (NodeRef)attributeService.getAttribute(ShareContentPost.ATTR_KEY_SHAREDIDS_ROOT, sharedId);
|
||||
}
|
||||
});
|
||||
|
||||
if (nodeRef == null)
|
||||
{
|
||||
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId);
|
||||
}
|
||||
|
||||
// note: relies on tenant-specific (ie. mangled) nodeRef
|
||||
String tenantDomain = tenantService.getDomain(nodeRef.getStoreRef().getIdentifier());
|
||||
|
||||
return new Pair<String, NodeRef>(tenantDomain, tenantService.getBaseName(nodeRef));
|
||||
}
|
||||
}
|
@@ -18,24 +18,13 @@
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.quickshare;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.thumbnail.ThumbnailDefinition;
|
||||
import org.alfresco.repo.web.scripts.WebScriptUtil;
|
||||
import org.alfresco.service.cmr.repository.ContentData;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.NoSuchPersonException;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.thumbnail.ThumbnailService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
@@ -51,25 +40,12 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
* Note: authenticated web script (equivalent to unauthenticated version - see QuickShareMetaDataGet)
|
||||
*
|
||||
* @author janv
|
||||
* @since Cloud/4.2
|
||||
*/
|
||||
public class MetaDataGet extends AbstractQuickShareContent
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(QuickShareMetaDataGet.class);
|
||||
|
||||
private PersonService personService;
|
||||
private ThumbnailService thumbnailService;
|
||||
|
||||
public void setPersonService(PersonService personService)
|
||||
{
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
public void setThumbnailService(ThumbnailService thumbnailService)
|
||||
{
|
||||
this.thumbnailService = thumbnailService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(final WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
@@ -84,7 +60,7 @@ public class MetaDataGet extends AbstractQuickShareContent
|
||||
|
||||
try
|
||||
{
|
||||
Map<String, Object> model = getMetaDataModel(nodeRef);
|
||||
Map<String, Object> model = quickShareService.getMetaData(nodeRef);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -99,92 +75,4 @@ public class MetaDataGet extends AbstractQuickShareContent
|
||||
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find nodeRef: "+inre.getNodeRef());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Map<String, Object> getMetaDataModel(NodeRef nodeRef)
|
||||
{
|
||||
QName typeQName = nodeService.getType(nodeRef);
|
||||
if (! typeQName.equals(ContentModel.TYPE_CONTENT))
|
||||
{
|
||||
throw new InvalidNodeRefException(nodeRef);
|
||||
}
|
||||
|
||||
Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
|
||||
ContentData contentData = (ContentData)nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
|
||||
|
||||
String modifierUserName = (String)nodeProps.get(ContentModel.PROP_MODIFIER);
|
||||
Map<QName, Serializable> personProps = null;
|
||||
if (modifierUserName != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
NodeRef personRef = personService.getPerson(modifierUserName);
|
||||
if (personRef != null)
|
||||
{
|
||||
personProps = nodeService.getProperties(personRef);
|
||||
}
|
||||
}
|
||||
catch (NoSuchPersonException nspe)
|
||||
{
|
||||
// absorb this exception - eg. System (or maybe the user has been deleted)
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("MetaDataGet - no such person: "+modifierUserName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> metadata = new HashMap<String, Object>(8);
|
||||
|
||||
metadata.put("name", nodeProps.get(ContentModel.PROP_NAME));
|
||||
metadata.put("title", nodeProps.get(ContentModel.PROP_TITLE));
|
||||
|
||||
if (contentData != null)
|
||||
{
|
||||
metadata.put("mimetype", contentData.getMimetype());
|
||||
metadata.put("size", contentData.getSize());
|
||||
}
|
||||
else
|
||||
{
|
||||
metadata.put("size", 0L);
|
||||
}
|
||||
|
||||
metadata.put("modified", nodeProps.get(ContentModel.PROP_MODIFIED));
|
||||
|
||||
if (personProps != null)
|
||||
{
|
||||
metadata.put("modifierFirstName", personProps.get(ContentModel.PROP_FIRSTNAME));
|
||||
metadata.put("modifierLastName", personProps.get(ContentModel.PROP_LASTNAME));
|
||||
}
|
||||
|
||||
// thumbnail defs for this nodeRef
|
||||
List<String> thumbnailDefs = new ArrayList<String>(7);
|
||||
if (contentData != null)
|
||||
{
|
||||
// Note: thumbnail defs only appear in this list if they can produce a thumbnail for the content
|
||||
// found in the content property of this node. This will be determined by looking at the mimetype of the content
|
||||
// and the destination mimetype of the thumbnail.
|
||||
List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(contentData.getMimetype(), contentData.getSize());
|
||||
for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions)
|
||||
{
|
||||
thumbnailDefs.add(thumbnailDefinition.getName());
|
||||
}
|
||||
}
|
||||
metadata.put("thumbnailDefinitions", thumbnailDefs);
|
||||
|
||||
// thumbnail instances for this nodeRef
|
||||
List<NodeRef> thumbnailRefs = thumbnailService.getThumbnails(nodeRef, ContentModel.PROP_CONTENT, null, null);
|
||||
List<String> thumbnailNames = new ArrayList<String>(thumbnailRefs.size());
|
||||
for (NodeRef thumbnailRef : thumbnailRefs)
|
||||
{
|
||||
thumbnailNames.add((String)nodeService.getProperty(thumbnailRef, ContentModel.PROP_NAME));
|
||||
}
|
||||
metadata.put("thumbnailNames", thumbnailNames);
|
||||
|
||||
metadata.put("lastThumbnailModificationData", (List<String>)nodeProps.get(ContentModel.PROP_LAST_THUMBNAIL_MODIFICATION_DATA));
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||
model.put("item", metadata);
|
||||
return model;
|
||||
}
|
||||
}
|
@@ -25,11 +25,11 @@ import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.QuickShareModel;
|
||||
import org.alfresco.repo.tenant.TenantService;
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||
import org.alfresco.repo.web.scripts.content.ContentGet;
|
||||
import org.alfresco.service.cmr.attributes.AttributeService;
|
||||
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
||||
import org.alfresco.service.cmr.quickshare.QuickShareService;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
@@ -51,6 +51,7 @@ import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||
* WARNING: **unauthenticated** web script (equivalent to authenticated version - see ContentGet.java)
|
||||
*
|
||||
* @author janv
|
||||
* @since Cloud/4.2
|
||||
*/
|
||||
public class QuickShareContentGet extends ContentGet
|
||||
{
|
||||
@@ -58,8 +59,7 @@ public class QuickShareContentGet extends ContentGet
|
||||
|
||||
private NodeService nodeService;
|
||||
private NamespaceService namespaceService;
|
||||
private AttributeService attributeService;
|
||||
private TenantService tenantService;
|
||||
private QuickShareService quickShareSerivce;
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
@@ -76,14 +76,9 @@ public class QuickShareContentGet extends ContentGet
|
||||
super.setNamespaceService(namespaceService);
|
||||
}
|
||||
|
||||
public void setAttributeService(AttributeService attributeService)
|
||||
public void setQuickShareService(QuickShareService quickShareService)
|
||||
{
|
||||
this.attributeService = attributeService;
|
||||
}
|
||||
|
||||
public void setTenantService(TenantService tenantService)
|
||||
{
|
||||
this.tenantService = tenantService;
|
||||
this.quickShareSerivce = quickShareService;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled)
|
||||
@@ -115,7 +110,7 @@ public class QuickShareContentGet extends ContentGet
|
||||
|
||||
try
|
||||
{
|
||||
Pair<String, NodeRef> pair = ShareContentPost.getTenantNodeRefFromSharedId(attributeService, tenantService, sharedId);
|
||||
Pair<String, NodeRef> pair = quickShareSerivce.getTenantNodeRefFromSharedId(sharedId);
|
||||
final String tenantDomain = pair.getFirst();
|
||||
final NodeRef nodeRef = pair.getSecond();
|
||||
|
||||
@@ -140,6 +135,11 @@ public class QuickShareContentGet extends ContentGet
|
||||
}
|
||||
|
||||
}
|
||||
catch (InvalidSharedIdException ex)
|
||||
{
|
||||
logger.error("Unable to find: "+sharedId);
|
||||
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
|
||||
}
|
||||
catch (InvalidNodeRefException inre)
|
||||
{
|
||||
logger.error("Unable to find: "+sharedId+" ["+inre.getNodeRef()+"]");
|
||||
|
@@ -22,12 +22,8 @@ import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.QuickShareModel;
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
@@ -44,6 +40,7 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
* WARNING: **unauthenticated** web script (equivalent to authenticated version - see MetaDataGet.java)
|
||||
*
|
||||
* @author janv
|
||||
* @since Cloud/4.2
|
||||
*/
|
||||
public class QuickShareMetaDataGet extends MetaDataGet
|
||||
{
|
||||
@@ -67,29 +64,12 @@ public class QuickShareMetaDataGet extends MetaDataGet
|
||||
|
||||
try
|
||||
{
|
||||
Pair<String, NodeRef> pair = getTenantNodeRefFromSharedId(attributeService, tenantService, sharedId);
|
||||
final String tenantDomain = pair.getFirst();
|
||||
final NodeRef nodeRef = pair.getSecond();
|
||||
|
||||
Map<String, Object> model = TenantUtil.runAsSystemTenant(new TenantRunAsWork<Map<String, Object>>()
|
||||
{
|
||||
public Map<String, Object> doWork() throws Exception
|
||||
{
|
||||
if (! nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE))
|
||||
{
|
||||
throw new InvalidNodeRefException(nodeRef);
|
||||
return quickShareService.getMetaData(sharedId);
|
||||
}
|
||||
|
||||
return getMetaDataModel(nodeRef);
|
||||
}
|
||||
}, tenantDomain);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
catch (InvalidSharedIdException ex)
|
||||
{
|
||||
logger.debug("QuickShare - retrieved metadata: "+sharedId+" ["+nodeRef+"]["+model+"]");
|
||||
}
|
||||
|
||||
return model;
|
||||
logger.error("Unable to find: "+sharedId);
|
||||
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
|
||||
}
|
||||
catch (InvalidNodeRefException inre)
|
||||
{
|
||||
|
@@ -20,11 +20,14 @@ package org.alfresco.repo.web.scripts.quickshare;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.QuickShareModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
|
||||
import org.alfresco.repo.content.transform.ContentTransformer;
|
||||
@@ -44,6 +47,8 @@ import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
import org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest;
|
||||
@@ -64,6 +69,8 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
|
||||
private static final String USER_ONE = "UserOne-"+RUN_ID;
|
||||
private static final String USER_TWO = "UserTwo-"+RUN_ID;
|
||||
|
||||
private final static String COPY_URL = "/slingshot/doclib/action/copy-to/node/{copy_dest}";
|
||||
|
||||
private final static String SHARE_URL = "/api/internal/shared/share/{node_ref_3}";
|
||||
|
||||
private final static String UNSHARE_URL = "/api/internal/shared/unshare/{shared_id}";
|
||||
@@ -92,6 +99,8 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
|
||||
private Repository repositoryHelper;
|
||||
private RetryingTransactionHelper transactionHelper;
|
||||
|
||||
private NodeRef userOneHome;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception
|
||||
{
|
||||
@@ -125,7 +134,8 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
|
||||
|
||||
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
|
||||
props.put(ContentModel.PROP_NAME, TEST_NAME);
|
||||
ChildAssociationRef result = nodeService.createNode(repositoryHelper.getUserHome(personService.getPerson(USER_ONE)),
|
||||
userOneHome = repositoryHelper.getUserHome(personService.getPerson(USER_ONE));
|
||||
ChildAssociationRef result = nodeService.createNode(userOneHome,
|
||||
ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS,
|
||||
ContentModel.TYPE_CONTENT, props);
|
||||
|
||||
@@ -271,6 +281,45 @@ public class QuickShareRestApiTest extends BaseWebScriptTest
|
||||
rsp = sendRequest(new GetRequest(SHARE_CONTENT_THUMBNAIL_URL.replace("{shared_id}", sharedId).replace("{thumbnailname}", "doclib")), expectedStatusNotFound, USER_TWO);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verifies that copying a shared node does not across the shared aspect and it's associated properties.
|
||||
* @throws IOException
|
||||
* @throws UnsupportedEncodingException
|
||||
* @throws JSONException
|
||||
*/
|
||||
public void testCopy() throws UnsupportedEncodingException, IOException, JSONException
|
||||
{
|
||||
final int expectedStatusOK = 200;
|
||||
|
||||
String testNodeRef = testNode.toString().replace("://", "/");
|
||||
String userOneNodeRef = userOneHome.toString().replace("://", "/");
|
||||
|
||||
// As user one ...
|
||||
|
||||
// share
|
||||
Response rsp = sendRequest(new PostRequest(SHARE_URL.replace("{node_ref_3}", testNodeRef), "", APPLICATION_JSON), expectedStatusOK, USER_ONE);
|
||||
JSONObject jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
|
||||
String sharedId = jsonRsp.getString("sharedId");
|
||||
assertNotNull(sharedId);
|
||||
assertEquals(22, sharedId.length()); // note: we may have to adjust/remove this check if we change length of id (or it becomes variable length)
|
||||
|
||||
JSONObject jsonReq = new JSONObject();
|
||||
JSONArray nodeRefs = new JSONArray();
|
||||
nodeRefs.put(testNode.toString());
|
||||
jsonReq.put("nodeRefs", nodeRefs);
|
||||
jsonReq.put("parentId", userOneHome);
|
||||
|
||||
rsp = sendRequest(new PostRequest(COPY_URL.replace("{copy_dest}", userOneNodeRef), jsonReq.toString(), APPLICATION_JSON), expectedStatusOK, USER_ONE);
|
||||
jsonRsp = new JSONObject(new JSONTokener(rsp.getContentAsString()));
|
||||
|
||||
JSONArray copyResults = jsonRsp.getJSONArray("results");
|
||||
JSONObject copyResult = copyResults.getJSONObject(0);
|
||||
|
||||
String copyNodeRef = copyResult.getString("nodeRef");
|
||||
|
||||
assertFalse(nodeService.hasAspect(new NodeRef(copyNodeRef), QuickShareModel.ASPECT_QSHARE));
|
||||
}
|
||||
|
||||
private void createUser(String userName)
|
||||
{
|
||||
if (! authenticationService.authenticationExists(userName))
|
||||
|
@@ -48,6 +48,7 @@ import org.springframework.extensions.webscripts.WebScriptResponse;
|
||||
* WARNING: **unauthenticated** web script (equivalent to authenticated version - see "thumbnail.get.js")
|
||||
*
|
||||
* @author janv
|
||||
* @since Cloud/4.2
|
||||
*/
|
||||
public class QuickShareThumbnailContentGet extends QuickShareContentGet
|
||||
{
|
||||
|
@@ -44,6 +44,7 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
* Note: authenticated web script
|
||||
*
|
||||
* @author janv
|
||||
* @since Cloud/4.2
|
||||
*/
|
||||
public class ShareContentGet extends AbstractQuickShareContent
|
||||
{
|
||||
@@ -74,7 +75,7 @@ public class ShareContentGet extends AbstractQuickShareContent
|
||||
|
||||
try
|
||||
{
|
||||
Pair<String, NodeRef> pair = getTenantNodeRefFromSharedId(attributeService, tenantService, sharedId);
|
||||
Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
|
||||
final String tenantDomain = pair.getFirst();
|
||||
final NodeRef nodeRef = pair.getSecond();
|
||||
|
||||
|
@@ -18,26 +18,15 @@
|
||||
*/
|
||||
package org.alfresco.repo.web.scripts.quickshare;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.QuickShareModel;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||
import org.alfresco.repo.web.scripts.WebScriptUtil;
|
||||
import org.alfresco.service.cmr.quickshare.QuickShareDTO;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.safehaus.uuid.UUID;
|
||||
import org.safehaus.uuid.UUIDGenerator;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
import org.springframework.extensions.webscripts.Status;
|
||||
import org.springframework.extensions.webscripts.WebScriptException;
|
||||
@@ -52,13 +41,10 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
* Note: authenticated web script
|
||||
*
|
||||
* @author janv
|
||||
* @since Cloud/4.2
|
||||
*/
|
||||
public class ShareContentPost extends AbstractQuickShareContent
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(ShareContentPost.class);
|
||||
|
||||
/* package */ static final String ATTR_KEY_SHAREDIDS_ROOT = ".sharedIds";
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
@@ -78,53 +64,10 @@ public class ShareContentPost extends AbstractQuickShareContent
|
||||
|
||||
try
|
||||
{
|
||||
QName typeQName = nodeService.getType(nodeRef);
|
||||
if (! typeQName.equals(ContentModel.TYPE_CONTENT))
|
||||
{
|
||||
throw new InvalidNodeRefException(nodeRef);
|
||||
}
|
||||
|
||||
final String sharedId;
|
||||
|
||||
if (! nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE))
|
||||
{
|
||||
UUID uuid = UUIDGenerator.getInstance().generateRandomBasedUUID();
|
||||
sharedId = Base64.encodeBase64URLSafeString(uuid.toByteArray()); // => 22 chars (eg. q3bEKPeDQvmJYgt4hJxOjw)
|
||||
|
||||
Map<QName,Serializable> props = new HashMap<QName,Serializable>(2);
|
||||
props.put(QuickShareModel.PROP_QSHARE_SHAREDID, sharedId);
|
||||
props.put(QuickShareModel.PROP_QSHARE_SHAREDBY, AuthenticationUtil.getRunAsUser());
|
||||
|
||||
nodeService.addAspect(nodeRef, QuickShareModel.ASPECT_QSHARE, props);
|
||||
|
||||
final NodeRef tenantNodeRef = tenantService.getName(nodeRef);
|
||||
|
||||
TenantUtil.runAsDefaultTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
attributeService.setAttribute(tenantNodeRef, ATTR_KEY_SHAREDIDS_ROOT, sharedId);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("QuickShare - shared content: "+sharedId+" ["+nodeRef+"]");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sharedId = (String)nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("QuickShare - content already shared: "+sharedId+" ["+nodeRef+"]");
|
||||
}
|
||||
}
|
||||
QuickShareDTO dto = quickShareService.shareContent(nodeRef);
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||
model.put("sharedId", sharedId);
|
||||
model.put("sharedDTO", dto);
|
||||
return model;
|
||||
}
|
||||
catch (InvalidNodeRefException inre)
|
||||
|
@@ -23,21 +23,7 @@ import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.QuickShareModel;
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.tenant.TenantUtil;
|
||||
import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.EqualsHelper;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
@@ -54,29 +40,12 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
* Note: authenticated web script
|
||||
*
|
||||
* @author janv
|
||||
* @since Cloud/4.2
|
||||
*/
|
||||
public class UnshareContentDelete extends AbstractQuickShareContent implements NodeServicePolicies.BeforeDeleteNodePolicy
|
||||
public class UnshareContentDelete extends AbstractQuickShareContent
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(ShareContentPost.class);
|
||||
|
||||
protected PolicyComponent policyComponent;
|
||||
|
||||
public void setPolicyComponent(PolicyComponent policyComponent)
|
||||
{
|
||||
this.policyComponent = policyComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* The initialise method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
// Register interest in the beforeDeleteNode policy - note: currently for content only !!
|
||||
policyComponent.bindClassBehaviour(
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "beforeDeleteNode"),
|
||||
ContentModel.TYPE_CONTENT,
|
||||
new JavaBehaviour(this, "beforeDeleteNode"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
@@ -96,39 +65,7 @@ public class UnshareContentDelete extends AbstractQuickShareContent implements N
|
||||
|
||||
try
|
||||
{
|
||||
Pair<String, NodeRef> pair = getTenantNodeRefFromSharedId(attributeService, tenantService, sharedId);
|
||||
final String tenantDomain = pair.getFirst();
|
||||
final NodeRef nodeRef = pair.getSecond();
|
||||
|
||||
TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
QName typeQName = nodeService.getType(nodeRef);
|
||||
if (! typeQName.equals(ContentModel.TYPE_CONTENT))
|
||||
{
|
||||
throw new InvalidNodeRefException(nodeRef);
|
||||
}
|
||||
|
||||
String nodeSharedId = (String)nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
|
||||
|
||||
if (! EqualsHelper.nullSafeEquals(nodeSharedId, sharedId))
|
||||
{
|
||||
logger.warn("SharedId mismatch: expected="+sharedId+",actual="+nodeSharedId);
|
||||
}
|
||||
|
||||
nodeService.removeAspect(nodeRef, QuickShareModel.ASPECT_QSHARE);
|
||||
|
||||
return null;
|
||||
}
|
||||
}, tenantDomain);
|
||||
|
||||
removeSharedId(sharedId);
|
||||
|
||||
if (logger.isInfoEnabled())
|
||||
{
|
||||
logger.info("QuickShare - unshared content: "+sharedId+" ["+nodeRef+"]");
|
||||
}
|
||||
quickShareService.unshareContent(sharedId);
|
||||
|
||||
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||
model.put("success", Boolean.TRUE);
|
||||
@@ -140,44 +77,4 @@ public class UnshareContentDelete extends AbstractQuickShareContent implements N
|
||||
throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId);
|
||||
}
|
||||
}
|
||||
|
||||
// behaviour - currently registered for content only !!
|
||||
// note: will remove "share" even if node is only being archived (ie. moved to trash) => a subsequent restore will *not* restore the "share"
|
||||
public void beforeDeleteNode(final NodeRef beforeDeleteNodeRef)
|
||||
{
|
||||
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
String sharedId = (String)nodeService.getProperty(beforeDeleteNodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
|
||||
if (sharedId != null)
|
||||
{
|
||||
Pair<String, NodeRef> pair = getTenantNodeRefFromSharedId(attributeService, tenantService, sharedId);
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
final String tenantDomain = pair.getFirst();
|
||||
final NodeRef nodeRef = pair.getSecond();
|
||||
|
||||
// note: deleted nodeRef might not match, eg. for upload new version -> checkin -> delete working copy
|
||||
if (nodeRef.equals(beforeDeleteNodeRef))
|
||||
{
|
||||
removeSharedId(sharedId);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void removeSharedId(final String sharedId)
|
||||
{
|
||||
TenantUtil.runAsDefaultTenant(new TenantRunAsWork<Void>()
|
||||
{
|
||||
public Void doWork() throws Exception
|
||||
{
|
||||
attributeService.removeAttribute(ShareContentPost.ATTR_KEY_SHAREDIDS_ROOT, sharedId);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user