mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
125605 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125498 slanglois: MNT-16155 Update source headers - remove svn:eol-style property on Java and JSP source files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125783 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,171 +1,171 @@
|
||||
package org.alfresco.repo.node.integrity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Event raised to check the source multiplicity for an association type
|
||||
* from the given node.
|
||||
* <p>
|
||||
* Checks are ignored is the target node doesn't exist.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class AssocSourceMultiplicityIntegrityEvent extends AbstractIntegrityEvent
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(AssocSourceMultiplicityIntegrityEvent.class);
|
||||
|
||||
/** true if the assoc type may not be valid, e.g. during association deletions */
|
||||
private boolean isDelete;
|
||||
|
||||
public AssocSourceMultiplicityIntegrityEvent(
|
||||
NodeService nodeService,
|
||||
DictionaryService dictionaryService,
|
||||
NodeRef targetNodeRef,
|
||||
QName assocTypeQName,
|
||||
boolean isDelete)
|
||||
{
|
||||
super(nodeService, dictionaryService, targetNodeRef, assocTypeQName, null);
|
||||
this.isDelete = isDelete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (!super.equals(obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// so far, so good
|
||||
AssocSourceMultiplicityIntegrityEvent that = (AssocSourceMultiplicityIntegrityEvent) obj;
|
||||
return this.isDelete == that.isDelete;
|
||||
}
|
||||
|
||||
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 (!isDelete) // strict about the type
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the source multiplicity has not been violated for the
|
||||
* target of the association.
|
||||
*/
|
||||
protected void checkSourceMultiplicity(
|
||||
List<IntegrityRecord> eventResults,
|
||||
AssociationDefinition assocDef,
|
||||
QName assocTypeQName,
|
||||
NodeRef targetNodeRef)
|
||||
{
|
||||
// get the source multiplicity
|
||||
boolean mandatory = assocDef.isSourceMandatory();
|
||||
boolean allowMany = assocDef.isSourceMany();
|
||||
// do we need to check
|
||||
if (!mandatory && allowMany)
|
||||
{
|
||||
// it is not mandatory and it allows many on both sides of the assoc
|
||||
return;
|
||||
}
|
||||
|
||||
// check the target of the association if this is a delete
|
||||
if (isDelete)
|
||||
{
|
||||
// get the class the association is defined for and see if it is an aspect
|
||||
ClassDefinition classDef = assocDef.getTargetClass();
|
||||
if (classDef.isAspect())
|
||||
{
|
||||
// see if the target node has the aspect applied, if it does not
|
||||
// there's no need to check multiplicity
|
||||
if (!this.nodeService.hasAspect(targetNodeRef, classDef.getName()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int actualSize = 0;
|
||||
if (assocDef.isChild())
|
||||
{
|
||||
// check the parent assocs present
|
||||
List<ChildAssociationRef> parentAssocRefs = nodeService.getParentAssocs(
|
||||
targetNodeRef,
|
||||
assocTypeQName,
|
||||
RegexQNamePattern.MATCH_ALL);
|
||||
actualSize = parentAssocRefs.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
// check the source assocs present
|
||||
List<AssociationRef> sourceAssocRefs = nodeService.getSourceAssocs(targetNodeRef, assocTypeQName);
|
||||
actualSize = sourceAssocRefs.size();
|
||||
}
|
||||
|
||||
if ((mandatory && actualSize == 0) || (!allowMany && actualSize > 1))
|
||||
{
|
||||
if (actualSize == 0)
|
||||
{
|
||||
// ALF-9591: Integrity check: Association source multiplicity checking is incorrect
|
||||
// At this point, there is no point worrying. There are no more associations
|
||||
// pointing *to* this node and therefore the checking of the source
|
||||
// multiplicity (a feature of the source type/aspect) is not relevant
|
||||
return;
|
||||
}
|
||||
|
||||
String parentOrSourceStr = (assocDef.isChild() ? "parent" : "source");
|
||||
IntegrityRecord result = new IntegrityRecord(
|
||||
"The association " + parentOrSourceStr + " multiplicity has been violated: \n" +
|
||||
" Target Node: " + targetNodeRef + "\n" +
|
||||
" Association: " + assocDef + "\n" +
|
||||
" Required " + parentOrSourceStr + " Multiplicity: " + getMultiplicityString(mandatory, allowMany) + "\n" +
|
||||
" Actual " + parentOrSourceStr + " Multiplicity: " + actualSize);
|
||||
eventResults.add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.alfresco.repo.node.integrity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.ClassDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.namespace.RegexQNamePattern;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Event raised to check the source multiplicity for an association type
|
||||
* from the given node.
|
||||
* <p>
|
||||
* Checks are ignored is the target node doesn't exist.
|
||||
*
|
||||
* @author Derek Hulley
|
||||
*/
|
||||
public class AssocSourceMultiplicityIntegrityEvent extends AbstractIntegrityEvent
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(AssocSourceMultiplicityIntegrityEvent.class);
|
||||
|
||||
/** true if the assoc type may not be valid, e.g. during association deletions */
|
||||
private boolean isDelete;
|
||||
|
||||
public AssocSourceMultiplicityIntegrityEvent(
|
||||
NodeService nodeService,
|
||||
DictionaryService dictionaryService,
|
||||
NodeRef targetNodeRef,
|
||||
QName assocTypeQName,
|
||||
boolean isDelete)
|
||||
{
|
||||
super(nodeService, dictionaryService, targetNodeRef, assocTypeQName, null);
|
||||
this.isDelete = isDelete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (!super.equals(obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// so far, so good
|
||||
AssocSourceMultiplicityIntegrityEvent that = (AssocSourceMultiplicityIntegrityEvent) obj;
|
||||
return this.isDelete == that.isDelete;
|
||||
}
|
||||
|
||||
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 (!isDelete) // strict about the type
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the source multiplicity has not been violated for the
|
||||
* target of the association.
|
||||
*/
|
||||
protected void checkSourceMultiplicity(
|
||||
List<IntegrityRecord> eventResults,
|
||||
AssociationDefinition assocDef,
|
||||
QName assocTypeQName,
|
||||
NodeRef targetNodeRef)
|
||||
{
|
||||
// get the source multiplicity
|
||||
boolean mandatory = assocDef.isSourceMandatory();
|
||||
boolean allowMany = assocDef.isSourceMany();
|
||||
// do we need to check
|
||||
if (!mandatory && allowMany)
|
||||
{
|
||||
// it is not mandatory and it allows many on both sides of the assoc
|
||||
return;
|
||||
}
|
||||
|
||||
// check the target of the association if this is a delete
|
||||
if (isDelete)
|
||||
{
|
||||
// get the class the association is defined for and see if it is an aspect
|
||||
ClassDefinition classDef = assocDef.getTargetClass();
|
||||
if (classDef.isAspect())
|
||||
{
|
||||
// see if the target node has the aspect applied, if it does not
|
||||
// there's no need to check multiplicity
|
||||
if (!this.nodeService.hasAspect(targetNodeRef, classDef.getName()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int actualSize = 0;
|
||||
if (assocDef.isChild())
|
||||
{
|
||||
// check the parent assocs present
|
||||
List<ChildAssociationRef> parentAssocRefs = nodeService.getParentAssocs(
|
||||
targetNodeRef,
|
||||
assocTypeQName,
|
||||
RegexQNamePattern.MATCH_ALL);
|
||||
actualSize = parentAssocRefs.size();
|
||||
}
|
||||
else
|
||||
{
|
||||
// check the source assocs present
|
||||
List<AssociationRef> sourceAssocRefs = nodeService.getSourceAssocs(targetNodeRef, assocTypeQName);
|
||||
actualSize = sourceAssocRefs.size();
|
||||
}
|
||||
|
||||
if ((mandatory && actualSize == 0) || (!allowMany && actualSize > 1))
|
||||
{
|
||||
if (actualSize == 0)
|
||||
{
|
||||
// ALF-9591: Integrity check: Association source multiplicity checking is incorrect
|
||||
// At this point, there is no point worrying. There are no more associations
|
||||
// pointing *to* this node and therefore the checking of the source
|
||||
// multiplicity (a feature of the source type/aspect) is not relevant
|
||||
return;
|
||||
}
|
||||
|
||||
String parentOrSourceStr = (assocDef.isChild() ? "parent" : "source");
|
||||
IntegrityRecord result = new IntegrityRecord(
|
||||
"The association " + parentOrSourceStr + " multiplicity has been violated: \n" +
|
||||
" Target Node: " + targetNodeRef + "\n" +
|
||||
" Association: " + assocDef + "\n" +
|
||||
" Required " + parentOrSourceStr + " Multiplicity: " + getMultiplicityString(mandatory, allowMany) + "\n" +
|
||||
" Actual " + parentOrSourceStr + " Multiplicity: " + actualSize);
|
||||
eventResults.add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user