mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
RM-1639 (Recordable Version Configuration Rule)
* Refactored code (added recordable version config service) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@89727 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.recordableversion;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.script.slingshot.Version;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* Recordable version config service interface
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.3
|
||||
*/
|
||||
public interface RecordableVersionConfigService
|
||||
{
|
||||
/**
|
||||
* Gets the recordable versions
|
||||
*
|
||||
* @param nodeRef The node reference for which the recordable versions should be retrieved
|
||||
* @return The list of recordable versions
|
||||
*/
|
||||
List<Version> getVersions(NodeRef nodeRef);
|
||||
|
||||
/**
|
||||
* Sets the recordable version for the given node
|
||||
*
|
||||
* @param nodeRef The node reference for which the recorable version should be set
|
||||
* @param version The version to be set
|
||||
*/
|
||||
void setVersion(NodeRef nodeRef, String version);
|
||||
}
|
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* 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.recordableversion;
|
||||
|
||||
import static org.alfresco.module.org_alfresco_module_rm.version.RecordableVersionPolicy.NONE;
|
||||
import static org.alfresco.util.ParameterCheck.mandatory;
|
||||
import static org.alfresco.util.ParameterCheck.mandatoryString;
|
||||
import static org.apache.commons.lang.StringUtils.isNotBlank;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.script.slingshot.Version;
|
||||
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.alfresco.service.cmr.repository.NodeService;
|
||||
|
||||
/**
|
||||
* Recordable version config service
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.3
|
||||
*/
|
||||
public class RecordableVersionConfigServiceImpl implements RecordableVersionConfigService, RecordableVersionModel
|
||||
{
|
||||
/** Node service */
|
||||
private NodeService nodeService;
|
||||
|
||||
/**
|
||||
* Gets the node service
|
||||
*
|
||||
* @return The node service
|
||||
*/
|
||||
protected NodeService getNodeService()
|
||||
{
|
||||
return this.nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the node service
|
||||
*
|
||||
* @param nodeService The node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.recordableversion.RecordableVersionConfigService#getVersions(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
@Override
|
||||
public List<Version> getVersions(NodeRef nodeRef)
|
||||
{
|
||||
mandatory("nodeRef", nodeRef);
|
||||
|
||||
RecordableVersionPolicy[] recordableVersionPolicies = RecordableVersionPolicy.values();
|
||||
List<Version> versions = new ArrayList<Version>(recordableVersionPolicies.length);
|
||||
|
||||
for (RecordableVersionPolicy recordableVersionPolicy : recordableVersionPolicies)
|
||||
{
|
||||
String policy = recordableVersionPolicy.toString();
|
||||
boolean selected = isVersionPolicySelected(recordableVersionPolicy, nodeRef);
|
||||
versions.add(new Version(policy, selected));
|
||||
}
|
||||
|
||||
return versions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.recordableversion.RecordableVersionConfigService#setVersion(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setVersion(NodeRef nodeRef, String version)
|
||||
{
|
||||
mandatory("nodeRef", nodeRef);
|
||||
mandatoryString("recordedVersion", version);
|
||||
|
||||
RecordableVersionPolicy recordableVersionPolicy = RecordableVersionPolicy.valueOf(version);
|
||||
getNodeService().setProperty(nodeRef, PROP_RECORDABLE_VERSION_POLICY, recordableVersionPolicy);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) getNodeService().getProperty(nodeRef, PROP_RECORDABLE_VERSION_POLICY);
|
||||
if (isNotBlank(policy))
|
||||
{
|
||||
if (RecordableVersionPolicy.valueOf(policy).equals(recordableVersionPolicy))
|
||||
{
|
||||
isVersionPolicySelected = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (recordableVersionPolicy.equals(NONE))
|
||||
{
|
||||
isVersionPolicySelected = true;
|
||||
}
|
||||
}
|
||||
return isVersionPolicySelected;
|
||||
}
|
||||
}
|
@@ -18,16 +18,13 @@
|
||||
*/
|
||||
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.recordableversion.RecordableVersionConfigService;
|
||||
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;
|
||||
@@ -38,68 +35,41 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.3
|
||||
*/
|
||||
public class RecordedVersionConfigGet extends AbstractRmWebScript implements RecordableVersionModel
|
||||
public class RecordedVersionConfigGet extends AbstractRmWebScript
|
||||
{
|
||||
/** Recordable version config service */
|
||||
private RecordableVersionConfigService recordableVersionConfigService;
|
||||
|
||||
/**
|
||||
* Gets the recordable version config service
|
||||
*
|
||||
* @return The recordable version config service
|
||||
*/
|
||||
protected RecordableVersionConfigService getRecordableVersionConfigService()
|
||||
{
|
||||
return this.recordableVersionConfigService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the recordable version config service
|
||||
*
|
||||
* @param recordableVersionConfigService The recordable version config service
|
||||
*/
|
||||
public void setRecordableVersionConfigService(RecordableVersionConfigService recordableVersionConfigService)
|
||||
{
|
||||
this.recordableVersionConfigService = recordableVersionConfigService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
NodeRef nodeRef = parseRequestForNodeRef(req);
|
||||
List<Version> recordableVersions = getRecordableVersionConfigService().getVersions(nodeRef);
|
||||
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) getNodeService().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;
|
||||
}
|
||||
}
|
||||
|
@@ -24,9 +24,8 @@ import static org.alfresco.util.WebScriptUtils.getStringValueFromJSONObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.recordableversion.RecordableVersionConfigService;
|
||||
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.JSONObject;
|
||||
import org.springframework.extensions.webscripts.Cache;
|
||||
@@ -39,11 +38,34 @@ import org.springframework.extensions.webscripts.WebScriptRequest;
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.3
|
||||
*/
|
||||
public class RecordedVersionConfigPost extends AbstractRmWebScript implements RecordableVersionModel
|
||||
public class RecordedVersionConfigPost extends AbstractRmWebScript
|
||||
{
|
||||
// Constant for recorded version parameter
|
||||
/** Constant for recorded version parameter */
|
||||
public static final String RECORDED_VERSION = "recordedVersion";
|
||||
|
||||
/** Recordable version config service */
|
||||
private RecordableVersionConfigService recordableVersionConfigService;
|
||||
|
||||
/**
|
||||
* Gets the recordable version config service
|
||||
*
|
||||
* @return The recordable version config service
|
||||
*/
|
||||
protected RecordableVersionConfigService getRecordableVersionConfigService()
|
||||
{
|
||||
return this.recordableVersionConfigService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the recordable version config service
|
||||
*
|
||||
* @param recordableVersionConfigService The recordable version config service
|
||||
*/
|
||||
public void setRecordableVersionConfigService(RecordableVersionConfigService recordableVersionConfigService)
|
||||
{
|
||||
this.recordableVersionConfigService = recordableVersionConfigService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.web.scripts.DeclarativeWebScript#executeImpl(org.alfresco.web.scripts.WebScriptRequest, org.alfresco.web.scripts.Status, org.alfresco.web.scripts.Cache)
|
||||
*/
|
||||
@@ -51,8 +73,8 @@ public class RecordedVersionConfigPost extends AbstractRmWebScript implements Re
|
||||
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||
{
|
||||
NodeRef nodeRef = parseRequestForNodeRef(req);
|
||||
RecordableVersionPolicy recordableVersionPolicy = getRecordableVersionPolicy(req);
|
||||
getNodeService().setProperty(nodeRef, PROP_RECORDABLE_VERSION_POLICY, recordableVersionPolicy);
|
||||
String policy = getRecordableVersionPolicy(req);
|
||||
getRecordableVersionConfigService().setVersion(nodeRef, policy);
|
||||
return new HashMap<String, Object>(1);
|
||||
}
|
||||
|
||||
@@ -62,10 +84,9 @@ public class RecordedVersionConfigPost extends AbstractRmWebScript implements Re
|
||||
* @param The webscript request
|
||||
* @return The recordable version policy
|
||||
*/
|
||||
private RecordableVersionPolicy getRecordableVersionPolicy(WebScriptRequest req)
|
||||
private String getRecordableVersionPolicy(WebScriptRequest req)
|
||||
{
|
||||
JSONObject requestContent = getRequestContentAsJsonObject(req);
|
||||
String recordedVersion = getStringValueFromJSONObject(requestContent, RECORDED_VERSION);
|
||||
return RecordableVersionPolicy.valueOf(recordedVersion);
|
||||
return getStringValueFromJSONObject(requestContent, RECORDED_VERSION);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* 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 static org.alfresco.util.ParameterCheck.mandatory;
|
||||
import static org.alfresco.util.ParameterCheck.mandatoryString;
|
||||
|
||||
/**
|
||||
* Recordable version class
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 2.3
|
||||
*/
|
||||
public class Version
|
||||
{
|
||||
/** The version policy */
|
||||
private String policy;
|
||||
|
||||
/** Is the version selected */
|
||||
private boolean selected;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param policy The version policy
|
||||
* @param selected Is the version selected
|
||||
*/
|
||||
public Version(String policy, boolean selected)
|
||||
{
|
||||
mandatoryString("policy", policy);
|
||||
mandatory("selected", selected);
|
||||
|
||||
setPolicy(policy);
|
||||
setSelected(selected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the version policy
|
||||
*
|
||||
* @return The version policy
|
||||
*/
|
||||
public String getPolicy()
|
||||
{
|
||||
return this.policy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the version policy
|
||||
*
|
||||
* @param policy The version policy
|
||||
*/
|
||||
private void setPolicy(String policy)
|
||||
{
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the version selected
|
||||
*
|
||||
* @return <code>true</code> if the version is selected, <code>false</code> otherwise
|
||||
*/
|
||||
public boolean isSelected()
|
||||
{
|
||||
return this.selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the version as selected
|
||||
*
|
||||
* @param selected <code>true</code> if the version should be selected, <code>false</code> otherwise
|
||||
*/
|
||||
private void setSelected(boolean selected)
|
||||
{
|
||||
this.selected = selected;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user