use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException 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.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class ProcessesImpl method convertAssociationDefinitionValue.
protected Object convertAssociationDefinitionValue(AssociationDefinition associationDef, String variableName, Object variableValue) {
if (variableValue != null && ContentModel.TYPE_PERSON.equals(associationDef.getTargetClass().getName())) {
if (associationDef.isTargetMany()) {
if (variableValue instanceof List<?>) {
List<NodeRef> personList = new ArrayList<NodeRef>();
List<?> values = (List<?>) variableValue;
for (Object value : values) {
NodeRef personRef = getPersonNodeRef(value.toString());
if (personRef == null) {
throw new InvalidArgumentException(value.toString() + " is not a valid person user id");
}
personList.add(personRef);
}
variableValue = personList;
} else {
throw new InvalidArgumentException(variableName + " should have an array value");
}
} else {
NodeRef personRef = getPersonNodeRef(variableValue.toString());
if (personRef == null) {
throw new InvalidArgumentException(variableValue.toString() + " is not a valid person user id");
}
variableValue = personRef;
}
} else if (variableValue != null && ContentModel.TYPE_AUTHORITY_CONTAINER.equals(associationDef.getTargetClass().getName())) {
if (associationDef.isTargetMany()) {
if (variableValue instanceof List<?>) {
List<NodeRef> authorityList = new ArrayList<NodeRef>();
List<?> values = (List<?>) variableValue;
for (Object value : values) {
NodeRef authorityRef = authorityService.getAuthorityNodeRef(value.toString());
if (authorityRef == null) {
throw new InvalidArgumentException(value.toString() + " is not a valid authority id");
}
authorityList.add(authorityRef);
}
variableValue = authorityList;
} else {
throw new InvalidArgumentException(variableName + " should have an array value");
}
} else {
NodeRef authorityRef = authorityService.getAuthorityNodeRef(variableValue.toString());
if (authorityRef == null) {
throw new InvalidArgumentException(variableValue.toString() + " is not a valid authority id");
}
variableValue = authorityRef;
}
}
return variableValue;
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class InfoWebScriptGet method execute.
@Override
public void execute(final Api api, WebScriptRequest req, WebScriptResponse res) throws IOException {
ResourceDictionary resourceDic = lookupDictionary.getDictionary();
final Map<String, ResourceWithMetadata> apiResources = resourceDic.getAllResources().get(api);
if (apiResources == null) {
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_INVALID_API);
}
assistant.getJsonHelper().withWriter(res.getOutputStream(), new Writer() {
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
List<ExecutionResult> entities = new ArrayList<ExecutionResult>();
for (ResourceWithMetadata resource : apiResources.values()) {
entities.add(new ExecutionResult(resource.getMetaData(), null));
}
Collections.sort(entities, new Comparator<ExecutionResult>() {
public int compare(ExecutionResult r1, ExecutionResult r2) {
return ((ResourceMetadata) r1.getRoot()).getUniqueId().compareTo(((ResourceMetadata) r2.getRoot()).getUniqueId());
}
});
objectMapper.writeValue(generator, CollectionWithPagingInfo.asPaged(Paging.DEFAULT, entities));
}
});
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class DeploymentsImpl method getDeployment.
@Override
public Deployment getDeployment(String deploymentId) {
// Only admin-user is allowed to get deployments
if (!authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
throw new PermissionDeniedException();
}
RepositoryService repositoryService = activitiProcessEngine.getRepositoryService();
DeploymentQuery query = repositoryService.createDeploymentQuery().deploymentId(deploymentId);
if (tenantService.isEnabled() && deployWorkflowsInTenant) {
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
}
org.activiti.engine.repository.Deployment deployment = null;
try {
deployment = query.singleResult();
} catch (ActivitiException e) {
// The next exception will cause a response status 400: Bad request
throw new InvalidArgumentException("Invalid deployment id: " + deploymentId);
}
if (deployment == null) {
// The next exception will cause a response status 404: Not found
throw new EntityNotFoundException(deploymentId);
}
Deployment deploymentRest = new Deployment(deployment);
return deploymentRest;
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class WorkflowRestImpl method deleteItemFromProcess.
/**
* Delete an item from the process package variable
*/
public void deleteItemFromProcess(String itemId, String processId) {
NodeRef nodeRef = getNodeRef(itemId);
ActivitiScriptNode packageScriptNode = null;
try {
packageScriptNode = (ActivitiScriptNode) activitiProcessEngine.getRuntimeService().getVariable(processId, BPM_PACKAGE);
} catch (ActivitiObjectNotFoundException e) {
throw new EntityNotFoundException(processId);
}
if (packageScriptNode == null) {
throw new InvalidArgumentException("process doesn't contain a workflow package variable");
}
boolean itemIdFoundInPackage = false;
List<ChildAssociationRef> documentList = nodeService.getChildAssocs(packageScriptNode.getNodeRef());
for (ChildAssociationRef childAssociationRef : documentList) {
if (childAssociationRef.getChildRef().equals(nodeRef)) {
itemIdFoundInPackage = true;
break;
}
}
if (itemIdFoundInPackage == false) {
throw new EntityNotFoundException("Item " + itemId + " not found in the process package variable");
}
try {
nodeService.removeChild(packageScriptNode.getNodeRef(), nodeRef);
activitiWorkflowEngine.dispatchPackageUpdatedEvent(packageScriptNode, null, null, processId, null);
} catch (InvalidNodeRefException e) {
throw new EntityNotFoundException("Item " + itemId + " not found");
}
}
Aggregations