diff options
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-conflict-manager/src/main')
4 files changed, 67 insertions, 103 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManager.java b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManager.java index 28c32e049f..1231469f31 100644 --- a/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManager.java +++ b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManager.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.conflicts; import org.openecomp.conflicts.types.Conflict; @@ -27,14 +26,13 @@ import org.openecomp.sdc.versioning.dao.types.Version; public interface ConflictsManager { - boolean isConflicted(String itemId, Version version); + boolean isConflicted(String itemId, Version version); - ItemVersionConflict getConflict(String itemId, Version version); + ItemVersionConflict getConflict(String itemId, Version version); - void finalizeMerge(String itemId, Version version); + void finalizeMerge(String itemId, Version version); - Conflict getConflict(String itemId, Version version, String conflictId); + Conflict getConflict(String itemId, Version version, String conflictId); - void resolveConflict(String itemId, Version version, String conflictId, - ConflictResolution resolution); + void resolveConflict(String itemId, Version version, String conflictId, ConflictResolution resolution); } diff --git a/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManagerFactory.java b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManagerFactory.java index 7a24cfd311..b13a4329c3 100644 --- a/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManagerFactory.java +++ b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManagerFactory.java @@ -22,8 +22,8 @@ package org.openecomp.sdc.conflicts; import org.openecomp.core.factory.api.AbstractComponentFactory; import org.openecomp.core.factory.api.AbstractFactory; - public abstract class ConflictsManagerFactory extends AbstractComponentFactory<ConflictsManager> { + public static ConflictsManagerFactory getInstance() { return AbstractFactory.getInstance(ConflictsManagerFactory.class); } diff --git a/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerFactoryImpl.java b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerFactoryImpl.java index 2d703c4a87..72347580b0 100644 --- a/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerFactoryImpl.java +++ b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerFactoryImpl.java @@ -19,17 +19,16 @@ */ package org.openecomp.sdc.conflicts.impl; - import org.openecomp.conflicts.dao.ConflictsDaoFactory; import org.openecomp.sdc.conflicts.ConflictsManager; import org.openecomp.sdc.conflicts.ConflictsManagerFactory; public class ConflictsManagerFactoryImpl extends ConflictsManagerFactory { - private static final ConflictsManager INSTANCE = - new ConflictsManagerImpl(ConflictsDaoFactory.getInstance().createInterface()); - @Override - public ConflictsManager createInterface() { - return INSTANCE; - } + private static final ConflictsManager INSTANCE = new ConflictsManagerImpl(ConflictsDaoFactory.getInstance().createInterface()); + + @Override + public ConflictsManager createInterface() { + return INSTANCE; + } } diff --git a/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerImpl.java b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerImpl.java index 284823baac..5ae23783c4 100644 --- a/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,9 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.conflicts.impl; +import java.util.Optional; import org.openecomp.conflicts.ItemMergeHandler; import org.openecomp.conflicts.ItemMergeHandlerFactory; import org.openecomp.conflicts.dao.ConflictsDao; @@ -33,100 +33,67 @@ import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.conflicts.ConflictsManager; import org.openecomp.sdc.versioning.dao.types.Version; -import java.util.Optional; - public class ConflictsManagerImpl implements ConflictsManager { - private static final String ELEMENT_CONFLICT_NOT_EXIST_ERR_ID = "ELEMENT_CONFLICT_NOT_EXIST"; - private static final String ELEMENT_CONFLICT_NOT_EXISTS_MSG = - "Item Id %s, version Id %s, element conflict with Id %s does not exists."; - - private final ConflictsDao conflictsDao; - - public ConflictsManagerImpl(ConflictsDao conflictsDao) { - this.conflictsDao = conflictsDao; - } - - @Override - public boolean isConflicted(String itemId, Version version) { - Optional<ItemMergeHandler> itemMergeHandler = - ItemMergeHandlerFactory.getInstance().createInterface(itemId); - - return conflictsDao.isConflicted(itemId, version) || - (itemMergeHandler.isPresent() && - itemMergeHandler.get().isConflicted(itemId, version)); - } - - @Override - public ItemVersionConflict getConflict(String itemId, Version version) { - ItemVersionConflict conflicts = conflictsDao.getConflict(itemId, version); + private static final String ELEMENT_CONFLICT_NOT_EXIST_ERR_ID = "ELEMENT_CONFLICT_NOT_EXIST"; + private static final String ELEMENT_CONFLICT_NOT_EXISTS_MSG = "Item Id %s, version Id %s, element conflict with Id %s does not exists."; + private final ConflictsDao conflictsDao; - ItemMergeHandlerFactory.getInstance().createInterface(itemId) - .ifPresent(itemMergeHandler -> itemMergeHandler - .postListConflicts(itemId, version, conflicts)); - - return conflicts; - } - - @Override - public void finalizeMerge(String itemId, Version version) { - ItemMergeHandlerFactory.getInstance().createInterface(itemId) - .ifPresent(mergeHandler -> mergeHandler.finalizeMerge(itemId, version)); - } - - @Override - public Conflict getConflict(String itemId, Version version, String conflictId) { - Optional<ItemMergeHandler> itemMergeHandler = - ItemMergeHandlerFactory.getInstance().createInterface(itemId); - if (itemMergeHandler.isPresent()) { - Optional<Conflict> conflict = - itemMergeHandler.get().getConflict(itemId, version, conflictId); - if (conflict.isPresent()) { - return conflict.get(); - } + public ConflictsManagerImpl(ConflictsDao conflictsDao) { + this.conflictsDao = conflictsDao; } - Conflict conflict = conflictsDao.getConflict(itemId, version, conflictId); - - itemMergeHandler.ifPresent(mergeHandler -> - mergeHandler.postGetConflict(itemId, version, conflict)); - - if (conflict == null) { - throw getConflictNotExistException(itemId, version, conflictId); + @Override + public boolean isConflicted(String itemId, Version version) { + Optional<ItemMergeHandler> itemMergeHandler = ItemMergeHandlerFactory.getInstance().createInterface(itemId); + return conflictsDao.isConflicted(itemId, version) || (itemMergeHandler.isPresent() && itemMergeHandler.get().isConflicted(itemId, version)); } - return conflict; - } - @Override - public void resolveConflict(String itemId, Version version, String conflictId, - ConflictResolution resolution) { - if (Resolution.OTHER.equals(resolution.getResolution())) { - throw new UnsupportedOperationException( - "Resolution other than 'THEIRS' or 'YOURS' is not supported."); + @Override + public ItemVersionConflict getConflict(String itemId, Version version) { + ItemVersionConflict conflicts = conflictsDao.getConflict(itemId, version); + ItemMergeHandlerFactory.getInstance().createInterface(itemId) + .ifPresent(itemMergeHandler -> itemMergeHandler.postListConflicts(itemId, version, conflicts)); + return conflicts; } - Optional<ItemMergeHandler> itemMergeHandler = - ItemMergeHandlerFactory.getInstance().createInterface(itemId); - if (!itemMergeHandler.isPresent() || - !itemMergeHandler.get() - .resolveConflict(itemId, version, conflictId, resolution)) { - - getConflict(itemId, version, conflictId); // validate that the conflict exist - itemMergeHandler.ifPresent(mergeHandler -> - mergeHandler.preResolveConflict(itemId, version, conflictId, resolution)); + @Override + public void finalizeMerge(String itemId, Version version) { + ItemMergeHandlerFactory.getInstance().createInterface(itemId).ifPresent(mergeHandler -> mergeHandler.finalizeMerge(itemId, version)); + } - conflictsDao.resolveConflict(itemId, version, conflictId, resolution); + @Override + public Conflict getConflict(String itemId, Version version, String conflictId) { + Optional<ItemMergeHandler> itemMergeHandler = ItemMergeHandlerFactory.getInstance().createInterface(itemId); + if (itemMergeHandler.isPresent()) { + Optional<Conflict> conflict = itemMergeHandler.get().getConflict(itemId, version, conflictId); + if (conflict.isPresent()) { + return conflict.get(); + } + } + Conflict conflict = conflictsDao.getConflict(itemId, version, conflictId); + itemMergeHandler.ifPresent(mergeHandler -> mergeHandler.postGetConflict(itemId, version, conflict)); + if (conflict == null) { + throw getConflictNotExistException(itemId, version, conflictId); + } + return conflict; } - } - private CoreException getConflictNotExistException(String itemId, Version version, - String conflictId) { - return new CoreException(new ErrorCode.ErrorCodeBuilder() - .withCategory(ErrorCategory.APPLICATION) - .withId(ELEMENT_CONFLICT_NOT_EXIST_ERR_ID) - .withMessage( - String.format(ELEMENT_CONFLICT_NOT_EXISTS_MSG, itemId, version.getId(), conflictId)) - .build()); - } + @Override + public void resolveConflict(String itemId, Version version, String conflictId, ConflictResolution resolution) { + if (Resolution.OTHER.equals(resolution.getResolution())) { + throw new UnsupportedOperationException("Resolution other than 'THEIRS' or 'YOURS' is not supported."); + } + Optional<ItemMergeHandler> itemMergeHandler = ItemMergeHandlerFactory.getInstance().createInterface(itemId); + if (!itemMergeHandler.isPresent() || !itemMergeHandler.get().resolveConflict(itemId, version, conflictId, resolution)) { + getConflict(itemId, version, conflictId); // validate that the conflict exist + itemMergeHandler.ifPresent(mergeHandler -> mergeHandler.preResolveConflict(itemId, version, conflictId, resolution)); + conflictsDao.resolveConflict(itemId, version, conflictId, resolution); + } + } + private CoreException getConflictNotExistException(String itemId, Version version, String conflictId) { + return new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId(ELEMENT_CONFLICT_NOT_EXIST_ERR_ID) + .withMessage(String.format(ELEMENT_CONFLICT_NOT_EXISTS_MSG, itemId, version.getId(), conflictId)).build()); + } } |