1 17 package org.alfresco.repo.importer.view; 18 19 import java.io.Serializable ; 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.HashMap ; 23 import java.util.HashSet ; 24 import java.util.List ; 25 import java.util.Map ; 26 import java.util.Set ; 27 28 import org.alfresco.model.ContentModel; 29 import org.alfresco.repo.importer.ImportNode; 30 import org.alfresco.service.cmr.dictionary.AspectDefinition; 31 import org.alfresco.service.cmr.dictionary.AssociationDefinition; 32 import org.alfresco.service.cmr.dictionary.ChildAssociationDefinition; 33 import org.alfresco.service.cmr.dictionary.ClassDefinition; 34 import org.alfresco.service.cmr.dictionary.DataTypeDefinition; 35 import org.alfresco.service.cmr.dictionary.PropertyDefinition; 36 import org.alfresco.service.cmr.dictionary.TypeDefinition; 37 import org.alfresco.service.cmr.repository.NodeRef; 38 import org.alfresco.service.cmr.security.AccessPermission; 39 import org.alfresco.service.cmr.security.AccessStatus; 40 import org.alfresco.service.cmr.security.AuthorityType; 41 import org.alfresco.service.cmr.security.PermissionService; 42 import org.alfresco.service.namespace.QName; 43 44 45 51 public class NodeContext extends ElementContext 52 implements ImportNode 53 { 54 private ParentContext parentContext; 55 private boolean isReference = false; 56 private NodeRef nodeRef; 57 private String importId; private String uuid; private TypeDefinition typeDef; 60 private String childName; 61 private Map <QName, AspectDefinition> nodeAspects = new HashMap <QName, AspectDefinition>(); 62 private Map <QName, ChildAssociationDefinition> nodeChildAssocs = new HashMap <QName, ChildAssociationDefinition>(); 63 private Map <QName, Serializable > nodeProperties = new HashMap <QName, Serializable >(); 64 private Map <QName, DataTypeDefinition> propertyDatatypes = new HashMap <QName, DataTypeDefinition>(); 65 66 private boolean inherit = true; 68 private List <AccessPermission> accessControlEntries = new ArrayList <AccessPermission>(); 69 70 71 78 public NodeContext(QName elementName, ParentContext parentContext, TypeDefinition typeDef) 79 { 80 super(elementName, parentContext.getDictionaryService(), parentContext.getImporter()); 81 this.parentContext = parentContext; 82 this.typeDef = typeDef; 83 this.uuid = null; 84 } 85 86 89 public ParentContext getParentContext() 90 { 91 return parentContext; 92 } 93 94 97 public TypeDefinition getTypeDefinition() 98 { 99 return typeDef; 100 } 101 102 106 public boolean isReference() 107 { 108 return isReference; 109 } 110 111 114 public void setReference(boolean isReference) 115 { 116 this.isReference = isReference; 117 } 118 119 124 public void setTypeDefinition(TypeDefinition typeDef) 125 { 126 this.typeDef = typeDef; 127 } 128 129 132 public NodeRef getNodeRef() 133 { 134 return nodeRef; 135 } 136 137 140 public void setNodeRef(NodeRef nodeRef) 141 { 142 this.nodeRef = nodeRef; 143 } 144 145 149 public String getUUID() 150 { 151 return uuid; 152 } 153 154 157 public void setUUID(String uuid) 158 { 159 this.uuid = uuid; 160 } 161 162 166 public String getImportId() 167 { 168 return importId; 169 } 170 171 174 public void setImportId(String importId) 175 { 176 this.importId = importId; 177 } 178 179 182 public String getChildName() 183 { 184 return childName; 185 } 186 187 190 public void setChildName(String childName) 191 { 192 this.childName = childName; 193 } 194 195 198 public void setInheritPermissions(boolean inherit) 199 { 200 this.inherit = inherit; 201 } 202 203 206 public boolean getInheritPermissions() 207 { 208 return this.inherit; 209 } 210 211 216 public void addPropertyCollection(QName property) 217 { 218 PropertyDefinition propDef = getDictionaryService().getProperty(property); 221 ClassDefinition classDef = (propDef == null) ? null : propDef.getContainerClass(); 222 if (classDef != null) 223 { 224 if (!isImportableClass(classDef.getName())) 225 { 226 return; 227 } 228 } 229 230 List <Serializable >values = new ArrayList <Serializable >(); 232 nodeProperties.put(property, (Serializable )values); 233 } 234 235 236 242 public void addProperty(QName property, String value) 243 { 244 PropertyDefinition propDef = getDictionaryService().getProperty(property); 247 248 if (propDef != null && propDef.getName().equals(ContentModel.PROP_NODE_UUID)) 250 { 251 uuid = value; 252 } 253 254 ClassDefinition classDef = (propDef == null) ? null : propDef.getContainerClass(); 256 if (classDef != null) 257 { 258 if (!isImportableClass(classDef.getName())) 259 { 260 return; 261 } 262 } 263 264 Serializable newValue = value; 266 Serializable existingValue = nodeProperties.get(property); 267 if (existingValue != null) 268 { 269 if (existingValue instanceof Collection ) 270 { 271 ((Collection <Serializable >)existingValue).add(value); 273 newValue = existingValue; 274 } 275 else 276 { 277 List <Serializable >values = new ArrayList <Serializable >(); 279 values.add((String )existingValue); 280 values.add(value); 281 newValue = (Serializable )values; 282 } 283 } 284 nodeProperties.put(property, newValue); 285 } 286 287 293 public void addDatatype(QName property, DataTypeDefinition datatype) 294 { 295 propertyDatatypes.put(property, datatype); 296 } 297 298 301 public Map <QName, DataTypeDefinition> getPropertyDatatypes() 302 { 303 return propertyDatatypes; 304 } 305 306 309 public Map <QName, Serializable > getProperties() 310 { 311 return nodeProperties; 312 } 313 314 319 public void addAspect(AspectDefinition aspect) 320 { 321 if (isImportableClass(aspect.getName())) 322 { 323 nodeAspects.put(aspect.getName(), aspect); 324 } 325 } 326 327 330 public Set <QName> getNodeAspects() 331 { 332 return nodeAspects.keySet(); 333 } 334 335 342 public void addAccessControlEntry(AccessStatus accessStatus, String authority, String permission) 343 { 344 if (permission.equalsIgnoreCase("guest")) 347 { 348 permission = PermissionService.CONSUMER; 349 } 350 351 ACE ace = new ACE(); 352 ace.accessStatus = accessStatus; 353 ace.authority = authority; 354 ace.permission = permission; 355 accessControlEntries.add(ace); 356 } 357 358 363 public List <AccessPermission> getAccessControlEntries() 364 { 365 return accessControlEntries; 366 } 367 368 375 public Object determineDefinition(QName defName) 376 { 377 Object def = determineAspect(defName); 378 if (def == null) 379 { 380 def = determineProperty(defName); 381 if (def == null) 382 { 383 def = determineAssociation(defName); 384 } 385 } 386 return def; 387 } 388 389 395 public AspectDefinition determineAspect(QName defName) 396 { 397 AspectDefinition def = null; 398 if (nodeAspects.containsKey(defName) == false) 399 { 400 def = getDictionaryService().getAspect(defName); 401 } 402 return def; 403 } 404 405 411 public PropertyDefinition determineProperty(QName defName) 412 { 413 PropertyDefinition def = null; 414 if (nodeProperties.containsKey(defName) == false) 415 { 416 def = (typeDef == null) ? null : getDictionaryService().getProperty(typeDef.getName(), defName); 417 if (def == null) 418 { 419 Set <AspectDefinition> allAspects = new HashSet <AspectDefinition>(); 420 if (typeDef != null) 421 { 422 allAspects.addAll(typeDef.getDefaultAspects()); 423 } 424 allAspects.addAll(nodeAspects.values()); 425 for (AspectDefinition aspectDef : allAspects) 426 { 427 def = getDictionaryService().getProperty(aspectDef.getName(), defName); 428 if (def != null) 429 { 430 break; 431 } 432 } 433 } 434 } 435 return def; 436 } 437 438 444 public AssociationDefinition determineAssociation(QName defName) 445 { 446 AssociationDefinition def = null; 447 if (nodeChildAssocs.containsKey(defName) == false) 448 { 449 def = getDictionaryService().getAssociation(defName); 450 } 451 return def; 452 } 453 454 460 private boolean isImportableClass(QName className) 461 { 462 return !(className.equals(ContentModel.ASPECT_REFERENCEABLE) || 463 className.equals(ContentModel.ASPECT_VERSIONABLE)); 464 } 465 466 469 @Override 470 public String toString() 471 { 472 return "NodeContext[childName=" + getChildName() + ",type=" + (typeDef == null ? "null" : typeDef.getName()) + ",nodeRef=" + nodeRef + 473 ",aspects=" + nodeAspects.values() + ",parentContext=" + parentContext.toString() + "]"; 474 } 475 476 479 private class ACE implements AccessPermission 480 { 481 private AccessStatus accessStatus; 482 private String authority; 483 private String permission; 484 485 489 public String getPermission() 490 { 491 return permission; 492 } 493 494 498 public AccessStatus getAccessStatus() 499 { 500 return accessStatus; 501 } 502 503 507 public String getAuthority() 508 { 509 return authority; 510 } 511 512 516 public AuthorityType getAuthorityType() 517 { 518 return null; 519 } 520 } 521 522 } 523 | Popular Tags |