1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.filter.internal.job; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Provider; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
30 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
31 |
|
import org.xwiki.component.manager.ComponentManager; |
32 |
|
import org.xwiki.filter.input.InputFilterStream; |
33 |
|
import org.xwiki.filter.input.InputFilterStreamFactory; |
34 |
|
import org.xwiki.filter.job.FilterConversionFinished; |
35 |
|
import org.xwiki.filter.job.FilterConversionStarted; |
36 |
|
import org.xwiki.filter.job.FilterStreamConverterJobRequest; |
37 |
|
import org.xwiki.filter.job.FilterStreamJobRequest; |
38 |
|
import org.xwiki.filter.output.OutputFilterStream; |
39 |
|
import org.xwiki.filter.output.OutputFilterStreamFactory; |
40 |
|
import org.xwiki.job.AbstractJob; |
41 |
|
import org.xwiki.job.DefaultJobStatus; |
42 |
|
import org.xwiki.job.GroupedJob; |
43 |
|
import org.xwiki.job.JobGroupPath; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@version |
49 |
|
@since |
50 |
|
|
51 |
|
@Component |
52 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
53 |
|
@Named(FilterStreamConverterJob.JOBTYPE) |
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 5 |
Complexity Density: 0.36 |
|
54 |
|
public class FilterStreamConverterJob |
55 |
|
extends AbstractJob<FilterStreamConverterJobRequest, DefaultJobStatus<FilterStreamConverterJobRequest>> |
56 |
|
implements GroupedJob |
57 |
|
{ |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
public static final String JOBTYPE = "filter.converter"; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
public static final JobGroupPath ROOT_GROUP = |
67 |
|
new JobGroupPath(Arrays.asList(FilterStreamJobRequest.JOBID_PREFIX, "converter")); |
68 |
|
|
69 |
|
@Inject |
70 |
|
@Named("context") |
71 |
|
private Provider<ComponentManager> componentManagerProvider; |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
73 |
7 |
@Override... |
74 |
|
public String getType() |
75 |
|
{ |
76 |
7 |
return JOBTYPE; |
77 |
|
} |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
1 |
@Override... |
80 |
|
public JobGroupPath getGroupPath() |
81 |
|
{ |
82 |
1 |
return ROOT_GROUP; |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
85 |
1 |
@Override... |
86 |
|
protected void runInternal() throws Exception |
87 |
|
{ |
88 |
1 |
InputFilterStreamFactory inputFactory = this.componentManagerProvider.get() |
89 |
|
.getInstance(InputFilterStreamFactory.class, getRequest().getInputType().serialize()); |
90 |
|
|
91 |
1 |
InputFilterStream inputFilter = inputFactory.createInputFilterStream(getRequest().getInputProperties()); |
92 |
|
|
93 |
1 |
OutputFilterStreamFactory outputFactory = this.componentManagerProvider.get() |
94 |
|
.getInstance(OutputFilterStreamFactory.class, getRequest().getOutputType().serialize()); |
95 |
|
|
96 |
1 |
OutputFilterStream outputFilter = outputFactory.createOutputFilterStream(getRequest().getOutputProperties()); |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
1 |
inputFilter.read(outputFilter.getFilter()); |
101 |
|
|
102 |
1 |
inputFilter.close(); |
103 |
1 |
outputFilter.close(); |
104 |
|
} |
105 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
106 |
1 |
@Override... |
107 |
|
protected void jobStarting() |
108 |
|
{ |
109 |
1 |
this.observationManager.notify(new FilterConversionStarted(getRequest().getId(), getType(), this.request), |
110 |
|
this); |
111 |
|
|
112 |
1 |
super.jobStarting(); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
115 |
1 |
@Override... |
116 |
|
protected void jobFinished(Throwable error) |
117 |
|
{ |
118 |
1 |
try { |
119 |
1 |
super.jobFinished(error); |
120 |
|
} finally { |
121 |
1 |
this.observationManager.notify(new FilterConversionFinished(getRequest().getId(), getType(), this.request), |
122 |
|
this); |
123 |
|
} |
124 |
|
} |
125 |
|
} |