1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.notifications.notifiers.internal.email

File SortedEvent.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart6.png
72% of files have more coverage

Code metrics

2
19
12
1
163
75
13
0.68
1.58
12
1.08

Classes

Class Line # Actions
SortedEvent 38 19 0% 13 13
0.606060660.6%
 

Contributing tests

This file is covered by 1 test. .

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.notifications.notifiers.internal.email;
21   
22    import java.util.ArrayList;
23    import java.util.Collections;
24    import java.util.Comparator;
25    import java.util.Date;
26    import java.util.List;
27   
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.notifications.CompositeEvent;
30   
31    /**
32    * Wrap a {@link CompositeEvent} so that we can store the HTML-rendered and plain text-rendered version of the event
33    * next to the event.
34    *
35    * @version $Id: 52c7812d879b0bb1a4c3913faaf93ef4bcdd2aaf $
36    * @since 9.11RC1
37    */
 
38    public class SortedEvent
39    {
40    private CompositeEvent event;
41   
42    private String html;
43   
44    private String plainText;
45   
46    private List<SortedEvent> eventsWithTheSameDocument = new ArrayList<>();
47   
48    private List<SortedEvent> children = new ArrayList<>();
49   
50    /**
51    * Create a SortedEvent.
52    * @param event the event to wrap
53    * @param html the HTML-rendered version of the event
54    * @param plainText the plain text-rendered version of the event
55    */
 
56  4 toggle public SortedEvent(CompositeEvent event, String html, String plainText)
57    {
58  4 this.event = event;
59  4 this.html = html;
60  4 this.plainText = plainText;
61    }
62   
63    /**
64    * @return get the event
65    */
 
66  18 toggle public CompositeEvent getEvent()
67    {
68  18 return event;
69    }
70   
71    /**
72    * @return the HTML-rendered version of the event
73    */
 
74  2 toggle public String getHtml()
75    {
76  2 return html;
77    }
78   
79    /**
80    * @return the plain text-rendered version of the event
81    */
 
82  0 toggle public String getPlainText()
83    {
84  0 return plainText;
85    }
86   
87    /**
88    * Add an event that concern a document that is a child of the document concern by this event.
89    * @param event the event to add as a child
90    */
 
91  0 toggle public void addChild(SortedEvent event)
92    {
93  0 children.add(event);
94    }
95   
96    /**
97    * @return the events concerning children of the document concern by this event
98    */
 
99  2 toggle public List<SortedEvent> getChildren()
100    {
101  2 Collections.sort(children, Comparator.comparing(e -> e.getEvent().getDocument()));
102  2 return children;
103    }
104   
105    /**
106    * @param sortedEvent event to compare
107    * @return true if the current event concerns a document that is a parent of the document concerned by the other
108    * event.
109    */
 
110  2 toggle public boolean isParent(SortedEvent sortedEvent)
111    {
112  2 DocumentReference document = getDocument();
113  2 return document != null
114    && !document.equals(sortedEvent.getDocument())
115    && document.getName().equals("WebHome")
116    && sortedEvent.getDocument().hasParent(document.getLastSpaceReference());
117    }
118   
119    /**
120    * @return true if the event has children
121    */
 
122  2 toggle public boolean hasChildren()
123    {
124  2 return !children.isEmpty();
125    }
126   
127    /**
128    * @return a list of sorted events that concern the same document
129    */
 
130  2 toggle public List<SortedEvent> getEventsWithTheSameDocument()
131    {
132  2 return eventsWithTheSameDocument;
133    }
134   
135    /**
136    * Add a sorted event in the list of events that concern the same document.
137    * @param event event to add
138    */
 
139  0 toggle public void addEventWithTheSameDocument(SortedEvent event)
140    {
141  0 eventsWithTheSameDocument.add(event);
142  0 if (event.hasChildren()) {
143  0 children.addAll(event.children);
144  0 event.children.clear();
145    }
146    }
147   
148    /**
149    * @return document concerned by the event (can be null)
150    */
 
151  14 toggle public DocumentReference getDocument()
152    {
153  14 return event.getDocument();
154    }
155   
156    /**
157    * @return the date of the most recent event
158    */
 
159  0 toggle public Date getDate()
160    {
161  0 return event.getDate();
162    }
163    }