001/*
002 * (C) Copyright 2011 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 *     Nuxeo - initial API and implementation
018 */
019package org.nuxeo.ecm.platform.routing.api.helper;
020
021import org.nuxeo.ecm.core.api.CoreSession;
022import org.nuxeo.ecm.core.api.DocumentModel;
023import org.nuxeo.ecm.core.api.IdRef;
024import org.nuxeo.ecm.core.api.UnrestrictedSessionRunner;
025import org.nuxeo.ecm.platform.routing.api.DocumentRoutingConstants;
026
027/***
028 * Set the position of the child to be run once the step with the given id it's finished.
029 *
030 * @since 5.5
031 * @deprecated since 5.9.2 - Use only routes of type 'graph'
032 */
033@Deprecated
034public class ConditionalFolderUpdateRunner {
035
036    protected String stepDocId;
037
038    public ConditionalFolderUpdateRunner(String stepDocId) {
039        this.stepDocId = stepDocId;
040    }
041
042    public void setStepToBeExecutedNext(CoreSession session, final String nextStepPos) {
043        new UnrestrictedSessionRunner(session) {
044
045            @Override
046            public void run() {
047                // get the parent container and set on it the id of the doc
048                // to be run next
049                DocumentModel condFolder = session.getDocument(session.getParentDocumentRef(new IdRef(stepDocId)));
050                if (!condFolder.hasFacet(DocumentRoutingConstants.CONDITIONAL_STEP_FACET)) {
051                    return;
052                }
053                condFolder.setPropertyValue(DocumentRoutingConstants.STEP_TO_BE_EXECUTED_NEXT_PROPERTY_NAME,
054                        nextStepPos);
055                session.saveDocument(condFolder);
056            }
057        }.runUnrestricted();
058    }
059}