use of org.alfresco.rest.workflow.api.model.Variable in project alfresco-remote-api by Alfresco.
the class ProcessesImpl method updateVariableInProcess.
protected Variable updateVariableInProcess(String processId, String processDefinitionId, Variable variable) {
if (variable.getName() == null) {
throw new InvalidArgumentException("Variable name is required.");
}
// Get start-task definition for explicit typing of variables submitted at the start
String formKey = null;
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinitionId);
if (startFormData != null) {
formKey = startFormData.getFormKey();
}
DataTypeDefinition dataTypeDefinition = null;
TypeDefinition startTaskTypeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(formKey, true);
TypeDefinitionContext context = new TypeDefinitionContext(startTaskTypeDefinition, getQNameConverter());
if (context.getPropertyDefinition(variable.getName()) != null) {
dataTypeDefinition = context.getPropertyDefinition(variable.getName()).getDataType();
if (variable.getType() != null && dataTypeDefinition.getName().toPrefixString(namespaceService).equals(variable.getType()) == false) {
throw new InvalidArgumentException("type of variable " + variable.getName() + " should be " + dataTypeDefinition.getName().toPrefixString(namespaceService));
}
} else if (context.getAssociationDefinition(variable.getName()) != null) {
dataTypeDefinition = dictionaryService.getDataType(DataTypeDefinition.NODE_REF);
}
if (dataTypeDefinition == null && variable.getType() != null) {
try {
QName dataType = QName.createQName(variable.getType(), namespaceService);
dataTypeDefinition = dictionaryService.getDataType(dataType);
} catch (InvalidQNameException iqne) {
throw new InvalidArgumentException("Unsupported type of variable: '" + variable.getType() + "'.");
}
} else if (dataTypeDefinition == null) {
// Fallback to raw value when no type has been passed and not present in model
dataTypeDefinition = dictionaryService.getDataType(restVariableHelper.extractTypeFromValue(variable.getValue()));
}
if (dataTypeDefinition == null) {
throw new InvalidArgumentException("Unsupported type of variable: '" + variable.getType() + "'.");
}
Object actualValue = null;
if ("java.util.Date".equalsIgnoreCase(dataTypeDefinition.getJavaClassName())) {
// fix for different ISO 8601 Date format classes in Alfresco (org.alfresco.util and Spring Surf)
actualValue = ISO8601DateFormat.parse((String) variable.getValue());
} else if (variable.getName().equals(WorkflowConstants.PROP_INITIATOR)) {
// update the initiator if exists
NodeRef initiator = getNodeRef((String) variable.getValue());
if (nodeService.exists(initiator)) {
actualValue = getNodeConverter().convertNode(initiator);
// Also update the initiator home reference, if one exists
NodeRef initiatorHome = (NodeRef) nodeService.getProperty(initiator, ContentModel.PROP_HOMEFOLDER);
if (initiatorHome != null) {
Variable initiatorHomeVar = new Variable();
initiatorHomeVar.setName(WorkflowConstants.PROP_INITIATOR_HOME);
initiatorHomeVar.setValue(initiatorHome);
updateVariableInProcess(processId, processDefinitionId, initiatorHomeVar);
}
} else {
throw new InvalidArgumentException("Variable value should be a valid person NodeRef.");
}
} else {
if (context.getAssociationDefinition(variable.getName()) != null) {
actualValue = convertAssociationDefinitionValue(context.getAssociationDefinition(variable.getName()), variable.getName(), variable.getValue());
} else {
actualValue = DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition, variable.getValue());
}
}
activitiProcessEngine.getRuntimeService().setVariable(processId, variable.getName(), actualValue);
// Variable value needs to be of type NodeRef
if (actualValue instanceof ActivitiScriptNode) {
variable.setValue(((ActivitiScriptNode) actualValue).getNodeRef());
} else {
variable.setValue(actualValue);
}
// Set actual used type before returning
variable.setType(dataTypeDefinition.getName().toPrefixString(namespaceService));
return variable;
}
use of org.alfresco.rest.workflow.api.model.Variable in project alfresco-remote-api by Alfresco.
the class RestVariableHelper method getVariables.
/**
* @param variables raw variables
* @param typeDefinition the typê definition for the start-task of the process, used to extract types.
* @return list of {@link Variable}, representing the given raw variables
*/
public List<Variable> getVariables(Map<String, Object> variables, TypeDefinition typeDefinition) {
List<Variable> result = new ArrayList<Variable>();
TypeDefinitionContext context = new TypeDefinitionContext(typeDefinition, getQNameConverter());
Variable variable = null;
for (Entry<String, Object> entry : variables.entrySet()) {
if (!INTERNAL_PROPERTIES.contains(entry.getKey())) {
variable = new Variable();
variable.setName(entry.getKey());
// Set value and type
setVariableValueAndType(variable, entry.getValue(), context);
result.add(variable);
}
}
return result;
}
Aggregations