mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-1633 (Recorded Version Configuration Action)
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@82333 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -613,4 +613,16 @@
|
|||||||
<bean id="webscript.org.alfresco.rma.hold.put"
|
<bean id="webscript.org.alfresco.rma.hold.put"
|
||||||
class="org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPut"
|
class="org.alfresco.module.org_alfresco_module_rm.script.hold.HoldPut"
|
||||||
parent="rmBaseHold" />
|
parent="rmBaseHold" />
|
||||||
|
|
||||||
|
<!-- REST impl for POST recorded version config -->
|
||||||
|
<bean id="webscript.org.alfresco.slingshot.documentlibrary.action.recorded-version-config.post"
|
||||||
|
class="org.alfresco.module.org_alfresco_module_rm.script.slingshot.RecordedVersionConfigPost"
|
||||||
|
parent="rmBaseWebscript">
|
||||||
|
</bean>
|
||||||
|
|
||||||
|
<!-- REST impl for GET recorded version config -->
|
||||||
|
<bean id="webscript.org.alfresco.slingshot.documentlibrary.action.recorded-version-config.get"
|
||||||
|
class="org.alfresco.module.org_alfresco_module_rm.script.slingshot.RecordedVersionConfigGet"
|
||||||
|
parent="rmBaseWebscript">
|
||||||
|
</bean>
|
||||||
</beans>
|
</beans>
|
@@ -0,0 +1,9 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Gets Recorded Version Config</shortname>
|
||||||
|
<description>Gets Recorded Version Config Data</description>
|
||||||
|
<url>/slingshot/doclib/action/recorded-version-config/node/{store_type}/{store_id}/{id}</url>
|
||||||
|
<format default="json">argument</format>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction allow="readonly">required</transaction>
|
||||||
|
<lifecycle>internal</lifecycle>
|
||||||
|
</webscript>
|
@@ -0,0 +1,16 @@
|
|||||||
|
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||||
|
{
|
||||||
|
"data":
|
||||||
|
{
|
||||||
|
"recordableVersions":
|
||||||
|
[
|
||||||
|
<#list recordableVersions as recordableVersion>
|
||||||
|
{
|
||||||
|
"policy": "${recordableVersion.policy}",
|
||||||
|
"selected": ${recordableVersion.selected?c}
|
||||||
|
}<#if recordableVersion_has_next>,</#if>
|
||||||
|
</#list>
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</#escape>
|
@@ -0,0 +1,9 @@
|
|||||||
|
<webscript>
|
||||||
|
<shortname>Sets Recorded Version Config</shortname>
|
||||||
|
<description>Sets Recorded Version Config Data</description>
|
||||||
|
<url>/slingshot/doclib/action/recorded-version-config/node/{store_type}/{store_id}/{id}</url>
|
||||||
|
<format default="json">argument</format>
|
||||||
|
<authentication>user</authentication>
|
||||||
|
<transaction>required</transaction>
|
||||||
|
<lifecycle>internal</lifecycle>
|
||||||
|
</webscript>
|
@@ -0,0 +1 @@
|
|||||||
|
{}
|
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.module.org_alfresco_module_rm.script.slingshot;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.script.AbstractRmWebScript;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST API to get the recorded version config for a document
|
||||||
|
*
|
||||||
|
* @author Tuna Aksoy
|
||||||
|
* @since 2.3
|
||||||
|
*/
|
||||||
|
public class RecordedVersionConfigGet extends AbstractRmWebScript implements RecordableVersionModel
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
|
{
|
||||||
|
RecordableVersionPolicy[] recordableVersionPolicies = RecordableVersionPolicy.values();
|
||||||
|
List<Map<String, Object>> recordableVersions = new ArrayList<Map<String,Object>>(recordableVersionPolicies.length);
|
||||||
|
NodeRef documentNodeRef = parseRequestForNodeRef(req);
|
||||||
|
|
||||||
|
for (RecordableVersionPolicy recordableVersionPolicy : recordableVersionPolicies)
|
||||||
|
{
|
||||||
|
recordableVersions.add(buildRecordableVersionData(recordableVersionPolicy, documentNodeRef));
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||||
|
model.put("recordableVersions", recordableVersions);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the recordable version data
|
||||||
|
*
|
||||||
|
* @param recordableVersionPolicy The recordable version policy
|
||||||
|
* @param nodeRef Node reference of the document
|
||||||
|
* @return A map containing the information about recordable version policy and if this policy is selected for the document
|
||||||
|
*/
|
||||||
|
private Map<String, Object> buildRecordableVersionData(RecordableVersionPolicy recordableVersionPolicy, NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
Map<String, Object> recordableVersionData = new HashMap<String, Object>(2);
|
||||||
|
recordableVersionData.put("policy", recordableVersionPolicy.toString());
|
||||||
|
recordableVersionData.put("selected", isVersionPolicySelected(recordableVersionPolicy, nodeRef));
|
||||||
|
return recordableVersionData;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the specified recordable version policy has been selected for the document
|
||||||
|
*
|
||||||
|
* @param recordableVersionPolicy The recordable version policy
|
||||||
|
* @param nodeRef Node reference of the document
|
||||||
|
* @return <code>true</code> if the specified recordable version policy has been selected for the document, <code>false</code> otherwise
|
||||||
|
*/
|
||||||
|
private boolean isVersionPolicySelected(RecordableVersionPolicy recordableVersionPolicy, NodeRef nodeRef)
|
||||||
|
{
|
||||||
|
boolean isVersionPolicySelected = false;
|
||||||
|
String policy = (String) nodeService.getProperty(nodeRef, PROP_RECORDABLE_VERSION_POLICY);
|
||||||
|
if (StringUtils.isNotBlank(policy))
|
||||||
|
{
|
||||||
|
if (RecordableVersionPolicy.valueOf(policy).equals(recordableVersionPolicy))
|
||||||
|
{
|
||||||
|
isVersionPolicySelected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (recordableVersionPolicy.equals(RecordableVersionPolicy.NONE))
|
||||||
|
{
|
||||||
|
isVersionPolicySelected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isVersionPolicySelected;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.alfresco.module.org_alfresco_module_rm.script.slingshot;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.script.AbstractRmWebScript;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionModel;
|
||||||
|
import org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.json.JSONTokener;
|
||||||
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
|
import org.springframework.extensions.webscripts.Status;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptException;
|
||||||
|
import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST API to set the recorded version config for a document
|
||||||
|
*
|
||||||
|
* @author Tuna Aksoy
|
||||||
|
* @since 2.3
|
||||||
|
*/
|
||||||
|
public class RecordedVersionConfigPost extends AbstractRmWebScript implements RecordableVersionModel
|
||||||
|
{
|
||||||
|
// Constant for recorded version parameter
|
||||||
|
private static final String RECORDED_VERSION = "recordedVersion";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
|
{
|
||||||
|
NodeRef nodeRef = parseRequestForNodeRef(req);
|
||||||
|
RecordableVersionPolicy recordableVersionPolicy = getRecordableVersionPolicy(req);
|
||||||
|
nodeService.setProperty(nodeRef, PROP_RECORDABLE_VERSION_POLICY, recordableVersionPolicy);
|
||||||
|
return new HashMap<String, Object>(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the recordable version policy from the request
|
||||||
|
*
|
||||||
|
* @param The webscript request
|
||||||
|
* @return The recordable version policy
|
||||||
|
*/
|
||||||
|
private RecordableVersionPolicy getRecordableVersionPolicy(WebScriptRequest req)
|
||||||
|
{
|
||||||
|
String recordedVersion = getRecordedVersion(req);
|
||||||
|
return RecordableVersionPolicy.valueOf(recordedVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the recorded version parameter value from the request
|
||||||
|
*
|
||||||
|
* @param req The webscript request
|
||||||
|
* @return The recorded version parameter value
|
||||||
|
*/
|
||||||
|
private String getRecordedVersion(WebScriptRequest req)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Convert the request content to JSON
|
||||||
|
String content = req.getContent().getContent();
|
||||||
|
JSONObject jsonObject = new JSONObject(new JSONTokener(content));
|
||||||
|
checkMandatoryJsonParam(jsonObject, RECORDED_VERSION);
|
||||||
|
return jsonObject.getString(RECORDED_VERSION);
|
||||||
|
}
|
||||||
|
catch (JSONException | IOException ex)
|
||||||
|
{
|
||||||
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
|
||||||
|
"Could not parse JSON from req.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user