Skip to content

Commit

Permalink
[Misc] Minor refactoring of AbstractCopyOrMoveJob
Browse files Browse the repository at this point in the history
(cherry picked from commit 1e080ae)
  • Loading branch information
surli committed Dec 10, 2024
1 parent ead6a77 commit 4353cda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ protected void getEntities(EntityReference entityReference)

EntityReference destination = this.request.getDestination();

try {
checkSourceDestination(entityReference, destination);
if (isSourceDestinationCompatible(entityReference, destination, true)) {
super.getEntities(entityReference);
} catch (InternalCopyOrMoveJobException e) {
this.logger.error(e.getMessage());
}
}

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

EntityReference destination = this.request.getDestination();

try {
checkSourceDestination(source, destination);
} catch (InternalCopyOrMoveJobException e) {
// We already have logged possible problems as part of the call in #getEntities.
if (!isSourceDestinationCompatible(source, destination, false)) {
return;
}

Expand All @@ -141,25 +137,32 @@ protected void process(EntityReference source)
}
}

private void checkSourceDestination(EntityReference source, EntityReference destination)
throws InternalCopyOrMoveJobException
private boolean isSourceDestinationCompatible(EntityReference source, EntityReference destination, boolean log)
{
boolean result = true;
if (processOnlySameSourceDestinationTypes() && source.getType() != destination.getType()) {
throw new InternalCopyOrMoveJobException(
String.format("You cannot change the entity type (from [%s] to [%s]).",
if (log) {
this.logger.error("You cannot change the entity type (from [{}] to [{}]).",
source.getType(),
destination.getType()));
destination.getType());
}
result = false;
}

if (isDescendantOrSelf(destination, source)) {
throw new InternalCopyOrMoveJobException(
String.format("Cannot make [%s] a descendant of itself.", source));
if (log) {
this.logger.error("Cannot make [{}] a descendant of itself.", source);
}
result = false;
}

if (source.getParent() != null && source.getParent().equals(destination)) {
throw new InternalCopyOrMoveJobException(
String.format("Cannot move [%s] into [%s], it's already there.", source, destination));
if (log) {
this.logger.error("Cannot move [{}] into [{}], it's already there.", source, destination);
}
result = false;
}
return result;
}

private boolean isDescendantOrSelf(EntityReference alice, EntityReference bob)
Expand Down

This file was deleted.

0 comments on commit 4353cda

Please sign in to comment.