Search in sources :

Example 11 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.

the class DownloadRestApiTest method createNode.

private NodeRef createNode(NodeRef parentNode, String nodeCmName, QName nodeType, String ownerUserName) {
    QName childName = QName.createQName(NamespaceService.APP_MODEL_1_0_URI, nodeCmName);
    Map<QName, Serializable> props = new HashMap<QName, Serializable>();
    props.put(ContentModel.PROP_NAME, nodeCmName);
    ChildAssociationRef childAssoc = nodeService.createNode(parentNode, ContentModel.ASSOC_CONTAINS, childName, nodeType, props);
    return childAssoc.getChildRef();
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 12 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.

the class PeopleImpl method getAvatarOriginal.

private NodeRef getAvatarOriginal(NodeRef personNode) {
    NodeRef avatarOrigNodeRef = null;
    List<ChildAssociationRef> avatarChildAssocs = nodeService.getChildAssocs(personNode, Collections.singleton(ContentModel.ASSOC_PREFERENCE_IMAGE));
    if (avatarChildAssocs.size() > 0) {
        ChildAssociationRef ref = avatarChildAssocs.get(0);
        avatarOrigNodeRef = ref.getChildRef();
    } else {
        // TODO do we still need this ? - backward compatible with JSF web-client avatar
        List<AssociationRef> avatorAssocs = nodeService.getTargetAssocs(personNode, ContentModel.ASSOC_AVATAR);
        if (avatorAssocs.size() > 0) {
            AssociationRef ref = avatorAssocs.get(0);
            avatarOrigNodeRef = ref.getTargetRef();
        }
    }
    return avatarOrigNodeRef;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef)

Example 13 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.

the class RenditionsImpl method getRenditions.

@Override
public CollectionWithPagingInfo<Rendition> getRenditions(NodeRef nodeRef, Parameters parameters) {
    final NodeRef validatedNodeRef = validateNode(nodeRef.getStoreRef(), nodeRef.getId());
    String contentMimeType = getMimeType(validatedNodeRef);
    Query query = parameters.getQuery();
    boolean includeCreated = true;
    boolean includeNotCreated = true;
    String status = getStatus(parameters);
    if (status != null) {
        includeCreated = RenditionStatus.CREATED.equals(RenditionStatus.valueOf(status));
        includeNotCreated = !includeCreated;
    }
    Map<String, Rendition> apiRenditions = new TreeMap<>();
    if (includeNotCreated) {
        // List all available thumbnail definitions
        List<ThumbnailDefinition> thumbnailDefinitions = thumbnailService.getThumbnailRegistry().getThumbnailDefinitions(contentMimeType, -1);
        for (ThumbnailDefinition thumbnailDefinition : thumbnailDefinitions) {
            apiRenditions.put(thumbnailDefinition.getName(), toApiRendition(thumbnailDefinition));
        }
    }
    List<ChildAssociationRef> nodeRefRenditions = renditionService.getRenditions(validatedNodeRef);
    if (!nodeRefRenditions.isEmpty()) {
        for (ChildAssociationRef childAssociationRef : nodeRefRenditions) {
            NodeRef renditionNodeRef = childAssociationRef.getChildRef();
            Rendition apiRendition = toApiRendition(renditionNodeRef);
            if (includeCreated) {
                // Replace/append any thumbnail definitions with created rendition info
                apiRenditions.put(apiRendition.getId(), apiRendition);
            } else {
                // Remove any thumbnail definitions that has been created from the list,
                // as the filter requires only the Not_Created renditions
                apiRenditions.remove(apiRendition.getId());
            }
        }
    }
    // Wrap paging info, as the core service doesn't support paging
    Paging paging = parameters.getPaging();
    PagingResults<Rendition> results = Util.wrapPagingResults(paging, apiRenditions.values());
    return CollectionWithPagingInfo.asPaged(paging, results.getPage(), results.hasMoreItems(), results.getTotalResultCount().getFirst());
}
Also used : Query(org.alfresco.rest.framework.resource.parameters.where.Query) Rendition(org.alfresco.rest.api.model.Rendition) Paging(org.alfresco.rest.framework.resource.parameters.Paging) TreeMap(java.util.TreeMap) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) ThumbnailDefinition(org.alfresco.repo.thumbnail.ThumbnailDefinition)

Example 14 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef 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());
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 15 with ChildAssociationRef

use of org.alfresco.service.cmr.repository.ChildAssociationRef in project alfresco-remote-api by Alfresco.

the class AbstractNodeRelation method listNodeChildAssocs.

protected CollectionWithPagingInfo<Node> listNodeChildAssocs(List<ChildAssociationRef> childAssocRefs, Parameters parameters, Boolean isPrimary, boolean returnChild) {
    Map<QName, String> qnameMap = new HashMap<>(3);
    Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
    List<String> includeParam = parameters.getInclude();
    List<Node> collection = new ArrayList<Node>(childAssocRefs.size());
    for (ChildAssociationRef childAssocRef : childAssocRefs) {
        if (isPrimary == null || (isPrimary == childAssocRef.isPrimary())) {
            // minimal info by default (unless "include"d otherwise)
            NodeRef nodeRef = (returnChild ? childAssocRef.getChildRef() : childAssocRef.getParentRef());
            Node node = nodes.getFolderOrDocument(nodeRef, null, null, includeParam, mapUserInfo);
            QName assocTypeQName = childAssocRef.getTypeQName();
            if (!EXCLUDED_NS.contains(assocTypeQName.getNamespaceURI())) {
                String assocType = qnameMap.get(assocTypeQName);
                if (assocType == null) {
                    assocType = assocTypeQName.toPrefixString(namespaceService);
                    qnameMap.put(assocTypeQName, assocType);
                }
                node.setAssociation(new AssocChild(assocType, childAssocRef.isPrimary()));
                collection.add(node);
            }
        }
    }
    return listPage(collection, parameters.getPaging());
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) Node(org.alfresco.rest.api.model.Node) ArrayList(java.util.ArrayList) AssocChild(org.alfresco.rest.api.model.AssocChild) UserInfo(org.alfresco.rest.api.model.UserInfo) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef)

Aggregations

ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)258 NodeRef (org.alfresco.service.cmr.repository.NodeRef)202 QName (org.alfresco.service.namespace.QName)109 Test (org.junit.Test)56 HashMap (java.util.HashMap)54 BaseUnitTest (org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest)53 ArrayList (java.util.ArrayList)52 Serializable (java.io.Serializable)42 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)25 FacesContext (javax.faces.context.FacesContext)22 Map (java.util.Map)19 UserTransaction (javax.transaction.UserTransaction)18 Node (org.alfresco.web.bean.repository.Node)17 Date (java.util.Date)15 StoreRef (org.alfresco.service.cmr.repository.StoreRef)13 NodeService (org.alfresco.service.cmr.repository.NodeService)12 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)12 List (java.util.List)11 StringPropertyValue (org.alfresco.solr.client.StringPropertyValue)11 IOException (java.io.IOException)10