Search in sources :

Example 41 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.

the class ImapServiceImpl method getUnsubscribedFolders.

private Set<NodeRef> getUnsubscribedFolders(String userName) {
    Set<NodeRef> result = new HashSet<NodeRef>();
    PersonService personService = serviceRegistry.getPersonService();
    NodeRef userRef = null;
    if (personService.personExists(userName)) {
        userRef = personService.getPerson(userName);
    }
    if (userRef != null) {
        List<AssociationRef> unsubscribedFodlers = nodeService.getTargetAssocs(userRef, ImapModel.ASSOC_IMAP_UNSUBSCRIBED);
        for (AssociationRef asocRef : unsubscribedFodlers) {
            result.add(asocRef.getTargetRef());
        }
    }
    return result;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) PersonService(org.alfresco.service.cmr.security.PersonService) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) HashSet(java.util.HashSet)

Example 42 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method getTargetAssocs.

@Override
public List<AssociationRef> getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern) {
    NodeServiceTrait theTrait = getTrait();
    List<AssociationRef> targetAssocs = null;
    Reference reference = Reference.fromNodeRef(sourceRef);
    if (reference != null) {
        if (smartStore.canMaterialize(reference)) {
            NodeRef materializedReferece = smartStore.materialize(reference);
            targetAssocs = theTrait.getTargetAssocs(materializedReferece, qnamePattern);
        } else {
            targetAssocs = new LinkedList<>();
        }
    } else {
        targetAssocs = theTrait.getTargetAssocs(sourceRef, qnamePattern);
    }
    List<AssociationRef> virtualizedIfNeededTargetAssocs = null;
    Reference sourceReference = Reference.fromNodeRef(sourceRef);
    if (sourceReference != null) {
        virtualizedIfNeededTargetAssocs = new LinkedList<>();
        for (AssociationRef associationRef : targetAssocs) {
            NodeRef targetNodeRef = associationRef.getTargetRef();
            Reference targetReference = NodeProtocol.newReference(targetNodeRef, sourceReference.execute(new GetParentReferenceMethod()));
            AssociationRef virtualAssocRef = new AssociationRef(associationRef.getId(), sourceRef, associationRef.getTypeQName(), targetReference.toNodeRef(targetNodeRef.getStoreRef()));
            virtualizedIfNeededTargetAssocs.add(virtualAssocRef);
        }
    } else {
        virtualizedIfNeededTargetAssocs = targetAssocs;
        if (DownloadModel.TYPE_DOWNLOAD.equals(environment.getType(sourceRef))) {
            if (qnamePattern.isMatch(DownloadModel.ASSOC_REQUESTED_NODES)) {
                List<AssociationRef> virtualTargetAssocs = getDownloadTargetAssocs(sourceRef);
                virtualizedIfNeededTargetAssocs.addAll(virtualTargetAssocs);
            }
        }
    }
    return virtualizedIfNeededTargetAssocs;
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 43 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method getSourceAssocs.

@Override
public List<AssociationRef> getSourceAssocs(NodeRef targetRef, QNamePattern qnamePattern) {
    NodeServiceTrait theTrait = getTrait();
    Reference reference = Reference.fromNodeRef(targetRef);
    if (reference != null) {
        List<AssociationRef> materialAssocs = new ArrayList<AssociationRef>();
        if (smartStore.canMaterialize(reference)) {
            List<AssociationRef> sourceAssocs = theTrait.getSourceAssocs(smartStore.materialize(reference), qnamePattern);
            for (AssociationRef associationRef : sourceAssocs) {
                NodeRef sourceRef = associationRef.getSourceRef();
                Reference sourceReference = NodeProtocol.newReference(sourceRef, reference.execute(new GetParentReferenceMethod()));
                AssociationRef virtualAssocRef = new AssociationRef(associationRef.getId(), sourceReference.toNodeRef(), associationRef.getTypeQName(), targetRef);
                materialAssocs.add(virtualAssocRef);
            }
        }
        return materialAssocs;
    } else {
        return theTrait.getSourceAssocs(targetRef, qnamePattern);
    }
}
Also used : GetParentReferenceMethod(org.alfresco.repo.virtual.ref.GetParentReferenceMethod) NodeRef(org.alfresco.service.cmr.repository.NodeRef) NodeServiceTrait(org.alfresco.repo.node.db.traitextender.NodeServiceTrait) Reference(org.alfresco.repo.virtual.ref.Reference) ArrayList(java.util.ArrayList) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 44 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.

the class VirtualNodeServiceExtension method createAssociation.

@Override
public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) {
    Reference targetReference = Reference.fromNodeRef(targetRef);
    if (targetReference != null && getTrait().getType(materializeIfPossible(sourceRef)).equals(DownloadModel.TYPE_DOWNLOAD)) {
        // NOTE : this is enables downloads of virtual structures
        createDownloadAssociation(sourceRef, targetRef);
        AssociationRef assocRef = new AssociationRef(sourceRef, assocTypeQName, targetRef);
        return assocRef;
    } else {
        return getTrait().createAssociation(materializeIfPossible(sourceRef), materializeIfPossible(targetRef), assocTypeQName);
    }
}
Also used : Reference(org.alfresco.repo.virtual.ref.Reference) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 45 with AssociationRef

use of org.alfresco.service.cmr.repository.AssociationRef in project alfresco-repository by Alfresco.

the class AbstractNodeDAOImpl method getSourceNodeAssocs.

@Override
public Collection<Pair<Long, AssociationRef>> getSourceNodeAssocs(Long targetNodeId, QName typeQName) {
    Long typeQNameId = null;
    if (typeQName != null) {
        Pair<Long, QName> typeQNamePair = qnameDAO.getQName(typeQName);
        if (typeQNamePair == null) {
            // No such QName
            return Collections.emptyList();
        }
        typeQNameId = typeQNamePair.getFirst();
    }
    List<NodeAssocEntity> nodeAssocEntities = selectNodeAssocsByTarget(targetNodeId, typeQNameId);
    List<Pair<Long, AssociationRef>> results = new ArrayList<Pair<Long, AssociationRef>>(nodeAssocEntities.size());
    for (NodeAssocEntity nodeAssocEntity : nodeAssocEntities) {
        Long assocId = nodeAssocEntity.getId();
        AssociationRef assocRef = nodeAssocEntity.getAssociationRef(qnameDAO);
        results.add(new Pair<Long, AssociationRef>(assocId, assocRef));
    }
    return results;
}
Also used : QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) Pair(org.alfresco.util.Pair)

Aggregations

AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)138 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)112 NodeRef (org.alfresco.service.cmr.repository.NodeRef)102 QName (org.alfresco.service.namespace.QName)56 ArrayList (java.util.ArrayList)44 Serializable (java.io.Serializable)30 Test (org.junit.Test)26 HashMap (java.util.HashMap)24 List (java.util.List)15 Pair (org.alfresco.util.Pair)14 HashSet (java.util.HashSet)13 Map (java.util.Map)13 StoreRef (org.alfresco.service.cmr.repository.StoreRef)12 BaseSpringTest (org.alfresco.util.BaseSpringTest)10 Extend (org.alfresco.traitextender.Extend)8 Iterator (java.util.Iterator)7 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)7 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)7 Path (org.alfresco.service.cmr.repository.Path)6 Version (org.alfresco.service.cmr.version.Version)6