Search in sources :

Example 26 with AssociationDefinition

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

the class IntegrityChecker method onAddAspect.

/**
 * @see PropertiesIntegrityEvent
 * @see AssocTargetMultiplicityIntegrityEvent
 */
public void onAddAspect(NodeRef nodeRef, QName aspectTypeQName) {
    if (!storesToIgnore.contains(tenantService.getBaseName(nodeRef.getStoreRef()).toString())) {
        IntegrityEvent event = null;
        // check properties on node
        event = new PropertiesIntegrityEvent(nodeService, dictionaryService, nodeRef);
        save(event);
        // check for associations defined on the aspect
        AspectDefinition aspectDef = dictionaryService.getAspect(aspectTypeQName);
        if (aspectDef == null) {
            throw new DictionaryException("The aspect type is not recognized: " + aspectTypeQName);
        }
        Map<QName, AssociationDefinition> assocDefs = aspectDef.getAssociations();
        // check the multiplicity of each association with the node acting as a source
        for (AssociationDefinition assocDef : assocDefs.values()) {
            QName assocTypeQName = assocDef.getName();
            // check target multiplicity
            event = new AssocTargetMultiplicityIntegrityEvent(nodeService, dictionaryService, nodeRef, assocTypeQName, false);
            save(event);
        }
    }
}
Also used : AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) QName(org.alfresco.service.namespace.QName) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException)

Example 27 with AssociationDefinition

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

the class IncompleteNodeTagger method processNode.

private void processNode(NodeRef nodeRef, Set<QName> assocTypes) {
    // get the node aspects
    Set<QName> aspectTypeQNames = nodeService.getAspects(nodeRef);
    boolean isTagged = aspectTypeQNames.contains(ContentModel.ASPECT_INCOMPLETE);
    // get the node properties
    Map<QName, Serializable> nodeProperties = nodeService.getProperties(nodeRef);
    // get the node type
    QName nodeTypeQName = nodeService.getType(nodeRef);
    // get property definitions for the node type
    TypeDefinition typeDef = dictionaryService.getType(nodeTypeQName);
    if (typeDef == null) {
        throw new AlfrescoRuntimeException("Node type is not recognised: " + nodeTypeQName);
    }
    Collection<PropertyDefinition> propertyDefs = typeDef.getProperties().values();
    // check them
    boolean classPropertiesOK = checkProperties(propertyDefs, nodeProperties);
    // were there outstanding properties to check?
    if (!classPropertiesOK) {
        addOrRemoveTag(nodeRef, true, isTagged);
        // no further checking required
        return;
    }
    for (QName aspectTypeQName : aspectTypeQNames) {
        // get property definitions for the aspect
        AspectDefinition aspectDef = dictionaryService.getAspect(aspectTypeQName);
        if (aspectDef == null) {
            // The aspect is not registered so we ignore it
            continue;
        }
        propertyDefs = aspectDef.getProperties().values();
        // check them
        boolean aspectPropertiesOK = checkProperties(propertyDefs, nodeProperties);
        // were there outstanding properties to check?
        if (!aspectPropertiesOK) {
            addOrRemoveTag(nodeRef, true, isTagged);
            // no further checking required
            return;
        }
    }
    // test associations
    if (assocTypes != null) {
        Map<QName, AssociationDefinition> assocDefs = typeDef.getAssociations();
        if (assocTypes.size() > 0) {
            // check only those associations that have changed
            for (QName assocType : assocTypes) {
                AssociationDefinition assocDef = assocDefs.get(assocType);
                if (assocDef != null) {
                    if (!checkAssociation(nodeRef, assocDef)) {
                        addOrRemoveTag(nodeRef, true, isTagged);
                        return;
                    }
                }
            }
        } else {
            // check all associations (typically for new objects)
            for (QName assocType : assocDefs.keySet()) {
                AssociationDefinition assocDef = assocDefs.get(assocType);
                if (assocDef != null) {
                    if (!checkAssociation(nodeRef, assocDef)) {
                        addOrRemoveTag(nodeRef, true, isTagged);
                        return;
                    }
                }
            }
        }
    }
    // all properties and associations passed (both class- and aspect-defined) - remove aspect
    addOrRemoveTag(nodeRef, false, isTagged);
}
Also used : Serializable(java.io.Serializable) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) QName(org.alfresco.service.namespace.QName) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 28 with AssociationDefinition

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

the class VersionServiceImpl method defaultOnCreateVersion.

@Override
protected void defaultOnCreateVersion(QName classRef, NodeRef nodeRef, Map<String, Serializable> versionProperties, PolicyScope nodeDetails) {
    ClassDefinition classDefinition = this.dictionaryService.getClass(classRef);
    if (classDefinition != null) {
        boolean wasMLAware = MLPropertyInterceptor.setMLAware(true);
        try {
            // Copy the properties (along with their aspect)
            Map<QName, PropertyDefinition> propertyDefinitions = classDefinition.getProperties();
            for (QName propertyName : propertyDefinitions.keySet()) {
                Serializable propValue = this.nodeService.getProperty(nodeRef, propertyName);
                nodeDetails.addProperty(classRef, propertyName, propValue);
            }
            // Also copy the aspect with no properties in its definition
            if (classDefinition.isAspect() && !nodeDetails.getAspects().contains(classRef)) {
                nodeDetails.addAspect(classRef);
            }
        } finally {
            MLPropertyInterceptor.setMLAware(wasMLAware);
        }
        // Version the associations (child and target)
        Map<QName, AssociationDefinition> assocDefs = classDefinition.getAssociations();
        // TODO: Need way of getting child assocs of a given type
        if (classDefinition.isContainer()) {
            List<ChildAssociationRef> childAssocRefs = this.nodeService.getChildAssocs(nodeRef);
            for (ChildAssociationRef childAssocRef : childAssocRefs) {
                if (assocDefs.containsKey(childAssocRef.getTypeQName())) {
                    nodeDetails.addChildAssociation(classDefinition.getName(), childAssocRef);
                }
            }
        }
        // TODO: Need way of getting assocs of a given type
        List<AssociationRef> nodeAssocRefs = this.nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
        for (AssociationRef nodeAssocRef : nodeAssocRefs) {
            if (assocDefs.containsKey(nodeAssocRef.getTypeQName())) {
                nodeDetails.addAssociation(classDefinition.getName(), nodeAssocRef);
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) QName(org.alfresco.service.namespace.QName) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef) PropertyDefinition(org.alfresco.service.cmr.dictionary.PropertyDefinition) AssociationRef(org.alfresco.service.cmr.repository.AssociationRef) ChildAssociationRef(org.alfresco.service.cmr.repository.ChildAssociationRef)

Example 29 with AssociationDefinition

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

the class ChildAssocEntity method getChildNameUnique.

/**
 * Apply the <b>cm:name</b> to the child association. If the child name is <tt>null</tt> then a GUID is generated as
 * a substitute.
 * <p>
 * Unknown associations or associations that do not require unique name checking will use a GUID for the child
 * name and the CRC value used <b>will be negative</b>.
 *
 * @param childName the <b>cm:name</b> applying to the association.
 */
public static Pair<String, Long> getChildNameUnique(DictionaryService dictionaryService, QName assocTypeQName, String childName) {
    if (childName == null) {
        throw new IllegalArgumentException("Child name may not be null.  Use the Node ID ...");
    }
    // 
    String childNameNewShort;
    // By default, they don't compete
    long childNameNewCrc = -1L;
    AssociationDefinition assocDef = dictionaryService.getAssociation(assocTypeQName);
    if (assocDef == null || !assocDef.isChild()) {
        if (logger.isWarnEnabled()) {
            logger.warn("No child association of this type could be found: " + assocTypeQName);
        }
        childNameNewShort = GUID.generate();
        childNameNewCrc = -1L * getChildNodeNameCrc(childNameNewShort);
    } else {
        ChildAssociationDefinition childAssocDef = (ChildAssociationDefinition) assocDef;
        if (childAssocDef.getDuplicateChildNamesAllowed()) {
            childNameNewShort = GUID.generate();
            childNameNewCrc = -1L * getChildNodeNameCrc(childNameNewShort);
        } else {
            String childNameNewLower = childName.toLowerCase();
            childNameNewShort = getChildNodeNameShort(childNameNewLower);
            childNameNewCrc = getChildNodeNameCrc(childNameNewLower);
        }
    }
    return new Pair<String, Long>(childNameNewShort, childNameNewCrc);
}
Also used : AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) Pair(org.alfresco.util.Pair)

Example 30 with AssociationDefinition

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

the class RepoDictionaryDAOTest method testChildAssocPropagate.

public void testChildAssocPropagate() {
    // Check the default value
    AssociationDefinition assocDef = service.getAssociation(QName.createQName(TEST_URL, "childassoc1"));
    assertNotNull("No such child association found", assocDef);
    assertTrue("Expected a child association", assocDef instanceof ChildAssociationDefinition);
    ChildAssociationDefinition childAssocDef = (ChildAssociationDefinition) assocDef;
    assertFalse("Expected 'false' for default timestamp propagation", childAssocDef.getPropagateTimestamps());
    // Check the explicit value
    assocDef = service.getAssociation(QName.createQName(TEST_URL, "childassocPropagate"));
    assertNotNull("No such child association found", assocDef);
    assertTrue("Expected a child association", assocDef instanceof ChildAssociationDefinition);
    childAssocDef = (ChildAssociationDefinition) assocDef;
    assertTrue("Expected 'true' for timestamp propagation", childAssocDef.getPropagateTimestamps());
}
Also used : AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition)

Aggregations

AssociationDefinition (org.alfresco.service.cmr.dictionary.AssociationDefinition)60 QName (org.alfresco.service.namespace.QName)46 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)24 ChildAssociationDefinition (org.alfresco.service.cmr.dictionary.ChildAssociationDefinition)19 NodeRef (org.alfresco.service.cmr.repository.NodeRef)17 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)15 HashMap (java.util.HashMap)13 Serializable (java.io.Serializable)11 ArrayList (java.util.ArrayList)11 ClassDefinition (org.alfresco.service.cmr.dictionary.ClassDefinition)9 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)7 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)6 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)6 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)6 Collection (java.util.Collection)5 AssociationRef (org.alfresco.service.cmr.repository.AssociationRef)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Map (java.util.Map)4 Pair (org.alfresco.util.Pair)3