use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class NodesImpl method getContent.
@Override
public BinaryResource getContent(NodeRef nodeRef, Parameters parameters, boolean recordActivity) {
if (!nodeMatches(nodeRef, Collections.singleton(ContentModel.TYPE_CONTENT), null, false)) {
throw new InvalidArgumentException("NodeId of content is expected: " + nodeRef.getId());
}
Map<QName, Serializable> nodeProps = nodeService.getProperties(nodeRef);
ContentData cd = (ContentData) nodeProps.get(ContentModel.PROP_CONTENT);
String name = (String) nodeProps.get(ContentModel.PROP_NAME);
org.alfresco.rest.framework.resource.content.ContentInfo ci = null;
String mimeType = null;
if (cd != null) {
mimeType = cd.getMimetype();
ci = new org.alfresco.rest.framework.resource.content.ContentInfoImpl(mimeType, cd.getEncoding(), cd.getSize(), cd.getLocale());
}
// By default set attachment header (with filename) unless attachment=false *and* content type is pre-configured as non-attach
boolean attach = true;
String attachment = parameters.getParameter("attachment");
if (attachment != null) {
Boolean a = Boolean.valueOf(attachment);
if (!a) {
if (nonAttachContentTypes.contains(mimeType)) {
attach = false;
} else {
logger.warn("Ignored attachment=false for " + nodeRef.getId() + " since " + mimeType + " is not in the whitelist for non-attach content types");
}
}
}
String attachFileName = (attach ? name : null);
if (recordActivity) {
final ActivityInfo activityInfo = getActivityInfo(getParentNodeRef(nodeRef), nodeRef);
postActivity(Activity_Type.DOWNLOADED, activityInfo, true);
}
return new NodeBinaryResource(nodeRef, ContentModel.PROP_CONTENT, ci, attachFileName);
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class NodesImpl method mapToNodeAspects.
public Set<QName> mapToNodeAspects(List<String> aspectNames) {
Set<QName> nodeAspects = new HashSet<>(aspectNames.size());
for (String aspectName : aspectNames) {
QName aspectQName = createQName(aspectName);
AspectDefinition ad = dictionaryService.getAspect(aspectQName);
if (ad != null) {
nodeAspects.add(aspectQName);
} else {
throw new InvalidArgumentException("Unknown aspect: " + aspectName);
}
}
return nodeAspects;
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class NodesImpl method mapToNodeProperties.
public Map<QName, Serializable> mapToNodeProperties(Map<String, Object> props) {
Map<QName, Serializable> nodeProps = new HashMap<>(props.size());
for (Entry<String, Object> entry : props.entrySet()) {
String propName = entry.getKey();
QName propQName = createQName(propName);
PropertyDefinition pd = dictionaryService.getProperty(propQName);
if (pd != null) {
Serializable value = null;
if (entry.getValue() != null) {
if (pd.getDataType().getName().equals(DataTypeDefinition.NODE_REF)) {
String nodeRefString = (String) entry.getValue();
if (!NodeRef.isNodeRef(nodeRefString)) {
value = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeRefString);
} else {
value = new NodeRef(nodeRefString);
}
} else {
value = (Serializable) entry.getValue();
}
}
nodeProps.put(propQName, value);
} else {
throw new InvalidArgumentException("Unknown property: " + propName);
}
}
return nodeProps;
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class NodesImpl method getDocument.
/**
* @deprecated note: currently required for backwards compat' (Favourites API)
*/
@Override
public Document getDocument(NodeRef nodeRef) {
Type type = getType(nodeRef);
if ((type != null) && type.equals(Type.DOCUMENT)) {
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
Document doc = new Document(nodeRef, getParentNodeRef(nodeRef), properties, null, sr);
doc.setVersionLabel((String) properties.get(ContentModel.PROP_VERSION_LABEL));
ContentData cd = (ContentData) properties.get(ContentModel.PROP_CONTENT);
if (cd != null) {
doc.setSizeInBytes(BigInteger.valueOf(cd.getSize()));
doc.setMimeType((cd.getMimetype()));
}
setCommonProps(doc, nodeRef, properties);
return doc;
} else {
throw new InvalidArgumentException("Node is not a file: " + nodeRef.getId());
}
}
use of org.alfresco.rest.framework.core.exceptions.InvalidArgumentException in project alfresco-remote-api by Alfresco.
the class NodesImpl method moveOrCopyNode.
@Override
public Node moveOrCopyNode(String sourceNodeId, String targetParentId, String name, Parameters parameters, boolean isCopy) {
if ((sourceNodeId == null) || (sourceNodeId.isEmpty())) {
throw new InvalidArgumentException("Missing sourceNodeId");
}
if ((targetParentId == null) || (targetParentId.isEmpty())) {
throw new InvalidArgumentException("Missing targetParentId");
}
final NodeRef parentNodeRef = validateOrLookupNode(targetParentId, null);
final NodeRef sourceNodeRef = validateOrLookupNode(sourceNodeId, null);
FileInfo fi = moveOrCopyImpl(sourceNodeRef, parentNodeRef, name, isCopy);
return getFolderOrDocument(fi.getNodeRef().getId(), parameters);
}
Aggregations