use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class ProcessesImpl method getProcesses.
@Override
public CollectionWithPagingInfo<ProcessInfo> getProcesses(Parameters parameters) {
Paging paging = parameters.getPaging();
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(PROCESS_COLLECTION_EQUALS_QUERY_PROPERTIES, null);
propertyWalker.setSupportedGreaterThanParameters(PROCESS_COLLECTION_GREATERTHAN_QUERY_PROPERTIES);
propertyWalker.setSupportedLessThanParameters(PROCESS_COLLECTION_LESSTHAN_QUERY_PROPERTIES);
propertyWalker.enableVariablesSupport(namespaceService, dictionaryService);
if (parameters.getQuery() != null) {
QueryHelper.walk(parameters.getQuery(), propertyWalker);
}
String status = propertyWalker.getProperty("status", WhereClauseParser.EQUALS);
String processDefinitionId = propertyWalker.getProperty("processDefinitionId", WhereClauseParser.EQUALS);
String businessKey = propertyWalker.getProperty("businessKey", WhereClauseParser.EQUALS);
String processDefinitionKey = propertyWalker.getProperty("processDefinitionKey", WhereClauseParser.EQUALS);
String startUserId = propertyWalker.getProperty("startUserId", WhereClauseParser.EQUALS);
Date startedAtGreaterThan = propertyWalker.getProperty("startedAt", WhereClauseParser.GREATERTHAN, Date.class);
Date startedAtLessThan = propertyWalker.getProperty("startedAt", WhereClauseParser.LESSTHAN, Date.class);
Date endedAtGreaterThan = propertyWalker.getProperty("endedAt", WhereClauseParser.GREATERTHAN, Date.class);
Date endedAtLessThan = propertyWalker.getProperty("endedAt", WhereClauseParser.LESSTHAN, Date.class);
Boolean includeVariables = propertyWalker.getProperty("includeVariables", WhereClauseParser.EQUALS, Boolean.class);
if (status != null && PROCESS_STATUS_LIST.contains(status) == false) {
throw new InvalidArgumentException("Invalid status parameter: " + status);
}
List<SortColumn> sortList = parameters.getSorting();
SortColumn sortColumn = null;
if (sortList != null && sortList.size() > 0) {
if (sortList.size() != 1) {
throw new InvalidArgumentException("Only one order by parameter is supported");
}
sortColumn = sortList.get(0);
}
final HistoricProcessInstanceQuery query = activitiProcessEngine.getHistoryService().createHistoricProcessInstanceQuery();
if (processDefinitionId != null)
query.processDefinitionId(processDefinitionId);
if (businessKey != null)
query.processInstanceBusinessKey(businessKey);
if (processDefinitionKey != null) {
if (tenantService.isEnabled() && deployWorkflowsInTenant) {
if (processDefinitionKey.startsWith("@" + TenantUtil.getCurrentDomain() + "@")) {
query.processDefinitionKey(processDefinitionKey);
} else {
query.processDefinitionKey("@" + TenantUtil.getCurrentDomain() + "@" + processDefinitionKey);
}
} else {
query.processDefinitionKey(processDefinitionKey);
}
}
if (startUserId != null)
query.startedBy(startUserId);
if (startedAtGreaterThan != null)
query.startedAfter(startedAtGreaterThan);
if (startedAtLessThan != null)
query.startedBefore(startedAtLessThan);
if (endedAtGreaterThan != null)
query.finishedAfter(endedAtGreaterThan);
if (endedAtLessThan != null)
query.finishedBefore(endedAtLessThan);
if (status == null || PROCESS_STATUS_ACTIVE.equals(status)) {
query.unfinished();
} else if (PROCESS_STATUS_COMPLETED.equals(status)) {
query.finished();
query.notDeleted();
} else if (PROCESS_STATUS_DELETED.equals(status)) {
query.deleted();
}
if (includeVariables != null && includeVariables) {
query.includeProcessVariables();
}
List<QueryVariableHolder> variableProperties = propertyWalker.getVariableProperties();
if (variableProperties != null) {
for (QueryVariableHolder queryVariableHolder : variableProperties) {
if (queryVariableHolder.getOperator() == WhereClauseParser.EQUALS) {
query.variableValueEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else if (queryVariableHolder.getOperator() == WhereClauseParser.GREATERTHAN) {
query.variableValueGreaterThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else if (queryVariableHolder.getOperator() == WhereClauseParser.GREATERTHANOREQUALS) {
query.variableValueGreaterThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else if (queryVariableHolder.getOperator() == WhereClauseParser.LESSTHAN) {
query.variableValueLessThan(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else if (queryVariableHolder.getOperator() == WhereClauseParser.LESSTHANOREQUALS) {
query.variableValueLessThanOrEqual(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else if (queryVariableHolder.getOperator() == WhereClauseParser.MATCHES) {
if (queryVariableHolder.getPropertyValue() instanceof String == false) {
throw new InvalidArgumentException("the matches operator can only be used with a String value for property " + queryVariableHolder.getPropertyName());
}
if (((String) queryVariableHolder.getPropertyValue()).startsWith("(?i)")) {
query.variableValueLikeIgnoreCase(queryVariableHolder.getPropertyName(), ((String) queryVariableHolder.getPropertyValue()).substring("(?i)".length()).toLowerCase());
} else {
query.variableValueLike(queryVariableHolder.getPropertyName(), (String) queryVariableHolder.getPropertyValue());
}
} else if (queryVariableHolder.getOperator() == WhereClauseParser.NEGATION) {
query.variableValueNotEquals(queryVariableHolder.getPropertyName(), queryVariableHolder.getPropertyValue());
} else {
throw new InvalidArgumentException("variable " + queryVariableHolder.getPropertyName() + " can only be used with an =, >, >=, <=, <, not, matches comparison type");
}
}
}
if (authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) {
// Admin is allowed to read all processes in the current tenant
if (tenantService.isEnabled()) {
query.variableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
}
} else {
// If non-admin user, involvement in the process is required (either owner, assignee or externally involved).
query.involvedUser(AuthenticationUtil.getRunAsUser());
}
if (sortColumn != null) {
if (PROCESS_COLLECTION_SORT_PROPERTIES.contains(sortColumn.column)) {
if ("processDefinitionId".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessDefinitionId();
} else if ("id".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessInstanceId();
} else if ("businessKey".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessInstanceBusinessKey();
} else if ("startedAt".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessInstanceStartTime();
} else if ("endedAt".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessInstanceEndTime();
} else if ("durationInMillis".equalsIgnoreCase(sortColumn.column)) {
query.orderByProcessInstanceDuration();
}
} else {
throw new InvalidArgumentException("sort " + sortColumn.column + " is not supported, supported items are " + Arrays.toString(PROCESS_COLLECTION_SORT_PROPERTIES.toArray()));
}
if (sortColumn.asc) {
query.asc();
} else {
query.desc();
}
} else {
query.orderByProcessInstanceStartTime().desc();
}
List<HistoricProcessInstance> processInstances = query.listPage(paging.getSkipCount(), paging.getMaxItems());
int totalCount = (int) query.count();
List<ProcessInfo> page = new ArrayList<ProcessInfo>(processInstances.size());
Map<String, TypeDefinition> definitionTypeMap = new HashMap<String, TypeDefinition>();
for (HistoricProcessInstance processInstance : processInstances) {
ProcessInfo processInfo = createProcessInfo(processInstance);
if (includeVariables != null && includeVariables) {
if (definitionTypeMap.containsKey(processInfo.getProcessDefinitionId()) == false) {
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processInfo.getProcessDefinitionId());
if (startFormData != null) {
String formKey = startFormData.getFormKey();
definitionTypeMap.put(processInfo.getProcessDefinitionId(), getWorkflowFactory().getTaskFullTypeDefinition(formKey, true));
}
}
if (definitionTypeMap.containsKey(processInfo.getProcessDefinitionId())) {
// Convert raw variables to Variable objects
List<Variable> resultingVariables = restVariableHelper.getVariables(processInstance.getProcessVariables(), definitionTypeMap.get(processInfo.getProcessDefinitionId()));
processInfo.setProcessVariables(resultingVariables);
}
}
page.add(processInfo);
}
return CollectionWithPagingInfo.asPaged(paging, page, (page.size() + paging.getSkipCount()) < totalCount, totalCount);
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method setConstraintOtherData.
private void setConstraintOtherData(CustomModelConstraint constraint, M2Constraint m2Constraint, String propDataType) {
if (m2Constraint.getType() == null) {
throw new InvalidArgumentException("cmm.rest_api.constraint_type_null");
}
ConstraintValidator constraintValidator = ConstraintValidator.findByType(m2Constraint.getType());
if (propDataType != null) {
// Check if the constraint can be used with given data type
constraintValidator.validateUsage(prefixedStringToQname(propDataType));
}
m2Constraint.setTitle(constraint.getTitle());
m2Constraint.setDescription(constraint.getDescription());
for (CustomModelNamedValue parameter : constraint.getParameters()) {
validateName(parameter.getName(), "cmm.rest_api.constraint_parameter_name_null");
if (parameter.getListValue() != null) {
if (propDataType != null && "allowedValues".equals(parameter.getName())) {
validateListConstraint(parameter.getListValue(), propDataType);
}
m2Constraint.createParameter(parameter.getName(), parameter.getListValue());
} else {
constraintValidator.validate(parameter.getName(), parameter.getSimpleValue());
m2Constraint.createParameter(parameter.getName(), parameter.getSimpleValue());
}
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method createCustomModelImpl.
private CustomModel createCustomModelImpl(CustomModel model, boolean basicModelOnly) {
M2Model m2Model = null;
if (basicModelOnly) {
m2Model = convertToM2Model(model, null, null, null);
} else {
m2Model = convertToM2Model(model, model.getTypes(), model.getAspects(), model.getConstraints());
}
boolean activate = ModelStatus.ACTIVE.equals(model.getStatus());
try {
CustomModelDefinition modelDefinition = customModelService.createCustomModel(m2Model, activate);
return new CustomModel(modelDefinition);
} catch (ModelExistsException me) {
throw new ConstraintViolatedException(me.getMessage());
} catch (CustomModelConstraintException ncx) {
throw new ConstraintViolatedException(ncx.getMessage());
} catch (InvalidCustomModelException iex) {
throw new InvalidArgumentException(iex.getMessage());
} catch (Exception e) {
throw new ApiException("cmm.rest_api.model_invalid", e);
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method createDownload.
@Override
public CustomModelDownload createDownload(String modelName, Parameters parameters) {
// Check the current user is authorised to export the model
validateCurrentUser();
if (modelName == null) {
throw new InvalidArgumentException(MODEL_NAME_NULL_ERR);
}
String propName = parameters.getParameter(PARAM_WITH_EXT_MODULE);
boolean withForm = Boolean.valueOf(propName);
try {
NodeRef nodeRef = customModelService.createDownloadNode(modelName, withForm);
return new CustomModelDownload(nodeRef);
} catch (Exception ex) {
String errorMsg = "cmm.rest_api.model_download_failure";
if (ex.getMessage() != null) {
errorMsg = ex.getMessage();
}
throw new ApiException(errorMsg, ex);
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CustomModelsImpl method resolveToUriAndPrefix.
/**
* Gets the namespace URI and prefix from the parent's name, provided that the
* given name is of a valid format. The valid format consist of a
* <i>namespace prefix</i>, a <i>colon</i> and a <i>name</i>. <b>E.g. sys:localized</b>
*
* @param parentName the parent name
* @return a pair of namespace URI and prefix object
*/
protected Pair<String, String> resolveToUriAndPrefix(String parentName) {
QName qName = prefixedStringToQname(parentName);
Collection<String> prefixes = namespaceService.getPrefixes(qName.getNamespaceURI());
if (prefixes.size() == 0) {
throw new InvalidArgumentException("cmm.rest_api.prefix_not_registered", new Object[] { qName.getNamespaceURI() });
}
String prefix = prefixes.iterator().next();
return new Pair<String, String>(qName.getNamespaceURI(), prefix);
}
Aggregations