use of org.alfresco.rest.api.model.NodeDefinition in project alfresco-remote-api by Alfresco.
the class NodeDefinitionMapperImpl method fromTypeDefinition.
@Override
public NodeDefinition fromTypeDefinition(TypeDefinition typeDefinition, MessageLookup messageLookup) {
if (typeDefinition == null) {
throw new AlfrescoRuntimeException("Undefined definition for the node");
}
NodeDefinition nodeDefinition = new NodeDefinition();
nodeDefinition.setProperties(getProperties(typeDefinition.getProperties(), messageLookup));
return nodeDefinition;
}
use of org.alfresco.rest.api.model.NodeDefinition in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testRetrieveNodeDefinition.
@Test
public void testRetrieveNodeDefinition() throws Exception {
setRequestContext(networkOne.getId(), user1, null);
String node1 = "nodeSample" + RUNID + "_1";
String node1Type = TYPE_CM_CONTENT;
Map<String, Object> props = new HashMap<>();
props.put("cm:title", "add aspect property");
Node node = createNode(Nodes.PATH_MY, node1, node1Type, props);
String nodeId = node.getId();
HttpResponse response = getSingle(NodesEntityResource.class, nodeId, null, 200);
Node nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
assertNull("Definition should not be retrieved unless included!", nodeResp.getDefinition());
Map params = new HashMap<>();
params.put("include", "definition");
response = getSingle(NodesEntityResource.class, nodeId, params, 200);
nodeResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
NodeDefinition nodeDefinition = nodeResp.getDefinition();
assertNotNull(nodeDefinition);
checkDefinitionProperties(nodeDefinition.getProperties());
}
use of org.alfresco.rest.api.model.NodeDefinition in project alfresco-remote-api by Alfresco.
the class NodesImpl method getFolderOrDocument.
@Override
public Node getFolderOrDocument(final NodeRef nodeRef, NodeRef parentNodeRef, QName nodeTypeQName, List<String> includeParam, Map<String, UserInfo> mapUserInfo) {
if (mapUserInfo == null) {
mapUserInfo = new HashMap<>(2);
}
if (includeParam == null) {
includeParam = Collections.emptyList();
}
Node node;
Map<QName, Serializable> properties = nodeService.getProperties(nodeRef);
PathInfo pathInfo = null;
if (includeParam.contains(PARAM_INCLUDE_PATH)) {
ChildAssociationRef archivedParentAssoc = (ChildAssociationRef) properties.get(ContentModel.PROP_ARCHIVED_ORIGINAL_PARENT_ASSOC);
pathInfo = lookupPathInfo(nodeRef, archivedParentAssoc);
}
if (nodeTypeQName == null) {
nodeTypeQName = getNodeType(nodeRef);
}
if (parentNodeRef == null) {
parentNodeRef = getParentNodeRef(nodeRef);
}
Type type = getType(nodeTypeQName, nodeRef);
if (type == null) {
// not direct folder (or file) ...
// might be sub-type of cm:cmobject (or a cm:link pointing to cm:cmobject or possibly even another cm:link)
node = new Node(nodeRef, parentNodeRef, properties, mapUserInfo, sr);
node.setIsFolder(false);
node.setIsFile(false);
} else if (type.equals(Type.DOCUMENT)) {
node = new Document(nodeRef, parentNodeRef, properties, mapUserInfo, sr);
} else if (type.equals(Type.FOLDER)) {
node = new Folder(nodeRef, parentNodeRef, properties, mapUserInfo, sr);
} else {
throw new RuntimeException("Unexpected - should not reach here: " + type);
}
if (includeParam.size() > 0) {
node.setProperties(mapFromNodeProperties(properties, includeParam, mapUserInfo, EXCLUDED_NS, EXCLUDED_PROPS));
}
Set<QName> aspects = null;
if (includeParam.contains(PARAM_INCLUDE_ASPECTNAMES)) {
aspects = nodeService.getAspects(nodeRef);
node.setAspectNames(mapFromNodeAspects(aspects, EXCLUDED_NS, EXCLUDED_ASPECTS));
}
if (includeParam.contains(PARAM_INCLUDE_ISLINK)) {
boolean isLink = isSubClass(nodeTypeQName, ContentModel.TYPE_LINK);
node.setIsLink(isLink);
}
if (includeParam.contains(PARAM_INCLUDE_ISLOCKED)) {
boolean isLocked = isLocked(nodeRef, aspects);
node.setIsLocked(isLocked);
}
if (includeParam.contains(PARAM_INCLUDE_ISFAVORITE)) {
boolean isFavorite = isFavorite(nodeRef);
node.setIsFavorite(isFavorite);
}
if (includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS)) {
// note: refactor when requirements change
Map<String, String> mapPermsToOps = new HashMap<>(3);
mapPermsToOps.put(PermissionService.DELETE, OP_DELETE);
mapPermsToOps.put(PermissionService.ADD_CHILDREN, OP_CREATE);
mapPermsToOps.put(PermissionService.WRITE, OP_UPDATE);
mapPermsToOps.put(PermissionService.CHANGE_PERMISSIONS, OP_UPDATE_PERMISSIONS);
List<String> allowableOperations = new ArrayList<>(3);
for (Entry<String, String> kv : mapPermsToOps.entrySet()) {
String perm = kv.getKey();
String op = kv.getValue();
if (perm.equals(PermissionService.ADD_CHILDREN) && Type.DOCUMENT.equals(type)) {
// special case: do not return "create" (as an allowable op) for file/content types - note: 'type' can be null
continue;
} else if (perm.equals(PermissionService.DELETE) && (isSpecialNode(nodeRef, nodeTypeQName))) {
// special case: do not return "delete" (as an allowable op) for specific system nodes
continue;
} else if (permissionService.hasPermission(nodeRef, perm) == AccessStatus.ALLOWED) {
allowableOperations.add(op);
}
}
node.setAllowableOperations((allowableOperations.size() > 0) ? allowableOperations : null);
}
if (includeParam.contains(PARAM_INCLUDE_PERMISSIONS)) {
Boolean inherit = permissionService.getInheritParentPermissions(nodeRef);
List<NodePermissions.NodePermission> inheritedPerms = new ArrayList<>(5);
List<NodePermissions.NodePermission> setDirectlyPerms = new ArrayList<>(5);
Set<String> settablePerms = null;
boolean allowRetrievePermission = true;
try {
for (AccessPermission accessPerm : permissionService.getAllSetPermissions(nodeRef)) {
NodePermissions.NodePermission nodePerm = new NodePermissions.NodePermission(accessPerm.getAuthority(), accessPerm.getPermission(), accessPerm.getAccessStatus().toString());
if (accessPerm.isSetDirectly()) {
setDirectlyPerms.add(nodePerm);
} else {
inheritedPerms.add(nodePerm);
}
}
settablePerms = permissionService.getSettablePermissions(nodeRef);
} catch (AccessDeniedException ade) {
// ignore - ie. denied access to retrieve permissions, eg. non-admin on root (Company Home)
allowRetrievePermission = false;
}
// returned only node info that he's allowed to see
if (allowRetrievePermission) {
NodePermissions nodePerms = new NodePermissions(inherit, inheritedPerms, setDirectlyPerms, settablePerms);
node.setPermissions(nodePerms);
}
}
if (includeParam.contains(PARAM_INCLUDE_ASSOCIATION)) {
// Ugh ... can we optimise this and return the actual assoc directly (via FileFolderService/GetChildrenCQ) ?
ChildAssociationRef parentAssocRef = nodeService.getPrimaryParent(nodeRef);
// note: parentAssocRef.parentRef can be null for -root- node !
if ((parentAssocRef == null) || (parentAssocRef.getParentRef() == null) || (!parentAssocRef.getParentRef().equals(parentNodeRef))) {
List<ChildAssociationRef> parentAssocRefs = nodeService.getParentAssocs(nodeRef);
for (ChildAssociationRef pAssocRef : parentAssocRefs) {
if (pAssocRef.getParentRef().equals(parentNodeRef)) {
// for now, assume same parent/child cannot appear more than once (due to unique name)
parentAssocRef = pAssocRef;
break;
}
}
}
if (parentAssocRef != null) {
QName assocTypeQName = parentAssocRef.getTypeQName();
if ((assocTypeQName != null) && (!EXCLUDED_NS.contains(assocTypeQName.getNamespaceURI()))) {
AssocChild childAssoc = new AssocChild(assocTypeQName.toPrefixString(namespaceService), parentAssocRef.isPrimary());
node.setAssociation(childAssoc);
}
}
}
if (includeParam.contains(PARAM_INCLUDE_DEFINITION)) {
NodeDefinition nodeDefinition = nodeDefinitionMapper.fromTypeDefinition(getTypeDefinition(nodeRef), dictionaryService);
node.setDefinition(nodeDefinition);
}
node.setNodeType(nodeTypeQName.toPrefixString(namespaceService));
node.setPath(pathInfo);
return node;
}
Aggregations