| 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.EntityType; |
| 26 |
|
import org.xwiki.model.reference.DocumentReference; |
| 27 |
|
import org.xwiki.model.reference.EntityReference; |
| 28 |
|
import org.xwiki.model.reference.SpaceReference; |
| 29 |
|
import org.xwiki.refactoring.job.CreateRequest; |
| 30 |
|
import org.xwiki.refactoring.job.EntityJobStatus; |
| 31 |
|
import org.xwiki.refactoring.job.RefactoringJobs; |
| 32 |
|
import org.xwiki.security.authorization.Right; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@version |
| 38 |
|
@since |
| 39 |
|
|
| 40 |
|
@Component |
| 41 |
|
@Named(RefactoringJobs.CREATE) |
| |
|
| 97.3% |
Uncovered Elements: 2 (74) |
Complexity: 24 |
Complexity Density: 0.51 |
|
| 42 |
|
public class CreateJob extends AbstractEntityJob<CreateRequest, EntityJobStatus<CreateRequest>> |
| 43 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 44 |
135 |
@Override... |
| 45 |
|
public String getType() |
| 46 |
|
{ |
| 47 |
135 |
return RefactoringJobs.CREATE; |
| 48 |
|
} |
| 49 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 50 |
27 |
@Override... |
| 51 |
|
protected EntityJobStatus<CreateRequest> createNewStatus(CreateRequest request) |
| 52 |
|
{ |
| 53 |
27 |
return new EntityJobStatus<>(request, this.observationManager, this.loggerManager, null); |
| 54 |
|
} |
| 55 |
|
|
| |
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 56 |
27 |
@Override... |
| 57 |
|
protected void process(EntityReference entityReference) |
| 58 |
|
{ |
| 59 |
|
|
| 60 |
|
|
| 61 |
27 |
switch (entityReference.getType()) { |
| 62 |
25 |
case DOCUMENT: |
| 63 |
25 |
process(new DocumentReference(entityReference)); |
| 64 |
25 |
break; |
| 65 |
2 |
case SPACE: |
| 66 |
2 |
process(new SpaceReference(entityReference)); |
| 67 |
2 |
break; |
| 68 |
0 |
default: |
| 69 |
0 |
this.logger.error("Unsupported entity type [{}].", entityReference.getType()); |
| 70 |
|
} |
| 71 |
|
} |
| 72 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 7 |
Complexity Density: 0.54 |
|
| 73 |
25 |
private void process(DocumentReference documentReference)... |
| 74 |
|
{ |
| 75 |
|
|
| 76 |
25 |
DocumentReference templateDocumentReference = null; |
| 77 |
25 |
if (this.request.getTemplateReference() != null |
| 78 |
|
&& this.request.getTemplateReference().extractReference(EntityType.DOCUMENT) != null) { |
| 79 |
21 |
templateDocumentReference = |
| 80 |
|
new DocumentReference(this.request.getTemplateReference().extractReference(EntityType.DOCUMENT)); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
25 |
progressManager.pushLevelProgress(3, this); |
| 84 |
|
|
| 85 |
25 |
try { |
| 86 |
25 |
progressManager.startStep(this, "Main document"); |
| 87 |
|
|
| 88 |
|
|
| 89 |
25 |
maybeCreate(documentReference, templateDocumentReference); |
| 90 |
|
|
| 91 |
25 |
progressManager.startStep(this, "Template children"); |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
25 |
if (this.request.isDeep() && isSpaceHomeReference(documentReference) && templateDocumentReference != null |
| 96 |
|
&& isSpaceHomeReference(templateDocumentReference)) { |
| 97 |
1 |
process(documentReference.getLastSpaceReference()); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
25 |
progressManager.startStep(this, "Remove lock from the main document"); |
| 101 |
|
|
| 102 |
|
|
| 103 |
25 |
this.modelBridge.removeLock(documentReference); |
| 104 |
|
} finally { |
| 105 |
|
|
| 106 |
25 |
this.progressManager.popLevelProgress(this); |
| 107 |
|
} |
| 108 |
|
} |
| 109 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 110 |
3 |
private void process(final SpaceReference newSpaceReference)... |
| 111 |
|
{ |
| 112 |
|
|
| 113 |
3 |
SpaceReference extractedSpaceReference = null; |
| 114 |
3 |
if (this.request.getTemplateReference() != null |
| 115 |
|
&& this.request.getTemplateReference().extractReference(EntityType.SPACE) != null) { |
| 116 |
2 |
extractedSpaceReference = |
| 117 |
|
new SpaceReference(this.request.getTemplateReference().extractReference(EntityType.SPACE)); |
| 118 |
|
} |
| 119 |
3 |
final SpaceReference templateSpaceReference = extractedSpaceReference; |
| 120 |
|
|
| 121 |
3 |
if (templateSpaceReference != null) { |
| 122 |
|
|
| 123 |
2 |
visitDocuments(templateSpaceReference, new Visitor<DocumentReference>() |
| 124 |
|
{ |
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 125 |
2 |
@Override... |
| 126 |
|
public void visit(final DocumentReference templateDocumentReference) |
| 127 |
|
{ |
| 128 |
2 |
DocumentReference newDocumentReference = |
| 129 |
|
templateDocumentReference.replaceParent(templateSpaceReference, newSpaceReference); |
| 130 |
2 |
maybeCreate(newDocumentReference, templateDocumentReference); |
| 131 |
|
} |
| 132 |
|
}); |
| 133 |
|
} else { |
| 134 |
|
|
| 135 |
1 |
DocumentReference newSpaceWebHomeReference = new DocumentReference("WebHome", newSpaceReference); |
| 136 |
1 |
maybeCreate(newSpaceWebHomeReference, null); |
| 137 |
|
} |
| 138 |
|
} |
| 139 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 7 |
Complexity Density: 0.54 |
|
| 140 |
28 |
private void maybeCreate(DocumentReference newDocumentReference, DocumentReference templateDocumentReference)... |
| 141 |
|
{ |
| 142 |
28 |
if (request.getSkippedEntities().contains(newDocumentReference)) { |
| 143 |
18 |
this.logger.debug("Skipping creation of document [{}], as specified in the request.", newDocumentReference); |
| 144 |
10 |
} else if (this.modelBridge.exists(newDocumentReference)) { |
| 145 |
|
|
| 146 |
1 |
this.logger.warn("Skipping creation of document [{}] because it already exists.", newDocumentReference); |
| 147 |
9 |
} else if (!hasAccess(Right.EDIT, newDocumentReference)) { |
| 148 |
1 |
this.logger.error("You are not allowed to create the document [{}].", newDocumentReference); |
| 149 |
8 |
} else if (templateDocumentReference == null) { |
| 150 |
|
|
| 151 |
2 |
this.modelBridge.create(newDocumentReference); |
| 152 |
6 |
} else if (!hasAccess(Right.VIEW, templateDocumentReference)) { |
| 153 |
1 |
this.logger.error("You are not allowed to view the template document [{}].", templateDocumentReference); |
| 154 |
5 |
} else if (!this.modelBridge.exists(templateDocumentReference)) { |
| 155 |
|
|
| 156 |
2 |
this.logger.error("Template document [{}] does not exist.", templateDocumentReference); |
| 157 |
|
} else { |
| 158 |
3 |
this.modelBridge.copy(templateDocumentReference, newDocumentReference); |
| 159 |
|
} |
| 160 |
|
} |
| 161 |
|
} |