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);
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class CommentsImpl method updateComment.
public Comment updateComment(String nodeId, Comment comment) {
try {
NodeRef nodeRef = nodes.validateNode(nodeId);
String commentNodeId = comment.getId();
NodeRef commentNodeRef = nodes.validateNode(commentNodeId);
String title = comment.getTitle();
String content = comment.getContent();
if (content == null) {
throw new InvalidArgumentException();
}
commentService.updateComment(commentNodeRef, title, content);
return toComment(nodeRef, commentNodeRef, INCLUDE_FULL_PERSON);
} 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 CommentsImpl method getComments.
public CollectionWithPagingInfo<Comment> getComments(String nodeId, Paging paging, List<String> include) {
final NodeRef nodeRef = nodes.validateNode(nodeId);
/* MNT-10536 : fix */
final Set<QName> contentAndFolders = new HashSet<>(Arrays.asList(ContentModel.TYPE_FOLDER, ContentModel.TYPE_CONTENT));
if (!nodes.nodeMatches(nodeRef, contentAndFolders, null)) {
throw new InvalidArgumentException("NodeId of folder or content is expected");
}
PagingRequest pagingRequest = Util.getPagingRequest(paging);
final PagingResults<NodeRef> pagingResults = commentService.listComments(nodeRef, pagingRequest);
final List<NodeRef> page = pagingResults.getPage();
List<Comment> comments = new AbstractList<>() {
@Override
public Comment get(int index) {
return toComment(nodeRef, page.get(index), include);
}
@Override
public int size() {
return page.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, comments, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst());
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class RecognizedParamsExtractor method getSort.
/**
* Takes the Sort parameter as a String and parses it into a List of SortColumn objects.
* The format is a comma seperated list of "columnName sortDirection",
* e.g. "name DESC, age ASC". It is not case sensitive and the sort direction is optional
* It default to sort ASCENDING.
*
* @param sortParams - String passed in on the request
* @return - the sort columns or an empty list if the params were invalid.
*/
default List<SortColumn> getSort(String sortParams) {
if (sortParams != null) {
StringTokenizer st = new StringTokenizer(sortParams, ",");
List<SortColumn> sortedColumns = new ArrayList<SortColumn>(st.countTokens());
while (st.hasMoreTokens()) {
String token = st.nextToken();
StringTokenizer columnDesc = new StringTokenizer(token, " ");
if (columnDesc.countTokens() <= 2) {
String columnName = columnDesc.nextToken();
String sortOrder = SortColumn.ASCENDING;
if (columnDesc.hasMoreTokens()) {
String sortDef = columnDesc.nextToken().toUpperCase();
if (SortColumn.ASCENDING.equals(sortDef) || SortColumn.DESCENDING.equals(sortDef)) {
sortOrder = sortDef;
} else {
rpeLogger().debug("Invalid sort order direction (" + sortDef + "). Valid values are " + SortColumn.ASCENDING + " or " + SortColumn.DESCENDING + ".");
throw new InvalidArgumentException("Unknown sort order direction '" + sortDef + "', expected asc or desc");
}
}
sortedColumns.add(new SortColumn(columnName, SortColumn.ASCENDING.equals(sortOrder)));
} else {
rpeLogger().debug("Invalid sort order definition (" + token + ")");
throw new InvalidArgumentException("Unknown sort order definition '" + token + "', expected 'field1,field2' or 'field1 asc,field2 desc' or similar");
}
// filteredProperties.add();
}
// BeanPropertiesFilter filter = new BeanPropertiesFilter(filteredProperties);
return sortedColumns;
}
return Collections.emptyList();
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class ResourceWebScriptPost method extractObjFromJson.
/**
* If the @WebApiParam has been used and set allowMultiple to false then this will get a single entry. It
* should error if an array is passed in.
* @param resourceMeta ResourceMetadata
* @param req WebScriptRequest
* @return Either an object
*/
private Object extractObjFromJson(ResourceMetadata resourceMeta, ResourceOperation operation, WebScriptRequest req) {
if (operation == null) {
return null;
}
Class<?> objType = resourceMeta.getObjectType(operation);
boolean isTypeOperation = resourceMeta.getType().equals(ResourceMetadata.RESOURCE_TYPE.OPERATION);
List<ResourceParameter> params = operation.getParameters();
if (!params.isEmpty()) {
for (ResourceParameter resourceParameter : params) {
// POST to collection may or may not support List as json body, Operations don't support a List as json body
boolean notMultiple = ((!resourceParameter.isAllowMultiple()) || isTypeOperation);
if (ResourceParameter.KIND.HTTP_BODY_OBJECT.equals(resourceParameter.getParamType()) && notMultiple) {
// Only allow 1 value.
try {
Object jsonContent = null;
if (objType != null) {
// check if the body is optional and is not provided
if (!resourceParameter.isRequired() && Integer.valueOf(req.getHeader("content-length")) <= 0) {
// in some cases the body is optional and the json doesn't need to be extracted
return null;
} else {
jsonContent = extractJsonContent(req, assistant.getJsonHelper(), objType);
}
}
if (isTypeOperation) {
return jsonContent;
} else {
return Arrays.asList(jsonContent);
}
} catch (InvalidArgumentException iae) {
if (iae.getMessage().contains("START_ARRAY") && iae.getMessage().contains("line: 1, column: 1")) {
throw new UnsupportedResourceOperationException("Only 1 entity is supported in the HTTP request body");
} else {
throw iae;
}
}
}
}
}
if (objType == null) {
return null;
}
if (isTypeOperation) {
// Operations don't support a List as json body
return extractJsonContent(req, assistant.getJsonHelper(), objType);
} else {
return extractJsonContentAsList(req, assistant.getJsonHelper(), objType);
}
}
Aggregations