protected List < ItemState > reindexSameNameSiblings ( NodeData cause , ItemDataConsumer dataManager ) throws RepositoryException { List < ItemState > changes = new ArrayList < ItemState > ( ) ; NodeData parentNodeData = ( NodeData ) dataManager . getItemData ( cause . getParentIdentifier ( ) ) ; NodeData nextSibling = ( NodeData ) dataManager . getItemData ( parentNodeData , new QPathEntry ( cause . getQPath ( ) . getName ( ) , cause . getQPath ( ) . getIndex ( ) + 1 ) , ItemType . NODE ) ; String reindexedId = null ; // repeat till next sibling exists and it's not a caused Node (deleted or moved to) or just // reindexed while ( nextSibling != null && ! nextSibling . getIdentifier ( ) . equals ( cause . getIdentifier ( ) ) && ! nextSibling . getIdentifier ( ) . equals ( reindexedId ) ) { QPath siblingOldPath = QPath . makeChildPath ( nextSibling . getQPath ( ) . makeParentPath ( ) , nextSibling . getQPath ( ) . getName ( ) , nextSibling . getQPath ( ) . getIndex ( ) ) ; // update with new index QPath siblingPath = QPath . makeChildPath ( nextSibling . getQPath ( ) . makeParentPath ( ) , nextSibling . getQPath ( ) . getName ( ) , nextSibling . getQPath ( ) . getIndex ( ) - 1 ) ; NodeData reindexed = new TransientNodeData ( siblingPath , nextSibling . getIdentifier ( ) , nextSibling . getPersistedVersion ( ) , nextSibling . getPrimaryTypeName ( ) , nextSibling . getMixinTypeNames ( ) , nextSibling . getOrderNumber ( ) , nextSibling . getParentIdentifier ( ) , nextSibling . getACL ( ) ) ; reindexedId = reindexed . getIdentifier ( ) ; ItemState reindexedState = ItemState . createUpdatedState ( reindexed ) ; changes . add ( reindexedState ) ; itemsPool . reload ( reindexed ) ; reloadDescendants ( siblingOldPath , siblingPath ) ; // next... nextSibling = ( NodeData ) dataManager . getItemData ( parentNodeData , new QPathEntry ( nextSibling . getQPath ( ) . getName ( ) , nextSibling . getQPath ( ) . getIndex ( ) + 1 ) , ItemType . NODE ) ; } return changes ; }
Reindex same - name siblings of the node Reindex is actual for remove move only . If node is added then its index always is a last in list of childs .