1 17 package org.alfresco.repo.node.integrity; 18 19 import java.io.Serializable ; 20 import java.util.Collection ; 21 import java.util.List ; 22 import java.util.Map ; 23 import java.util.Set ; 24 25 import org.alfresco.service.cmr.dictionary.AspectDefinition; 26 import org.alfresco.service.cmr.dictionary.DictionaryService; 27 import org.alfresco.service.cmr.dictionary.PropertyDefinition; 28 import org.alfresco.service.cmr.dictionary.TypeDefinition; 29 import org.alfresco.service.cmr.repository.InvalidNodeRefException; 30 import org.alfresco.service.cmr.repository.NodeRef; 31 import org.alfresco.service.cmr.repository.NodeService; 32 import org.alfresco.service.namespace.QName; 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 36 41 public class PropertiesIntegrityEvent extends AbstractIntegrityEvent 42 { 43 private static Log logger = LogFactory.getLog(PropertiesIntegrityEvent.class); 44 45 protected PropertiesIntegrityEvent( 46 NodeService nodeService, 47 DictionaryService dictionaryService, 48 NodeRef nodeRef) 49 { 50 super(nodeService, dictionaryService, nodeRef, null, null); 51 } 52 53 public void checkIntegrity(List <IntegrityRecord> eventResults) 54 { 55 try 56 { 57 checkAllProperties(getNodeRef(), eventResults); 58 } 59 catch (InvalidNodeRefException e) 60 { 61 if (logger.isDebugEnabled()) 63 { 64 logger.debug("Event ignored - node gone: " + this); 65 } 66 eventResults.clear(); 67 return; 68 } 69 } 70 71 77 private void checkAllProperties(NodeRef nodeRef, List <IntegrityRecord> eventResults) 78 { 79 Map <QName, Serializable > nodeProperties = nodeService.getProperties(nodeRef); 81 82 QName nodeTypeQName = nodeService.getType(nodeRef); 84 TypeDefinition typeDef = dictionaryService.getType(nodeTypeQName); 86 Collection <PropertyDefinition> propertyDefs = typeDef.getProperties().values(); 87 checkAllProperties(nodeRef, nodeTypeQName, propertyDefs, nodeProperties, eventResults); 89 90 Set <QName> aspectTypeQNames = nodeService.getAspects(nodeRef); 92 for (QName aspectTypeQName : aspectTypeQNames) 93 { 94 AspectDefinition aspectDef = dictionaryService.getAspect(aspectTypeQName); 96 propertyDefs = aspectDef.getProperties().values(); 97 checkAllProperties(nodeRef, aspectTypeQName, propertyDefs, nodeProperties, eventResults); 99 } 100 } 102 103 111 private void checkAllProperties( 112 NodeRef nodeRef, 113 QName typeQName, 114 Collection <PropertyDefinition> propertyDefs, 115 Map <QName, Serializable > nodeProperties, 116 Collection <IntegrityRecord> eventResults) 117 { 118 if (propertyDefs == null || propertyDefs.isEmpty()) 120 { 121 return; 122 } 123 for (PropertyDefinition propertyDef : propertyDefs) 124 { 125 QName propertyQName = propertyDef.getName(); 126 Serializable propertyValue = nodeProperties.get(propertyQName); 127 if (propertyDef.isMandatory() && !nodeProperties.containsKey(propertyQName)) 129 { 130 IntegrityRecord result = new IntegrityRecord( 131 "Mandatory property not set: \n" + 132 " Node: " + nodeRef + "\n" + 133 " Type: " + typeQName + "\n" + 134 " Property: " + propertyQName); 135 eventResults.add(result); 136 continue; 138 } 139 } 141 } 142 } 143 | Popular Tags |