001/*
002 * (C) Copyright 2009 Nuxeo SA (http://nuxeo.com/) and others.
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 * Contributors:
017 *     arussel
018 */
019package org.nuxeo.ecm.platform.routing.api;
020
021import org.nuxeo.ecm.core.api.CoreSession;
022import org.nuxeo.ecm.core.api.DocumentModel;
023
024/**
025 * The DocumentRoutingPersister is responsible creating a folder structure to persist {@link DocumentRoute} instance,
026 * persisting new {@link DocumentRoute} instances and creating {@link DocumentRoute} model from {@link DocumentRoute}
027 * instance.
028 *
029 * @author arussel
030 */
031public interface DocumentRoutingPersister {
032    /**
033     * The name of the document in which will be create
034     */
035    String DocumentRouteInstanceRootName = "DocumentRouteInstancesRoot";
036
037    /**
038     * Get or create the parent folder for a {@link DocumentRoute} route instance.
039     *
040     * @param document The {@link DocumentRoute} model from which the instance will be created. Its metadata may be used
041     *            when creating the parent.
042     * @return The parent folder in which the {@link DocumentRoute} will be persisted.
043     */
044    DocumentModel getParentFolderForDocumentRouteInstance(DocumentModel document, CoreSession session);
045
046    /**
047     * Creates a blank {@link DocumentRoute} instance from a model.
048     *
049     * @param model the model
050     * @return The created {@link DocumentRoute}
051     */
052    DocumentModel createDocumentRouteInstanceFromDocumentRouteModel(DocumentModel model, CoreSession session);
053
054    DocumentModel saveDocumentRouteInstanceAsNewModel(DocumentModel routeInstance, DocumentModel parentFolder,
055            String newName, CoreSession session);
056
057    /**
058     * Will get, and create if it does not exists the root document in which {@link DocumentRoute} structure will be
059     * created.
060     *
061     * @param session The session use to get or create the document.
062     * @return The root of the {@link DocumentRoute} structure.
063     */
064    DocumentModel getOrCreateRootOfDocumentRouteInstanceStructure(CoreSession session);
065
066    /**
067     * Returns a folder in which new model, created from an instance of route will be stored.
068     *
069     * @param session the session of the user
070     * @param instance the instance that will be persisted as new model.
071     */
072    DocumentModel getParentFolderForNewModel(CoreSession session, DocumentModel instance);
073
074    /**
075     * Return the new name of a model when it is created from an instance.
076     *
077     * @see DocumentRoutingService#saveRouteAsNewModel(DocumentRoute, CoreSession)
078     * @return the new name
079     */
080    String getNewModelName(DocumentModel instance);
081
082    /**
083     * Gets or creates the parent folder for a {@link DocumentRoute} route instance.
084     *
085     * @return The parent folder in which the {@link DocumentRoute} will be persisted.
086     * @since 5.6
087     */
088    DocumentModel getParentFolderForDocumentRouteModels(CoreSession session);
089}