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 AssocSourceTypeIntegrityEvent extends AbstractIntegrityEvent 41 { 42 private static Log logger = LogFactory.getLog(AssocSourceTypeIntegrityEvent.class); 43 44 public AssocSourceTypeIntegrityEvent( 45 NodeService nodeService, 46 DictionaryService dictionaryService, 47 NodeRef sourceNodeRef, 48 QName assocTypeQName) 49 { 50 super(nodeService, dictionaryService, sourceNodeRef, assocTypeQName, null); 51 } 52 53 public void checkIntegrity(List <IntegrityRecord> eventResults) 54 { 55 QName assocTypeQName = getTypeQName(); 56 NodeRef sourceNodeRef = getNodeRef(); 57 QName sourceNodeTypeQName = getNodeType(sourceNodeRef); 59 if (sourceNodeTypeQName == 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 " Source Node Type: " + sourceNodeTypeQName + "\n" + 78 " Association Type: " + assocTypeQName); 79 eventResults.add(result); 80 return; 81 } 82 83 checkSourceType(eventResults, assocDef, sourceNodeRef, sourceNodeTypeQName); 85 } 86 87 90 protected void checkSourceType( 91 List <IntegrityRecord> eventResults, 92 AssociationDefinition assocDef, 93 NodeRef sourceNodeRef, 94 QName sourceNodeTypeQName) 95 { 96 ClassDefinition sourceDef = assocDef.getSourceClass(); 98 if (sourceDef instanceof TypeDefinition) 99 { 100 if (!dictionaryService.isSubClass(sourceNodeTypeQName, sourceDef.getName())) 102 { 103 IntegrityRecord result = new IntegrityRecord( 104 "The association source type is incorrect: \n" + 105 " Association: " + assocDef + "\n" + 106 " Required Source Type: " + sourceDef.getName() + "\n" + 107 " Actual Source Type: " + sourceNodeTypeQName); 108 eventResults.add(result); 109 } 110 } 111 else if (sourceDef instanceof AspectDefinition) 112 { 113 Set <QName> sourceAspects = nodeService.getAspects(sourceNodeRef); 115 boolean found = false; 116 for (QName sourceAspectTypeQName : sourceAspects) 117 { 118 if (dictionaryService.isSubClass(sourceAspectTypeQName, sourceDef.getName())) 119 { 120 found = true; 121 break; 122 } 123 } 124 if (!found) 125 { 126 IntegrityRecord result = new IntegrityRecord( 127 "The association source is missing the aspect required for this association: \n" + 128 " Association: " + assocDef + "\n" + 129 " Required Source Aspect: " + sourceDef.getName() + "\n" + 130 " Actual Source Aspects: " + sourceAspects); 131 eventResults.add(result); 132 } 133 } 134 else 135 { 136 IntegrityRecord result = new IntegrityRecord( 137 "Unknown ClassDefinition subclass on the source definition: \n" + 138 " Association: " + assocDef + "\n" + 139 " Source Definition: " + sourceDef.getName()); 140 eventResults.add(result); 141 } 142 } 143 } 144 | Popular Tags |