Search in sources :

Example 46 with AssociationRef

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

the class AbstractNodeDAOImpl method getNodeAssocsToAndFrom.

@Override
public Collection<Pair<Long, AssociationRef>> getNodeAssocsToAndFrom(Long nodeId) {
    List<NodeAssocEntity> nodeAssocEntities = selectNodeAssocs(nodeId);
    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 : ArrayList(java.util.ArrayList) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) Pair(org.alfresco.util.Pair)

Example 47 with AssociationRef

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

the class AbstractNodeDAOImpl method getTargetAssocsByPropertyValue.

@Override
public Collection<Pair<Long, AssociationRef>> getTargetAssocsByPropertyValue(Long sourceNodeId, QName typeQName, QName propertyQName, Serializable propertyValue) {
    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();
    }
    Long propertyQNameId = null;
    NodePropertyValue nodeValue = null;
    if (propertyQName != null) {
        Pair<Long, QName> propQNamePair = qnameDAO.getQName(propertyQName);
        if (propQNamePair == null) {
            // No such QName
            return Collections.emptyList();
        }
        propertyQNameId = propQNamePair.getFirst();
        PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
        nodeValue = nodePropertyHelper.makeNodePropertyValue(propertyDef, propertyValue);
        if (nodeValue != null) {
            switch(nodeValue.getPersistedType()) {
                // Boolean
                case 1:
                // long
                case 3:
                // double
                case 5:
                case // string
                6:
                    // no floats due to the range errors testing equality on a float.
                    break;
                default:
                    throw new IllegalArgumentException("method not supported for persisted value type " + nodeValue.getPersistedType());
            }
        }
    }
    List<NodeAssocEntity> nodeAssocEntities = selectNodeAssocsBySourceAndPropertyValue(sourceNodeId, typeQNameId, propertyQNameId, nodeValue);
    // Create custom result
    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) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) Pair(org.alfresco.util.Pair)

Example 48 with AssociationRef

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

the class MultiTNodeServiceInterceptor method convertOutboundValue.

/**
 * Convert outbound single value to spoofed (ie. without tenant prefix) value.
 */
@SuppressWarnings("unchecked")
private Object convertOutboundValue(Object rawValue) {
    if (rawValue == null) {
        return null;
    }
    Object value = rawValue;
    if (rawValue instanceof Collection) {
        // Deal with collections
        value = convertOutboundValues((Collection<Object>) rawValue);
    } else if (rawValue instanceof StoreRef) {
        StoreRef ref = (StoreRef) rawValue;
        value = tenantService.getBaseName(ref);
    } else if (rawValue instanceof NodeRef) {
        NodeRef ref = (NodeRef) rawValue;
        value = tenantService.getBaseName(ref);
    } else if (rawValue instanceof ChildAssociationRef) {
        ChildAssociationRef ref = (ChildAssociationRef) rawValue;
        value = tenantService.getBaseName(ref);
    } else if (rawValue instanceof AssociationRef) {
        AssociationRef ref = (AssociationRef) rawValue;
        value = tenantService.getBaseName(ref);
    } else if (rawValue instanceof Path) {
        Path ref = (Path) rawValue;
        Path outboundPath = new Path();
        Iterator<Path.Element> itr = ref.iterator();
        while (itr.hasNext()) {
            Path.Element pathElement = itr.next();
            if (pathElement instanceof Path.ChildAssocElement) {
                pathElement = new Path.ChildAssocElement(tenantService.getBaseName(((Path.ChildAssocElement) pathElement).getRef()));
            }
            outboundPath.append(pathElement);
        }
        value = outboundPath;
    }
    // Done
    return value;
}
Also used : Path(org.alfresco.service.cmr.repository.Path) StoreRef(org.alfresco.service.cmr.repository.StoreRef) NodeRef(org.alfresco.service.cmr.repository.NodeRef) Iterator(java.util.Iterator) Collection(java.util.Collection) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 49 with AssociationRef

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

the class TemplateNode method getSourceAssocs.

/**
 * @return Source associations for this Node. As a Map of assoc name to a List of TemplateNodes.
 */
public Map<String, List<TemplateNode>> getSourceAssocs() {
    if (this.sourceAssocs == null) {
        List<AssociationRef> refs = this.services.getNodeService().getSourceAssocs(this.nodeRef, RegexQNamePattern.MATCH_ALL);
        this.sourceAssocs = new QNameMap<String, List<TemplateNode>>(this);
        for (AssociationRef ref : refs) {
            String qname = ref.getTypeQName().toString();
            List<TemplateNode> nodes = this.sourceAssocs.get(qname);
            if (nodes == null) {
                // first access for the list for this qname
                nodes = new ArrayList<TemplateNode>(4);
                this.sourceAssocs.put(ref.getTypeQName().toString(), nodes);
            }
            nodes.add(new TemplateNode(ref.getSourceRef(), this.services, this.imageResolver));
        }
    }
    return this.sourceAssocs;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 50 with AssociationRef

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

the class NodeStoreInspector method outputNode.

/**
 * Output the node
 *
 * @param iIndent int
 * @param nodeService NodeService
 * @param nodeRef NodeRef
 * @return String
 */
private static String outputNode(int iIndent, NodeService nodeService, NodeRef nodeRef) {
    StringBuilder builder = new StringBuilder();
    try {
        QName nodeType = nodeService.getType(nodeRef);
        builder.append(getIndent(iIndent)).append("node: ").append(nodeRef.getId()).append(" (").append(nodeType.getLocalName());
        Collection<QName> aspects = nodeService.getAspects(nodeRef);
        for (QName aspect : aspects) {
            builder.append(", ").append(aspect.getLocalName());
        }
        builder.append(")\n");
        Map<QName, Serializable> props = nodeService.getProperties(nodeRef);
        for (QName name : props.keySet()) {
            String valueAsString = "null";
            Serializable value = props.get(name);
            if (value != null) {
                valueAsString = value.toString();
            }
            builder.append(getIndent(iIndent + 1)).append("@").append(name.getLocalName()).append(" = ").append(valueAsString).append("\n");
        }
        Collection<ChildAssociationRef> childAssocRefs = nodeService.getChildAssocs(nodeRef);
        for (ChildAssociationRef childAssocRef : childAssocRefs) {
            builder.append(getIndent(iIndent + 1)).append("-> ").append(childAssocRef.getQName().toString()).append(" (").append(childAssocRef.getQName().toString()).append(")\n");
            builder.append(outputNode(iIndent + 2, nodeService, childAssocRef.getChildRef()));
        }
        Collection<AssociationRef> assocRefs = nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
        for (AssociationRef assocRef : assocRefs) {
            builder.append(getIndent(iIndent + 1)).append("-> associated to ").append(assocRef.getTargetRef().getId()).append("\n");
        }
    } catch (InvalidNodeRefException invalidNode) {
        invalidNode.printStackTrace();
    }
    return builder.toString();
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

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