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