| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.eventstream.internal; |
| 21 |
|
|
| 22 |
|
import java.util.Date; |
| 23 |
|
import java.util.UUID; |
| 24 |
|
|
| 25 |
|
import javax.inject.Inject; |
| 26 |
|
import javax.inject.Singleton; |
| 27 |
|
|
| 28 |
|
import org.xwiki.bridge.DocumentAccessBridge; |
| 29 |
|
import org.xwiki.component.annotation.Component; |
| 30 |
|
import org.xwiki.context.Execution; |
| 31 |
|
import org.xwiki.eventstream.Event; |
| 32 |
|
import org.xwiki.eventstream.EventFactory; |
| 33 |
|
import org.xwiki.model.EntityType; |
| 34 |
|
import org.xwiki.model.reference.DocumentReference; |
| 35 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
@link@link@link |
| 39 |
|
|
| 40 |
|
@version |
| 41 |
|
|
| 42 |
|
@Component |
| 43 |
|
@Singleton |
| |
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 4 |
Complexity Density: 0.33 |
|
| 44 |
|
public class DefaultEventFactory implements EventFactory |
| 45 |
|
{ |
| 46 |
|
|
| 47 |
|
private static final String EVENT_GROUP_ID = Event.class.getCanonicalName().concat("_groupId"); |
| 48 |
|
|
| 49 |
|
|
| 50 |
|
@Inject |
| 51 |
|
private Execution execution; |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
@Inject |
| 55 |
|
private EntityReferenceResolver<String> resolver; |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
@Inject |
| 59 |
|
private DocumentAccessBridge bridge; |
| 60 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
| 61 |
18 |
@Override... |
| 62 |
|
public Event createEvent() |
| 63 |
|
{ |
| 64 |
18 |
Event result = new DefaultEvent(); |
| 65 |
18 |
result.setId(UUID.randomUUID().toString()); |
| 66 |
18 |
result.setGroupId(getCurrentGroupId()); |
| 67 |
18 |
result.setUser(new DocumentReference(this.resolver.resolve(this.bridge.getCurrentUser(), EntityType.DOCUMENT))); |
| 68 |
18 |
result.setDate(new Date()); |
| 69 |
18 |
return result; |
| 70 |
|
} |
| 71 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 72 |
17 |
@Override... |
| 73 |
|
public Event createRawEvent() |
| 74 |
|
{ |
| 75 |
17 |
return new DefaultEvent(); |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
|
| 82 |
|
@return |
| 83 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 84 |
18 |
private String getCurrentGroupId()... |
| 85 |
|
{ |
| 86 |
18 |
String currentGroup = (String) this.execution.getContext().getProperty(EVENT_GROUP_ID); |
| 87 |
18 |
if (currentGroup == null) { |
| 88 |
17 |
currentGroup = UUID.randomUUID().toString(); |
| 89 |
17 |
this.execution.getContext().setProperty(EVENT_GROUP_ID, currentGroup); |
| 90 |
|
} |
| 91 |
18 |
return currentGroup; |
| 92 |
|
} |
| 93 |
|
} |