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.restapi.server.jaxrs.routing.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    @Override
050    public void run() {
051        DocumentModel workflowInstanceDoc = session.getDocument(new IdRef(workflowInstanceId));
052        workflowInstance = workflowInstanceDoc.getAdapter(GraphRoute.class);
053        node = workflowInstance.getNode(nodeId);
054        workflowInstanceDoc.detach(true);
055        node.getDocument().detach(true);
056    }
057
058}