Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

107281: Merged NESS/5.1.N-2015-05-26 (5.1.0) to HEAD-BUG-FIX (5.1/Cloud)
      105463: ACE-3984 : Add support for link creation via Repository REST API
        - added the functionality for creating document links
      105467: ACE-3984 : Add support for link creation via Repository REST API
        - reverted fix to add modifications
      105468: ACE-3984 : Add support for link creation via Repository REST API
        - added java backed webscripts for creating and deleting links
        - added service for handling document links operations
      106865: ACE-3984 : Add support for link creation via Repository REST API
        - added copyright notice
        - added class level comment to AbstractDocLink


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@107492 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tatyana Valkevych
2015-07-01 12:32:43 +00:00
parent e18c35db17
commit a5f8df310a
8 changed files with 479 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<webscript>
<shortname>Create document link</shortname>
<description>Creates a link to a document in a given folder</description>
<url>/api/node/doclink/{store_type}/{store_id}/{id}</url>
<url>/api/site/doclink/{site}/{container}/{path}</url>
<url>/api/site/doclink/{site}/{container}</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
<args>
<arg>
<shortname>store_type</shortname>
<description>Protocol for the source store, e.g. workspace or versionstore.</description>
</arg>
<arg>
<shortname>store_id</shortname>
<description>The source identifier, which may be specific to the protocol, e.g. spacesstore.</description>
</arg>
<arg>
<shortname>id</shortname>
<description>The identifier of the source node.</description>
</arg>
<arg>
<shortname>site</shortname>
<description>The site ID of the source.</description>
</arg>
<arg>
<shortname>container</shortname>
<description>The container folder for the site.</description>
</arg>
<arg>
<shortname>path</shortname>
<description>The path to the source node in the site's container.</description>
</arg>
</args>
<requests>
<request>
<format>json</format>
<type>
<![CDATA[{ "destinationNodeRef" : string }]]>
</type>
</request>
</requests>
<responses>
<response>
<format>json</format>
<type>
<![CDATA[{ "linkNodeRef" : string }]]>
</type>
</response>
</responses>
</webscript>

View File

@@ -0,0 +1,5 @@
<#escape x as jsonUtils.encodeJSONString(x)>
{
"linkNodeRef": "${linkNodeRef}"
}
</#escape>

View File

@@ -0,0 +1,57 @@
<webscript>
<shortname>Delete links of a document</shortname>
<description>Delete all links having as given destination</description>
<url>/api/node/doclink/{store_type}/{store_id}/{id}/delete</url>
<url>/api/site/doclink/{site}/{container}/{path}/delete</url>
<url>/api/site/doclink/{site}/{container}/delete</url>
<format default="json">argument</format>
<authentication>user</authentication>
<transaction>required</transaction>
<args>
<arg>
<shortname>store_type</shortname>
<description>Protocol for the destination store, e.g. workspace or versionstore.</description>
</arg>
<arg>
<shortname>store_id</shortname>
<description>The destination identifier, which may be specific to the protocol, e.g. spacesstore.</description>
</arg>
<arg>
<shortname>id</shortname>
<description>The identifier of the destination node.</description>
</arg>
<arg>
<shortname>site</shortname>
<description>The site ID of the destination.</description>
</arg>
<arg>
<shortname>container</shortname>
<description>The container folder for the site.</description>
</arg>
<arg>
<shortname>path</shortname>
<description>The path to the destination node in the site's container.</description>
</arg>
</args>
<requests>
</requests>
<responses>
<response>
<format>json</format>
<type>
<![CDATA[
<pre>
{
"total": "3",
"deleted": "1",
"error details": [
"workspace://SpacesStore/48afc4b7-d91a-4167-8b9e-db14961b8fed 04290001 Access Denied. You do not have the appropriate permissions to perform this operation.",
"workspace://SpacesStore/10b18342-8e70-4dc0-ba73-4b0a6fdf5a9b 04290002 Access Denied. You do not have the appropriate permissions to perform this operation."
]
}
</pre>
]]>
</type>
</response>
</responses>
</webscript>

View File

@@ -0,0 +1,13 @@
<#escape x as jsonUtils.encodeJSONString(x)>
{
"found": "${total_count}",
"deleted": "${deleted_count}",
"error details" :
[
<#list error_details?keys as key>
"${key} - ${error_details[key]}"
<#if key_has_next>,</#if>
</#list>
]
}
</#escape>

View File

@@ -1841,4 +1841,20 @@
</property>
</bean>
<bean id="webscript.org.alfresco.repository.doclink.doclink.post"
class="org.alfresco.repo.web.scripts.doclink.DocLinkPost"
parent="webscript">
<property name="nodeService" ref="NodeService" />
<property name="siteService" ref="SiteService" />
<property name="documentLinkService" ref="DocumentLinkService" />
</bean>
<bean id="webscript.org.alfresco.repository.doclink.doclinks.delete"
class="org.alfresco.repo.web.scripts.doclink.DocLinksDelete"
parent="webscript">
<property name="nodeService" ref="NodeService" />
<property name="siteService" ref="SiteService" />
<property name="documentLinkService" ref="DocumentLinkService" />
</bean>
</beans>

View File

@@ -0,0 +1,137 @@
/*
* Copyright (C) 2005-2015 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.doclink;
import java.util.Map;
import java.util.StringTokenizer;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.DocumentLinkService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.util.ParameterCheck;
import org.alfresco.util.PropertyCheck;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
/**
* This class contains common code for doclink webscripts controllers
*
* @author Ana Bozianu
* @since 5.1
*/
public abstract class AbstractDocLink extends DeclarativeWebScript
{
private static String PARAM_STORE_TYPE = "store_type";
private static String PARAM_STORE_ID = "store_id";
private static String PARAM_ID = "id";
private static String PARAM_SITE = "site";
private static String PARAM_CONTAINER = "container";
private static String PARAM_PATH = "path";
protected NodeService nodeService;
protected SiteService siteService;
protected DocumentLinkService documentLinkService;
protected NodeRef parseNodeRefFromTemplateArgs(Map<String, String> templateVars)
{
if (templateVars == null)
{
return null;
}
String storeTypeArg = templateVars.get(PARAM_STORE_TYPE);
String storeIdArg = templateVars.get(PARAM_STORE_ID);
String idArg = templateVars.get(PARAM_ID);
if (storeTypeArg != null)
{
ParameterCheck.mandatoryString("storeTypeArg", storeTypeArg);
ParameterCheck.mandatoryString("storeIdArg", storeIdArg);
ParameterCheck.mandatoryString("idArg", idArg);
/*
* NodeRef based request
* <url>URL_BASE/{store_type}/{store_id}/{id}</url>
*/
return new NodeRef(storeTypeArg, storeIdArg, idArg);
}
else
{
String siteArg = templateVars.get(PARAM_SITE);
String containerArg = templateVars.get(PARAM_CONTAINER);
String pathArg = templateVars.get(PARAM_PATH);
if (siteArg != null)
{
ParameterCheck.mandatoryString("siteArg", siteArg);
ParameterCheck.mandatoryString("containerArg", containerArg);
/*
* Site based request <url>URL_BASE/{site}/{container}</url> or
* <url>URL_BASE/{site}/{container}/{path}</url>
*/
SiteInfo site = siteService.getSite(siteArg);
PropertyCheck.mandatory(this, "site", site);
NodeRef node = siteService.getContainer(site.getShortName(), containerArg);
if (node == null)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid 'container' variable");
}
if (pathArg != null)
{
// <url>URL_BASE/{site}/{container}/{path}</url>
StringTokenizer st = new StringTokenizer(pathArg, "/");
while (st.hasMoreTokens())
{
String childName = st.nextToken();
node = nodeService.getChildByName(node, ContentModel.ASSOC_CONTAINS, childName);
if (node == null)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid 'path' variable");
}
}
}
return node;
}
}
return null;
}
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setSiteService(SiteService siteService)
{
this.siteService = siteService;
}
public void setDocumentLinkService(DocumentLinkService documentLinkService)
{
this.documentLinkService = documentLinkService;
}
}

View File

@@ -0,0 +1,110 @@
/*
* Copyright (C) 2005-2015 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.doclink;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.ParameterCheck;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* This class is the controller for the doclink.post webscript doclink.post is a
* webscript for creating a link of a document within a target destination
*
* @author Ana Bozianu
* @since 5.1
*/
public class DocLinkPost extends AbstractDocLink
{
private static String PARAM_DESTINATION_NODE = "destinationNodeRef";
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef sourceNodeRef = null;
NodeRef destinationNodeRef = null;
/* Parse the template vars */
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
sourceNodeRef = parseNodeRefFromTemplateArgs(templateVars);
/* Parse the JSON content */
JSONObject json = null;
String contentType = req.getContentType();
if (contentType != null && contentType.indexOf(';') != -1)
{
contentType = contentType.substring(0, contentType.indexOf(';'));
}
if (MimetypeMap.MIMETYPE_JSON.equals(contentType))
{
try
{
json = (JSONObject) JSONValue.parseWithException(req.getContent().getContent());
}
catch (IOException io)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + io.getMessage());
}
catch (ParseException pe)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON: " + pe.getMessage());
}
}
else
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "invalid request content type");
}
/* Parse the destination NodeRef parameter */
String destinationNodeParam = (String) json.get(PARAM_DESTINATION_NODE);
ParameterCheck.mandatoryString("destinationNodeParam", destinationNodeParam);
destinationNodeRef = new NodeRef(destinationNodeParam);
/* Create link */
NodeRef linkNodeRef = null;
try
{
linkNodeRef = documentLinkService.createDocumentLink(sourceNodeRef, destinationNodeRef);
}
catch (IllegalArgumentException ex)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid Arguments: " + ex.getMessage());
}
catch (AccessDeniedException e)
{
throw new WebScriptException(Status.STATUS_FORBIDDEN, "You don't have permission to perform this operation");
}
/* Build response */
Map<String, Object> model = new HashMap<String, Object>();
model.put("linkNodeRef", linkNodeRef.toString());
return model;
}
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright (C) 2005-2015 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 <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.web.scripts.doclink;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.repository.DeleteLinksStatusReport;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* This class is the controller for the doclink.post webscript doclink.post is a
* webscript for creating a link of a document within a target destination
*
* @author Ana Bozianu
* @since 5.1
*/
public class DocLinksDelete extends AbstractDocLink
{
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef destinationNodeRef = null;
/* Parse the template vars */
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
destinationNodeRef = parseNodeRefFromTemplateArgs(templateVars);
/* Delete links */
DeleteLinksStatusReport report;
try
{
report = documentLinkService.deleteLinksToDocument(destinationNodeRef);
}
catch (IllegalArgumentException ex)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid Arguments: " + ex.getMessage());
}
catch (AccessDeniedException e)
{
throw new WebScriptException(Status.STATUS_FORBIDDEN, "You don't have permission to perform this operation");
}
/* Build response */
Map<String, Object> model = new HashMap<String, Object>();
model.put("total_count", report.getTotalLinksFoundCount());
model.put("deleted_count", report.getDeletedLinksCount());
Map<String, String> errorDetails = new HashMap<String, String>();
Iterator<Entry<NodeRef, Throwable>> it = report.getErrorDetails().entrySet().iterator();
while (it.hasNext())
{
Map.Entry<NodeRef, Throwable> pair = it.next();
Throwable th = pair.getValue();
errorDetails.put(pair.getKey().toString(), th.getMessage());
}
model.put("error_details", errorDetails);
return model;
}
}