use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class NodesImpl method getFolder.
/**
* @deprecated note: currently required for backwards compat' (Favourites API)
*/
@Override
public Folder getFolder(NodeRef nodeRef) {
Type type = getType(nodeRef);
if ((type != null) && type.equals(Type.FOLDER)) {
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
Folder folder = new Folder(nodeRef, getParentNodeRef(nodeRef), properties, null, sr);
setCommonProps(folder, nodeRef, properties);
return folder;
} else {
throw new InvalidArgumentException("Node is not a folder: " + nodeRef.getId());
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class NodesImpl method addChildren.
public List<AssocChild> addChildren(String parentNodeId, List<AssocChild> entities) {
NodeRef parentNodeRef = validateNode(parentNodeId);
List<AssocChild> result = new ArrayList<>(entities.size());
for (AssocChild assoc : entities) {
String childId = assoc.getChildId();
if (childId == null) {
throw new InvalidArgumentException("Missing childId");
}
QName assocTypeQName = getAssocType(assoc.getAssocType());
try {
NodeRef childNodeRef = validateNode(childId);
String nodeName = (String) nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
QName assocChildQName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, QName.createValidLocalName(nodeName));
nodeService.addChild(parentNodeRef, childNodeRef, assocTypeQName, assocChildQName);
} catch (AssociationExistsException aee) {
throw new ConstraintViolatedException(aee.getMessage());
} catch (DuplicateChildNodeNameException dcne) {
throw new ConstraintViolatedException(dcne.getMessage());
}
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 buildSearchTypesAndIgnoreAspects.
protected Pair<Set<QName>, Set<QName>> buildSearchTypesAndIgnoreAspects(final Parameters parameters) {
// filters
Boolean includeFolders = null;
Boolean includeFiles = null;
QName filterNodeTypeQName = null;
// note: for files/folders, include subtypes by default (unless filtering by a specific nodeType - see below)
boolean filterIncludeSubTypes = true;
Query q = parameters.getQuery();
if (q != null) {
// filtering via "where" clause
MapBasedQueryWalker propertyWalker = createListChildrenQueryWalker();
QueryHelper.walk(q, propertyWalker);
Boolean isFolder = propertyWalker.getProperty(PARAM_ISFOLDER, WhereClauseParser.EQUALS, Boolean.class);
Boolean isFile = propertyWalker.getProperty(PARAM_ISFILE, WhereClauseParser.EQUALS, Boolean.class);
if (isFolder != null) {
includeFolders = isFolder;
}
if (isFile != null) {
includeFiles = isFile;
}
if (Boolean.TRUE.equals(includeFiles) && Boolean.TRUE.equals(includeFolders)) {
throw new InvalidArgumentException("Invalid filter (isFile=true and isFolder=true) - a node cannot be both a file and a folder");
}
String nodeTypeStr = propertyWalker.getProperty(PARAM_NODETYPE, WhereClauseParser.EQUALS, String.class);
if ((nodeTypeStr != null) && (!nodeTypeStr.isEmpty())) {
if ((isFile != null) || (isFolder != null)) {
throw new InvalidArgumentException("Invalid filter - nodeType and isFile/isFolder are mutually exclusive");
}
Pair<QName, Boolean> pair = parseNodeTypeFilter(nodeTypeStr);
filterNodeTypeQName = pair.getFirst();
filterIncludeSubTypes = pair.getSecond();
}
}
if (filterNodeTypeQName == null) {
if ((includeFiles == null) && (includeFolders == null)) {
// no additional filtering
filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
} else if ((includeFiles != null) && (includeFolders != null)) {
if ((!includeFiles) && (!includeFolders)) {
// no files or folders
filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
}
} else if ((includeFiles != null) && (!includeFiles)) {
// no files
filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
} else if ((includeFolders != null) && (!includeFolders)) {
// no folders
filterNodeTypeQName = ContentModel.TYPE_CMOBJECT;
}
}
return buildSearchTypesAndIgnoreAspects(filterNodeTypeQName, filterIncludeSubTypes, ignoreQNames, includeFiles, includeFolders);
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class QuickShareLinksImpl method create.
/**
* Create quick share.
* <p>
* Requires authenticated access.
*
* @param nodeIds
* @param parameters
* @return
*/
public List<QuickShareLink> create(List<QuickShareLink> nodeIds, Parameters parameters) {
checkEnabled();
List<QuickShareLink> result = new ArrayList<>(nodeIds.size());
List<String> includeParam = parameters != null ? parameters.getInclude() : Collections.<String>emptyList();
for (QuickShareLink qs : nodeIds) {
String nodeId = qs.getNodeId();
if (nodeId == null) {
throw new InvalidArgumentException("A valid nodeId must be specified !");
}
NodeRef nodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeId);
try {
// Note: will throw InvalidNodeRefException (=> 404) if node does not exist
String sharedId = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
if (sharedId != null) {
throw new ConstraintViolatedException("sharedId already exists: " + nodeId + " [" + sharedId + "]");
}
// Note: since we already check node exists above, we can assume that InvalidNodeRefException (=> 404) here means not content (see type check)
try {
QuickShareDTO qsDto = quickShareService.shareContent(nodeRef, qs.getExpiresAt());
result.add(getQuickShareInfo(qsDto.getId(), false, includeParam));
} catch (InvalidNodeRefException inre) {
throw new InvalidArgumentException("Unable to create shared link to non-file content: " + nodeId);
} catch (QuickShareLinkExpiryActionException ex) {
throw new InvalidArgumentException(ex.getMessage());
}
} catch (AccessDeniedException ade) {
throw new PermissionDeniedException("Unable to create shared link to node that does not exist: " + nodeId);
} catch (InvalidNodeRefException inre) {
logger.warn("Unable to create shared link: [" + nodeRef + "]");
throw new EntityNotFoundException(nodeId);
}
}
return result;
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class RenditionsImpl method getRenditionByName.
protected NodeRef getRenditionByName(NodeRef nodeRef, String renditionId, Parameters parameters) {
if (nodeRef == null) {
return null;
}
if (StringUtils.isEmpty(renditionId)) {
throw new InvalidArgumentException("renditionId can't be null or empty.");
}
// Thumbnails have a cm: prefix.
QName renditionQName = QName.resolveToQName(namespaceService, renditionId);
ChildAssociationRef nodeRefRendition = renditionService.getRenditionByName(nodeRef, renditionQName);
if (nodeRefRendition == null) {
return null;
}
return tenantService.getName(nodeRef, nodeRefRendition.getChildRef());
}
Aggregations