mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged V2.0-BUG-FIX to V2.0 :
43623: RM-541 (Error shown in firebug when the details page of a record is open) 43661: RM-550 (JS Error while declaring a record) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.0@43714 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,35 +1,40 @@
|
|||||||
<#escape x as jsonUtils.encodeJSONString(x)>
|
<#escape x as jsonUtils.encodeJSONString(x)>
|
||||||
{
|
{
|
||||||
"data":
|
"data":
|
||||||
{
|
{
|
||||||
"url": "${nextaction.url}",
|
<#if nextaction.notFound?? && nextaction.notFound>
|
||||||
"name": "${nextaction.name}",
|
"notFound": ${nextaction.notFound?string},
|
||||||
"label": "${nextaction.label}",
|
"message": "${nextaction.message}"
|
||||||
"eventsEligible": ${nextaction.eventsEligible?string},
|
<#else>
|
||||||
<#if nextaction.asOf??>"asOf": "${nextaction.asOf}",</#if>
|
"url": "${nextaction.url}",
|
||||||
<#if nextaction.startedAt??>"startedAt": "${nextaction.startedAt}",</#if>
|
"name": "${nextaction.name}",
|
||||||
<#if nextaction.startedBy??>"startedBy": "${nextaction.startedBy}",</#if>
|
"label": "${nextaction.label}",
|
||||||
<#if nextaction.startedByFirstName??>"startedByFirstName": "${nextaction.startedByFirstName}",</#if>
|
"eventsEligible": ${nextaction.eventsEligible?string},
|
||||||
<#if nextaction.startedByLastName??>"startedByLastName": "${nextaction.startedByLastName}",</#if>
|
<#if nextaction.asOf??>"asOf": "${nextaction.asOf}",</#if>
|
||||||
<#if nextaction.completedAt??>"completedAt": "${nextaction.completedAt}",</#if>
|
<#if nextaction.startedAt??>"startedAt": "${nextaction.startedAt}",</#if>
|
||||||
<#if nextaction.completedBy??>"completedBy": "${nextaction.completedBy}",</#if>
|
<#if nextaction.startedBy??>"startedBy": "${nextaction.startedBy}",</#if>
|
||||||
<#if nextaction.completedByFirstName??>"completedByFirstName": "${nextaction.completedByFirstName}",</#if>
|
<#if nextaction.startedByFirstName??>"startedByFirstName": "${nextaction.startedByFirstName}",</#if>
|
||||||
<#if nextaction.completedByLastName??>"completedByLastName": "${nextaction.completedByLastName}",</#if>
|
<#if nextaction.startedByLastName??>"startedByLastName": "${nextaction.startedByLastName}",</#if>
|
||||||
"events":
|
<#if nextaction.completedAt??>"completedAt": "${nextaction.completedAt}",</#if>
|
||||||
[
|
<#if nextaction.completedBy??>"completedBy": "${nextaction.completedBy}",</#if>
|
||||||
<#list nextaction.events as event>
|
<#if nextaction.completedByFirstName??>"completedByFirstName": "${nextaction.completedByFirstName}",</#if>
|
||||||
{
|
<#if nextaction.completedByLastName??>"completedByLastName": "${nextaction.completedByLastName}",</#if>
|
||||||
"name": "${event.name}",
|
"events":
|
||||||
"label": "${event.label}",
|
[
|
||||||
"complete": ${event.complete?string},
|
<#list nextaction.events as event>
|
||||||
<#if event.completedAt??>"completedAt": "${event.completedAt}",</#if>
|
{
|
||||||
<#if event.completedBy??>"completedBy": "${event.completedBy}",</#if>
|
"name": "${event.name}",
|
||||||
<#if event.completedByFirstName??>"completedByFirstName": "${event.completedByFirstName}",</#if>
|
"label": "${event.label}",
|
||||||
<#if event.completedByLastName??>"completedByLastName": "${event.completedByLastName}",</#if>
|
"complete": ${event.complete?string},
|
||||||
"automatic": ${event.automatic?string}
|
<#if event.completedAt??>"completedAt": "${event.completedAt}",</#if>
|
||||||
}<#if event_has_next>,</#if>
|
<#if event.completedBy??>"completedBy": "${event.completedBy}",</#if>
|
||||||
</#list>
|
<#if event.completedByFirstName??>"completedByFirstName": "${event.completedByFirstName}",</#if>
|
||||||
]
|
<#if event.completedByLastName??>"completedByLastName": "${event.completedByLastName}",</#if>
|
||||||
}
|
"automatic": ${event.automatic?string}
|
||||||
|
}<#if event_has_next>,</#if>
|
||||||
|
</#list>
|
||||||
|
]
|
||||||
|
</#if>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</#escape>
|
</#escape>
|
@@ -29,6 +29,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
|
import org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase;
|
||||||
|
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.service.cmr.action.Action;
|
import org.alfresco.service.cmr.action.Action;
|
||||||
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
import org.alfresco.service.cmr.dictionary.AspectDefinition;
|
||||||
@@ -48,189 +49,174 @@ import org.springframework.extensions.surf.util.I18NUtil;
|
|||||||
*/
|
*/
|
||||||
public class DeclareRecordAction extends RMActionExecuterAbstractBase
|
public class DeclareRecordAction extends RMActionExecuterAbstractBase
|
||||||
{
|
{
|
||||||
/** I18N */
|
/** I18N */
|
||||||
private static final String MSG_UNDECLARED_ONLY_RECORDS = "rm.action.undeclared-only-records";
|
private static final String MSG_UNDECLARED_ONLY_RECORDS = "rm.action.undeclared-only-records";
|
||||||
private static final String MSG_NO_DECLARE_MAND_PROP = "rm.action.no-declare-mand-prop";
|
private static final String MSG_NO_DECLARE_MAND_PROP = "rm.action.no-declare-mand-prop";
|
||||||
|
|
||||||
/** Logger */
|
|
||||||
private static Log logger = LogFactory.getLog(DeclareRecordAction.class);
|
|
||||||
|
|
||||||
/**
|
/** Logger */
|
||||||
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action,
|
private static Log logger = LogFactory.getLog(DeclareRecordAction.class);
|
||||||
* org.alfresco.service.cmr.repository.NodeRef)
|
|
||||||
*/
|
/**
|
||||||
@Override
|
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
|
||||||
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
|
*/
|
||||||
{
|
@Override
|
||||||
if (recordsManagementService.isRecord(actionedUponNodeRef) == true)
|
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
|
||||||
{
|
{
|
||||||
if (recordsManagementService.isRecordDeclared(actionedUponNodeRef) == false)
|
if (recordsManagementService.isRecord(actionedUponNodeRef) == true)
|
||||||
|
{
|
||||||
|
if (recordsManagementService.isRecordDeclared(actionedUponNodeRef) == false)
|
||||||
|
{
|
||||||
|
List<String> missingProperties = new ArrayList<String>(5);
|
||||||
|
// Aspect not already defined - check mandatory properties then add
|
||||||
|
if (mandatoryPropertiesSet(actionedUponNodeRef, missingProperties) == true)
|
||||||
{
|
{
|
||||||
List<String> missingProperties = new ArrayList<String>(5);
|
// Add the declared aspect
|
||||||
// Aspect not already defined - check mandatory properties then add
|
Map<QName, Serializable> declaredProps = new HashMap<QName, Serializable>(2);
|
||||||
if (mandatoryPropertiesSet(actionedUponNodeRef, missingProperties) == true)
|
declaredProps.put(PROP_DECLARED_AT, new Date());
|
||||||
{
|
declaredProps.put(PROP_DECLARED_BY, AuthenticationUtil.getRunAsUser());
|
||||||
// Add the declared aspect
|
this.nodeService.addAspect(actionedUponNodeRef, ASPECT_DECLARED_RECORD, declaredProps);
|
||||||
Map<QName, Serializable> declaredProps = new HashMap<QName, Serializable>(2);
|
|
||||||
declaredProps.put(PROP_DECLARED_AT, new Date());
|
|
||||||
declaredProps.put(PROP_DECLARED_BY, AuthenticationUtil.getRunAsUser());
|
|
||||||
this.nodeService.addAspect(actionedUponNodeRef, ASPECT_DECLARED_RECORD, declaredProps);
|
|
||||||
|
|
||||||
// remove all owner related rights
|
|
||||||
this.ownableService.setOwner(actionedUponNodeRef, OwnableService.NO_OWNER);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException(buildMissingPropertiesErrorString(missingProperties));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, actionedUponNodeRef.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String buildMissingPropertiesErrorString(List<String> missingProperties)
|
|
||||||
{
|
|
||||||
StringBuilder builder = new StringBuilder(255);
|
|
||||||
builder.append(I18NUtil.getMessage(MSG_NO_DECLARE_MAND_PROP));
|
|
||||||
builder.append(" ");
|
|
||||||
for (String missingProperty : missingProperties)
|
|
||||||
{
|
|
||||||
builder.append(missingProperty)
|
|
||||||
.append(", ");
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// remove all owner related rights
|
||||||
* Helper method to check whether all the mandatory properties of the node have been set
|
this.ownableService.setOwner(actionedUponNodeRef, OwnableService.NO_OWNER);
|
||||||
*
|
|
||||||
* @param nodeRef
|
|
||||||
* node reference
|
|
||||||
* @return boolean true if all mandatory properties are set, false otherwise
|
|
||||||
*/
|
|
||||||
private boolean mandatoryPropertiesSet(NodeRef nodeRef, List<String> missingProperties)
|
|
||||||
{
|
|
||||||
boolean result = true;
|
|
||||||
|
|
||||||
Map<QName, Serializable> nodeRefProps = this.nodeService.getProperties(nodeRef);
|
|
||||||
|
|
||||||
QName nodeRefType = this.nodeService.getType(nodeRef);
|
|
||||||
|
|
||||||
TypeDefinition typeDef = this.dictionaryService.getType(nodeRefType);
|
|
||||||
for (PropertyDefinition propDef : typeDef.getProperties().values())
|
|
||||||
{
|
|
||||||
if (propDef.isMandatory() == true)
|
|
||||||
{
|
|
||||||
if (nodeRefProps.get(propDef.getName()) == null)
|
|
||||||
{
|
|
||||||
logMissingProperty(propDef, missingProperties);
|
|
||||||
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != false)
|
|
||||||
{
|
|
||||||
Set<QName> aspects = this.nodeService.getAspects(nodeRef);
|
|
||||||
for (QName aspect : aspects)
|
|
||||||
{
|
|
||||||
AspectDefinition aspectDef = this.dictionaryService.getAspect(aspect);
|
|
||||||
for (PropertyDefinition propDef : aspectDef.getProperties().values())
|
|
||||||
{
|
|
||||||
if (propDef.isMandatory() == true)
|
|
||||||
{
|
|
||||||
if (nodeRefProps.get(propDef.getName()) == null)
|
|
||||||
{
|
|
||||||
logMissingProperty(propDef, missingProperties);
|
|
||||||
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Log information about missing properties.
|
|
||||||
*
|
|
||||||
* @param propDef property definition
|
|
||||||
* @param missingProperties missing properties
|
|
||||||
*/
|
|
||||||
private void logMissingProperty(PropertyDefinition propDef, List<String> missingProperties)
|
|
||||||
{
|
|
||||||
if (logger.isWarnEnabled())
|
|
||||||
{
|
|
||||||
StringBuilder msg = new StringBuilder();
|
|
||||||
msg.append("Mandatory property missing: ").append(propDef.getName());
|
|
||||||
logger.warn(msg.toString());
|
|
||||||
}
|
|
||||||
missingProperties.add(propDef.getName().toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase#getProtectedAspects()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Set<QName> getProtectedAspects()
|
|
||||||
{
|
|
||||||
HashSet<QName> qnames = new HashSet<QName>();
|
|
||||||
qnames.add(ASPECT_DECLARED_RECORD);
|
|
||||||
return qnames;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase#isExecutableImpl(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, boolean)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected boolean isExecutableImpl(NodeRef filePlanComponent, Map<String, Serializable> parameters, boolean throwException)
|
|
||||||
{
|
|
||||||
if (recordsManagementService.isRecord(filePlanComponent) == true)
|
|
||||||
{
|
|
||||||
if (recordsManagementService.isRecordDeclared(filePlanComponent) == false)
|
|
||||||
{
|
|
||||||
// Aspect not already defined - check mandatory properties then add
|
|
||||||
List<String> missingProperties = new ArrayList<String>(10);
|
|
||||||
if (mandatoryPropertiesSet(filePlanComponent, missingProperties) == true)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (throwException)
|
|
||||||
{
|
|
||||||
throw new AlfrescoRuntimeException(buildMissingPropertiesErrorString(missingProperties));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
logger.debug(buildMissingPropertiesErrorString(missingProperties));
|
||||||
|
action.setParameterValue(ActionExecuterAbstractBase.PARAM_RESULT, "missingProperties");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
if (throwException)
|
{
|
||||||
{
|
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, actionedUponNodeRef.toString()));
|
||||||
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, filePlanComponent.toString()));
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
private String buildMissingPropertiesErrorString(List<String> missingProperties)
|
||||||
return false;
|
{
|
||||||
}
|
StringBuilder builder = new StringBuilder(255);
|
||||||
}
|
builder.append(I18NUtil.getMessage(MSG_NO_DECLARE_MAND_PROP));
|
||||||
|
builder.append(" ");
|
||||||
|
for (String missingProperty : missingProperties)
|
||||||
|
{
|
||||||
|
builder.append(missingProperty)
|
||||||
|
.append(", ");
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to check whether all the mandatory properties of the node have been set
|
||||||
|
*
|
||||||
|
* @param nodeRef node reference
|
||||||
|
* @return boolean true if all mandatory properties are set, false otherwise
|
||||||
|
*/
|
||||||
|
private boolean mandatoryPropertiesSet(NodeRef nodeRef, List<String> missingProperties)
|
||||||
|
{
|
||||||
|
boolean result = true;
|
||||||
|
|
||||||
|
Map<QName, Serializable> nodeRefProps = this.nodeService.getProperties(nodeRef);
|
||||||
|
|
||||||
|
QName nodeRefType = this.nodeService.getType(nodeRef);
|
||||||
|
|
||||||
|
TypeDefinition typeDef = this.dictionaryService.getType(nodeRefType);
|
||||||
|
for (PropertyDefinition propDef : typeDef.getProperties().values())
|
||||||
|
{
|
||||||
|
if (propDef.isMandatory() == true)
|
||||||
|
{
|
||||||
|
if (nodeRefProps.get(propDef.getName()) == null)
|
||||||
|
{
|
||||||
|
logMissingProperty(propDef, missingProperties);
|
||||||
|
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result != false)
|
||||||
|
{
|
||||||
|
Set<QName> aspects = this.nodeService.getAspects(nodeRef);
|
||||||
|
for (QName aspect : aspects)
|
||||||
|
{
|
||||||
|
AspectDefinition aspectDef = this.dictionaryService.getAspect(aspect);
|
||||||
|
for (PropertyDefinition propDef : aspectDef.getProperties().values())
|
||||||
|
{
|
||||||
|
if (propDef.isMandatory() == true)
|
||||||
|
{
|
||||||
|
if (nodeRefProps.get(propDef.getName()) == null)
|
||||||
|
{
|
||||||
|
logMissingProperty(propDef, missingProperties);
|
||||||
|
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log information about missing properties.
|
||||||
|
*
|
||||||
|
* @param propDef property definition
|
||||||
|
* @param missingProperties missing properties
|
||||||
|
*/
|
||||||
|
private void logMissingProperty(PropertyDefinition propDef, List<String> missingProperties)
|
||||||
|
{
|
||||||
|
if (logger.isWarnEnabled())
|
||||||
|
{
|
||||||
|
StringBuilder msg = new StringBuilder();
|
||||||
|
msg.append("Mandatory property missing: ").append(propDef.getName());
|
||||||
|
logger.warn(msg.toString());
|
||||||
|
}
|
||||||
|
missingProperties.add(propDef.getName().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase#getProtectedAspects()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Set<QName> getProtectedAspects()
|
||||||
|
{
|
||||||
|
HashSet<QName> qnames = new HashSet<QName>();
|
||||||
|
qnames.add(ASPECT_DECLARED_RECORD);
|
||||||
|
return qnames;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.alfresco.module.org_alfresco_module_rm.action.RMActionExecuterAbstractBase#isExecutableImpl(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, boolean)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected boolean isExecutableImpl(NodeRef filePlanComponent, Map<String, Serializable> parameters, boolean throwException)
|
||||||
|
{
|
||||||
|
if (recordsManagementService.isRecord(filePlanComponent) == true)
|
||||||
|
{
|
||||||
|
if (recordsManagementService.isRecordDeclared(filePlanComponent) == false)
|
||||||
|
{
|
||||||
|
// Aspect not already defined - check mandatory properties then add
|
||||||
|
List<String> missingProperties = new ArrayList<String>(10);
|
||||||
|
if (mandatoryPropertiesSet(filePlanComponent, missingProperties) == true)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (throwException)
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException(I18NUtil.getMessage(MSG_UNDECLARED_ONLY_RECORDS, filePlanComponent.toString()));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -23,8 +23,6 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction;
|
import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction;
|
||||||
import org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails;
|
import org.alfresco.module.org_alfresco_module_rm.event.EventCompletionDetails;
|
||||||
@@ -68,9 +66,12 @@ public class DispositionLifecycleGet extends DispositionAbstractBase
|
|||||||
DispositionAction nextAction = this.dispositionService.getNextDispositionAction(nodeRef);
|
DispositionAction nextAction = this.dispositionService.getNextDispositionAction(nodeRef);
|
||||||
if (nextAction == null)
|
if (nextAction == null)
|
||||||
{
|
{
|
||||||
status.setCode(HttpServletResponse.SC_NOT_FOUND,
|
Map<String, Object> nextActionModel = new HashMap<String, Object>(2);
|
||||||
"Node " + nodeRef.toString() + " does not have a disposition lifecycle");
|
nextActionModel.put("notFound", true);
|
||||||
return null;
|
nextActionModel.put("message", "Node " + nodeRef.toString() + " does not have a disposition lifecycle");
|
||||||
|
Map<String, Object> model = new HashMap<String, Object>(1);
|
||||||
|
model.put("nextaction", nextActionModel);
|
||||||
|
return model;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -50,175 +50,173 @@ import org.json.JSONTokener;
|
|||||||
*/
|
*/
|
||||||
public class RmActionPost extends DeclarativeWebScript
|
public class RmActionPost extends DeclarativeWebScript
|
||||||
{
|
{
|
||||||
private static Log logger = LogFactory.getLog(RmActionPost.class);
|
private static Log logger = LogFactory.getLog(RmActionPost.class);
|
||||||
|
|
||||||
private static final String PARAM_NAME = "name";
|
|
||||||
private static final String PARAM_NODE_REF = "nodeRef";
|
|
||||||
private static final String PARAM_NODE_REFS = "nodeRefs";
|
|
||||||
private static final String PARAM_PARAMS = "params";
|
|
||||||
|
|
||||||
private NodeService nodeService;
|
|
||||||
private RecordsManagementActionService rmActionService;
|
|
||||||
|
|
||||||
public void setNodeService(NodeService nodeService)
|
|
||||||
{
|
|
||||||
this.nodeService = nodeService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRecordsManagementActionService(RecordsManagementActionService rmActionService)
|
private static final String PARAM_NAME = "name";
|
||||||
{
|
private static final String PARAM_NODE_REF = "nodeRef";
|
||||||
this.rmActionService = rmActionService;
|
private static final String PARAM_NODE_REFS = "nodeRefs";
|
||||||
}
|
private static final String PARAM_PARAMS = "params";
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
private NodeService nodeService;
|
||||||
@Override
|
private RecordsManagementActionService rmActionService;
|
||||||
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
|
||||||
{
|
|
||||||
String reqContentAsString;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
reqContentAsString = req.getContent().getContent();
|
|
||||||
}
|
|
||||||
catch (IOException iox)
|
|
||||||
{
|
|
||||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
|
|
||||||
"Could not read content from req.", iox);
|
|
||||||
}
|
|
||||||
|
|
||||||
String actionName = null;
|
public void setNodeService(NodeService nodeService)
|
||||||
List<NodeRef> targetNodeRefs = null;
|
{
|
||||||
Map<String, Serializable> actionParams = new HashMap<String, Serializable>(3);
|
this.nodeService = nodeService;
|
||||||
|
}
|
||||||
try
|
|
||||||
{
|
|
||||||
JSONObject jsonObj = new JSONObject(new JSONTokener(reqContentAsString));
|
|
||||||
|
|
||||||
// Get the action name
|
|
||||||
if (jsonObj.has(PARAM_NAME) == true)
|
|
||||||
{
|
|
||||||
actionName = jsonObj.getString(PARAM_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the target references
|
|
||||||
if (jsonObj.has(PARAM_NODE_REF) == true)
|
|
||||||
{
|
|
||||||
NodeRef nodeRef = new NodeRef(jsonObj.getString(PARAM_NODE_REF));
|
|
||||||
targetNodeRefs = new ArrayList<NodeRef>(1);
|
|
||||||
targetNodeRefs.add(nodeRef);
|
|
||||||
}
|
|
||||||
if (jsonObj.has(PARAM_NODE_REFS) == true)
|
|
||||||
{
|
|
||||||
JSONArray jsonArray = jsonObj.getJSONArray(PARAM_NODE_REFS);
|
|
||||||
if (jsonArray.length() != 0)
|
|
||||||
{
|
|
||||||
targetNodeRefs = new ArrayList<NodeRef>(jsonArray.length());
|
|
||||||
for (int i = 0; i < jsonArray.length(); i++)
|
|
||||||
{
|
|
||||||
NodeRef nodeRef = new NodeRef(jsonArray.getString(i));
|
|
||||||
targetNodeRefs.add(nodeRef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// params are optional.
|
|
||||||
if (jsonObj.has(PARAM_PARAMS))
|
|
||||||
{
|
|
||||||
JSONObject paramsObj = jsonObj.getJSONObject(PARAM_PARAMS);
|
|
||||||
for (Iterator iter = paramsObj.keys(); iter.hasNext(); )
|
|
||||||
{
|
|
||||||
Object nextKey = iter.next();
|
|
||||||
String nextKeyString = (String)nextKey;
|
|
||||||
Object nextValue = paramsObj.get(nextKeyString);
|
|
||||||
|
|
||||||
// Check for date values
|
|
||||||
if (nextValue instanceof JSONObject)
|
|
||||||
{
|
|
||||||
if (((JSONObject)nextValue).has("iso8601") == true)
|
|
||||||
{
|
|
||||||
String dateStringValue = ((JSONObject)nextValue).getString("iso8601");
|
|
||||||
nextValue = ISO8601DateFormat.parse(dateStringValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
actionParams.put(nextKeyString, (Serializable)nextValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (JSONException exception)
|
|
||||||
{
|
|
||||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Unable to parse request JSON.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// validate input: check for mandatory params.
|
|
||||||
// Some RM actions can be posted without a nodeRef.
|
|
||||||
if (actionName == null)
|
|
||||||
{
|
|
||||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
|
|
||||||
"A mandatory parameter has not been provided in URL");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that all the nodes provided exist and build report string
|
public void setRecordsManagementActionService(RecordsManagementActionService rmActionService)
|
||||||
StringBuffer targetNodeRefsString = new StringBuffer(30);
|
{
|
||||||
boolean firstTime = true;
|
this.rmActionService = rmActionService;
|
||||||
for (NodeRef targetNodeRef : targetNodeRefs)
|
}
|
||||||
{
|
|
||||||
if (nodeService.exists(targetNodeRef) == false)
|
|
||||||
{
|
|
||||||
throw new WebScriptException(Status.STATUS_NOT_FOUND,
|
|
||||||
"The targetNode does not exist (" + targetNodeRef.toString() + ")");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the string
|
|
||||||
if (firstTime == true)
|
|
||||||
{
|
|
||||||
firstTime = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
targetNodeRefsString.append(", ");
|
|
||||||
}
|
|
||||||
targetNodeRefsString.append(targetNodeRef.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Proceed to execute the specified action on the specified node.
|
@SuppressWarnings("unchecked")
|
||||||
if (logger.isDebugEnabled())
|
@Override
|
||||||
{
|
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
|
||||||
StringBuilder msg = new StringBuilder();
|
{
|
||||||
msg.append("Executing Record Action ")
|
String reqContentAsString;
|
||||||
.append(actionName)
|
try
|
||||||
.append(", (")
|
{
|
||||||
.append(targetNodeRefsString.toString())
|
reqContentAsString = req.getContent().getContent();
|
||||||
.append("), ")
|
}
|
||||||
.append(actionParams);
|
catch (IOException iox)
|
||||||
logger.debug(msg.toString());
|
{
|
||||||
}
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
|
||||||
|
"Could not read content from req.", iox);
|
||||||
Map<String, Object> model = new HashMap<String, Object>();
|
}
|
||||||
if (targetNodeRefs.isEmpty())
|
|
||||||
{
|
|
||||||
RecordsManagementActionResult result = this.rmActionService.executeRecordsManagementAction(actionName, actionParams);
|
|
||||||
if (result.getValue() != null)
|
|
||||||
{
|
|
||||||
model.put("result", result.getValue().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Map<NodeRef, RecordsManagementActionResult> resultMap = this.rmActionService.executeRecordsManagementAction(targetNodeRefs, actionName, actionParams);
|
|
||||||
Map<String, String> results = new HashMap<String, String>(resultMap.size());
|
|
||||||
for (NodeRef nodeRef : resultMap.keySet())
|
|
||||||
{
|
|
||||||
Object value = resultMap.get(nodeRef).getValue();
|
|
||||||
if (value != null)
|
|
||||||
{
|
|
||||||
results.put(nodeRef.toString(), resultMap.get(nodeRef).getValue().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
model.put("results", results);
|
|
||||||
}
|
|
||||||
|
|
||||||
model.put("message", "Successfully queued action [" + actionName + "] on " + targetNodeRefsString.toString());
|
|
||||||
|
|
||||||
return model;
|
String actionName = null;
|
||||||
}
|
List<NodeRef> targetNodeRefs = new ArrayList<NodeRef>(1);
|
||||||
|
Map<String, Serializable> actionParams = new HashMap<String, Serializable>(3);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
JSONObject jsonObj = new JSONObject(new JSONTokener(reqContentAsString));
|
||||||
|
|
||||||
|
// Get the action name
|
||||||
|
if (jsonObj.has(PARAM_NAME) == true)
|
||||||
|
{
|
||||||
|
actionName = jsonObj.getString(PARAM_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the target references
|
||||||
|
if (jsonObj.has(PARAM_NODE_REF) == true)
|
||||||
|
{
|
||||||
|
NodeRef nodeRef = new NodeRef(jsonObj.getString(PARAM_NODE_REF));
|
||||||
|
targetNodeRefs.add(nodeRef);
|
||||||
|
}
|
||||||
|
if (jsonObj.has(PARAM_NODE_REFS) == true)
|
||||||
|
{
|
||||||
|
JSONArray jsonArray = jsonObj.getJSONArray(PARAM_NODE_REFS);
|
||||||
|
if (jsonArray.length() != 0)
|
||||||
|
{
|
||||||
|
targetNodeRefs = new ArrayList<NodeRef>(jsonArray.length());
|
||||||
|
for (int i = 0; i < jsonArray.length(); i++)
|
||||||
|
{
|
||||||
|
NodeRef nodeRef = new NodeRef(jsonArray.getString(i));
|
||||||
|
targetNodeRefs.add(nodeRef);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// params are optional.
|
||||||
|
if (jsonObj.has(PARAM_PARAMS))
|
||||||
|
{
|
||||||
|
JSONObject paramsObj = jsonObj.getJSONObject(PARAM_PARAMS);
|
||||||
|
for (Iterator<String> iter = paramsObj.keys(); iter.hasNext(); )
|
||||||
|
{
|
||||||
|
String nextKeyString = iter.next();
|
||||||
|
Object nextValue = paramsObj.get(nextKeyString);
|
||||||
|
|
||||||
|
// Check for date values
|
||||||
|
if (nextValue instanceof JSONObject)
|
||||||
|
{
|
||||||
|
if (((JSONObject)nextValue).has("iso8601") == true)
|
||||||
|
{
|
||||||
|
String dateStringValue = ((JSONObject)nextValue).getString("iso8601");
|
||||||
|
nextValue = ISO8601DateFormat.parse(dateStringValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
actionParams.put(nextKeyString, (Serializable)nextValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (JSONException exception)
|
||||||
|
{
|
||||||
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Unable to parse request JSON.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// validate input: check for mandatory params.
|
||||||
|
// Some RM actions can be posted without a nodeRef.
|
||||||
|
if (actionName == null)
|
||||||
|
{
|
||||||
|
throw new WebScriptException(Status.STATUS_BAD_REQUEST,
|
||||||
|
"A mandatory parameter has not been provided in URL");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check that all the nodes provided exist and build report string
|
||||||
|
StringBuffer targetNodeRefsString = new StringBuffer(30);
|
||||||
|
boolean firstTime = true;
|
||||||
|
for (NodeRef targetNodeRef : targetNodeRefs)
|
||||||
|
{
|
||||||
|
if (nodeService.exists(targetNodeRef) == false)
|
||||||
|
{
|
||||||
|
throw new WebScriptException(Status.STATUS_NOT_FOUND,
|
||||||
|
"The targetNode does not exist (" + targetNodeRef.toString() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the string
|
||||||
|
if (firstTime == true)
|
||||||
|
{
|
||||||
|
firstTime = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
targetNodeRefsString.append(", ");
|
||||||
|
}
|
||||||
|
targetNodeRefsString.append(targetNodeRef.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Proceed to execute the specified action on the specified node.
|
||||||
|
if (logger.isDebugEnabled())
|
||||||
|
{
|
||||||
|
StringBuilder msg = new StringBuilder();
|
||||||
|
msg.append("Executing Record Action ")
|
||||||
|
.append(actionName)
|
||||||
|
.append(", (")
|
||||||
|
.append(targetNodeRefsString.toString())
|
||||||
|
.append("), ")
|
||||||
|
.append(actionParams);
|
||||||
|
logger.debug(msg.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> model = new HashMap<String, Object>();
|
||||||
|
if (targetNodeRefs.isEmpty())
|
||||||
|
{
|
||||||
|
RecordsManagementActionResult result = this.rmActionService.executeRecordsManagementAction(actionName, actionParams);
|
||||||
|
if (result.getValue() != null)
|
||||||
|
{
|
||||||
|
model.put("result", result.getValue().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Map<NodeRef, RecordsManagementActionResult> resultMap = this.rmActionService.executeRecordsManagementAction(targetNodeRefs, actionName, actionParams);
|
||||||
|
Map<String, String> results = new HashMap<String, String>(resultMap.size());
|
||||||
|
for (NodeRef nodeRef : resultMap.keySet())
|
||||||
|
{
|
||||||
|
Object value = resultMap.get(nodeRef).getValue();
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
results.put(nodeRef.toString(), resultMap.get(nodeRef).getValue().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
model.put("results", results);
|
||||||
|
}
|
||||||
|
|
||||||
|
model.put("message", "Successfully queued action [" + actionName + "] on " + targetNodeRefsString.toString());
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user