use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class MapBasedQueryWalker method getProperty.
/**
* Get the property value, converted to the requested type.
*
* @param propertyName name of the parameter
* @param type int
* @param returnType type of object to return
* @return the converted parameter value. Null, if the property has no
* value.
* @throws IllegalArgumentException when no conversion for the given
* returnType is available or if returnType is null.
* @throws InvalidArgumentException when conversion to the given type was
* not possible due to an error while converting
*/
@SuppressWarnings("unchecked")
public <T extends Object> T getProperty(String propertyName, int type, Class<T> returnType) {
if (returnType == null) {
throw new IllegalArgumentException("ReturnType cannot be null");
}
try {
Object result = null;
String stringValue = getProperty(propertyName, type);
if (stringValue != null) {
result = ConvertUtils.convert(stringValue, returnType);
if ((result instanceof String) && (!returnType.equals(String.class))) {
// If a string is returned, no converter has been found (for non-String return type)
throw new IllegalArgumentException("Unable to convert parameter to type: " + returnType.getName());
}
}
return (T) result;
} catch (ConversionException ce) {
// Conversion failed, wrap in Illegal
throw new InvalidArgumentException("Query property value for '" + propertyName + "' should be a valid " + returnType.getSimpleName());
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionsImpl method getProcessDefinitions.
@Override
public CollectionWithPagingInfo<ProcessDefinition> getProcessDefinitions(Parameters parameters) {
ProcessDefinitionQuery query = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionCategoryNotEquals(WorkflowDeployer.CATEGORY_ALFRESCO_INTERNAL);
MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(PROCESS_DEFINITION_COLLECTION_EQUALS_QUERY_PROPERTIES, PROCESS_DEFINITION_COLLECTION_MATCHES_QUERY_PROPERTIES);
boolean keyQueryIncluded = false;
if (parameters.getQuery() != null) {
QueryHelper.walk(parameters.getQuery(), propertyWalker);
// Property equals
String categoryProperty = propertyWalker.getProperty("category", WhereClauseParser.EQUALS);
if (categoryProperty != null) {
query.processDefinitionCategory(categoryProperty);
}
String keyProperty = propertyWalker.getProperty("key", WhereClauseParser.EQUALS);
if (keyProperty != null) {
query.processDefinitionKey(getProcessDefinitionKey(keyProperty));
keyQueryIncluded = true;
}
String nameProperty = propertyWalker.getProperty("name", WhereClauseParser.EQUALS);
if (nameProperty != null) {
query.processDefinitionName(nameProperty);
}
Integer versionProperty = propertyWalker.getProperty("version", WhereClauseParser.EQUALS, Integer.class);
if (versionProperty != null) {
query.processDefinitionVersion(versionProperty);
}
String deploymentProperty = propertyWalker.getProperty("deploymentId", WhereClauseParser.EQUALS);
if (deploymentProperty != null) {
query.deploymentId(deploymentProperty);
}
// Property matches
String categoryMatchesProperty = propertyWalker.getProperty("category", WhereClauseParser.MATCHES);
if (categoryMatchesProperty != null) {
query.processDefinitionCategoryLike(categoryMatchesProperty);
}
String keyMatchesProperty = propertyWalker.getProperty("key", WhereClauseParser.MATCHES);
if (keyMatchesProperty != null) {
query.processDefinitionKeyLike(getProcessDefinitionKey(keyMatchesProperty));
keyQueryIncluded = true;
}
String nameLikeProperty = propertyWalker.getProperty("name", WhereClauseParser.MATCHES);
if (nameLikeProperty != null) {
query.processDefinitionNameLike(nameLikeProperty);
}
}
// Filter based on tenant, if required
if (keyQueryIncluded == false && tenantService.isEnabled() && deployWorkflowsInTenant) {
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
}
List<SortColumn> sortList = parameters.getSorting();
SortColumn sortColumn = null;
if (sortList != null && sortList.size() > 0) {
if (sortList.size() != 1) {
throw new InvalidArgumentException("Only one orderBy parameter is supported");
}
sortColumn = sortList.get(0);
switch(sortColumn.column) {
case "id":
query.orderByProcessDefinitionId();
break;
case "deploymentId":
query.orderByDeploymentId();
break;
case "key":
query.orderByProcessDefinitionKey();
break;
case "category":
query.orderByProcessDefinitionCategory();
break;
case "version":
query.orderByProcessDefinitionVersion();
break;
case "name":
query.orderByProcessDefinitionName();
break;
default:
throw new InvalidArgumentException("OrderBy " + sortColumn.column + " is not supported, supported items are " + PROCESS_DEFINITION_COLLECTION_SORT_PROPERTIES);
}
if (sortColumn.asc) {
query.asc();
} else {
query.desc();
}
} else {
query.orderByProcessDefinitionId().asc();
}
List<org.activiti.engine.repository.ProcessDefinition> processDefinitions = query.listPage(parameters.getPaging().getSkipCount(), parameters.getPaging().getMaxItems());
int totalCount = (int) query.count();
List<ProcessDefinition> page = new ArrayList<ProcessDefinition>(processDefinitions.size());
for (org.activiti.engine.repository.ProcessDefinition processDefinition : processDefinitions) {
page.add(createProcessDefinitionRest((ProcessDefinitionEntity) processDefinition));
}
return CollectionWithPagingInfo.asPaged(parameters.getPaging(), page, (page.size() + parameters.getPaging().getSkipCount()) < totalCount, totalCount);
}
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 deleteCustomAspect.
@Override
public void deleteCustomAspect(String modelName, String aspectName) {
// Check the current user is authorised to delete the custom model's aspect
validateCurrentUser();
if (aspectName == null) {
throw new InvalidArgumentException(ASPECT_NAME_NULL_ERR);
}
ModelDetails existingModelDetails = new ModelDetails(getCustomModelImpl(modelName));
if (existingModelDetails.isActive()) {
throw new ConstraintViolatedException("cmm.rest_api.aspect_cannot_delete");
}
Map<String, CustomAspect> allAspects = transformToMap(existingModelDetails.getAspects(), toNameFunction());
CustomAspect aspectToBeDeleted = allAspects.get(aspectName);
if (aspectToBeDeleted == null) {
throw new EntityNotFoundException(aspectName);
}
// Validate aspect's dependency
validateTypeAspectDelete(allAspects.values(), aspectToBeDeleted.getPrefixedName());
// Remove the validated aspect
allAspects.remove(aspectName);
existingModelDetails.setAspects(new ArrayList<>(allAspects.values()));
updateModel(existingModelDetails, "cmm.rest_api.aspect_delete_failure");
}
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());
}
}
}
Aggregations