1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.refactoring.internal.job; |
21 |
|
|
22 |
|
import javax.inject.Named; |
23 |
|
|
24 |
|
import org.xwiki.component.annotation.Component; |
25 |
|
import org.xwiki.model.reference.DocumentReference; |
26 |
|
import org.xwiki.model.reference.EntityReference; |
27 |
|
import org.xwiki.model.reference.SpaceReference; |
28 |
|
import org.xwiki.refactoring.job.EntityJobStatus; |
29 |
|
import org.xwiki.refactoring.job.EntityRequest; |
30 |
|
import org.xwiki.refactoring.job.RefactoringJobs; |
31 |
|
import org.xwiki.security.authorization.Right; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
39 |
|
@Component |
40 |
|
@Named(RefactoringJobs.DELETE) |
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 13 |
Complexity Density: 0.62 |
|
41 |
|
public class DeleteJob extends AbstractEntityJob<EntityRequest, EntityJobStatus<EntityRequest>> |
42 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
43 |
130 |
@Override... |
44 |
|
public String getType() |
45 |
|
{ |
46 |
130 |
return RefactoringJobs.DELETE; |
47 |
|
} |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
26 |
@Override... |
50 |
|
protected EntityJobStatus<EntityRequest> createNewStatus(EntityRequest request) |
51 |
|
{ |
52 |
26 |
return new EntityJobStatus<EntityRequest>(request, this.observationManager, this.loggerManager, null); |
53 |
|
} |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.33 |
|
55 |
26 |
@Override... |
56 |
|
protected void process(EntityReference entityReference) |
57 |
|
{ |
58 |
|
|
59 |
|
|
60 |
26 |
switch (entityReference.getType()) { |
61 |
16 |
case DOCUMENT: |
62 |
16 |
process(new DocumentReference(entityReference)); |
63 |
15 |
break; |
64 |
9 |
case SPACE: |
65 |
9 |
process(new SpaceReference(entityReference)); |
66 |
4 |
break; |
67 |
1 |
default: |
68 |
1 |
this.logger.error("Unsupported entity type [{}].", entityReference.getType()); |
69 |
|
} |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
72 |
16 |
private void process(DocumentReference documentReference)... |
73 |
|
{ |
74 |
16 |
if (this.request.isDeep() && isSpaceHomeReference(documentReference)) { |
75 |
1 |
process(documentReference.getLastSpaceReference()); |
76 |
|
} else { |
77 |
15 |
maybeDelete(documentReference); |
78 |
|
} |
79 |
|
} |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
10 |
private void process(SpaceReference spaceReference)... |
82 |
|
{ |
83 |
10 |
visitDocuments(spaceReference, new Visitor<DocumentReference>() |
84 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
12 |
@Override... |
86 |
|
public void visit(DocumentReference documentReference) |
87 |
|
{ |
88 |
12 |
maybeDelete(documentReference); |
89 |
|
} |
90 |
|
}); |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
93 |
27 |
private void maybeDelete(DocumentReference documentReference)... |
94 |
|
{ |
95 |
27 |
if (!this.modelBridge.exists(documentReference)) { |
96 |
3 |
this.logger.warn("Skipping [{}] because it doesn't exist.", documentReference); |
97 |
24 |
} else if (!hasAccess(Right.DELETE, documentReference)) { |
98 |
1 |
this.logger.error("You are not allowed to delete [{}].", documentReference); |
99 |
|
} else { |
100 |
23 |
this.modelBridge.delete(documentReference); |
101 |
|
} |
102 |
|
} |
103 |
|
} |