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);
}
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());
}
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);
}
}
}
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);
}
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);
}
Aggregations