1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wiki.internal.descriptor.listener; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.xwiki.bridge.event.DocumentCreatedEvent; |
30 |
|
import org.xwiki.bridge.event.DocumentDeletedEvent; |
31 |
|
import org.xwiki.bridge.event.DocumentUpdatedEvent; |
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.model.EntityType; |
34 |
|
import org.xwiki.model.reference.EntityReference; |
35 |
|
import org.xwiki.observation.EventListener; |
36 |
|
import org.xwiki.observation.event.Event; |
37 |
|
import org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor; |
38 |
|
import org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilder; |
39 |
|
import org.xwiki.wiki.internal.descriptor.document.WikiDescriptorDocumentHelper; |
40 |
|
import org.xwiki.wiki.internal.manager.WikiDescriptorCache; |
41 |
|
|
42 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
43 |
|
import com.xpn.xwiki.objects.BaseObject; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@version |
49 |
|
@since |
50 |
|
|
51 |
|
@Component |
52 |
|
@Named("wikidescriptor") |
53 |
|
@Singleton |
|
|
| 96.9% |
Uncovered Elements: 1 (32) |
Complexity: 12 |
Complexity Density: 0.67 |
|
54 |
|
public class WikiDescriptorListener implements EventListener |
55 |
|
{ |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
static final EntityReference SERVER_CLASS = new EntityReference("XWikiServerClass", EntityType.DOCUMENT, |
60 |
|
new EntityReference("XWiki", EntityType.SPACE)); |
61 |
|
|
62 |
|
@Inject |
63 |
|
private WikiDescriptorBuilder builder; |
64 |
|
|
65 |
|
@Inject |
66 |
|
private WikiDescriptorCache cache; |
67 |
|
|
68 |
|
@Inject |
69 |
|
private WikiDescriptorDocumentHelper wikiDescriptorDocumentHelper; |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
512 |
@Override... |
72 |
|
public String getName() |
73 |
|
{ |
74 |
512 |
return "wikidescriptor"; |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
64 |
@Override... |
78 |
|
public List<Event> getEvents() |
79 |
|
{ |
80 |
64 |
return Arrays |
81 |
|
.<Event> asList(new DocumentCreatedEvent(), new DocumentUpdatedEvent(), new DocumentDeletedEvent()); |
82 |
|
} |
83 |
|
|
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 6 |
Complexity Density: 0.67 |
|
84 |
3971 |
@Override... |
85 |
|
public void onEvent(Event event, Object source, Object data) |
86 |
|
{ |
87 |
3971 |
XWikiDocument document = (XWikiDocument) source; |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
3971 |
if (event instanceof DocumentDeletedEvent || event instanceof DocumentUpdatedEvent) { |
92 |
586 |
removeExistingDescriptor(document.getOriginalDocument()); |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
3971 |
List<BaseObject> serverClassObjects = document.getXObjects(SERVER_CLASS); |
97 |
3971 |
if (serverClassObjects != null && !serverClassObjects.isEmpty()) { |
98 |
106 |
DefaultWikiDescriptor descriptor = this.builder.buildDescriptorObject(serverClassObjects, document); |
99 |
106 |
if (descriptor != null) { |
100 |
106 |
this.cache.add(descriptor); |
101 |
106 |
this.cache.setWikiIds(null); |
102 |
|
} |
103 |
|
} |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
106 |
586 |
private void removeExistingDescriptor(XWikiDocument document)... |
107 |
|
{ |
108 |
586 |
List<BaseObject> existingServerClassObjects = document.getXObjects(SERVER_CLASS); |
109 |
586 |
if (existingServerClassObjects != null && !existingServerClassObjects.isEmpty()) { |
110 |
72 |
String wikiId = |
111 |
|
this.wikiDescriptorDocumentHelper.getWikiIdFromDocumentReference(document.getDocumentReference()); |
112 |
72 |
DefaultWikiDescriptor existingDescriptor = this.cache.getFromId(wikiId); |
113 |
72 |
if (existingDescriptor != null) { |
114 |
46 |
this.cache.remove(existingDescriptor); |
115 |
46 |
this.cache.setWikiIds(null); |
116 |
|
} |
117 |
|
} |
118 |
|
} |
119 |
|
} |