mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +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:
@@ -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