1 17 package org.alfresco.repo.node.integrity; 18 19 import java.util.List ; 20 import java.util.Set ; 21 22 import org.alfresco.service.cmr.dictionary.AspectDefinition; 23 import org.alfresco.service.cmr.dictionary.AssociationDefinition; 24 import org.alfresco.service.cmr.dictionary.ClassDefinition; 25 import org.alfresco.service.cmr.dictionary.DictionaryService; 26 import org.alfresco.service.cmr.dictionary.TypeDefinition; 27 import org.alfresco.service.cmr.repository.NodeRef; 28 import org.alfresco.service.cmr.repository.NodeService; 29 import org.alfresco.service.namespace.QName; 30 import org.apache.commons.logging.Log; 31 import org.apache.commons.logging.LogFactory; 32 33 40 public class AssocTargetTypeIntegrityEvent extends AbstractIntegrityEvent 41 { 42 private static Log logger = LogFactory.getLog(AssocTargetTypeIntegrityEvent.class); 43 44 public AssocTargetTypeIntegrityEvent( 45 NodeService nodeService, 46 DictionaryService dictionaryService, 47 NodeRef targetNodeRef, 48 QName assocTypeQName) 49 { 50 super(nodeService, dictionaryService, targetNodeRef, assocTypeQName, null); 51 } 52 53 public void checkIntegrity(List <IntegrityRecord> eventResults) 54 { 55 QName assocTypeQName = getTypeQName(); 56 NodeRef targetNodeRef = getNodeRef(); 57 QName targetNodeTypeQName = getNodeType(targetNodeRef); 59 if (targetNodeTypeQName == null) 60 { 61 if (logger.isDebugEnabled()) 63 { 64 logger.debug("Ignoring integrity check - node gone: \n" + 65 " event: " + this); 66 } 67 return; 68 } 69 70 AssociationDefinition assocDef = getAssocDef(eventResults, assocTypeQName); 72 if (assocDef == null) 74 { 75 IntegrityRecord result = new IntegrityRecord( 76 "Association type does not exist: \n" + 77 " Target Node Type: " + targetNodeTypeQName + "\n" + 78 " Association Type: " + assocTypeQName); 79 eventResults.add(result); 80 return; 81 } 82 83 checkTargetType(eventResults, assocDef, targetNodeRef, targetNodeTypeQName); 85 } 86 87 90 protected void checkTargetType( 91 List <IntegrityRecord> eventResults, 92 AssociationDefinition assocDef, 93 NodeRef targetNodeRef, 94 QName targetNodeTypeQName) 95 { 96 ClassDefinition targetDef = assocDef.getTargetClass(); 98 if (targetDef instanceof TypeDefinition) 99 { 100 if (!dictionaryService.isSubClass(targetNodeTypeQName, targetDef.getName())) 102 { 103 IntegrityRecord result = new IntegrityRecord( 104 "The association target type is incorrect: \n" + 105 " Association: " + assocDef + "\n" + 106 " Required Target Type: " + targetDef.getName() + "\n" + 107 " Actual Target Type: " + targetNodeTypeQName); 108 eventResults.add(result); 109 } 110 } 111 else if (targetDef instanceof AspectDefinition) 112 { 113 Set <QName> targetAspects = nodeService.getAspects(targetNodeRef); 115 boolean found = false; 116 for (QName targetAspectTypeQName : targetAspects) 117 { 118 if (dictionaryService.isSubClass(targetAspectTypeQName, targetDef.getName())) 119 { 120 found = true; 121 break; 122 } 123 } 124 if (!found) 125 { 126 IntegrityRecord result = new IntegrityRecord( 127 "The association target is missing the aspect required for this association: \n" + 128 " Association: " + assocDef + "\n" + 129 " Required Target Aspect: " + targetDef.getName() + "\n" + 130 " Actual Target Aspects: " + targetAspects); 131 eventResults.add(result); 132 } 133 } 134 else 135 { 136 IntegrityRecord result = new IntegrityRecord( 137 "Unknown ClassDefinition subclass on the target definition: \n" + 138 " Association: " + assocDef + "\n" + 139 " Source Definition: " + targetDef.getName()); 140 eventResults.add(result); 141 } 142 } 143 } 144 | Popular Tags |