| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.annotation.maintainer.internal; |
| 21 |
|
|
| 22 |
|
import java.util.ArrayList; |
| 23 |
|
import java.util.Arrays; |
| 24 |
|
import java.util.List; |
| 25 |
|
|
| 26 |
|
import javax.inject.Inject; |
| 27 |
|
import javax.inject.Named; |
| 28 |
|
import javax.inject.Singleton; |
| 29 |
|
|
| 30 |
|
import org.slf4j.Logger; |
| 31 |
|
import org.xwiki.annotation.maintainer.AnnotationMaintainer; |
| 32 |
|
import org.xwiki.annotation.maintainer.MaintainerServiceException; |
| 33 |
|
import org.xwiki.bridge.DocumentModelBridge; |
| 34 |
|
import org.xwiki.bridge.event.DocumentUpdatedEvent; |
| 35 |
|
import org.xwiki.component.annotation.Component; |
| 36 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
| 37 |
|
import org.xwiki.observation.EventListener; |
| 38 |
|
import org.xwiki.observation.event.Event; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
@version |
| 45 |
|
@since |
| 46 |
|
|
| 47 |
|
@Component |
| 48 |
|
@Named("document-content-annotation-updater") |
| 49 |
|
@Singleton |
| |
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 6 |
Complexity Density: 0.5 |
|
| 50 |
|
public class DocumentContentAnnotationUpdateListener implements EventListener |
| 51 |
|
{ |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
@Inject |
| 56 |
|
private EntityReferenceSerializer<String> serializer; |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
@Inject |
| 62 |
|
private AnnotationMaintainer maintainer; |
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
@Inject |
| 68 |
|
private Logger logger; |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
private volatile boolean isUpdating; |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
private final List<Event> eventsList = new ArrayList<Event>(Arrays.asList(new DocumentUpdatedEvent())); |
| 81 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
0 |
@Override... |
| 83 |
|
public List<Event> getEvents() |
| 84 |
|
{ |
| 85 |
0 |
return eventsList; |
| 86 |
|
} |
| 87 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 88 |
0 |
@Override... |
| 89 |
|
public String getName() |
| 90 |
|
{ |
| 91 |
0 |
return "DocumentContentAnnotationUpdateListener"; |
| 92 |
|
} |
| 93 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.4 |
|
| 94 |
0 |
@Override... |
| 95 |
|
public void onEvent(Event event, Object source, Object data) |
| 96 |
|
{ |
| 97 |
0 |
DocumentModelBridge currentDocument = (DocumentModelBridge) source; |
| 98 |
|
|
| 99 |
0 |
DocumentModelBridge previousDocument = currentDocument.getOriginalDocument(); |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
0 |
if (!isUpdating && !previousDocument.getContent().equals(currentDocument.getContent())) { |
| 104 |
0 |
isUpdating = true; |
| 105 |
0 |
String content = currentDocument.getContent(); |
| 106 |
0 |
String previousContent = previousDocument.getContent(); |
| 107 |
|
|
| 108 |
|
|
| 109 |
0 |
try { |
| 110 |
0 |
maintainer.updateAnnotations(this.serializer.serialize(currentDocument.getDocumentReference()), |
| 111 |
|
previousContent, content); |
| 112 |
|
} catch (MaintainerServiceException e) { |
| 113 |
0 |
this.logger.warn(e.getMessage(), e); |
| 114 |
|
|
| 115 |
|
} |
| 116 |
0 |
isUpdating = false; |
| 117 |
|
} |
| 118 |
|
} |
| 119 |
|
} |