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 /** 055 * @param routeInstance 056 * @param parentFolder 057 * @return 058 */ 059 DocumentModel saveDocumentRouteInstanceAsNewModel(DocumentModel routeInstance, DocumentModel parentFolder, 060 String newName, CoreSession session); 061 062 /** 063 * Will get, and create if it does not exists the root document in which {@link DocumentRoute} structure will be 064 * created. 065 * 066 * @param session The session use to get or create the document. 067 * @return The root of the {@link DocumentRoute} structure. 068 */ 069 DocumentModel getOrCreateRootOfDocumentRouteInstanceStructure(CoreSession session); 070 071 /** 072 * Returns a folder in which new model, created from an instance of route will be stored. 073 * 074 * @param session the session of the user 075 * @param instance the instance that will be persisted as new model. 076 */ 077 DocumentModel getParentFolderForNewModel(CoreSession session, DocumentModel instance); 078 079 /** 080 * Return the new name of a model when it is created from an instance. 081 * 082 * @see DocumentRoutingService#saveRouteAsNewModel(DocumentRoute, String, CoreSession) 083 * @return the new name 084 */ 085 String getNewModelName(DocumentModel instance); 086 087 /** 088 * Gets or creates the parent folder for a {@link DocumentRoute} route instance. 089 * 090 * @return The parent folder in which the {@link DocumentRoute} will be persisted. 091 * @since 5.6 092 */ 093 DocumentModel getParentFolderForDocumentRouteModels(CoreSession session); 094}