mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Re-org of DocLib data webscripts to support both site-format and noderef-format references. New DocLib "generic action" function which enables much easier addition of new actions.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9638 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,7 +19,15 @@ main();
|
||||
function main()
|
||||
{
|
||||
// Params object contains commonly-used arguments
|
||||
var params = getInputParams();
|
||||
var params;
|
||||
if (url.templateArgs.storetype != undefined)
|
||||
{
|
||||
params = getNodeRefInputParams();
|
||||
}
|
||||
else
|
||||
{
|
||||
params = getSiteInputParams();
|
||||
}
|
||||
if (typeof params == "string")
|
||||
{
|
||||
status.setCode(status.STATUS_BAD_REQUEST, params);
|
||||
@@ -68,12 +76,12 @@ function main()
|
||||
|
||||
|
||||
/**
|
||||
* Get and check existence of mandatory input parameter
|
||||
* Get and check existence of mandatory input parameters (Site-based)
|
||||
*
|
||||
* @method getInputParams
|
||||
* @method getSiteInputParams
|
||||
* @return {object|string} object literal containing parameters value or string error
|
||||
*/
|
||||
function getInputParams()
|
||||
function getSiteInputParams()
|
||||
{
|
||||
var params = {};
|
||||
var error = null;
|
||||
@@ -140,7 +148,68 @@ function getInputParams()
|
||||
{
|
||||
containerId: containerId,
|
||||
siteId: siteId,
|
||||
filePath: filePath
|
||||
filePath: filePath,
|
||||
usingNodeRef: false
|
||||
}
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
error = e.toString();
|
||||
}
|
||||
|
||||
// Return the params object, or the error string if it was set
|
||||
return (error !== null ? error : params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and check existence of mandatory input parameters (nodeRef-based)
|
||||
*
|
||||
* @method getNodeRefInputParams
|
||||
* @return {object|string} object literal containing parameters value or string error
|
||||
*/
|
||||
function getNodeRefInputParams()
|
||||
{
|
||||
var params = {};
|
||||
var error = null;
|
||||
|
||||
try
|
||||
{
|
||||
// First try to get the parameters from the URI
|
||||
var storeType = url.templateArgs.storetype;
|
||||
var storeId = url.templateArgs.storeid;
|
||||
var id = url.templateArgs.id;
|
||||
|
||||
// Was a JSON parameter list supplied?
|
||||
// TODO: Also handle multiple files
|
||||
if (typeof json == "object")
|
||||
{
|
||||
if (!json.isNull("storetype"))
|
||||
{
|
||||
storeType = json.get("storetype");
|
||||
}
|
||||
if (!json.isNull("storeid"))
|
||||
{
|
||||
storeId = json.get("storeid");
|
||||
}
|
||||
if (!json.isNull("id"))
|
||||
{
|
||||
id = json.get("id");
|
||||
}
|
||||
}
|
||||
|
||||
var nodeRef = storeType + "://" + storeId + "/" + id;
|
||||
var node = search.findNode(nodeRef);
|
||||
|
||||
if (node === null)
|
||||
{
|
||||
return "'" + nodeRef + "' is not valid.";
|
||||
}
|
||||
|
||||
// Populate the return object
|
||||
params =
|
||||
{
|
||||
nodeRef: nodeRef,
|
||||
usingNodeRef: true
|
||||
}
|
||||
}
|
||||
catch(e)
|
||||
@@ -164,6 +233,11 @@ function getRootNode(p_params)
|
||||
var rootNode = null;
|
||||
var error = null;
|
||||
|
||||
if (p_params.usingNodeRef)
|
||||
{
|
||||
return search.findNode(p_params.nodeRef);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Find the site
|
||||
@@ -205,7 +279,7 @@ function getAssetNode(p_rootNode, p_assetPath)
|
||||
|
||||
try
|
||||
{
|
||||
if (p_assetPath.length > 0)
|
||||
if (p_assetPath && (p_assetPath.length > 0))
|
||||
{
|
||||
assetNode = assetNode.childByNamePath(p_assetPath);
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
<webscript>
|
||||
<shortname>cancel-checkout</shortname>
|
||||
<description>Document List Action - Cancel check-out for file</description>
|
||||
<url>/slingshot/doclib/action/cancel-checkout/site/{siteid}/{containerId}/{filepath}</url>
|
||||
<url>/slingshot/doclib/action/cancel-checkout/node/{storetype}/{storeid}/{id}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,58 @@
|
||||
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/action.lib.js">
|
||||
|
||||
/**
|
||||
* Cancel checkout file action
|
||||
* @method POST
|
||||
* @param uri {string} /{siteId}/{containerId}/{filepath}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Entrypoint required by action.lib.js
|
||||
*
|
||||
* @method runAction
|
||||
* @param p_params {object} standard action parameters: nodeRef, siteId, containerId, filePath
|
||||
* @return {object|null} object representation of action result
|
||||
*/
|
||||
function runAction(p_params)
|
||||
{
|
||||
var results;
|
||||
|
||||
try
|
||||
{
|
||||
var assetNode = getAssetNode(p_params.rootNode, p_params.filePath);
|
||||
|
||||
// Must have assetNode by this point
|
||||
if (typeof assetNode == "string")
|
||||
{
|
||||
status.setCode(status.STATUS_NOT_FOUND, "Not found: " + p_params.filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
// Checkin the asset
|
||||
var originalDoc = assetNode.cancelCheckout();
|
||||
if (originalDoc === null)
|
||||
{
|
||||
status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, "Could not cancel checkout: " + p_params.filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
var resultId = originalDoc.name;
|
||||
var resultNodeRef = originalDoc.nodeRef.toString();
|
||||
|
||||
// Construct the result object
|
||||
results = [
|
||||
{
|
||||
id: resultId,
|
||||
nodeRef: resultNodeRef,
|
||||
action: "cancelCheckoutAsset",
|
||||
success: true
|
||||
}];
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, e.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
@@ -0,0 +1,2 @@
|
||||
<#import "action.lib.ftl" as actionLib />
|
||||
<@actionLib.resultsJSON results=results />
|
@@ -0,0 +1,9 @@
|
||||
<webscript>
|
||||
<shortname>checkin</shortname>
|
||||
<description>Document List Action - Check-in file</description>
|
||||
<url>/slingshot/doclib/action/checkin/site/{siteid}/{containerId}/{filepath}</url>
|
||||
<url>/slingshot/doclib/action/checkin/node/{storetype}/{storeid}/{id}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
@@ -0,0 +1,58 @@
|
||||
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/action.lib.js">
|
||||
|
||||
/**
|
||||
* Checkin file action
|
||||
* @method POST
|
||||
* @param uri {string} /{siteId}/{containerId}/{filepath}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Entrypoint required by action.lib.js
|
||||
*
|
||||
* @method runAction
|
||||
* @param p_params {object} standard action parameters: nodeRef, siteId, containerId, filePath
|
||||
* @return {object|null} object representation of action result
|
||||
*/
|
||||
function runAction(p_params)
|
||||
{
|
||||
var results;
|
||||
|
||||
try
|
||||
{
|
||||
var assetNode = getAssetNode(p_params.rootNode, p_params.filePath);
|
||||
|
||||
// Must have assetNode by this point
|
||||
if (typeof assetNode == "string")
|
||||
{
|
||||
status.setCode(status.STATUS_NOT_FOUND, "Not found: " + p_params.filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
// Checkin the asset
|
||||
var originalDoc = assetNode.checkin();
|
||||
if (originalDoc === null)
|
||||
{
|
||||
status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, "Could not checkin: " + p_params.filePath);
|
||||
return;
|
||||
}
|
||||
|
||||
var resultId = assetNode.name;
|
||||
var resultNodeRef = originalDoc.nodeRef.toString();
|
||||
|
||||
// Construct the result object
|
||||
results = [
|
||||
{
|
||||
id: resultId,
|
||||
nodeRef: resultNodeRef,
|
||||
action: "checkinAsset",
|
||||
success: true
|
||||
}];
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, e.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
@@ -0,0 +1,2 @@
|
||||
<#import "action.lib.ftl" as actionLib />
|
||||
<@actionLib.resultsJSON results=results />
|
@@ -1,7 +1,8 @@
|
||||
<webscript>
|
||||
<shortname>checkout</shortname>
|
||||
<description>Document List Action - Check-out file</description>
|
||||
<url>/slingshot/doclib/action/checkout/{siteid}/{containerId}/{filepath}</url>
|
||||
<url>/slingshot/doclib/action/checkout/site/{siteid}/{containerId}/{filepath}</url>
|
||||
<url>/slingshot/doclib/action/checkout/node/{storetype}/{storeid}/{id}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
|
@@ -1,8 +1,10 @@
|
||||
<webscript>
|
||||
<shortname>file</shortname>
|
||||
<description>Document List Action - Delete file</description>
|
||||
<url>/slingshot/doclib/action/file/{siteid}/{containerId}/{filepath}</url>
|
||||
<url>/slingshot/doclib/action/folder/{siteid}/{containerId}/{filepath}</url>
|
||||
<url>/slingshot/doclib/action/file/site/{siteid}/{containerId}/{filepath}</url>
|
||||
<url>/slingshot/doclib/action/folder/site/{siteid}/{containerId}/{filepath}</url>
|
||||
<url>/slingshot/doclib/action/file/node/{storetype}/{storeid}/{id}</url>
|
||||
<url>/slingshot/doclib/action/folder/node/{storetype}/{storeid}/{id}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
|
@@ -19,7 +19,15 @@ function runAction(p_params)
|
||||
|
||||
try
|
||||
{
|
||||
var assetNode = getAssetNode(p_params.rootNode, p_params.filePath);
|
||||
var assetNode;
|
||||
if (p_params.usingNodeRef)
|
||||
{
|
||||
assetNode = p_params.nodeRef;
|
||||
}
|
||||
else
|
||||
{
|
||||
assetNode = getAssetNode(p_params.rootNode, p_params.filePath);
|
||||
}
|
||||
|
||||
// Must have assetNode by this point
|
||||
if (typeof assetNode == "string")
|
||||
|
@@ -1,9 +1,11 @@
|
||||
<webscript>
|
||||
<shortname>folder</shortname>
|
||||
<description>Document List Action - Create folder</description>
|
||||
<url>/slingshot/doclib/action/folder/{siteid}/{containerId}</url>
|
||||
<url>/slingshot/doclib/action/folder/{siteid}/{containerId}/{filepath}</url>
|
||||
<url>/slingshot/doclib/action/folder/site/{siteid}/{containerId}</url>
|
||||
<url>/slingshot/doclib/action/folder/site/{siteid}/{containerId}/{filepath}</url>
|
||||
<url>/slingshot/doclib/action/folder/node/{storetype}/{storeid}/{id}</url>
|
||||
<format default="json">argument</format>
|
||||
<authentication>user</authentication>
|
||||
<transaction>required</transaction>
|
||||
</webscript>
|
||||
</webscript>
|
||||
|
||||
|
@@ -43,6 +43,7 @@ function getDoclist(siteId, path, type, filter)
|
||||
else
|
||||
{
|
||||
pathNode = containerNode;
|
||||
path = "";
|
||||
}
|
||||
|
||||
if (pathNode === null)
|
||||
@@ -114,6 +115,7 @@ function getDoclist(siteId, path, type, filter)
|
||||
items.push(
|
||||
{
|
||||
asset: asset,
|
||||
parent: path,
|
||||
status: itemStatus,
|
||||
owner: itemOwner,
|
||||
actionSet: actionSet
|
||||
|
@@ -15,6 +15,7 @@
|
||||
"mimetype": "${d.mimetype!""}",
|
||||
"icon32": "${d.icon32}",
|
||||
"name": "${d.name?replace(" (Working Copy)", "")?html}",
|
||||
"parent": "${item.parent}",
|
||||
"status": "<#list item.status as s>${s}<#if s_has_next>,</#if></#list>",
|
||||
"lockedBy": "${item.owner}",
|
||||
"title": "${(d.properties.title!"")?html}",
|
||||
|
Reference in New Issue
Block a user