001/* 002 * (C) Copyright 2013 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-2.1.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 * Mariana Cedica 016 */ 017package org.nuxeo.ecm.platform.routing.core.api; 018 019import java.io.Serializable; 020import java.util.ArrayList; 021import java.util.Collection; 022import java.util.Iterator; 023import java.util.List; 024import java.util.ListIterator; 025 026import org.nuxeo.ecm.platform.routing.core.impl.GraphNode; 027import org.nuxeo.ecm.platform.routing.core.impl.GraphNode.TaskInfo; 028 029/** 030 * Wraps the list of {@link GraphNode.TaskInfo} on a {@link GraphNode} to expose in a pretty way information to MVEL 031 * scripts. 032 * 033 * @since 5.7.3 034 */ 035public class TasksInfoWrapper implements List<GraphNode.TaskInfo>, Serializable { 036 037 private static final long serialVersionUID = 1L; 038 039 protected List<GraphNode.TaskInfo> tasks; 040 041 public TasksInfoWrapper() { 042 tasks = new ArrayList<GraphNode.TaskInfo>(); 043 } 044 045 public TasksInfoWrapper(List<GraphNode.TaskInfo> tasks) { 046 this.tasks = tasks; 047 } 048 049 public int getNumberEndedWithStatus(String status) { 050 int noEndedWithStatus = 0; 051 for (GraphNode.TaskInfo taskInfo : tasks) { 052 if (taskInfo.getStatus() != null && status.equals(taskInfo.getStatus())) { 053 noEndedWithStatus++; 054 } 055 } 056 return noEndedWithStatus; 057 } 058 059 @Override 060 public int size() { 061 return tasks.size(); 062 } 063 064 @Override 065 public boolean isEmpty() { 066 return tasks.isEmpty(); 067 } 068 069 @Override 070 public boolean contains(Object o) { 071 return tasks.contains(o); 072 } 073 074 @Override 075 public Iterator<TaskInfo> iterator() { 076 return tasks.iterator(); 077 } 078 079 @Override 080 public Object[] toArray() { 081 return tasks.toArray(); 082 } 083 084 @Override 085 public <T> T[] toArray(T[] a) { 086 return tasks.toArray(a); 087 } 088 089 @Override 090 public boolean add(TaskInfo e) { 091 return tasks.add(e); 092 } 093 094 @Override 095 public boolean remove(Object o) { 096 return tasks.remove(o); 097 } 098 099 @Override 100 public boolean containsAll(Collection<?> c) { 101 return tasks.containsAll(c); 102 } 103 104 @Override 105 public boolean addAll(Collection<? extends TaskInfo> c) { 106 return tasks.addAll(c); 107 } 108 109 @Override 110 public boolean addAll(int index, Collection<? extends TaskInfo> c) { 111 return tasks.addAll(index, c); 112 } 113 114 @Override 115 public boolean removeAll(Collection<?> c) { 116 return tasks.removeAll(c); 117 } 118 119 @Override 120 public boolean retainAll(Collection<?> c) { 121 return tasks.retainAll(c); 122 } 123 124 @Override 125 public void clear() { 126 tasks.clear(); 127 128 } 129 130 @Override 131 public TaskInfo get(int index) { 132 return tasks.get(index); 133 } 134 135 @Override 136 public TaskInfo set(int index, TaskInfo element) { 137 return tasks.set(index, element); 138 } 139 140 @Override 141 public void add(int index, TaskInfo element) { 142 tasks.add(index, element); 143 144 } 145 146 @Override 147 public TaskInfo remove(int index) { 148 return tasks.remove(index); 149 } 150 151 @Override 152 public int indexOf(Object o) { 153 return tasks.indexOf(o); 154 } 155 156 @Override 157 public int lastIndexOf(Object o) { 158 return tasks.lastIndexOf(o); 159 } 160 161 @Override 162 public ListIterator<TaskInfo> listIterator() { 163 return tasks.listIterator(); 164 } 165 166 @Override 167 public ListIterator<TaskInfo> listIterator(int index) { 168 return tasks.listIterator(index); 169 } 170 171 @Override 172 public List<TaskInfo> subList(int fromIndex, int toIndex) { 173 return tasks.subList(fromIndex, toIndex); 174 } 175}