001/*
002 * (C) Copyright 2010 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 *     Alexandre Russel
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.DocumentRoute;
024import org.nuxeo.ecm.platform.routing.api.DocumentRouteStep;
025
026/**
027 * Allows to resume a route from the id of a step.
028 *
029 * @author <a href="mailto:arussel@nuxeo.com">Alexandre Russel</a>
030 * @deprecated since 5.9.2 - Use only routes of type 'graph'
031 */
032@Deprecated
033public class StepResumeRunner {
034
035    protected String stepDocId;
036
037    public StepResumeRunner(String stepDocId) {
038        this.stepDocId = stepDocId;
039    }
040
041    public void resumeStep(CoreSession session) {
042        DocumentModel model = session.getDocument(new IdRef(stepDocId));
043        DocumentRouteStep step = model.getAdapter(DocumentRouteStep.class);
044        step.setDone(session);
045        new UnrestrictedSessionRunner(session) {
046            @Override
047            public void run() {
048                DocumentModel model = session.getDocument(new IdRef(stepDocId));
049                DocumentRouteStep step = model.getAdapter(DocumentRouteStep.class);
050                DocumentRoute route = step.getDocumentRoute(session);
051                route.run(session);
052            }
053        }.runUnrestricted();
054    }
055}