use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class GroupsImpl 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;
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class NodesImpl method addTargets.
public List<AssocTarget> addTargets(String sourceNodeId, List<AssocTarget> entities) {
List<AssocTarget> result = new ArrayList<>(entities.size());
NodeRef srcNodeRef = validateNode(sourceNodeId);
for (AssocTarget assoc : entities) {
String targetNodeId = assoc.getTargetId();
if (targetNodeId == null) {
throw new InvalidArgumentException("Missing targetId");
}
String assocTypeStr = assoc.getAssocType();
QName assocTypeQName = getAssocType(assocTypeStr);
try {
NodeRef tgtNodeRef = validateNode(targetNodeId);
nodeAssocService.createAssociation(srcNodeRef, tgtNodeRef, assocTypeQName);
} catch (AssociationExistsException aee) {
throw new ConstraintViolatedException("Node association '" + assocTypeStr + "' already exists from " + sourceNodeId + " to " + targetNodeId);
} catch (IllegalArgumentException iae) {
// note: for now, we assume it is invalid assocType - alternatively, we could attempt to pre-validate via dictionary.getAssociation
throw new InvalidArgumentException(sourceNodeId + "," + assocTypeStr + "," + targetNodeId);
}
result.add(assoc);
}
return result;
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class NodesImpl method updateContent.
@Override
public Node updateContent(String fileNodeId, BasicContentInfo contentInfo, InputStream stream, Parameters parameters) {
if (contentInfo.getMimeType().toLowerCase().startsWith("multipart")) {
throw new UnsupportedMediaTypeException("Cannot update using " + contentInfo.getMimeType());
}
final NodeRef nodeRef = validateNode(fileNodeId);
if (!nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false)) {
throw new InvalidArgumentException("NodeId of content is expected: " + nodeRef.getId());
}
Boolean versionMajor = null;
String str = parameters.getParameter(PARAM_VERSION_MAJOR);
if (str != null) {
versionMajor = Boolean.valueOf(str);
}
String versionComment = parameters.getParameter(PARAM_VERSION_COMMENT);
String fileName = parameters.getParameter(PARAM_NAME);
if (fileName != null) {
// optionally rename, before updating the content
nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, fileName);
} else {
fileName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
}
return updateExistingFile(null, nodeRef, fileName, contentInfo, stream, parameters, versionMajor, versionComment);
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class NodesImpl method parseNodeTypeFilter.
private Pair<QName, Boolean> parseNodeTypeFilter(String nodeTypeStr) {
// default nodeType filtering is without subTypes (unless nodeType value is suffixed with ' INCLUDESUBTYPES')
boolean filterIncludeSubTypes = false;
int idx = nodeTypeStr.lastIndexOf(' ');
if (idx > 0) {
String suffix = nodeTypeStr.substring(idx);
if (suffix.equalsIgnoreCase(" " + PARAM_INCLUDE_SUBTYPES)) {
filterIncludeSubTypes = true;
nodeTypeStr = nodeTypeStr.substring(0, idx);
}
}
QName filterNodeTypeQName = createQName(nodeTypeStr);
if (dictionaryService.getType(filterNodeTypeQName) == null) {
throw new InvalidArgumentException("Unknown filter nodeType: " + nodeTypeStr);
}
return new Pair<>(filterNodeTypeQName, filterIncludeSubTypes);
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class NodesImpl method requestRenditions.
private void requestRenditions(List<ThumbnailDefinition> thumbnailDefs, Node fileNode) {
if (thumbnailDefs != null) {
ThumbnailRegistry registry = thumbnailService.getThumbnailRegistry();
for (ThumbnailDefinition thumbnailDef : thumbnailDefs) {
NodeRef sourceNodeRef = fileNode.getNodeRef();
String mimeType = fileNode.getContent().getMimeType();
long size = fileNode.getContent().getSizeInBytes();
// Check if anything is currently available to generate thumbnails for the specified mimeType
if (!registry.isThumbnailDefinitionAvailable(null, mimeType, size, sourceNodeRef, thumbnailDef)) {
throw new InvalidArgumentException("Unable to create thumbnail '" + thumbnailDef.getName() + "' for " + mimeType + " as no transformer is currently available.");
}
Action action = ThumbnailHelper.createCreateThumbnailAction(thumbnailDef, sr);
// Queue async creation of thumbnail
actionService.executeAction(action, sourceNodeRef, true, true);
}
}
}
Aggregations