001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 */
017package org.nuxeo.ecm.platform.routing.api.helper;
018
019import org.nuxeo.ecm.core.api.CoreSession;
020import org.nuxeo.ecm.core.api.DocumentModel;
021import org.nuxeo.ecm.core.api.IdRef;
022import org.nuxeo.ecm.core.api.UnrestrictedSessionRunner;
023import org.nuxeo.ecm.platform.routing.api.DocumentRoutingConstants;
024
025/***
026 * Set the position of the child to be run once the step with the given id it's finished.
027 *
028 * @since 5.5
029 * @deprecated since 5.9.2 - Use only routes of type 'graph'
030 */
031@Deprecated
032public class ConditionalFolderUpdateRunner {
033
034    protected String stepDocId;
035
036    public ConditionalFolderUpdateRunner(String stepDocId) {
037        this.stepDocId = stepDocId;
038    }
039
040    public void setStepToBeExecutedNext(CoreSession session, final String nextStepPos) {
041        new UnrestrictedSessionRunner(session) {
042
043            @Override
044            public void run() {
045                // get the parent container and set on it the id of the doc
046                // to be run next
047                DocumentModel condFolder = session.getDocument(session.getParentDocumentRef(new IdRef(stepDocId)));
048                if (!condFolder.hasFacet(DocumentRoutingConstants.CONDITIONAL_STEP_FACET)) {
049                    return;
050                }
051                condFolder.setPropertyValue(DocumentRoutingConstants.STEP_TO_BE_EXECUTED_NEXT_PROPERTY_NAME,
052                        nextStepPos);
053                session.saveDocument(condFolder);
054            }
055        }.runUnrestricted();
056    }
057}