1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.watchlist.internal.notification

File EventsAndSubscribersSource.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

0
11
5
1
102
43
5
0.45
2.2
5
1

Classes

Class Line # Actions
EventsAndSubscribersSource 38 11 0% 5 5
0.687568.8%
 

Contributing tests

This file is covered by 10 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.watchlist.internal.notification;
21   
22    import java.util.List;
23    import java.util.Map;
24   
25    import org.apache.commons.collections4.ListUtils;
26    import org.apache.commons.lang3.builder.ToStringBuilder;
27    import org.xwiki.model.reference.DocumentReference;
28    import org.xwiki.text.XWikiToStringBuilder;
29    import org.xwiki.watchlist.internal.api.WatchListEvent;
30   
31    /**
32    * Represents the inputs of the {@link WatchListEventMimeMessageFactory}: a list of events and a list of subscribers
33    * that might be interested.
34    *
35    * @version $Id: 0ce818a463c8c9967c5969a85b77a1fb6fe06001 $
36    * @since 7.1M1
37    */
 
38    public class EventsAndSubscribersSource
39    {
40    /**
41    * The list of subscribers to process.
42    */
43    public static final String SUBSCRIBERS_PARAMETER = "subscribers";
44   
45    /**
46    * The list of events to process.
47    */
48    public static final String EVENTS_PARAMETER = "events";
49   
50    private List<WatchListEvent> events;
51   
52    private List<DocumentReference> subscribers;
53   
54    /**
55    * @param events see {@link #getEvents()}
56    * @param subscribers see {@link #getSubscribers()}
57    */
 
58  71 toggle public EventsAndSubscribersSource(List<WatchListEvent> events, List<DocumentReference> subscribers)
59    {
60  71 this.events = events;
61  71 this.subscribers = subscribers;
62    }
63   
64    /**
65    * @return the list of events that should be considered
66    */
 
67  35 toggle public List<WatchListEvent> getEvents()
68    {
69  35 return events;
70    }
71   
72    /**
73    * @return the list of subscribers that might be interested in the events
74    */
 
75  30 toggle public List<DocumentReference> getSubscribers()
76    {
77  30 return subscribers;
78    }
79   
80    /**
81    * @param sourceMap a Map containing the list of events and subscribers to iterate over. The supported map keys are
82    * {@code events} and {@code subscribers}
83    * @return the typed instance representing the inputs passed
84    */
 
85  60 toggle public static EventsAndSubscribersSource parse(Map<String, Object> sourceMap)
86    {
87  60 List<WatchListEvent> events = ListUtils.emptyIfNull((List<WatchListEvent>) sourceMap.get(EVENTS_PARAMETER));
88  60 List<DocumentReference> subscribers =
89    ListUtils.emptyIfNull((List<DocumentReference>) sourceMap.get(SUBSCRIBERS_PARAMETER));
90   
91  60 return new EventsAndSubscribersSource(events, subscribers);
92    }
93   
 
94  0 toggle @Override
95    public String toString()
96    {
97  0 ToStringBuilder builder = new XWikiToStringBuilder(this);
98  0 builder.append(EVENTS_PARAMETER, getEvents());
99  0 builder.append(SUBSCRIBERS_PARAMETER, getSubscribers());
100  0 return builder.toString();
101    }
102    }