Search in sources :

Example 51 with AssociationDefinition

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

the class DbNodeServiceImpl method propagateTimeStamps.

/**
 * Propagate, if necessary, a <b>cm:modified</b> timestamp change to the parent of the
 * given association, along with the <b>cm:modifier</b> of who changed it.
 * The parent node has to be <b>cm:auditable</b> and the association
 * has to be marked for propagation as well.
 *
 * @param assocRef          the association to propagate along
 */
private void propagateTimeStamps(ChildAssociationRef assocRef) {
    if (!enableTimestampPropagation) {
        // Bypassed on a system-wide basis
        return;
    }
    // First check if the association type warrants propagation in the first place
    AssociationDefinition assocDef = dictionaryService.getAssociation(assocRef.getTypeQName());
    if (assocDef == null || !assocDef.isChild()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Not propagating cm:auditable for unknown association type " + assocRef.getTypeQName());
        }
        return;
    }
    ChildAssociationDefinition childAssocDef = (ChildAssociationDefinition) assocDef;
    if (!childAssocDef.getPropagateTimestamps()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Not propagating cm:auditable for association type " + childAssocDef.getName());
        }
        return;
    }
    // The dictionary says propagate.  Now get the parent node and prompt the touch.
    NodeRef parentNodeRef = assocRef.getParentRef();
    // Do not propagate if the cm:auditable behaviour is off
    if (!policyBehaviourFilter.isEnabled(parentNodeRef, ContentModel.ASPECT_AUDITABLE)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Not propagating cm:auditable for non-auditable parent on " + assocRef);
        }
        return;
    }
    Pair<Long, NodeRef> parentNodePair = getNodePairNotNull(parentNodeRef);
    Long parentNodeId = parentNodePair.getFirst();
    // Get the ID of the child that triggered this update
    NodeRef childNodeRef = assocRef.getChildRef();
    Pair<Long, NodeRef> childNodePair = getNodePairNotNull(childNodeRef);
    Long childNodeId = childNodePair.getFirst();
    // post-commit isolated transaction.
    if (TransactionalResourceHelper.getMap(KEY_AUDITABLE_PROPAGATION_PRE).containsKey(parentNodeId)) {
        // Modified By will be taken from the previous node to touch it
        if (logger.isDebugEnabled()) {
            logger.debug("Update of cm:auditable already requested for " + parentNodePair);
        }
        return;
    }
    if (nodeDAO.isInCurrentTxn(parentNodeId)) {
        // The parent and child are in the same transaction
        TransactionalResourceHelper.getMap(KEY_AUDITABLE_PROPAGATION_PRE).put(parentNodeId, childNodeId);
        // Make sure that it is not processed after the transaction
        TransactionalResourceHelper.getMap(KEY_AUDITABLE_PROPAGATION_POST).remove(parentNodeId);
        if (logger.isDebugEnabled()) {
            logger.debug("Performing in-transaction cm:auditable update for " + parentNodePair + " from " + childNodePair);
        }
    } else {
        TransactionalResourceHelper.getMap(KEY_AUDITABLE_PROPAGATION_POST).put(parentNodeId, childNodeId);
        if (logger.isDebugEnabled()) {
            logger.debug("Requesting later cm:auditable update for " + parentNodePair + " from " + childNodePair);
        }
    }
    // Bind a listener for post-transaction manipulation
    AlfrescoTransactionSupport.bindListener(auditableTransactionListener);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition)

Example 52 with AssociationDefinition

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

the class DbNodeServiceImpl method getMissingAspectsAssoc.

private Set<QName> getMissingAspectsAssoc(Set<QName> existingAspects, Map<QName, Serializable> existingProperties, QName assocTypeQName) {
    AssociationDefinition assocDef = dictionaryService.getAssociation(assocTypeQName);
    if (assocDef == null) {
        return Collections.emptySet();
    }
    ClassDefinition classDefinition = assocDef.getSourceClass();
    return getMissingAspects(existingAspects, existingProperties, classDefinition.getName());
}
Also used : ChildAssociationDefinition(org.alfresco.service.cmr.dictionary.ChildAssociationDefinition) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition)

Example 53 with AssociationDefinition

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

the class IntegrityChecker method onCreateNode.

/**
 * @see PropertiesIntegrityEvent
 * @see AssocTargetRoleIntegrityEvent
 * @see AssocTargetMultiplicityIntegrityEvent
 */
public void onCreateNode(ChildAssociationRef childAssocRef) {
    NodeRef childRef = childAssocRef.getChildRef();
    if (!storesToIgnore.contains(tenantService.getBaseName(childRef.getStoreRef()).toString())) {
        IntegrityEvent event = null;
        // check properties on child node
        event = new PropertiesIntegrityEvent(nodeService, dictionaryService, childRef);
        save(event);
        // check that the multiplicity and other properties of the new association are allowed
        onCreateChildAssociation(childAssocRef, false);
        // check mandatory aspects
        event = new AspectsIntegrityEvent(nodeService, dictionaryService, childRef);
        save(event);
        // check for associations defined on the new node (child)
        QName childNodeTypeQName = nodeService.getType(childRef);
        ClassDefinition nodeTypeDef = dictionaryService.getClass(childNodeTypeQName);
        if (nodeTypeDef == null) {
            throw new DictionaryException("The node type is not recognized: " + childNodeTypeQName);
        }
        Map<QName, AssociationDefinition> childAssocDefs = nodeTypeDef.getAssociations();
        // check the multiplicity of each association with the node acting as a source
        for (AssociationDefinition assocDef : childAssocDefs.values()) {
            QName assocTypeQName = assocDef.getName();
            // check target multiplicity
            event = new AssocTargetMultiplicityIntegrityEvent(nodeService, dictionaryService, childRef, assocTypeQName, false);
            save(event);
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) QName(org.alfresco.service.namespace.QName) ClassDefinition(org.alfresco.service.cmr.dictionary.ClassDefinition) DictionaryException(org.alfresco.service.cmr.dictionary.DictionaryException)

Example 54 with AssociationDefinition

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

the class AssocSourceMultiplicityIntegrityEvent method checkIntegrity.

public void checkIntegrity(List<IntegrityRecord> eventResults) {
    QName assocTypeQName = getTypeQName();
    NodeRef targetNodeRef = getNodeRef();
    // event is irrelevant if the node is gone
    QName targetNodeTypeQName = getNodeType(targetNodeRef);
    if (targetNodeTypeQName == null) {
        // target or source is missing
        if (logger.isDebugEnabled()) {
            logger.debug("Ignoring integrity check - node gone: \n" + "   event: " + this);
        }
        return;
    }
    // get the association def
    AssociationDefinition assocDef = getAssocDef(eventResults, assocTypeQName);
    // the association definition must exist
    if (assocDef == null) {
        if (// strict about the type
        !isDelete) {
            IntegrityRecord result = new IntegrityRecord("Association type does not exist: \n" + "   Target Node: " + targetNodeRef + "\n" + "   Target Node Type: " + targetNodeTypeQName + "\n" + "   Association Type: " + assocTypeQName);
            eventResults.add(result);
            return;
        } else // not strict about the type
        {
            return;
        }
    }
    // perform required checks
    checkSourceMultiplicity(eventResults, assocDef, assocTypeQName, targetNodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) QName(org.alfresco.service.namespace.QName)

Example 55 with AssociationDefinition

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

the class AssocTargetMultiplicityIntegrityEvent method checkIntegrity.

public void checkIntegrity(List<IntegrityRecord> eventResults) {
    QName assocTypeQName = getTypeQName();
    NodeRef sourceNodeRef = getNodeRef();
    // event is irrelevant if the node is gone
    QName sourceNodeTypeQName = getNodeType(sourceNodeRef);
    if (sourceNodeTypeQName == null) {
        // target or target is missing
        if (logger.isDebugEnabled()) {
            logger.debug("Ignoring integrity check - node gone: \n" + "   event: " + this);
        }
        return;
    }
    // get the association def
    AssociationDefinition assocDef = getAssocDef(eventResults, assocTypeQName);
    // the association definition must exist
    if (assocDef == null) {
        if (// strict about the type
        !isDelete) {
            IntegrityRecord result = new IntegrityRecord("Association type does not exist: \n" + "   Source Node: " + sourceNodeRef + "\n" + "   Source Node Type: " + sourceNodeTypeQName + "\n" + "   Association Type: " + assocTypeQName);
            eventResults.add(result);
            return;
        } else // not strict about the type
        {
            return;
        }
    }
    // perform required checks
    checkTargetMultiplicity(eventResults, assocDef, assocTypeQName, sourceNodeRef);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) AssociationDefinition(org.alfresco.service.cmr.dictionary.AssociationDefinition) QName(org.alfresco.service.namespace.QName)

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