| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.annotation.internal; |
| 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.Provider; |
| 28 |
|
import javax.inject.Singleton; |
| 29 |
|
|
| 30 |
|
import org.slf4j.Logger; |
| 31 |
|
import org.xwiki.annotation.AnnotationConfiguration; |
| 32 |
|
import org.xwiki.bridge.event.DocumentCreatedEvent; |
| 33 |
|
import org.xwiki.bridge.event.DocumentUpdatedEvent; |
| 34 |
|
import org.xwiki.component.annotation.Role; |
| 35 |
|
import org.xwiki.model.reference.DocumentReference; |
| 36 |
|
import org.xwiki.observation.EventListener; |
| 37 |
|
import org.xwiki.observation.event.Event; |
| 38 |
|
import org.xwiki.observation.event.filter.RegexEventFilter; |
| 39 |
|
|
| 40 |
|
import com.xpn.xwiki.XWikiContext; |
| 41 |
|
import com.xpn.xwiki.doc.MandatoryDocumentInitializer; |
| 42 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
@version |
| 49 |
|
@since |
| 50 |
|
|
| 51 |
|
@Role |
| 52 |
|
@Named(CheckAnnotationClassEventListener.NAME) |
| 53 |
|
@Singleton |
| |
|
| 22.2% |
Uncovered Elements: 14 (18) |
Complexity: 6 |
Complexity Density: 0.55 |
|
| 54 |
|
public class CheckAnnotationClassEventListener implements EventListener |
| 55 |
|
{ |
| 56 |
|
static final String NAME = "CheckAnnotationClassEventListener"; |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
private static final RegexEventFilter CONFIGURATION_DOCUMENT_REFERENCE = new RegexEventFilter(String.format( |
| 62 |
|
".*:%s.%s", AnnotationConfiguration.CONFIGURATION_PAGE_SPACE_NAME, |
| 63 |
|
AnnotationConfiguration.CONFIGURATION_PAGE_NAME)); |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
private static final List<Event> EVENTS = Arrays.<Event>asList(new DocumentUpdatedEvent( |
| 69 |
|
CONFIGURATION_DOCUMENT_REFERENCE), new DocumentCreatedEvent(CONFIGURATION_DOCUMENT_REFERENCE)); |
| 70 |
|
|
| 71 |
|
@Inject |
| 72 |
|
protected Provider<XWikiContext> xcontextProvider; |
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
@Inject |
| 78 |
|
protected AnnotationConfiguration configuration; |
| 79 |
|
|
| 80 |
|
@Inject |
| 81 |
|
@Named(AnnotationClassDocumentInitializer.HINT) |
| 82 |
|
protected MandatoryDocumentInitializer initializer; |
| 83 |
|
|
| 84 |
|
@Inject |
| 85 |
|
protected Logger logger; |
| 86 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 87 |
6 |
@Override... |
| 88 |
|
public String getName() |
| 89 |
|
{ |
| 90 |
6 |
return NAME; |
| 91 |
|
} |
| 92 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 93 |
1 |
@Override... |
| 94 |
|
public List<Event> getEvents() |
| 95 |
|
{ |
| 96 |
1 |
return EVENTS; |
| 97 |
|
} |
| 98 |
|
|
| |
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 99 |
0 |
@Override... |
| 100 |
|
public void onEvent(Event event, Object source, Object data) |
| 101 |
|
{ |
| 102 |
0 |
DocumentReference annotationClassReference = this.configuration.getAnnotationClassReference(); |
| 103 |
|
|
| 104 |
0 |
try { |
| 105 |
0 |
if (!this.configuration.isInstalled()) { |
| 106 |
|
|
| 107 |
0 |
return; |
| 108 |
|
} |
| 109 |
|
|
| 110 |
0 |
XWikiContext deprecatedContext = this.xcontextProvider.get(); |
| 111 |
0 |
XWikiDocument annotationClassDocument = |
| 112 |
|
deprecatedContext.getWiki().getDocument(annotationClassReference, deprecatedContext); |
| 113 |
|
|
| 114 |
0 |
if (this.initializer.updateDocument(annotationClassDocument)) { |
| 115 |
0 |
deprecatedContext.getWiki().saveDocument(annotationClassDocument, |
| 116 |
|
"Automatically added missing annotation class fields required by the Annotation Application.", |
| 117 |
|
deprecatedContext); |
| 118 |
|
} |
| 119 |
|
} catch (Exception e) { |
| 120 |
0 |
this.logger.error("Failed to update the configured annotation class [{}]", annotationClassReference, e); |
| 121 |
|
} |
| 122 |
|
} |
| 123 |
|
} |