1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.job.history.internal; |
21 |
|
|
22 |
|
import java.util.Collection; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import javax.inject.Named; |
26 |
|
|
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.component.manager.ComponentLookupException; |
29 |
|
import org.xwiki.extension.job.history.ExtensionJobHistoryRecord; |
30 |
|
import org.xwiki.extension.job.history.ReplayJobStatus; |
31 |
|
import org.xwiki.extension.job.history.ReplayRequest; |
32 |
|
import org.xwiki.extension.job.internal.AbstractExtensionJob; |
33 |
|
import org.xwiki.job.AbstractJob; |
34 |
|
import org.xwiki.job.GroupedJob; |
35 |
|
import org.xwiki.job.Job; |
36 |
|
import org.xwiki.job.JobGroupPath; |
37 |
|
import org.xwiki.job.Request; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@Component |
46 |
|
@Named(ReplayJob.JOB_TYPE) |
|
|
| 92.9% |
Uncovered Elements: 4 (56) |
Complexity: 14 |
Complexity Density: 0.38 |
|
47 |
|
public class ReplayJob extends AbstractJob<ReplayRequest, ReplayJobStatus> implements GroupedJob |
48 |
|
{ |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
public static final String JOB_TYPE = "replay"; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
private JobGroupPath groupPath; |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
5 |
@Override... |
63 |
|
public String getType() |
64 |
|
{ |
65 |
5 |
return JOB_TYPE; |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
68 |
3 |
@Override... |
69 |
|
public JobGroupPath getGroupPath() |
70 |
|
{ |
71 |
3 |
return this.groupPath; |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
74 |
4 |
@Override... |
75 |
|
public void initialize(Request request) |
76 |
|
{ |
77 |
4 |
super.initialize(request); |
78 |
|
|
79 |
|
|
80 |
4 |
String targetNamespace = getTargetNamespace(); |
81 |
4 |
if (targetNamespace != null) { |
82 |
1 |
this.groupPath = new JobGroupPath(targetNamespace, AbstractExtensionJob.ROOT_GROUP); |
83 |
|
} else { |
84 |
3 |
this.groupPath = AbstractExtensionJob.ROOT_GROUP; |
85 |
|
} |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
88 |
4 |
@Override... |
89 |
|
protected ReplayJobStatus createNewStatus(ReplayRequest request) |
90 |
|
{ |
91 |
4 |
return new ReplayJobStatus(request, this.observationManager, this.loggerManager); |
92 |
|
} |
93 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
|
94 |
1 |
@Override... |
95 |
|
protected void runInternal() throws Exception |
96 |
|
{ |
97 |
1 |
List<ExtensionJobHistoryRecord> records = this.request.getRecords(); |
98 |
1 |
if (records == null) { |
99 |
0 |
return; |
100 |
|
} |
101 |
|
|
102 |
1 |
this.progressManager.pushLevelProgress(records.size(), this); |
103 |
|
|
104 |
1 |
try { |
105 |
1 |
int currentRecordNumber = 0; |
106 |
1 |
for (ExtensionJobHistoryRecord record : records) { |
107 |
2 |
this.progressManager.startStep(this); |
108 |
2 |
this.status.setCurrentRecordNumber(currentRecordNumber++); |
109 |
2 |
replay(record); |
110 |
2 |
this.progressManager.endStep(this); |
111 |
|
} |
112 |
|
} finally { |
113 |
1 |
this.progressManager.popLevelProgress(this); |
114 |
|
} |
115 |
|
} |
116 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
117 |
2 |
private void replay(ExtensionJobHistoryRecord record) throws ComponentLookupException... |
118 |
|
{ |
119 |
2 |
Job job = this.componentManager.getInstance(Job.class, record.getJobType()); |
120 |
2 |
job.initialize(record.getRequest()); |
121 |
2 |
job.run(); |
122 |
|
} |
123 |
|
|
|
|
| 90.9% |
Uncovered Elements: 2 (22) |
Complexity: 6 |
Complexity Density: 0.43 |
|
124 |
4 |
private String getTargetNamespace()... |
125 |
|
{ |
126 |
4 |
List<ExtensionJobHistoryRecord> records = this.request.getRecords(); |
127 |
4 |
if (records == null) { |
128 |
0 |
return null; |
129 |
|
} |
130 |
|
|
131 |
4 |
String targetNamespace = null; |
132 |
4 |
for (ExtensionJobHistoryRecord record : records) { |
133 |
7 |
Collection<String> namespaces = record.getRequest().getNamespaces(); |
134 |
7 |
if (namespaces != null && namespaces.size() == 1) { |
135 |
5 |
String namespace = namespaces.iterator().next(); |
136 |
5 |
if (targetNamespace == null) { |
137 |
3 |
targetNamespace = namespace; |
138 |
2 |
} else if (!targetNamespace.equals(namespace)) { |
139 |
1 |
return null; |
140 |
|
} |
141 |
|
} else { |
142 |
2 |
return null; |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
1 |
return targetNamespace; |
147 |
|
} |
148 |
|
} |