From 5e363f538eb207e25eb49cb0e9e7a70626692477 Mon Sep 17 00:00:00 2001 From: Simon Urli Date: Tue, 10 Dec 2024 11:40:16 +0100 Subject: [PATCH] [Misc] Minor refactoring of AbstractCopyOrMoveJob (cherry picked from commit 1e080ae0eda401a9a9a509770e6752e7d00d1cce) --- .../internal/job/AbstractCopyOrMoveJob.java | 35 +++++++++-------- .../job/InternalCopyOrMoveJobException.java | 38 ------------------- 2 files changed, 19 insertions(+), 54 deletions(-) delete mode 100644 xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-api/src/main/java/org/xwiki/refactoring/internal/job/InternalCopyOrMoveJobException.java diff --git a/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-api/src/main/java/org/xwiki/refactoring/internal/job/AbstractCopyOrMoveJob.java b/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-api/src/main/java/org/xwiki/refactoring/internal/job/AbstractCopyOrMoveJob.java index 55a999a510f..419d32fd19f 100644 --- a/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-api/src/main/java/org/xwiki/refactoring/internal/job/AbstractCopyOrMoveJob.java +++ b/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-api/src/main/java/org/xwiki/refactoring/internal/job/AbstractCopyOrMoveJob.java @@ -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()); } } @@ -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; } @@ -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) diff --git a/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-api/src/main/java/org/xwiki/refactoring/internal/job/InternalCopyOrMoveJobException.java b/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-api/src/main/java/org/xwiki/refactoring/internal/job/InternalCopyOrMoveJobException.java deleted file mode 100644 index 2653e69b2b9..00000000000 --- a/xwiki-platform-core/xwiki-platform-refactoring/xwiki-platform-refactoring-api/src/main/java/org/xwiki/refactoring/internal/job/InternalCopyOrMoveJobException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * See the NOTICE file distributed with this work for additional - * information regarding copyright ownership. - * - * This is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ -package org.xwiki.refactoring.internal.job; - -/** - * Internal exception to be used in {@link AbstractCopyOrMoveJob}. - * - * @version $Id$ - * @since 16.10.0RC1 - */ -public class InternalCopyOrMoveJobException extends Exception -{ - /** - * Default constructor. - * @param message the message of the exception. - */ - public InternalCopyOrMoveJobException(String message) - { - super(message); - } -}