1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.watchlist.internal.documents; |
21 |
|
|
22 |
|
import java.util.Collection; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.annotation.Priority; |
26 |
|
import javax.inject.Inject; |
27 |
|
import javax.inject.Named; |
28 |
|
import javax.inject.Provider; |
29 |
|
import javax.inject.Singleton; |
30 |
|
|
31 |
|
import org.apache.commons.collections4.CollectionUtils; |
32 |
|
import org.apache.commons.lang3.StringUtils; |
33 |
|
import org.xwiki.component.annotation.Component; |
34 |
|
import org.xwiki.model.EntityType; |
35 |
|
import org.xwiki.model.reference.EntityReference; |
36 |
|
import org.xwiki.watchlist.internal.WatchListNotificationCache; |
37 |
|
import org.xwiki.watchlist.internal.api.AutomaticWatchMode; |
38 |
|
|
39 |
|
import com.xpn.xwiki.XWiki; |
40 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
41 |
|
import com.xpn.xwiki.internal.mandatory.AbstractMandatoryDocumentInitializer; |
42 |
|
import com.xpn.xwiki.objects.classes.BaseClass; |
43 |
|
import com.xpn.xwiki.objects.classes.DBListClass; |
44 |
|
import com.xpn.xwiki.objects.classes.ListClass; |
45 |
|
import com.xpn.xwiki.objects.classes.StaticListClass; |
46 |
|
|
47 |
|
|
48 |
|
@value |
49 |
|
|
50 |
|
@version |
51 |
|
|
52 |
|
@Component |
53 |
|
@Named(WatchListClassDocumentInitializer.DOCUMENT_FULL_NAME) |
54 |
|
@Singleton |
55 |
|
@Priority(10000) |
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 5 |
Complexity Density: 0.21 |
|
56 |
|
public class WatchListClassDocumentInitializer extends AbstractMandatoryDocumentInitializer |
57 |
|
{ |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
public static final String DOCUMENT_NAME = "WatchListClass"; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
public static final String DOCUMENT_FULL_NAME = XWiki.SYSTEM_SPACE + "." + DOCUMENT_NAME; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
public static final EntityReference DOCUMENT_REFERENCE = new EntityReference(DOCUMENT_NAME, EntityType.DOCUMENT, |
72 |
|
new EntityReference(XWiki.SYSTEM_SPACE, EntityType.SPACE)); |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
public static final String INTERVAL_PROPERTY = "interval"; |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
public static final String WIKIS_PROPERTY = "wikis"; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
public static final String SPACES_PROPERTY = "spaces"; |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
public static final String DOCUMENTS_PROPERTY = "documents"; |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
public static final String USERS_PROPERTY = "users"; |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
public static final String AUTOMATICWATCH_PROPERTY = "automaticwatch"; |
103 |
|
|
104 |
|
|
105 |
|
@value |
106 |
|
|
107 |
|
public static final String AUTOMATICWATCH_DEFAULT_VALUE = "default"; |
108 |
|
|
109 |
|
|
110 |
|
@value |
111 |
|
|
112 |
|
@Inject |
113 |
|
private Provider<WatchListNotificationCache> notificationCacheProvider; |
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
1 |
public WatchListClassDocumentInitializer()... |
119 |
|
{ |
120 |
1 |
super(DOCUMENT_REFERENCE); |
121 |
|
} |
122 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 2 |
Complexity Density: 0.12 |
|
123 |
4 |
@Override... |
124 |
|
public boolean updateDocument(XWikiDocument document) |
125 |
|
{ |
126 |
4 |
boolean needsUpdate = false; |
127 |
4 |
BaseClass bclass = document.getXClass(); |
128 |
|
|
129 |
|
|
130 |
4 |
needsUpdate |= bclass.addStaticListField(INTERVAL_PROPERTY, "Email Notifications Interval", ""); |
131 |
|
|
132 |
|
|
133 |
4 |
StaticListClass intervalClass = (StaticListClass) bclass.get(INTERVAL_PROPERTY); |
134 |
4 |
List<String> intervalValues = ListClass.getListFromString(intervalClass.getValues()); |
135 |
|
|
136 |
|
|
137 |
4 |
Collection<String> availableIntervals = notificationCacheProvider.get().getIntervals(); |
138 |
4 |
if (!CollectionUtils.disjunction(availableIntervals, intervalValues).isEmpty()) { |
139 |
3 |
needsUpdate = true; |
140 |
3 |
intervalClass.setValues(StringUtils.join(availableIntervals, ListClass.DEFAULT_SEPARATOR)); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
4 |
needsUpdate |= this.addWatchedElementField(bclass, WIKIS_PROPERTY, "Wiki List"); |
145 |
4 |
needsUpdate |= this.addWatchedElementField(bclass, SPACES_PROPERTY, "Space List"); |
146 |
4 |
needsUpdate |= this.addWatchedElementField(bclass, DOCUMENTS_PROPERTY, "Document List"); |
147 |
4 |
needsUpdate |= this.addWatchedElementField(bclass, USERS_PROPERTY, "User List"); |
148 |
|
|
149 |
|
|
150 |
4 |
String automaticWatchValues = |
151 |
|
String.format("%s%s%s", AUTOMATICWATCH_DEFAULT_VALUE, ListClass.DEFAULT_SEPARATOR, |
152 |
|
StringUtils.join(AutomaticWatchMode.values(), ListClass.DEFAULT_SEPARATOR)); |
153 |
4 |
needsUpdate |= bclass.addStaticListField(AUTOMATICWATCH_PROPERTY, "Automatic Watching", automaticWatchValues); |
154 |
|
|
155 |
|
|
156 |
4 |
needsUpdate |= setClassDocumentFields(document, "XWiki WatchList Notification Rules Class"); |
157 |
|
|
158 |
4 |
return needsUpdate; |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
@param |
163 |
|
@param |
164 |
|
@param |
165 |
|
@return |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
167 |
16 |
private boolean addWatchedElementField(BaseClass bclass, String name, String prettyName)... |
168 |
|
{ |
169 |
16 |
boolean needsUpdate = false; |
170 |
|
|
171 |
16 |
needsUpdate = bclass.addDBListField(name, prettyName, 80, true, null); |
172 |
16 |
if (needsUpdate) { |
173 |
|
|
174 |
4 |
DBListClass justAddedProperty = (DBListClass) bclass.get(name); |
175 |
4 |
justAddedProperty.setDisplayType(ListClass.DISPLAYTYPE_INPUT); |
176 |
|
} |
177 |
|
|
178 |
16 |
return needsUpdate; |
179 |
|
} |
180 |
|
} |