001/*
002 *  Copyright 2010 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016
017package org.ametys.plugins.repository;
018
019/**
020 * {@link AmetysObject} that can be ordered or moved
021 */
022public interface MovableAmetysObject extends AmetysObject
023{
024    /**
025     * Move the current object as a new child of the given object. This node will be the last child. You should call canMoveTo to know if this is a supported operation.
026     * @param newParent The new parent for the current object. Can not be null. Can not be a child of the current node. Must be a TraversableAmetyObject.
027     * @param renameIfExist true to rename moved page if a page with same name already exist
028     * @throws AmetysRepositoryException if an error occurs.
029     * @throws RepositoryIntegrityViolationException if a page with the same name already exists.
030     */
031    public void moveTo(AmetysObject newParent, boolean renameIfExist) throws AmetysRepositoryException, RepositoryIntegrityViolationException;
032
033    /**
034     * Test if a move can be a success or if it is impossible (e.g. due to the implementation of the target)
035     * @param newParent See moveTo.
036     * @return true if the move operation may succeed. If false is returned and you call moveTo anyway, you may encontered a RuntimeException (such as UnsupportedOperationException)
037     * @throws AmetysRepositoryException if an error occurs.
038     */
039    public boolean canMoveTo(AmetysObject newParent) throws AmetysRepositoryException;
040    
041    /**
042     * Order a node before another sibling node (or as the last node)
043     * @param siblingNode The node that will be the next sibling node of the current node. Must have the same parent as the current node. Can be null to set the current node as the last node.
044     * @throws AmetysRepositoryException if an error occurs.
045     */
046    public void orderBefore(AmetysObject siblingNode) throws AmetysRepositoryException;
047}