Skip to content

Commit 5e363f5

Browse files
committed
[Misc] Minor refactoring of AbstractCopyOrMoveJob
(cherry picked from commit 1e080ae)
1 parent 8da9e59 commit 5e363f5

File tree

2 files changed

+19
-54
lines changed

2 files changed

+19
-54
lines changed

xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-api/src/main/java/org/xwiki/refactoring/internal/job/AbstractCopyOrMoveJob.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,8 @@ protected void getEntities(EntityReference entityReference)
9292

9393
EntityReference destination = this.request.getDestination();
9494

95-
try {
96-
checkSourceDestination(entityReference, destination);
95+
if (isSourceDestinationCompatible(entityReference, destination, true)) {
9796
super.getEntities(entityReference);
98-
} catch (InternalCopyOrMoveJobException e) {
99-
this.logger.error(e.getMessage());
10097
}
10198
}
10299

@@ -118,9 +115,8 @@ protected void process(EntityReference source)
118115

119116
EntityReference destination = this.request.getDestination();
120117

121-
try {
122-
checkSourceDestination(source, destination);
123-
} catch (InternalCopyOrMoveJobException e) {
118+
// We already have logged possible problems as part of the call in #getEntities.
119+
if (!isSourceDestinationCompatible(source, destination, false)) {
124120
return;
125121
}
126122

@@ -141,25 +137,32 @@ protected void process(EntityReference source)
141137
}
142138
}
143139

144-
private void checkSourceDestination(EntityReference source, EntityReference destination)
145-
throws InternalCopyOrMoveJobException
140+
private boolean isSourceDestinationCompatible(EntityReference source, EntityReference destination, boolean log)
146141
{
142+
boolean result = true;
147143
if (processOnlySameSourceDestinationTypes() && source.getType() != destination.getType()) {
148-
throw new InternalCopyOrMoveJobException(
149-
String.format("You cannot change the entity type (from [%s] to [%s]).",
144+
if (log) {
145+
this.logger.error("You cannot change the entity type (from [{}] to [{}]).",
150146
source.getType(),
151-
destination.getType()));
147+
destination.getType());
148+
}
149+
result = false;
152150
}
153151

154152
if (isDescendantOrSelf(destination, source)) {
155-
throw new InternalCopyOrMoveJobException(
156-
String.format("Cannot make [%s] a descendant of itself.", source));
153+
if (log) {
154+
this.logger.error("Cannot make [{}] a descendant of itself.", source);
155+
}
156+
result = false;
157157
}
158158

159159
if (source.getParent() != null && source.getParent().equals(destination)) {
160-
throw new InternalCopyOrMoveJobException(
161-
String.format("Cannot move [%s] into [%s], it's already there.", source, destination));
160+
if (log) {
161+
this.logger.error("Cannot move [{}] into [{}], it's already there.", source, destination);
162+
}
163+
result = false;
162164
}
165+
return result;
163166
}
164167

165168
private boolean isDescendantOrSelf(EntityReference alice, EntityReference bob)

xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-api/src/main/java/org/xwiki/refactoring/internal/job/InternalCopyOrMoveJobException.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)