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