001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Julien Anguenot
011 *     Florent Guillaume
012 */
013
014package org.nuxeo.ecm.core.lifecycle;
015
016import java.util.Collection;
017import java.util.List;
018import java.util.Map;
019
020import org.nuxeo.ecm.core.api.LifeCycleException;
021import org.nuxeo.ecm.core.lifecycle.event.BulkLifeCycleChangeListener;
022import org.nuxeo.ecm.core.model.Document;
023
024/**
025 * Life cycle service.
026 *
027 * @see org.nuxeo.ecm.core.lifecycle.impl.LifeCycleServiceImpl
028 * @author Julien Anguenot
029 * @author Florent Guillaume
030 */
031public interface LifeCycleService {
032
033    /**
034     * Initializes the life cycle for the given document.
035     * <p>
036     * Document state will be set to the life cycle initial state.
037     *
038     * @param doc the document instance
039     * @throws LifeCycleException
040     */
041    void initialize(Document doc) throws LifeCycleException;
042
043    /**
044     * Initializes the life cycle for the given document.
045     * <p>
046     * Tries to set given state on document, if it's a valid initial state.
047     *
048     * @param doc the document instance
049     * @param initialStateName the initial state name
050     * @throws LifeCycleException
051     */
052    void initialize(Document doc, String initialStateName) throws LifeCycleException;
053
054    /**
055     * Follows a given transition.
056     *
057     * @param doc the Document instance
058     * @param transitionName the transition name
059     * @throws LifeCycleException
060     */
061    void followTransition(Document doc, String transitionName) throws LifeCycleException;
062
063    /**
064     * Returns a life cycle given its name.
065     *
066     * @param name the life cycle's name
067     * @return a life cycle descriptor instance or null if not found.
068     */
069    LifeCycle getLifeCycleByName(String name);
070
071    /**
072     * Returns all the registered life cycles.
073     *
074     * @return a collection of lifecycle descriptors
075     */
076    Collection<LifeCycle> getLifeCycles();
077
078    /**
079     * Returns the types which follow a given life cycle.
080     *
081     * @param lifeCycleName a string holding the name of the life cycle
082     * @return a collection of type names as strings
083     */
084    Collection<String> getTypesFor(String lifeCycleName);
085
086    /**
087     * Returns the lifecycle name that the given type follows.
088     *
089     * @param typeName the type's name
090     * @return the life cycle name
091     */
092    String getLifeCycleNameFor(String typeName);
093
094    /**
095     * Returns a list of transition for which, when a it is followed, it should no recurse in its children. The
096     * {@link BulkLifeCycleChangeListener} will listen to the transition taken event and call a follow transition on the
097     * children of the document if the document is folderish. It check this list of transition to find out if it should
098     * recurse.
099     *
100     * @see BulkLifeCycleChangeListener
101     * @param docTypeName The doc type
102     * @return a list of transition name
103     */
104    List<String> getNonRecursiveTransitionForDocType(String docTypeName);
105
106    /**
107     * Returns the mapping from types to life cycle names.
108     *
109     * @return a mapping from types to life cycle names
110     */
111    Map<String, String> getTypesMapping();
112
113    /**
114     * Returns the life cycle a given document follows.
115     *
116     * @param doc the document instance
117     * @return the life cycle instance
118     */
119    LifeCycle getLifeCycleFor(Document doc);
120
121    /**
122     * Sets the current state to the initial state as defined by the associated lifecycle.
123     *
124     * @param doc
125     * @throws LifeCycleException
126     */
127    void reinitLifeCycle(Document doc) throws LifeCycleException;
128
129}