use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class WorkflowRestImpl method createItemInProcess.
/**
* Create a new item in the process package variable
*/
public Item createItemInProcess(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");
}
// check if noderef exists
try {
nodeService.getProperties(nodeRef);
} catch (Exception e) {
throw new EntityNotFoundException("item with id " + nodeRef.toString() + " not found");
}
try {
QName workflowPackageItemId = QName.createQName("wpi", nodeRef.toString());
nodeService.addChild(packageScriptNode.getNodeRef(), nodeRef, WorkflowModel.ASSOC_PACKAGE_CONTAINS, workflowPackageItemId);
} catch (Exception e) {
throw new ApiException("could not add item to process " + e.getMessage(), e);
}
Item responseItem = createItemForNodeRef(nodeRef);
activitiWorkflowEngine.dispatchPackageUpdatedEvent(packageScriptNode, null, null, processId, null);
return responseItem;
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class WorkflowRestImpl method getParameter.
/**
* Get the first parameter value, converted to the requested type.
* @param parameters used to extract parameter value from
* @param parameterName name of the parameter
* @param returnType type of object to return
* @return the converted parameter value. Null, if the parameter 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
*/
@SuppressWarnings("unchecked")
public <T extends Object> T getParameter(Parameters parameters, String parameterName, Class<T> returnType) {
if (returnType == null) {
throw new IllegalArgumentException("ReturnType cannot be null");
}
try {
Object result = null;
String stringValue = parameters.getParameter(parameterName);
if (stringValue != null) {
result = ConvertUtils.convert(stringValue, returnType);
if (result instanceof String) {
// If a string is returned, no converter has been found
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("Parameter value for '" + parameterName + "' should be a valid " + returnType.getSimpleName());
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CommentsImpl method deleteComment.
@Override
public void deleteComment(String nodeId, String commentNodeId) {
try {
NodeRef nodeRef = nodes.validateNode(nodeId);
NodeRef commentNodeRef = nodes.validateNode(commentNodeId);
if (!nodeRef.equals(commentService.getDiscussableAncestor(commentNodeRef))) {
throw new InvalidArgumentException("Unexpected " + nodeId + "," + commentNodeId);
}
commentService.deleteComment(commentNodeRef);
} catch (IllegalArgumentException e) {
throw new ConstraintViolatedException(e.getMessage());
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class ActivitiesImpl method getUserActivities.
public CollectionWithPagingInfo<Activity> getUserActivities(String personId, final Parameters parameters) {
personId = people.validatePerson(personId);
Paging paging = parameters.getPaging();
String siteId = parameters.getParameter("siteId");
String who = parameters.getParameter("who");
ActivityWho activityWho = null;
if (who != null) {
try {
activityWho = ActivityWho.valueOf(who);
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException("Parameter who should be one of " + Arrays.toString(ActivityWho.values()));
}
}
if (siteId != null && !siteId.equals("")) {
SiteInfo siteInfo = sites.validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new EntityNotFoundException(siteId);
}
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
siteId = siteInfo.getShortName();
}
try {
PagingResults<ActivityFeedEntity> activities = null;
if (activityWho == null) {
activities = activityService.getPagedUserFeedEntries(personId, siteId, false, false, -1, Util.getPagingRequest(paging));
} else if (activityWho.equals(ActivityWho.me)) {
activities = activityService.getPagedUserFeedEntries(personId, siteId, false, true, -1, Util.getPagingRequest(paging));
} else if (activityWho.equals(ActivityWho.others)) {
activities = activityService.getPagedUserFeedEntries(personId, siteId, true, false, -1, Util.getPagingRequest(paging));
} else {
throw new InvalidArgumentException("Who argument is invalid.");
}
List<ActivityFeedEntity> feedEntities = activities.getPage();
List<Activity> ret = new ArrayList<Activity>(feedEntities.size());
for (ActivityFeedEntity entity : feedEntities) {
String feedSiteId = getSiteId(entity.getSiteNetwork());
String networkId = tenantService.getDomain(entity.getSiteNetwork());
Activity activity = new Activity(entity.getId(), networkId, feedSiteId, entity.getFeedUserId(), entity.getPostUserId(), entity.getPostDate(), entity.getActivityType(), getActivitySummary(entity));
ret.add(activity);
}
return CollectionWithPagingInfo.asPaged(paging, ret, activities.hasMoreItems(), activities.getTotalResultCount().getFirst());
} catch (JSONException e) {
throw new AlfrescoRuntimeException("", e);
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class GroupsFilter method getGroupsSortProp.
private Pair<String, Boolean> getGroupsSortProp(Parameters parameters) {
Pair<String, Boolean> sortProp;
List<SortColumn> sortCols = parameters.getSorting();
if ((sortCols != null) && (sortCols.size() > 0)) {
if (sortCols.size() > 1) {
throw new InvalidArgumentException("Multiple sort fields not allowed.");
}
SortColumn sortCol = sortCols.get(0);
String sortPropName = SORT_PARAMS_TO_NAMES.get(sortCol.column);
if (sortPropName == null) {
throw new InvalidArgumentException("Invalid sort field: " + sortCol.column);
}
sortProp = new Pair<>(sortPropName, (sortCol.asc ? Boolean.TRUE : Boolean.FALSE));
} else {
sortProp = getGroupsSortPropDefault();
}
return sortProp;
}
Aggregations