001/* 002 * (C) Copyright 2010-2012 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 * Florent Guillaume 017 */ 018package org.nuxeo.ecm.platform.routing.core.impl; 019 020import java.io.Serializable; 021import java.util.ArrayList; 022import java.util.List; 023import java.util.Map; 024 025import org.nuxeo.ecm.core.api.CoreSession; 026import org.nuxeo.ecm.core.api.DocumentModel; 027import org.nuxeo.ecm.core.api.DocumentModelList; 028import org.nuxeo.ecm.platform.routing.api.DocumentRouteElement; 029 030public abstract class AbstractRunner implements ElementRunner { 031 032 protected List<DocumentRouteElement> getChildrenElement(CoreSession session, DocumentRouteElement element) { 033 DocumentModelList children = session.getChildren(element.getDocument().getRef()); 034 List<DocumentRouteElement> elements = new ArrayList<DocumentRouteElement>(); 035 for (DocumentModel model : children) { 036 elements.add(model.getAdapter(DocumentRouteElement.class)); 037 } 038 return elements; 039 } 040 041 @Override 042 public void run(CoreSession session, DocumentRouteElement element, Map<String, Serializable> map) { 043 run(session, element); 044 } 045 046 @Override 047 public void resume(CoreSession session, DocumentRouteElement element, String nodeId, String taskId, 048 Map<String, Object> data, String status) { 049 throw new UnsupportedOperationException(); 050 } 051 052 @Deprecated 053 @Override 054 public void undo(CoreSession session, DocumentRouteElement element) { 055 throw new UnsupportedOperationException(); 056 } 057 058 @Override 059 public void cancel(CoreSession session, DocumentRouteElement element) { 060 List<DocumentRouteElement> children = getChildrenElement(session, element); 061 for (DocumentRouteElement child : children) { 062 child.cancel(session); 063 } 064 element.setCanceled(session); 065 } 066}