aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org
diff options
context:
space:
mode:
authortalig <talig@amdocs.com>2017-12-20 14:30:43 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-12-21 11:12:33 +0000
commit8e9c0653dd6c6862123c9609ae34e1206d86456e (patch)
tree5eeef00ec0677133baa439ca8d7ffd7aca4804b6 /openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org
parent785ebcc95de3e064e843bec04ba7a209d854fc7c (diff)
Add collaboration feature
Issue-ID: SDC-767 Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795 Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org')
-rw-r--r--openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManager.java20
-rw-r--r--openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManagerFactory.java30
-rw-r--r--openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerFactoryImpl.java35
-rw-r--r--openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerImpl.java112
4 files changed, 197 insertions, 0 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
new file mode 100644
index 0000000000..d7c5c3f5ba
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManager.java
@@ -0,0 +1,20 @@
+package org.openecomp.sdc.conflicts;
+
+import org.openecomp.conflicts.types.Conflict;
+import org.openecomp.conflicts.types.ConflictResolution;
+import org.openecomp.conflicts.types.ItemVersionConflict;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+public interface ConflictsManager {
+
+ boolean isConflicted(String itemId, Version version);
+
+ ItemVersionConflict getConflict(String itemId, Version version);
+
+ void finalizeMerge(String itemId, Version version);
+
+ Conflict getConflict(String itemId, Version version, String conflictId);
+
+ 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
new file mode 100644
index 0000000000..7a24cfd311
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/ConflictsManagerFactory.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+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
new file mode 100644
index 0000000000..2d703c4a87
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerFactoryImpl.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+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;
+ }
+}
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
new file mode 100644
index 0000000000..cb4c2dd993
--- /dev/null
+++ b/openecomp-be/backend/openecomp-sdc-conflict-manager/src/main/java/org/openecomp/sdc/conflicts/impl/ConflictsManagerImpl.java
@@ -0,0 +1,112 @@
+package org.openecomp.sdc.conflicts.impl;
+
+import org.openecomp.conflicts.ItemMergeHandler;
+import org.openecomp.conflicts.ItemMergeHandlerFactory;
+import org.openecomp.conflicts.dao.ConflictsDao;
+import org.openecomp.conflicts.types.Conflict;
+import org.openecomp.conflicts.types.ConflictResolution;
+import org.openecomp.conflicts.types.ItemVersionConflict;
+import org.openecomp.conflicts.types.Resolution;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+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);
+
+ 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();
+ }
+ }
+
+ 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;
+ }
+
+ @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());
+ }
+
+}