001/*
002 * (C) Copyright 2014 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 *     <a href="mailto:grenard@nuxeo.com">Guillaume Renard</a>
018 *
019 */
020
021package org.nuxeo.ecm.platform.routing.core.io;
022
023import org.nuxeo.ecm.core.api.CoreSession;
024import org.nuxeo.ecm.core.api.DocumentModel;
025import org.nuxeo.ecm.core.api.IdRef;
026import org.nuxeo.ecm.core.api.UnrestrictedSessionRunner;
027import org.nuxeo.ecm.platform.routing.core.impl.GraphNode;
028import org.nuxeo.ecm.platform.routing.core.impl.GraphRoute;
029
030/**
031 * @since 7.2
032 */
033public class NodeAccessRunner extends UnrestrictedSessionRunner {
034
035    GraphNode node;
036
037    GraphRoute workflowInstance;
038
039    String workflowInstanceId;
040
041    String nodeId;
042
043    public NodeAccessRunner(CoreSession session, String workflowInstanceId, String nodeId) {
044        super(session);
045        this.workflowInstanceId = workflowInstanceId;
046        this.nodeId = nodeId;
047    }
048
049    /**
050     * @since 8.2
051     */
052    public GraphNode getNode() {
053        return node;
054    }
055
056    /**
057     * @since 8.2
058     */
059    public GraphRoute getWorkflowInstance() {
060        return workflowInstance;
061    }
062
063    @Override
064    public void run() {
065        DocumentModel workflowInstanceDoc = session.getDocument(new IdRef(workflowInstanceId));
066        workflowInstance = workflowInstanceDoc.getAdapter(GraphRoute.class);
067        node = workflowInstance.getNode(nodeId);
068        workflowInstanceDoc.detach(true);
069        node.getDocument().detach(true);
070    }
071
072}