*/
protected synchronized boolean changeSiblingNodesPriorities(ALNode node, String parentNodeId, String nextNodeId ) throws PortalException {
ALNode firstNode = null, nextNode = null;
String firstNodeId = null;
int priority = 0, nextPriority = 0, prevPriority = 0, range[] = null, prevRange[] = null, nextRange[] = null;
PriorityRestriction priorityRestriction = null;
String nodeId = node.getId();
ALFolder parent = getLayoutFolder(parentNodeId);
if ( parentNodeId != null ) {
firstNodeId = parent.getFirstChildNodeId();
// if the node is equal the first node in the sibling line we get the next node
if ( nodeId.equals(firstNodeId) )
firstNodeId = node.getNextNodeId();
if ( firstNodeId == null ) return true;
} else
return false;
firstNode = getLayoutNode(firstNodeId);
if ( nextNodeId != null ) {
nextNode = getLayoutNode(nextNodeId);
nextPriority = nextNode.getPriority();
priorityRestriction = getPriorityRestriction(nextNode);
nextRange = priorityRestriction.getRange();
}
priority = node.getPriority();
priorityRestriction = getPriorityRestriction(node);
range = priorityRestriction.getRange();
// If we add a new node to the beginning of the sibling line
if ( firstNodeId.equals(nextNodeId) ) {
if ( range[1] <= nextRange[0] ) return false;
if ( priority > nextPriority ) return true;
if ( range[1] > nextPriority ) {
node.setPriority(range[1]);
return true;
}
if ( (nextPriority+1) <= range[1] && (nextPriority+1) >= range[0] ) {
node.setPriority(nextPriority+1);
return true;
}
}
// If we add a new node to the end of the sibling line
if ( nextNode == null ) {
// Getting the last node
ALNode lastNode = getLastSiblingNode(firstNodeId);
int lastPriority = lastNode.getPriority();
PriorityRestriction lastPriorityRestriction = getPriorityRestriction(lastNode);
int[] lastRange = lastPriorityRestriction.getRange();
if ( range[0] >= lastRange[1] ) return false;
if ( priority < lastPriority ) return true;
if ( range[0] < lastPriority ) {
node.setPriority(range[0]);
return true;
}
if ( (lastPriority-1) <= range[1] && (lastPriority-1) >= range[0] ) {
node.setPriority(range[0]);
return true;
}
}
// If we add a new node in a general case
if ( nextNode != null && !nextNode.equals(firstNode) && !nodeId.equals(nextNodeId) ) {
// Getting the last node
ALNode prevNode = getLayoutNode(nextNode.getPreviousNodeId());
prevPriority = prevNode.getPriority();
PriorityRestriction lastPriorityRestriction = getPriorityRestriction(prevNode);
prevRange = lastPriorityRestriction.getRange();
if ( range[1] <= nextRange[0] || range[0] >= prevRange[1] ) return false;
if ( priority < prevPriority && priority > nextPriority ) return true;