1 17 package org.alfresco.repo.version; 18 19 import java.io.Serializable ; 20 import java.util.ArrayList ; 21 import java.util.Collection ; 22 import java.util.Collections ; 23 import java.util.HashMap ; 24 import java.util.HashSet ; 25 import java.util.List ; 26 import java.util.Map ; 27 import java.util.Set ; 28 29 import org.alfresco.model.ContentModel; 30 import org.alfresco.service.cmr.dictionary.DictionaryService; 31 import org.alfresco.service.cmr.dictionary.InvalidAspectException; 32 import org.alfresco.service.cmr.repository.AssociationExistsException; 33 import org.alfresco.service.cmr.repository.AssociationRef; 34 import org.alfresco.service.cmr.repository.ChildAssociationRef; 35 import org.alfresco.service.cmr.repository.InvalidChildAssociationRefException; 36 import org.alfresco.service.cmr.repository.InvalidNodeRefException; 37 import org.alfresco.service.cmr.repository.NodeRef; 38 import org.alfresco.service.cmr.repository.NodeService; 39 import org.alfresco.service.cmr.repository.Path; 40 import org.alfresco.service.cmr.repository.StoreRef; 41 import org.alfresco.service.cmr.repository.NodeRef.Status; 42 import org.alfresco.service.cmr.search.QueryParameterDefinition; 43 import org.alfresco.service.cmr.search.SearchService; 44 import org.alfresco.service.namespace.NamespacePrefixResolver; 45 import org.alfresco.service.namespace.QName; 46 import org.alfresco.service.namespace.QNamePattern; 47 import org.alfresco.service.namespace.RegexQNamePattern; 48 49 50 55 public class NodeServiceImpl implements NodeService, VersionModel 56 { 57 60 private final static String MSG_UNSUPPORTED = 61 "This operation is not supported by a version store implementation of the node service."; 62 63 66 private static final QName rootAssocName = QName.createQName(VersionModel.NAMESPACE_URI, "versionedState"); 67 68 71 protected NodeService dbNodeService; 72 73 76 @SuppressWarnings ("unused") 77 private SearchService searcher; 78 79 82 protected DictionaryService dicitionaryService; 83 84 85 90 public void setDbNodeService(NodeService nodeService) 91 { 92 this.dbNodeService = nodeService; 93 } 94 95 100 public void setSearcher(SearchService searcher) 101 { 102 this.searcher = searcher; 103 } 104 105 110 public void setDictionaryService(DictionaryService dictionaryService) 111 { 112 this.dicitionaryService = dictionaryService; 113 } 114 115 118 public List <StoreRef> getStores() 119 { 120 return dbNodeService.getStores(); 121 } 122 123 126 public StoreRef createStore(String protocol, String identifier) 127 { 128 return dbNodeService.createStore(protocol, identifier); 129 } 130 131 134 public boolean exists(StoreRef storeRef) 135 { 136 return dbNodeService.exists(storeRef); 137 } 138 139 142 public boolean exists(NodeRef nodeRef) 143 { 144 return dbNodeService.exists(convertNodeRef(nodeRef)); 145 } 146 147 150 public Status getNodeStatus(NodeRef nodeRef) 151 { 152 return dbNodeService.getNodeStatus(nodeRef); 153 } 154 155 162 private NodeRef convertNodeRef(NodeRef nodeRef) 163 { 164 return new NodeRef(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, STORE_ID), nodeRef.getId()); 165 } 166 167 170 public NodeRef getRootNode(StoreRef storeRef) 171 { 172 return dbNodeService.getRootNode(storeRef); 173 } 174 175 178 public ChildAssociationRef createNode( 179 NodeRef parentRef, 180 QName assocTypeQName, 181 QName assocQName, 182 QName nodeTypeQName) throws InvalidNodeRefException 183 { 184 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 186 } 187 188 191 public ChildAssociationRef createNode( 192 NodeRef parentRef, 193 QName assocTypeQName, 194 QName assocQName, 195 QName nodeTypeQName, 196 Map <QName, Serializable > properties) throws InvalidNodeRefException 197 { 198 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 200 } 201 202 205 public void deleteNode(NodeRef nodeRef) throws InvalidNodeRefException 206 { 207 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 209 } 210 211 214 public ChildAssociationRef addChild(NodeRef parentRef, 215 NodeRef childRef, 216 QName assocTypeQName, 217 QName qname) throws InvalidNodeRefException 218 { 219 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 221 } 222 223 226 public void removeChild(NodeRef parentRef, NodeRef childRef) throws InvalidNodeRefException 227 { 228 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 230 } 231 232 235 public ChildAssociationRef moveNode(NodeRef nodeToMoveRef, NodeRef newParentRef, QName assocTypeQName, QName assocQName) throws InvalidNodeRefException 236 { 237 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 238 } 239 240 243 public void setChildAssociationIndex(ChildAssociationRef childAssocRef, int index) throws InvalidChildAssociationRefException 244 { 245 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 246 } 247 248 251 public QName getType(NodeRef nodeRef) throws InvalidNodeRefException 252 { 253 return (QName)this.dbNodeService.getProperty(convertNodeRef(nodeRef), PROP_QNAME_FROZEN_NODE_TYPE); 254 } 255 256 259 public void setType(NodeRef nodeRef, QName typeQName) throws InvalidNodeRefException 260 { 261 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 263 } 264 265 268 public void addAspect(NodeRef nodeRef, QName aspectRef, Map <QName, Serializable > aspectProperties) throws InvalidNodeRefException, InvalidAspectException 269 { 270 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 272 } 273 274 277 public boolean hasAspect(NodeRef nodeRef, QName aspectRef) throws InvalidNodeRefException, InvalidAspectException 278 { 279 return getAspects(nodeRef).contains(aspectRef); 280 } 281 282 285 public void removeAspect(NodeRef nodeRef, QName aspectRef) throws InvalidNodeRefException, InvalidAspectException 286 { 287 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 289 } 290 291 294 public Set <QName> getAspects(NodeRef nodeRef) throws InvalidNodeRefException 295 { 296 return new HashSet <QName>( 297 (ArrayList <QName>)this.dbNodeService.getProperty(convertNodeRef(nodeRef), PROP_QNAME_FROZEN_ASPECTS)); 298 } 299 300 303 public Map <QName, Serializable > getProperties(NodeRef nodeRef) throws InvalidNodeRefException 304 { 305 Map <QName, Serializable > result = new HashMap <QName, Serializable >(); 306 307 309 Collection <ChildAssociationRef> children = this.dbNodeService.getChildAssocs(convertNodeRef(nodeRef)); 310 for (ChildAssociationRef child : children) 311 { 312 if (child.getQName().equals(CHILD_QNAME_VERSIONED_ATTRIBUTES)) 313 { 314 NodeRef versionedAttribute = child.getChildRef(); 315 316 Serializable value = null; 318 QName qName = (QName)this.dbNodeService.getProperty(versionedAttribute, PROP_QNAME_QNAME); 319 Boolean isMultiValue = (Boolean )this.dbNodeService.getProperty(versionedAttribute, PROP_QNAME_IS_MULTI_VALUE); 320 if (isMultiValue.booleanValue() == false) 321 { 322 value = this.dbNodeService.getProperty(versionedAttribute, PROP_QNAME_VALUE); 323 } 324 else 325 { 326 value = this.dbNodeService.getProperty(versionedAttribute, PROP_QNAME_MULTI_VALUE); 327 } 328 329 result.put(qName, value); 330 } 331 } 332 333 return result; 334 } 335 336 339 public Serializable getProperty(NodeRef nodeRef, QName qname) throws InvalidNodeRefException 340 { 341 343 Map <QName, Serializable > properties = getProperties(convertNodeRef(nodeRef)); 344 return properties.get(qname); 345 } 346 347 350 public void setProperties(NodeRef nodeRef, Map <QName, Serializable > properties) throws InvalidNodeRefException 351 { 352 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 354 } 355 356 359 public void setProperty(NodeRef nodeRef, QName qame, Serializable value) throws InvalidNodeRefException 360 { 361 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 363 } 364 365 370 public List <ChildAssociationRef> getParentAssocs(NodeRef nodeRef) 371 { 372 return getParentAssocs(nodeRef, RegexQNamePattern.MATCH_ALL, RegexQNamePattern.MATCH_ALL); 373 } 374 375 380 public List <ChildAssociationRef> getParentAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern) 381 { 382 List <ChildAssociationRef> result = new ArrayList <ChildAssociationRef>(); 383 if (qnamePattern.isMatch(rootAssocName) == true) 384 { 385 result.add(new ChildAssociationRef( 386 ContentModel.ASSOC_CHILDREN, 387 dbNodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, STORE_ID)), 388 rootAssocName, 389 nodeRef)); 390 } 391 return result; 392 } 393 394 398 public List <ChildAssociationRef> getChildAssocs(NodeRef nodeRef) throws InvalidNodeRefException 399 { 400 return getChildAssocs(convertNodeRef(nodeRef), RegexQNamePattern.MATCH_ALL, RegexQNamePattern.MATCH_ALL); 401 } 402 403 406 public List <ChildAssociationRef> getChildAssocs(NodeRef nodeRef, QNamePattern typeQNamePattern, QNamePattern qnamePattern) throws InvalidNodeRefException 407 { 408 List <ChildAssociationRef> childAssocRefs = this.dbNodeService.getChildAssocs( 410 convertNodeRef(nodeRef), 411 RegexQNamePattern.MATCH_ALL, CHILD_QNAME_VERSIONED_CHILD_ASSOCS); 412 List <ChildAssociationRef> result = new ArrayList <ChildAssociationRef>(childAssocRefs.size()); 413 for (ChildAssociationRef childAssocRef : childAssocRefs) 414 { 415 NodeRef childRef = childAssocRef.getChildRef(); 417 NodeRef referencedNode = (NodeRef)this.dbNodeService.getProperty(childRef, ContentModel.PROP_REFERENCE); 418 419 QName qName = (QName)this.dbNodeService.getProperty(childRef, PROP_QNAME_ASSOC_QNAME); 421 422 if (qnamePattern.isMatch(qName) == true) 423 { 424 QName assocType = (QName)this.dbNodeService.getProperty(childRef, PROP_QNAME_ASSOC_TYPE_QNAME); 426 boolean isPrimary = ((Boolean )this.dbNodeService.getProperty(childRef, PROP_QNAME_IS_PRIMARY)).booleanValue(); 427 int nthSibling = ((Integer )this.dbNodeService.getProperty(childRef, PROP_QNAME_NTH_SIBLING)).intValue(); 428 429 ChildAssociationRef newChildAssocRef = new ChildAssociationRef( 431 assocType, 432 nodeRef, 433 qName, 434 referencedNode, 435 isPrimary, 436 nthSibling); 437 result.add(newChildAssocRef); 438 } 439 } 440 441 Collections.sort(result); 443 444 return result; 445 } 446 447 450 public ChildAssociationRef getPrimaryParent(NodeRef nodeRef) throws InvalidNodeRefException 451 { 452 return new ChildAssociationRef( 453 ContentModel.ASSOC_CHILDREN, 454 dbNodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, STORE_ID)), 455 rootAssocName, 456 nodeRef); 457 } 458 459 462 public AssociationRef createAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) 463 throws InvalidNodeRefException, AssociationExistsException 464 { 465 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 467 } 468 469 472 public void removeAssociation(NodeRef sourceRef, NodeRef targetRef, QName assocTypeQName) 473 { 474 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 476 } 477 478 481 public List <AssociationRef> getTargetAssocs(NodeRef sourceRef, QNamePattern qnamePattern) 482 { 483 List <ChildAssociationRef> childAssocRefs = this.dbNodeService.getChildAssocs( 485 convertNodeRef(sourceRef), 486 RegexQNamePattern.MATCH_ALL, CHILD_QNAME_VERSIONED_ASSOCS); 487 List <AssociationRef> result = new ArrayList <AssociationRef>(childAssocRefs.size()); 488 for (ChildAssociationRef childAssocRef : childAssocRefs) 489 { 490 NodeRef childRef = childAssocRef.getChildRef(); 492 NodeRef referencedNode = (NodeRef)this.dbNodeService.getProperty(childRef, ContentModel.PROP_REFERENCE); 493 494 QName qName = (QName)this.dbNodeService.getProperty(childRef, PROP_QNAME_ASSOC_TYPE_QNAME); 496 497 if (qnamePattern.isMatch(qName) == true) 498 { 499 AssociationRef newAssocRef = new AssociationRef(sourceRef, qName, referencedNode); 500 result.add(newAssocRef); 501 } 502 } 503 504 return result; 505 } 506 507 510 public List <AssociationRef> getSourceAssocs(NodeRef sourceRef, QNamePattern qnamePattern) 511 { 512 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 514 } 515 516 519 public Path getPath(NodeRef nodeRef) throws InvalidNodeRefException 520 { 521 ChildAssociationRef childAssocRef = getPrimaryParent(nodeRef); 522 Path path = new Path(); 523 path.append(new Path.ChildAssocElement(childAssocRef)); 524 return path; 525 } 526 527 530 public List <Path> getPaths(NodeRef nodeRef, boolean primaryOnly) throws InvalidNodeRefException 531 { 532 List <Path> paths = new ArrayList <Path>(1); 533 paths.add(getPath(nodeRef)); 534 return paths; 535 } 536 537 public List <NodeRef> selectNodes(NodeRef contextNode, String XPath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver, boolean followAllParentLinks) 538 { 539 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 541 } 542 543 public List <Serializable > selectProperties(NodeRef contextNode, String XPath, QueryParameterDefinition[] parameters, NamespacePrefixResolver namespacePrefixResolver, boolean followAllParentLinks) 544 { 545 throw new UnsupportedOperationException (MSG_UNSUPPORTED); 547 } 548 549 public boolean contains(NodeRef nodeRef, QName property, String sqlLikePattern) 550 { 551 throw new UnsupportedOperationException (); 553 } 554 555 public boolean like(NodeRef nodeRef, QName property, String sqlLikePattern, boolean includeFTS) 556 { 557 throw new UnsupportedOperationException (); 559 } 560 561 562 } 563 | Popular Tags |