aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core
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/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core
parent785ebcc95de3e064e843bec04ba7a209d854fc7c (diff)
Add collaboration feature
Issue-ID: SDC-767 Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795 Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core')
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculator.java12
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculatorFactory.java31
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/ItemDaoFactoryImpl.java36
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionDaoFactoryImpl.java36
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java4
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java104
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java165
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/convertor/ItemVersionToVersionConvertor.java49
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerFactoryImpl.java39
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java68
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorFactoryImpl.java14
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImpl.java53
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorFactoryImpl.java34
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java155
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java9
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java218
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/resources/factoryConfiguration.json3
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java265
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java124
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java399
20 files changed, 1733 insertions, 85 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculator.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculator.java
new file mode 100644
index 0000000000..dc9ac7b325
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculator.java
@@ -0,0 +1,12 @@
+package org.openecomp.sdc.versioning;
+
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.types.VersionCreationMethod;
+
+import java.util.Set;
+
+public interface VersionCalculator {
+ String calculate(String baseVersion, VersionCreationMethod creationMethod);
+
+ void injectAdditionalInfo(Version version, Set<String> existingVersions);
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculatorFactory.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculatorFactory.java
new file mode 100644
index 0000000000..85f02cd267
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculatorFactory.java
@@ -0,0 +1,31 @@
+/*-
+ * ============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.versioning;
+
+import org.openecomp.core.factory.api.AbstractComponentFactory;
+import org.openecomp.core.factory.api.AbstractFactory;
+
+public abstract class VersionCalculatorFactory extends AbstractComponentFactory<VersionCalculator> {
+
+ public static VersionCalculatorFactory getInstance() {
+ return AbstractFactory.getInstance(VersionCalculatorFactory.class);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/ItemDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/ItemDaoFactoryImpl.java
new file mode 100644
index 0000000000..0f9c9065d4
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/ItemDaoFactoryImpl.java
@@ -0,0 +1,36 @@
+/*-
+ * ============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.versioning.dao.impl;
+
+import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
+import org.openecomp.sdc.versioning.dao.ItemDao;
+import org.openecomp.sdc.versioning.dao.ItemDaoFactory;
+import org.openecomp.sdc.versioning.dao.impl.zusammen.ItemZusammenDaoImpl;
+
+public class ItemDaoFactoryImpl extends ItemDaoFactory {
+ private static ItemDao INSTANCE =
+ new ItemZusammenDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface());
+
+ @Override
+ public ItemDao createInterface() {
+ return INSTANCE;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionDaoFactoryImpl.java
new file mode 100644
index 0000000000..f8b0d71eb7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionDaoFactoryImpl.java
@@ -0,0 +1,36 @@
+/*-
+ * ============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.versioning.dao.impl;
+
+import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
+import org.openecomp.sdc.versioning.dao.VersionDao;
+import org.openecomp.sdc.versioning.dao.VersionDaoFactory;
+import org.openecomp.sdc.versioning.dao.impl.zusammen.VersionZusammenDaoImpl;
+
+public class VersionDaoFactoryImpl extends VersionDaoFactory {
+ private static VersionDao INSTANCE =
+ new VersionZusammenDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface());
+
+ @Override
+ public VersionDao createInterface() {
+ return INSTANCE;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java
index 5673da7070..0845beaa2f 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java
@@ -24,12 +24,12 @@ import com.datastax.driver.core.ColumnDefinitions;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.mapping.UDTMapper;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.core.nosqldb.api.NoSqlDb;
import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
import org.openecomp.core.util.UniqueValueUtil;
import org.openecomp.core.utilities.CommonMethods;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.versioning.dao.VersionableEntityDao;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.types.UniqueValueMetadata;
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java
new file mode 100644
index 0000000000..8fdcf71d59
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java
@@ -0,0 +1,104 @@
+package org.openecomp.sdc.versioning.dao.impl.zusammen;
+
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.item.Info;
+import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+import org.openecomp.core.zusammen.api.ZusammenUtil;
+import org.openecomp.sdc.versioning.dao.ItemDao;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.Item;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class ItemZusammenDaoImpl implements ItemDao {
+
+ private ZusammenAdaptor zusammenAdaptor;
+
+ public ItemZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) {
+ this.zusammenAdaptor = zusammenAdaptor;
+ }
+
+ @Override
+ public Collection<Item> list() {
+ return zusammenAdaptor.listItems(ZusammenUtil.createSessionContext())
+ .stream().map(this::mapFromZusammenItem)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public Item get(Item item) {
+ return mapFromZusammenItem(
+ zusammenAdaptor.getItem(ZusammenUtil.createSessionContext(), new Id(item.getId())));
+ }
+
+ @Override
+ public Item create(Item item) {
+ Id itemId = zusammenAdaptor
+ .createItem(ZusammenUtil.createSessionContext(), mapToZusammenItemInfo(item));
+ item.setId(itemId.getValue());
+ return item;
+ }
+
+ @Override
+ public void update(Item item) {
+ zusammenAdaptor
+ .updateItem(ZusammenUtil.createSessionContext(), new Id(item.getId()),
+ mapToZusammenItemInfo(item));
+ }
+
+ private Item mapFromZusammenItem(com.amdocs.zusammen.datatypes.item.Item zusammenItem) {
+ if (zusammenItem == null) {
+ return null;
+ }
+ Item item = new Item();
+ item.setId(zusammenItem.getId().getValue());
+ item.setName(zusammenItem.getInfo().getName());
+ item.setDescription(zusammenItem.getInfo().getDescription());
+
+ zusammenItem.getInfo().getProperties().entrySet()
+ .forEach(property -> addPropertyToItem(property.getKey(), property.getValue(), item));
+
+ item.setCreationTime(zusammenItem.getCreationTime());
+ item.setModificationTime(zusammenItem.getModificationTime());
+ return item;
+ }
+
+ private void addPropertyToItem(String propertyKey, Object propertyValue, Item item) {
+ switch (propertyKey) {
+ case InfoPropertyName.ITEM_TYPE:
+ item.setType((String) propertyValue);
+ break;
+ case InfoPropertyName.ITEM_VERSIONS_STATUSES:
+ for (Map.Entry<String, Number> statusCounter :
+ ((Map<String, Number>) propertyValue).entrySet()) {
+ item.getVersionStatusCounters().put(VersionStatus.valueOf(statusCounter.getKey()),
+ statusCounter.getValue().intValue());
+ }
+ break;
+ default:
+ item.addProperty(propertyKey, propertyValue);
+ }
+ }
+
+ private Info mapToZusammenItemInfo(Item item) {
+ Info info = new Info();
+ info.setName(item.getName());
+ info.setDescription(item.getDescription());
+ info.addProperty(InfoPropertyName.ITEM_TYPE, item.getType());
+ info.addProperty(InfoPropertyName.ITEM_VERSIONS_STATUSES, item.getVersionStatusCounters());
+ item.getProperties().entrySet()
+ .forEach(property -> info.addProperty(property.getKey(), property.getValue()));
+ return info;
+ }
+
+ private static final class InfoPropertyName {
+ private static final String ITEM_TYPE = "item_type";
+ private static final String ITEM_VERSIONS_STATUSES = "item_versions_statuses";
+
+ private InfoPropertyName() {
+ throw new IllegalStateException("Constants class");
+ }
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java
new file mode 100644
index 0000000000..195973bf5c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java
@@ -0,0 +1,165 @@
+package org.openecomp.sdc.versioning.dao.impl.zusammen;
+
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.item.Info;
+import com.amdocs.zusammen.datatypes.item.ItemVersion;
+import com.amdocs.zusammen.datatypes.item.ItemVersionData;
+import com.amdocs.zusammen.datatypes.item.ItemVersionStatus;
+import com.amdocs.zusammen.datatypes.item.SynchronizationStatus;
+import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+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.versioning.dao.VersionDao;
+import org.openecomp.sdc.versioning.dao.impl.zusammen.convertor.ItemVersionToVersionConvertor;
+import org.openecomp.sdc.versioning.dao.types.Revision;
+import org.openecomp.sdc.versioning.dao.types.SynchronizationState;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionState;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
+
+public class VersionZusammenDaoImpl implements VersionDao {
+
+ public static final class ZusammenProperty {
+ public static final String LABEL = "label";
+ public static final String STATUS = "status";
+
+ private ZusammenProperty() {
+ throw new IllegalStateException("Constants class");
+ }
+ }
+
+ private ZusammenAdaptor zusammenAdaptor;
+
+ public VersionZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) {
+ this.zusammenAdaptor = zusammenAdaptor;
+ }
+
+ @Override
+ public List<Version> list(String itemId) {
+ ItemVersionToVersionConvertor convertor = new ItemVersionToVersionConvertor();
+ return zusammenAdaptor.listPublicVersions(createSessionContext(), new Id(itemId)).stream()
+ .map(convertor::convert)
+ .collect(Collectors.toList());
+ }
+
+ @Override
+ public void create(String itemId, Version version) {
+ Id versionId =
+ zusammenAdaptor.createVersion(createSessionContext(), new Id(itemId),
+ version.getBaseId() == null ? null : new Id(version.getBaseId()),
+ mapToZusammenVersion(version));
+
+ version.setId(versionId.getValue());
+ }
+
+ @Override
+ public void update(String itemId, Version version) {
+ zusammenAdaptor.updateVersion(createSessionContext(), new Id(itemId), new Id(version.getId()),
+ mapToZusammenVersion(version));
+ }
+
+ @Override
+ public Optional<Version> get(String itemId, Version version) {
+ SessionContext context = createSessionContext();
+ Id itemIdObj = new Id(itemId);
+ Id versionId = new Id(version.getId());
+ ItemVersion itemVersion = zusammenAdaptor.getVersion(context, itemIdObj, versionId);
+
+ if (itemVersion == null) {
+ return Optional.empty();
+ }
+
+ VersionState versionState =
+ convertState(zusammenAdaptor.getVersionStatus(context, itemIdObj, versionId));
+ updateVersionStatus(context, itemIdObj, versionId, versionState, itemVersion);
+
+ Version result = new ItemVersionToVersionConvertor().convert(itemVersion);
+ result.setState(versionState);
+ return Optional.of(result);
+ }
+
+ @Override
+ public void delete(String itemId, Version version) {
+ throw new UnsupportedOperationException("Delete version operation is not yet supported.");
+ }
+
+ @Override
+ public void publish(String itemId, Version version, String message) {
+ zusammenAdaptor
+ .publishVersion(createSessionContext(), new Id(itemId), new Id(version.getId()), message);
+ }
+
+ @Override
+ public void sync(String itemId, Version version) {
+ zusammenAdaptor
+ .syncVersion(createSessionContext(), new Id(itemId), new Id(version.getId()));
+ }
+
+ @Override
+ public void forceSync(String itemId, Version version) {
+ zusammenAdaptor
+ .forceSyncVersion(createSessionContext(), new Id(itemId), new Id(version.getId()));
+ }
+
+ @Override
+ public void revert(String itemId, Version version, String revisionId) {
+ zusammenAdaptor.revert(createSessionContext(), itemId, version.getId(), revisionId);
+ }
+
+ @Override
+ public List<Revision> listRevisions(String itemId, Version version) {
+ return zusammenAdaptor.listRevisions(createSessionContext(), itemId, version.getId());
+ }
+
+ private void updateVersionStatus(SessionContext context, Id itemId, Id versionId,
+ VersionState versionState, ItemVersion itemVersion) {
+ if (versionState.getSynchronizationState() != SynchronizationState.UpToDate ||
+ versionState.isDirty()) {
+ String versionStatus = zusammenAdaptor.getPublicVersion(context, itemId, versionId)
+ .getData().getInfo().getProperty(ZusammenProperty.STATUS);
+ itemVersion.getData().getInfo().addProperty(ZusammenProperty.STATUS, versionStatus);
+ }
+ }
+
+ private ItemVersionData mapToZusammenVersion(Version version) {
+ Info info = new Info();
+ info.addProperty(ZusammenProperty.LABEL, version.toString());
+ info.addProperty(ZusammenProperty.STATUS, version.getStatus().name());
+ info.setName(version.getName());
+ info.setDescription(version.getDescription());
+
+ ItemVersionData itemVersionData = new ItemVersionData();
+ itemVersionData.setInfo(info);
+ return itemVersionData;
+ }
+
+ private VersionState convertState(ItemVersionStatus versionStatus) {
+ VersionState state = new VersionState();
+ state.setSynchronizationState(getSyncState(versionStatus.getSynchronizationStatus()));
+ state.setDirty(versionStatus.isDirty());
+ return state;
+ }
+
+ private SynchronizationState getSyncState(SynchronizationStatus synchronizationStatus) {
+ switch (synchronizationStatus) {
+ case UP_TO_DATE:
+ return SynchronizationState.UpToDate;
+ case OUT_OF_SYNC:
+ return SynchronizationState.OutOfSync;
+ case MERGING:
+ return SynchronizationState.Merging;
+ default:
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder()
+ .withCategory(ErrorCategory.APPLICATION)
+ .withId("UNKNOWN_VERSION_STATE")
+ .withMessage("Version state is unknown").build());
+ }
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/convertor/ItemVersionToVersionConvertor.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/convertor/ItemVersionToVersionConvertor.java
new file mode 100644
index 0000000000..f47b5aa612
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/convertor/ItemVersionToVersionConvertor.java
@@ -0,0 +1,49 @@
+package org.openecomp.sdc.versioning.dao.impl.zusammen.convertor;
+
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
+import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
+import com.amdocs.zusammen.datatypes.item.Item;
+import com.amdocs.zusammen.datatypes.item.ItemVersion;
+import org.openecomp.convertor.ElementConvertor;
+import org.openecomp.sdc.versioning.dao.impl.zusammen.VersionZusammenDaoImpl;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+
+public class ItemVersionToVersionConvertor extends ElementConvertor {
+ @Override
+ public Object convert(Element element) {
+ return null;
+ }
+
+ @Override
+ public Object convert(Item item) {
+ return null;
+ }
+
+ @Override
+ public Object convert(ElementInfo elementInfo) {
+ return null;
+ }
+
+ @Override
+ public Version convert(ItemVersion itemVersion) {
+ if (itemVersion == null) {
+ return null;
+ }
+ Version version = Version.valueOf(
+ itemVersion.getData().getInfo().getProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL));
+ version.setStatus(VersionStatus.valueOf(itemVersion.getData().getInfo()
+ .getProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS)));
+ version.setName(itemVersion.getData().getInfo().getName());
+ version.setDescription(itemVersion.getData().getInfo().getDescription());
+
+ version.setId(itemVersion.getId().getValue());
+ if (itemVersion.getBaseId() != null) {
+ version.setBaseId(itemVersion.getBaseId().getValue());
+ }
+ version.setCreationTime(itemVersion.getCreationTime());
+ version.setModificationTime(itemVersion.getModificationTime());
+ return version;
+ }
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerFactoryImpl.java
new file mode 100644
index 0000000000..ba5bd07d42
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerFactoryImpl.java
@@ -0,0 +1,39 @@
+/*-
+ * ============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.versioning.impl;
+
+import org.openecomp.sdc.itempermissions.PermissionsServicesFactory;
+import org.openecomp.sdc.notification.factories.SubscriptionServiceFactory;
+import org.openecomp.sdc.versioning.ItemManager;
+import org.openecomp.sdc.versioning.ItemManagerFactory;
+import org.openecomp.sdc.versioning.dao.ItemDaoFactory;
+
+public class ItemManagerFactoryImpl extends ItemManagerFactory {
+ private static final ItemManager INSTANCE =
+ new ItemManagerImpl(ItemDaoFactory.getInstance().createInterface(),
+ PermissionsServicesFactory.getInstance().createInterface(),
+ SubscriptionServiceFactory.getInstance().createInterface());
+
+ @Override
+ public ItemManager createInterface() {
+ return INSTANCE;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
new file mode 100644
index 0000000000..79284542fb
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
@@ -0,0 +1,68 @@
+package org.openecomp.sdc.versioning.impl;
+
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.openecomp.sdc.itempermissions.PermissionsServices;
+import org.openecomp.sdc.notification.services.SubscriptionService;
+import org.openecomp.sdc.versioning.ItemManager;
+import org.openecomp.sdc.versioning.dao.ItemDao;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.Item;
+
+import java.util.Collection;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+public class ItemManagerImpl implements ItemManager {
+ public static final String CREATE_ITEM = "Create_Item";
+
+ private ItemDao itemDao;
+ private PermissionsServices permissionsServices;
+ private SubscriptionService subscriptionService;
+
+ public ItemManagerImpl(ItemDao itemDao, PermissionsServices permissionsServices,
+ SubscriptionService subscriptionService) {
+ this.itemDao = itemDao;
+ this.permissionsServices = permissionsServices;
+ this.subscriptionService = subscriptionService;
+ }
+
+ @Override
+ public Collection<Item> list(Predicate<Item> predicate) {
+ return itemDao.list().stream().filter(predicate).collect(Collectors.toList());
+ }
+
+ @Override
+ public Item get(String itemId) {
+ Item item = new Item();
+ item.setId(itemId);
+ return itemDao.get(item);
+ }
+
+ @Override
+ public Item create(Item item) {
+ Item createdItem = itemDao.create(item);
+
+ String userId = SessionContextProviderFactory.getInstance()
+ .createInterface().get().getUser().getUserId();
+ String itemId = createdItem.getId();
+ permissionsServices.execute(itemId, userId, CREATE_ITEM);
+ subscriptionService.subscribe(userId, itemId);
+
+ return createdItem;
+ }
+
+ @Override
+ public void updateVersionStatus(String itemId, VersionStatus addedVersionStatus,
+ VersionStatus removedVersionStatus) {
+ Item item = get(itemId);
+ if (item == null) {
+ return;
+ }
+
+ item.addVersionStatus(addedVersionStatus);
+ if (removedVersionStatus != null) {
+ item.removeVersionStatus(removedVersionStatus);
+ }
+ itemDao.update(item);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorFactoryImpl.java
new file mode 100644
index 0000000000..2300f62180
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorFactoryImpl.java
@@ -0,0 +1,14 @@
+package org.openecomp.sdc.versioning.impl;
+
+import org.openecomp.sdc.versioning.VersionCalculator;
+import org.openecomp.sdc.versioning.VersionCalculatorFactory;
+
+public class MajorVersionCalculatorFactoryImpl extends VersionCalculatorFactory {
+ private static final VersionCalculator INSTANCE =
+ new MajorVersionCalculatorImpl();
+
+ @Override
+ public VersionCalculator createInterface() {
+ return INSTANCE;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImpl.java
new file mode 100644
index 0000000000..91c59e0efd
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImpl.java
@@ -0,0 +1,53 @@
+package org.openecomp.sdc.versioning.impl;
+
+import org.openecomp.core.utilities.CommonMethods;
+import org.openecomp.sdc.versioning.VersionCalculator;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.VersionCreationMethod;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class MajorVersionCalculatorImpl implements VersionCalculator {
+ private static final String INITIAL_VERSION = "1.0";
+ private static final String VERSION_STRING_VIOLATION_MSG =
+ "Version string must be in the format of: {integer}.{integer}";
+
+ @Override
+ public String calculate(String baseVersion, VersionCreationMethod creationMethod) {
+
+ if (baseVersion == null) {
+ return INITIAL_VERSION;
+ }
+
+ String[] versionLevels = baseVersion.split("\\.");
+ if (versionLevels.length != 2) {
+ throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
+ }
+
+ int index = Integer.parseInt(versionLevels[0]);
+ index++;
+ versionLevels[0] = Integer.toString(index);
+ versionLevels[1] = "0";
+
+ return CommonMethods.arrayToSeparatedString(versionLevels, '.');
+ }
+
+ @Override
+ public void injectAdditionalInfo(Version version, Set<String> existingVersions) {
+ String optionalVersion;
+ Set<VersionCreationMethod> optionalCreationMethods = new HashSet<>();
+ if(version.getStatus().equals(VersionStatus.Certified)) {
+ try {
+ optionalVersion = calculate(version.getName(), VersionCreationMethod.major);
+ if (!existingVersions.contains(optionalVersion)) {
+ optionalCreationMethods.add(VersionCreationMethod.major);
+ }
+ } catch (IllegalArgumentException iae) {
+ //not a valid creation method.
+ }
+ }
+ version.getAdditionalInfo().put("OptionalCreationMethods", optionalCreationMethods);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorFactoryImpl.java
new file mode 100644
index 0000000000..155aa9c5e6
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorFactoryImpl.java
@@ -0,0 +1,34 @@
+/*-
+ * ============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.versioning.impl;
+
+import org.openecomp.sdc.versioning.VersionCalculator;
+import org.openecomp.sdc.versioning.VersionCalculatorFactory;
+
+public class VersionCalculatorFactoryImpl extends VersionCalculatorFactory {
+ private static final VersionCalculator INSTANCE =
+ new VersionCalculatorImpl();
+
+ @Override
+ public VersionCalculator createInterface() {
+ return INSTANCE;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java
new file mode 100644
index 0000000000..b7008de867
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java
@@ -0,0 +1,155 @@
+package org.openecomp.sdc.versioning.impl;
+
+import org.openecomp.core.utilities.CommonMethods;
+import org.openecomp.sdc.versioning.VersionCalculator;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.VersionCreationMethod;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class VersionCalculatorImpl implements VersionCalculator {
+
+ private static final String INITIAL_VERSION = "1.0";
+ private static final String VERSION_STRING_VIOLATION_MSG =
+ "Version string must be in the format of: {integer}.{integer}";
+ private static final String PARENT_LEVEL_VERSION_CANNOT_BE_CREATED_FROM_TOP_LEVEL =
+ "Creation of parent level version on top level version is invalid.";
+ private static final String SUB_LEVEL_VERSION_CANNOT_BE_CREATED_FROM_LOWEST_LEVEL =
+ "Creation of parent level version on top level version is invalid.";
+
+ private static final String VERSION_CALCULATION_ERROR_MSG =
+ "Version calculation error.";
+
+ private static final String INVALID_CREATION_METHOD_MSG = "Invalid creation method-";
+
+
+ @Override
+ public String calculate(String baseVersion, VersionCreationMethod creationMethod) {
+
+ if (baseVersion == null) {
+ return INITIAL_VERSION;
+ }
+
+ String[] versionLevels = baseVersion.split("\\.");
+ if (versionLevels.length != 2) {
+ throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
+ }
+
+ int index;
+ switch (creationMethod) {
+ case major:
+ index = Integer.parseInt(versionLevels[0]);
+ index++;
+ versionLevels[0] = Integer.toString(index);
+ versionLevels[1] = "0";
+ break;
+ case minor:
+ index = Integer.parseInt(versionLevels[1]);
+ index++;
+ versionLevels[1] = Integer.toString(index);
+ break;
+ }
+ return CommonMethods.arrayToSeparatedString(versionLevels, '.');
+ }
+
+
+ // version calculator when there are no version restrictions
+ /* @Override
+ public String calculate(String baseVersion, VersionCreationMethod creationMethod) {
+
+ return calculate(baseVersion,creationMethod,2);
+ }
+
+ private String calculate(String baseVersion, VersionCreationMethod creationMethod,int
+ maxVersionLevels) {
+ if (baseVersion == null) {
+ return INITIAL_VERSION;
+ }
+
+ String[] versionLevels = baseVersion.split("\\.");
+ if (versionLevels.length > maxVersionLevels) {
+ throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
+ }
+
+ int index;
+ int versionLevel = calcVersionLevel(versionLevels);
+ if (versionLevel == -1) {
+ throw new IllegalArgumentException(
+ VERSION_STRING_VIOLATION_MSG + " given version:" + baseVersion);
+ }
+ int requiredVersionLevelIncrease;
+ switch (creationMethod) {
+ case parent_level:
+ if (versionLevel == 0) {
+ throw new IllegalArgumentException(
+ PARENT_LEVEL_VERSION_CANNOT_BE_CREATED_FROM_TOP_LEVEL + " version:" + baseVersion);
+
+ }
+ requiredVersionLevelIncrease = versionLevel - 1;
+ versionLevels[versionLevel] = "0";
+ index = Integer.getInteger(versionLevels[requiredVersionLevelIncrease]);
+ index++;
+ versionLevels[requiredVersionLevelIncrease] = Integer.toString(index);
+ break;
+ case same_level:
+ requiredVersionLevelIncrease = versionLevel;
+ index = Integer.valueOf(versionLevels[requiredVersionLevelIncrease]);
+ index++;
+ versionLevels[requiredVersionLevelIncrease] = Integer.toString(index);
+ break;
+ case sub_level:
+ if (versionLevel == versionLevels.length - 1) {
+ throw new IllegalArgumentException(
+ SUB_LEVEL_VERSION_CANNOT_BE_CREATED_FROM_LOWEST_LEVEL + " version:" + baseVersion);
+ }
+ requiredVersionLevelIncrease = versionLevel + 1;
+ if(requiredVersionLevelIncrease>maxVersionLevels){
+ throw new IllegalArgumentException(INVALID_CREATION_METHOD_MSG+" max " +
+ "levels:"+maxVersionLevels + "requested level:"+requiredVersionLevelIncrease);
+ }
+ String newVersion = baseVersion + ".1";
+ versionLevels = newVersion.split("\\.");
+
+ break;
+ default:
+ throw new IllegalArgumentException(VERSION_CALCULATION_ERROR_MSG + " base " +
+ "version:" + baseVersion + " creation method:" + creationMethod);
+
+ }
+
+ return CommonMethods.arrayToSeparatedString(versionLevels, '.');
+ }*/
+
+
+ @Override
+ public void injectAdditionalInfo(Version version, Set<String> existingVersions) {
+ String optionalVersion;
+ Set<VersionCreationMethod> optionalCreationMethods = new HashSet<>();
+ if(version.getStatus().equals(VersionStatus.Certified)) {
+ for (VersionCreationMethod versionCreationMethod : VersionCreationMethod.values()) {
+ try {
+ optionalVersion = calculate(version.getName(), versionCreationMethod);
+ if (!existingVersions.contains(optionalVersion)) {
+ optionalCreationMethods.add(versionCreationMethod);
+ }
+ } catch (IllegalArgumentException iae) {
+ //not a valid creation method.
+ }
+ }
+ }
+ version.getAdditionalInfo().put("OptionalCreationMethods", optionalCreationMethods);
+
+ }
+
+
+ private int calcVersionLevel(String[] versionLevels) {
+ for (int i = versionLevels.length - 1; i >= 0; i--) {
+ if (!versionLevels[i].equals("0")) {
+ return i;
+ }
+ }
+ return -1;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java
index 8ab5c608bf..b4dbcf3a08 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java
@@ -20,16 +20,21 @@
package org.openecomp.sdc.versioning.impl;
+import org.openecomp.sdc.versioning.ItemManagerFactory;
+import org.openecomp.sdc.versioning.VersionCalculatorFactory;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.VersioningManagerFactory;
+import org.openecomp.sdc.versioning.dao.VersionDaoFactory;
import org.openecomp.sdc.versioning.dao.VersionInfoDaoFactory;
import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDaoFactory;
public class VersioningManagerFactoryImpl extends VersioningManagerFactory {
private static final VersioningManager INSTANCE = new VersioningManagerImpl(
VersionInfoDaoFactory.getInstance().createInterface(),
- VersionInfoDeletedDaoFactory.getInstance().createInterface()
- );
+ VersionInfoDeletedDaoFactory.getInstance().createInterface(),
+ VersionDaoFactory.getInstance().createInterface(),
+ VersionCalculatorFactory.getInstance().createInterface(),
+ ItemManagerFactory.getInstance().createInterface());
@Override
public VersioningManager createInterface() {
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
index 4a49d5391f..7f983477cf 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
@@ -21,25 +21,31 @@
package org.openecomp.sdc.versioning.impl;
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.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
import org.openecomp.sdc.logging.types.LoggerConstants;
import org.openecomp.sdc.logging.types.LoggerErrorCode;
import org.openecomp.sdc.logging.types.LoggerErrorDescription;
import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
+import org.openecomp.sdc.versioning.ItemManager;
+import org.openecomp.sdc.versioning.VersionCalculator;
import org.openecomp.sdc.versioning.VersioningManager;
+import org.openecomp.sdc.versioning.dao.VersionDao;
import org.openecomp.sdc.versioning.dao.VersionInfoDao;
import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
import org.openecomp.sdc.versioning.dao.VersionableEntityDaoFactory;
+import org.openecomp.sdc.versioning.dao.types.Revision;
+import org.openecomp.sdc.versioning.dao.types.SynchronizationState;
import org.openecomp.sdc.versioning.dao.types.UserCandidateVersion;
import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.dao.types.VersionHistoryEntity;
import org.openecomp.sdc.versioning.dao.types.VersionInfoDeletedEntity;
import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.sdc.versioning.dao.types.VersionType;
-import org.openecomp.sdc.versioning.dao.types.VersionableEntityId;
import org.openecomp.sdc.versioning.errors.CheckinOnEntityLockedByOtherErrorBuilder;
import org.openecomp.sdc.versioning.errors.CheckinOnUnlockedEntityErrorBuilder;
import org.openecomp.sdc.versioning.errors.CheckoutOnLockedEntityErrorBuilder;
@@ -52,6 +58,7 @@ import org.openecomp.sdc.versioning.errors.EntityNotExistErrorBuilder;
import org.openecomp.sdc.versioning.errors.SubmitLockedEntityNotAllowedErrorBuilder;
import org.openecomp.sdc.versioning.errors.UndoCheckoutOnEntityLockedByOtherErrorBuilder;
import org.openecomp.sdc.versioning.errors.UndoCheckoutOnUnlockedEntityErrorBuilder;
+import org.openecomp.sdc.versioning.types.VersionCreationMethod;
import org.openecomp.sdc.versioning.types.VersionInfo;
import org.openecomp.sdc.versioning.types.VersionableEntityAction;
import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
@@ -66,18 +73,27 @@ import java.util.Set;
import java.util.stream.Collectors;
public class VersioningManagerImpl implements VersioningManager {
-
+ private static final Logger LOGGER = LoggerFactory.getLogger(VersioningManagerImpl.class);
private static final Version INITIAL_ACTIVE_VERSION = new Version(0, 0);
private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
private static Map<String, Set<VersionableEntityMetadata>> versionableEntities = new HashMap<>();
- private VersionInfoDao versionInfoDao;
- private VersionInfoDeletedDao versionInfoDeletedDao;
+ private final VersionInfoDao versionInfoDao;
+ private final VersionInfoDeletedDao versionInfoDeletedDao;
+ private VersionDao versionDao;
+ private VersionCalculator versionCalculator;
+ private ItemManager itemManager;
public VersioningManagerImpl(VersionInfoDao versionInfoDao,
- VersionInfoDeletedDao versionInfoDeletedDao) {
+ VersionInfoDeletedDao versionInfoDeletedDao,
+ VersionDao versionDao,
+ VersionCalculator versionCalculator,
+ ItemManager itemManager) {
this.versionInfoDao = versionInfoDao;
this.versionInfoDeletedDao = versionInfoDeletedDao;
+ this.versionDao = versionDao;
+ this.versionCalculator = versionCalculator;
+ this.itemManager = itemManager;
}
private static VersionInfo getVersionInfo(VersionInfoEntity versionInfoEntity, String user,
@@ -146,8 +162,12 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfo versionInfo = new VersionInfo();
versionInfo.setStatus(status);
activeVersion.setStatus(status);
- if(latestFinalVersion!= null) latestFinalVersion.setStatus(status);
- if(viewableVersions != null) viewableVersions.forEach(version->version.setStatus(status));
+ if (latestFinalVersion != null) {
+ latestFinalVersion.setStatus(status);
+ }
+ if (viewableVersions != null) {
+ viewableVersions.forEach(version -> version.setStatus(status));
+ }
versionInfo.setActiveVersion(activeVersion);
versionInfo.setLatestFinalVersion(latestFinalVersion);
versionInfo.setViewableVersions(toSortedList(viewableVersions));
@@ -166,11 +186,9 @@ public class VersioningManagerImpl implements VersioningManager {
private static List<Version> toSortedList(
Set<Version> versions) { // changing the Set to List in DB will require migration...
- return versions.stream().sorted((o1, o2) -> {
- return o1.getMajor() > o2.getMajor() ? 1
- : o1.getMajor() == o2.getMajor() ? (o1.getMinor() > o2.getMinor() ? 1
- : o1.getMinor() == o2.getMinor() ? 0 : -1) : -1;
- }).collect(Collectors.toList());
+ return versions.stream().sorted((o1, o2) -> o1.getMajor() > o2.getMajor() ? 1
+ : o1.getMajor() == o2.getMajor() ? (o1.getMinor() > o2.getMinor() ? 1
+ : o1.getMinor() == o2.getMinor() ? 0 : -1) : -1).collect(Collectors.toList());
}
private static List<Version> getFinalVersions(Set<Version> versions) {
@@ -263,8 +281,8 @@ public class VersioningManagerImpl implements VersioningManager {
LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't checkout versionable entity");
throw new CoreException(new CheckoutOnLockedEntityErrorBuilder(entityType, entityId,
versionInfoEntity.getCandidate().getUser()).build());
- case Final:
- case Available:
+ case Certified:
+ case Draft:
checkoutVersion = doCheckout(versionInfoEntity, user);
break;
default:
@@ -300,8 +318,8 @@ public class VersioningManagerImpl implements VersioningManager {
}
activeVersion = undoCheckout(versionInfoEntity);
break;
- case Final:
- case Available:
+ case Certified:
+ case Draft:
MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
LoggerTragetServiceName.UNDO_CHECKOUT_ENTITY, ErrorLevel.ERROR.name(),
LoggerErrorCode.PERMISSION_ERROR.getErrorCode(),
@@ -320,8 +338,9 @@ public class VersioningManagerImpl implements VersioningManager {
deleteVersionFromEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(),
versionInfoEntity.getCandidate().getVersion(), versionInfoEntity.getActiveVersion());
- versionInfoEntity.setStatus(versionInfoEntity.getActiveVersion().isFinal() ? VersionStatus.Final
- : VersionStatus.Available);
+ versionInfoEntity
+ .setStatus(versionInfoEntity.getActiveVersion().isFinal() ? VersionStatus.Certified
+ : VersionStatus.Draft);
versionInfoEntity.setCandidate(null);
versionInfoDao.update(versionInfoEntity);
return versionInfoEntity.getActiveVersion();
@@ -341,8 +360,8 @@ public class VersioningManagerImpl implements VersioningManager {
Version checkedInVersion = null;
switch (versionInfoEntity.getStatus()) {
- case Available:
- case Final:
+ case Draft:
+ case Certified:
MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
LoggerTragetServiceName.CHECKIN_ENTITY, ErrorLevel.ERROR.name(),
LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't checkin versionable entity");
@@ -379,7 +398,7 @@ public class VersioningManagerImpl implements VersioningManager {
Version submitVersion = null;
switch (versionInfoEntity.getStatus()) {
- case Final:
+ case Certified:
MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't submit versionable entity");
@@ -391,7 +410,7 @@ public class VersioningManagerImpl implements VersioningManager {
LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't submit versionable entity");
throw new CoreException(new SubmitLockedEntityNotAllowedErrorBuilder(entityType, entityId,
versionInfoEntity.getCandidate().getUser()).build());
- case Available:
+ case Draft:
submitVersion = doSubmit(versionInfoEntity, user, submitDescription);
break;
default:
@@ -444,6 +463,143 @@ public class VersioningManagerImpl implements VersioningManager {
return activeVersions;
}
+ @Override
+ public List<Version> list(String itemId) {
+
+ List<Version> versions = versionDao.list(itemId);
+ Set<String> versionsNames = versions.stream().map(Version::getName).collect(Collectors.toSet());
+ versions.forEach(version -> {
+ version.setAdditionalInfo(new HashMap<>());
+ versionCalculator.injectAdditionalInfo(version, versionsNames);
+ });
+ return versions;
+ }
+
+ @Override
+ public Version get(String itemId, Version version) {
+ return versionDao.get(itemId, version)
+ .map(retrievedVersion -> getUpdateRetrievedVersion(itemId, retrievedVersion))
+ .orElseGet(() -> getSyncedVersion(itemId, version));
+ }
+
+ private Version getUpdateRetrievedVersion(String itemId, Version version) {
+ if (version.getStatus() == VersionStatus.Certified &&
+ (version.getState().getSynchronizationState() == SynchronizationState.OutOfSync ||
+ version.getState().isDirty())) {
+ forceSync(itemId, version);
+ LOGGER.info("Item Id {}, version Id {}: Force sync is done", itemId, version.getId());
+ version = versionDao.get(itemId, version)
+ .orElseThrow(() -> new IllegalStateException(
+ "Get version after a successful force sync must return the version"));
+ }
+ return version;
+ }
+
+ private Version getSyncedVersion(String itemId, Version version) {
+ sync(itemId, version);
+ LOGGER.info("Item Id {}, version Id {}: First time sync is done", itemId, version.getId());
+ return versionDao.get(itemId, version)
+ .orElseThrow(() -> new IllegalStateException(
+ "Get version after a successful sync must return the version"));
+ }
+
+ @Override
+ public Version create(String itemId, Version version, VersionCreationMethod creationMethod) {
+ String baseVersionName = null;
+ if (version.getBaseId() == null) {
+ version.setDescription("Initial version");
+ } else {
+ baseVersionName = get(itemId, new Version(version.getBaseId())).getName();
+ }
+ String versionName = versionCalculator.calculate(baseVersionName, creationMethod);
+ validateVersionName(itemId, versionName);
+ version.setName(versionName);
+
+ versionDao.create(itemId, version);
+ itemManager.updateVersionStatus(itemId, VersionStatus.Draft, null);
+
+ publish(itemId, version, String.format("Initial version: %s ", version.getName()));
+ return version;
+ }
+
+ private void validateVersionName(String itemId, String versionName) {
+ if (versionDao.list(itemId).stream()
+ .anyMatch(version -> versionName.equals(version.getName()))) {
+ String errorDescription = String
+ .format("Item %s: create version failed, a version with the name %s already exist",
+ itemId, versionName);
+
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY,
+ LoggerTragetServiceName.CREATE_VERSION, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), errorDescription);
+
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder()
+ .withCategory(ErrorCategory.APPLICATION)
+ .withId("VERSION_NAME_ALREADY_EXIST")
+ .withMessage(errorDescription)
+ .build());
+ }
+ }
+
+ @Override
+ public void submit(String itemId, Version version, String submitDescription) {
+ version = get(itemId, version);
+
+ validateSubmit(itemId, version);
+
+ version.setStatus(VersionStatus.Certified);
+ versionDao.update(itemId, version);
+
+ publish(itemId, version, submitDescription);
+
+ itemManager.updateVersionStatus(itemId, VersionStatus.Certified, VersionStatus.Draft);
+ }
+
+ private void validateSubmit(String itemId, Version version) {
+ if (version.getStatus() == VersionStatus.Certified) {
+ String errorDescription = String
+ .format("Item %s: submit version failed, version %s is already Certified", itemId,
+ version.getId());
+
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), errorDescription);
+
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder()
+ .withCategory(ErrorCategory.APPLICATION)
+ .withId("VERSION_ALREADY_CERTIFIED")
+ .withMessage(errorDescription)
+ .build());
+ }
+ }
+
+ @Override
+ public void publish(String itemId, Version version, String message) {
+ versionDao.publish(itemId, version, message);
+ }
+
+
+ @Override
+ public void sync(String itemId, Version version) {
+ versionDao.sync(itemId, version);
+ }
+
+ @Override
+ public void forceSync(String itemId, Version version) {
+ versionDao.forceSync(itemId, version);
+ }
+
+ @Override
+ public void revert(String itemId, Version version, String revisionId) {
+ versionDao.revert(itemId, version, revisionId);
+ }
+
+ @Override
+ public List<Revision> listRevisions(String itemId, Version version) {
+ return versionDao.listRevisions(itemId, version);
+
+ }
+
private void markAsCheckedOut(VersionInfoEntity versionInfoEntity, String checkingOutUser) {
versionInfoEntity.setStatus(VersionStatus.Locked);
versionInfoEntity.setCandidate(new UserCandidateVersion(checkingOutUser,
@@ -491,7 +647,7 @@ public class VersioningManagerImpl implements VersioningManager {
versionInfoEntity.setCandidate(null);
versionInfoEntity.setActiveVersion(userCandidateVersion.getVersion());
versionInfoEntity.getViewableVersions().add(versionInfoEntity.getActiveVersion());
- versionInfoEntity.setStatus(VersionStatus.Available);
+ versionInfoEntity.setStatus(VersionStatus.Draft);
closeVersionOnEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(),
versionInfoEntity.getActiveVersion());
@@ -519,22 +675,12 @@ public class VersioningManagerImpl implements VersioningManager {
versionInfoEntity.setViewableVersions(viewableVersions);
versionInfoEntity.setActiveVersion(finalVersion);
versionInfoEntity.setLatestFinalVersion(finalVersion);
- versionInfoEntity.setStatus(VersionStatus.Final);
+ versionInfoEntity.setStatus(VersionStatus.Certified);
versionInfoDao.update(versionInfoEntity);
return finalVersion;
}
- private void createVersionHistory(VersionableEntityId entityId, Version version, String user,
- String description, VersionType type) {
- VersionHistoryEntity versionHistory = new VersionHistoryEntity(entityId);
- versionHistory.setVersion(version);
- versionHistory.setUser(user);
- versionHistory.setDescription(description);
- versionHistory.setType(type);
- //versionHistoryDao.create(versionHistory);
- }
-
private void initVersionOnEntity(String entityType, String entityId, Version baseVersion,
Version newVersion) {
Set<VersionableEntityMetadata> entityMetadatas = versionableEntities.get(entityType);
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/resources/factoryConfiguration.json
new file mode 100644
index 0000000000..d2d16eff37
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/resources/factoryConfiguration.json
@@ -0,0 +1,3 @@
+{
+ "org.openecomp.sdc.versioning.VersionCalculatorFactory": "org.openecomp.sdc.versioning.impl.MajorVersionCalculatorFactoryImpl"
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java
new file mode 100644
index 0000000000..1f1efdf6cb
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImplTest.java
@@ -0,0 +1,265 @@
+package org.openecomp.sdc.versioning.dao.impl.zusammen;
+
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.UserInfo;
+import com.amdocs.zusammen.datatypes.item.Info;
+import com.amdocs.zusammen.datatypes.item.ItemVersion;
+import com.amdocs.zusammen.datatypes.item.ItemVersionData;
+import com.amdocs.zusammen.datatypes.item.ItemVersionStatus;
+import com.amdocs.zusammen.datatypes.item.SynchronizationStatus;
+import org.mockito.ArgumentCaptor;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isNull;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+
+public class VersionZusammenDaoImplTest {
+
+ private static final String USER = "user1";
+ @Mock
+ private ZusammenAdaptor zusammenAdaptorMock;
+ @InjectMocks
+ private VersionZusammenDaoImpl versionDao;
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ SessionContextProviderFactory.getInstance().createInterface().create(USER);
+ }
+
+ @Test
+ public void testList() throws Exception {
+ String itemId = "itemId";
+ Id versionId1 = new Id("v1_id");
+ Id versionId2 = new Id("v2_id");
+ Id versionId3 = new Id("v3_id");
+
+ List<ItemVersion> zusammenVersions = Stream.of(
+ createZusammenVersion(versionId1, null, "version desc", "1.0", VersionStatus.Certified),
+ createZusammenVersion(versionId2, versionId1, "version desc", "2.0", VersionStatus.Certified
+ ),
+ createZusammenVersion(versionId3, versionId2, "version desc", "3.0", VersionStatus.Draft))
+ .collect(Collectors.toList());
+ doReturn(zusammenVersions).when(zusammenAdaptorMock)
+ .listPublicVersions(eq(createZusammenContext()), eq(new Id(itemId)));
+
+ List<Version> versions = versionDao.list(itemId);
+ Assert.assertEquals(versions.size(), 3);
+
+ int zusammenVersionIndex;
+ for (Version version : versions) {
+ zusammenVersionIndex = versionId1.getValue().equals(version.getId())
+ ? 0
+ : versionId2.getValue().equals(version.getId())
+ ? 1
+ : 2;
+ assetVersionEquals(version, zusammenVersions.get(zusammenVersionIndex));
+ }
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ testCreate(null);
+ }
+
+ @Test
+ public void testCreateBasedOn() throws Exception {
+ testCreate("baseId");
+ }
+
+ private void testCreate(String baseId) {
+ String itemId = "itemId";
+ Version version = new Version(1, 0);
+ version.setBaseId(baseId);
+ version.setName("version name");
+ version.setDescription("version description");
+ version.setStatus(VersionStatus.Draft);
+
+ doReturn(new Id("versionId")).when(zusammenAdaptorMock)
+ .createVersion(eq(createZusammenContext()), eq(new Id(itemId)),
+ baseId == null ? isNull(Id.class) : eq(new Id(baseId)), any(ItemVersionData.class));
+
+ ArgumentCaptor<ItemVersionData> capturedZusammenVersion =
+ ArgumentCaptor.forClass(ItemVersionData.class);
+
+ versionDao.create(itemId, version);
+
+ verify(zusammenAdaptorMock)
+ .createVersion(eq(createZusammenContext()), eq(new Id(itemId)),
+ baseId == null ? isNull(Id.class) : eq(new Id(baseId)),
+ capturedZusammenVersion.capture());
+
+ Info capturedInfo = capturedZusammenVersion.getValue().getInfo();
+ Assert.assertEquals(capturedInfo.getName(), version.getName());
+ Assert.assertEquals(capturedInfo.getDescription(), version.getDescription());
+ Assert.assertEquals(VersionStatus
+ .valueOf(capturedInfo.getProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS)),
+ version.getStatus());
+ Assert.assertEquals(capturedInfo.getProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL),
+ version.toString());
+ }
+
+ @Test
+ public void testUpdate() throws Exception {
+ String itemId = "itemId";
+ Version version = new Version(1, 0);
+ version.setId("versionId");
+ version.setBaseId("baseId");
+ version.setName("version name");
+ version.setDescription("version description");
+ version.setStatus(VersionStatus.Certified);
+
+ ArgumentCaptor<ItemVersionData> capturedZusammenVersion =
+ ArgumentCaptor.forClass(ItemVersionData.class);
+
+ versionDao.update(itemId, version);
+
+ verify(zusammenAdaptorMock)
+ .updateVersion(eq(createZusammenContext()), eq(new Id(itemId)), eq(new Id(version.getId())),
+ capturedZusammenVersion.capture());
+
+ Info capturedInfo = capturedZusammenVersion.getValue().getInfo();
+ Assert.assertEquals(capturedInfo.getName(), version.getName());
+ Assert.assertEquals(capturedInfo.getDescription(), version.getDescription());
+ Assert.assertEquals(VersionStatus
+ .valueOf(capturedInfo.getProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS)),
+ version.getStatus());
+ Assert.assertEquals(capturedInfo.getProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL),
+ version.toString());
+ }
+
+ @Test
+ public void testGetNonExisting() throws Exception {
+ Optional<Version> version = versionDao.get("itemId", new Version("versionId"));
+
+ Assert.assertEquals(version, Optional.empty());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+
+ SessionContext zusammenContext = createZusammenContext();
+ Id itemIdObj = new Id(itemId);
+ Id versionIdObj = new Id(versionId);
+
+ ItemVersion zusammenPrivateVersion =
+ createZusammenVersion(versionIdObj, new Id("baseId"), "version desc updated", "2.0",
+ VersionStatus.Draft);
+ doReturn(zusammenPrivateVersion).when(zusammenAdaptorMock)
+ .getVersion(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
+
+ doReturn(new ItemVersionStatus(SynchronizationStatus.UP_TO_DATE, true))
+ .when(zusammenAdaptorMock)
+ .getVersionStatus(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
+
+ ItemVersion zusammenPublicVersion =
+ createZusammenVersion(versionIdObj, new Id("baseId"), "version desc", "2.0",
+ VersionStatus.Certified);
+ doReturn(zusammenPublicVersion).when(zusammenAdaptorMock)
+ .getPublicVersion(eq(zusammenContext), eq(itemIdObj), eq(versionIdObj));
+
+ Optional<Version> version = versionDao.get(itemId, new Version(versionId));
+
+ Assert.assertTrue(version.isPresent());
+ zusammenPrivateVersion.getData().getInfo()
+ .addProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS,
+ VersionStatus.Certified.name());
+ assetVersionEquals(version.get(), zusammenPrivateVersion);
+ }
+
+ // TODO: 12/20/2017 complete tests
+ /* @Test
+ public void testDelete() throws Exception {
+
+ }
+
+ @Test
+ public void testPublish() throws Exception {
+
+ }
+
+ @Test
+ public void testSync() throws Exception {
+
+ }
+
+ @Test
+ public void testForceSync() throws Exception {
+
+ }
+
+ @Test
+ public void testRevert() throws Exception {
+
+ }
+
+ @Test
+ public void testListRevisions() throws Exception {
+
+ }*/
+
+ private void assetVersionEquals(Version version, ItemVersion zusammenVersion) {
+ Assert.assertEquals(version.getId(), zusammenVersion.getId().getValue());
+ Assert.assertEquals(version.getBaseId(),
+ zusammenVersion.getBaseId() == null ? null : zusammenVersion.getBaseId().getValue());
+ Info info = zusammenVersion.getData().getInfo();
+ Assert.assertEquals(version.getName(), info.getName());
+ Assert.assertEquals(version.getDescription(), info.getDescription());
+ Assert.assertEquals(version.getStatus(),
+ VersionStatus.valueOf(info.getProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS)));
+ String label = info.getProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL).toString();
+ Assert
+ .assertEquals(version.getMajor(), Integer.parseInt(label.substring(0, label.indexOf('.'))));
+ Assert.assertEquals(version.getMinor(),
+ Integer.parseInt(label.substring(label.indexOf('.') + 1, label.length())));
+ Assert.assertEquals(version.getCreationTime(), zusammenVersion.getCreationTime());
+ Assert.assertEquals(version.getModificationTime(), zusammenVersion.getModificationTime());
+ }
+
+ private ItemVersion createZusammenVersion(Id id, Id baseId, String description, String label,
+ VersionStatus status) {
+ ItemVersion version = new ItemVersion();
+ version.setId(id);
+ version.setBaseId(baseId);
+ Info info = new Info();
+ info.setName(id + "_name");
+ info.setDescription(description);
+ info.addProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL, label);
+ info.addProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS, status.name());
+ ItemVersionData data = new ItemVersionData();
+ data.setInfo(info);
+ version.setData(data);
+ version.setCreationTime(new Date());
+ version.setModificationTime(new Date());
+ return version;
+ }
+
+ private SessionContext createZusammenContext() {
+ SessionContext sessionContext = new SessionContext();
+ sessionContext.setUser(new UserInfo(USER));
+ sessionContext.setTenant("dox");
+ return sessionContext;
+ }
+
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java
new file mode 100644
index 0000000000..755bfb4442
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/ItemManagerImplTest.java
@@ -0,0 +1,124 @@
+package org.openecomp.sdc.versioning.impl;
+
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.openecomp.sdc.itempermissions.PermissionsServices;
+import org.openecomp.sdc.notification.services.SubscriptionService;
+import org.openecomp.sdc.versioning.dao.ItemDao;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+import org.openecomp.sdc.versioning.types.Item;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.Collection;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+public class ItemManagerImplTest {
+
+ @Mock
+ private ItemDao itemDao;
+ @Mock
+ private PermissionsServices permissionsServices;
+ @Mock
+ private SubscriptionService subscriptionService;
+ @InjectMocks
+ private ItemManagerImpl itemManager;
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testList() throws Exception {
+ doReturn(Stream.of(
+ createItem("item1", "A"),
+ createItem("item2", "B"),
+ createItem("item3", "B"),
+ createItem("item4", "A"))
+ .collect(Collectors.toList())).when(itemDao).list();
+
+ Collection<Item> items = itemManager.list(item -> "B".equals(item.getType()));
+ Assert.assertEquals(items.size(), 2);
+ Assert.assertTrue(items.stream().anyMatch(item -> "item2".equals(item.getName())));
+ Assert.assertTrue(items.stream().anyMatch(item -> "item3".equals(item.getName())));
+ }
+
+ @Test
+ public void testGetNotExisting() throws Exception {
+ Item item = itemManager.get("item1");
+ Assert.assertNull(item);
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ Item toBeReturned = new Item();
+ toBeReturned.setId("itemId");
+ doReturn(toBeReturned).when(itemDao).get(any(Item.class));
+
+ Item item = itemManager.get("itemId");
+ Assert.assertEquals(item.getId(), "itemId");
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ SessionContextProviderFactory.getInstance().createInterface().create("user1");
+
+ Item toBeReturned = new Item();
+ toBeReturned.setId("itemId");
+ doReturn(toBeReturned).when(itemDao).create(any(Item.class));
+
+ Item item = itemManager.create(createItem("item1", "A"));
+ Assert.assertEquals(item.getId(), "itemId");
+ }
+
+ @Test
+ public void testUpdateNotExistingVersionStatus() throws Exception {
+ itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ verify(itemDao, never()).update(any(Item.class));
+ }
+
+ @Test
+ public void testUpdateVersionStatusWhenNone() throws Exception {
+ Item item = new Item();
+ item.setId("itemId");
+ doReturn(item).when(itemDao).get(any(Item.class));
+
+ itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ verify(itemDao).update(item);
+ Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 1);
+ Assert.assertNull(item.getVersionStatusCounters().get(VersionStatus.Draft));
+ }
+
+ @Test
+ public void testUpdateVersionStatus() throws Exception {
+ Item item = new Item();
+ item.setId("itemId");
+ item.getVersionStatusCounters().put(VersionStatus.Certified, 2);
+ item.getVersionStatusCounters().put(VersionStatus.Draft, 5);
+ doReturn(item).when(itemDao).get(any(Item.class));
+
+ itemManager.updateVersionStatus("itemId", VersionStatus.Certified, VersionStatus.Draft);
+ verify(itemDao).update(item);
+ Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Certified).intValue(), 3);
+ Assert.assertEquals(item.getVersionStatusCounters().get(VersionStatus.Draft).intValue(), 4);
+ }
+
+ private Item createItem(String name, String type) {
+ Item item = new Item();
+ item.setId(name);
+ item.setName(name);
+ item.setType(type);
+ return item;
+ }
+
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java
index d35de4f3d1..2d1109abe6 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/impl/VersioningManagerImplTest.java
@@ -21,39 +21,326 @@
package org.openecomp.sdc.versioning.impl;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
import org.mockito.ArgumentCaptor;
-import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.versioning.dao.VersionInfoDao;
-import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
-import org.openecomp.sdc.versioning.dao.types.UserCandidateVersion;
+import org.openecomp.sdc.versioning.ItemManager;
+import org.openecomp.sdc.versioning.VersionCalculator;
+import org.openecomp.sdc.versioning.dao.VersionDao;
+import org.openecomp.sdc.versioning.dao.types.Revision;
+import org.openecomp.sdc.versioning.dao.types.SynchronizationState;
import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.dao.types.VersionInfoDeletedEntity;
-import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
+import org.openecomp.sdc.versioning.dao.types.VersionState;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.sdc.versioning.types.VersionInfo;
-import org.openecomp.sdc.versioning.types.VersionableEntityAction;
+import org.openecomp.sdc.versioning.types.VersionCreationMethod;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.openecomp.sdc.versioning.dao.types.SynchronizationState.OutOfSync;
+import static org.openecomp.sdc.versioning.dao.types.SynchronizationState.UpToDate;
+import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
+import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft;
public class VersioningManagerImplTest {
+ @Mock
+ private VersionDao versionDaoMock;
+ @Mock
+ private VersionCalculator versionCalculatorMock;
+ @Mock
+ private ItemManager itemManagerMock;
+ @InjectMocks
+ private VersioningManagerImpl versioningManager;
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testList() throws Exception {
+ String itemId = "itemId";
+
+ List<Version> returnedVersions = Stream.of(createVersion("1", null, null, false),
+ createVersion("2", null, null, false),
+ createVersion("3", null, null, false)).collect(Collectors.toList());
+ doReturn(returnedVersions).when(versionDaoMock).list(itemId);
+
+ List<Version> versions = versioningManager.list(itemId);
+ Assert.assertEquals(versions, returnedVersions);
+ }
+
+ @Test(expectedExceptions = Exception.class)
+ public void testGetNonExisting() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ doReturn(Optional.empty()).when(versionDaoMock).get(itemId, version);
+ doThrow(new Exception()).when(versionDaoMock).sync(itemId, version);
+
+ versioningManager.get(itemId, version);
+ }
+
+ @Test
+ public void testGetNonExistingForUser() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version requestedVersion = new Version(versionId);
+
+ Version returnedVersion = createVersion(versionId, Draft, UpToDate, false);
+ doReturn(Optional.empty()).doReturn(Optional.of(returnedVersion))
+ .when(versionDaoMock).get(itemId, requestedVersion);
+
+ Version version = versioningManager.get(itemId, requestedVersion);
+ Assert.assertEquals(version, returnedVersion);
+
+ verify(versionDaoMock, times(2)).get(itemId, requestedVersion);
+ verify(versionDaoMock).sync(itemId, requestedVersion);
+ }
+
+ @Test
+ public void testGetOutOfSyncCertified() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version requestedVersion = new Version(versionId);
+
+ Version returnedVersion = createVersion(versionId, Certified, UpToDate, false);
+ doReturn(Optional.of(createVersion(versionId, Certified, OutOfSync, false)))
+ .doReturn(Optional.of(returnedVersion))
+ .when(versionDaoMock).get(itemId, requestedVersion);
+
+ Version version = versioningManager.get(itemId, requestedVersion);
+ Assert.assertEquals(version, returnedVersion);
+
+ verify(versionDaoMock, times(2)).get(itemId, requestedVersion);
+ verify(versionDaoMock).forceSync(itemId, requestedVersion);
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version requestedVersion = new Version(versionId);
+
+ Version returnedVersion = createVersion(versionId, Draft, OutOfSync, true);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, requestedVersion);
+
+ Version version = versioningManager.get(itemId, requestedVersion);
+ Assert.assertEquals(version, returnedVersion);
+
+ verify(versionDaoMock).get(itemId, requestedVersion);
+ verify(versionDaoMock, never()).sync(any(), any());
+ verify(versionDaoMock, never()).forceSync(any(), any());
+ }
+
+ @Test
+ public void testCreate() throws Exception {
+ String itemId = "itemId";
+ Version requestedVersion = new Version();
+
+ String versionName = "versionName";
+ doReturn(versionName).when(versionCalculatorMock).calculate(null, VersionCreationMethod.major);
+
+ doReturn(Stream.of(createVersion("1", null, null, false),
+ createVersion("2", null, null, false),
+ createVersion("3", null, null, false)).collect(Collectors.toList()))
+ .when(versionDaoMock).list(itemId);
+
+ Version version =
+ versioningManager.create(itemId, requestedVersion, VersionCreationMethod.major);
+ Assert.assertNotNull(version);
+ Assert.assertEquals(version.getName(), versionName);
+
+ verify(versionDaoMock).create(itemId, requestedVersion);
+ verify(itemManagerMock).updateVersionStatus(itemId, Draft, null);
+ verify(versionDaoMock).publish(eq(itemId), eq(requestedVersion), anyString());
+ }
+
+ @Test
+ public void testCreateBasedOn() throws Exception {
+ String itemId = "itemId";
+ Version requestedVersion = new Version();
+ requestedVersion.setBaseId("baseVersionId");
+
+ Version baseVersion = createVersion(requestedVersion.getBaseId(), Certified, UpToDate, false);
+ // TODO: 12/13/2017 fix to eq(new Version("baseVersionId")) when version.equals will be fixed
+ doReturn(Optional.of(baseVersion)).when(versionDaoMock).get(eq(itemId), any(Version.class));
+
+ String versionName = "4.0";
+ doReturn(versionName)
+ .when(versionCalculatorMock).calculate(baseVersion.getName(), VersionCreationMethod.major);
+
+ doReturn(Stream.of(createVersion("1", null, null, false),
+ createVersion("2", null, null, false),
+ createVersion("3", null, null, false)).collect(Collectors.toList()))
+ .when(versionDaoMock).list(itemId);
+
+ Version version =
+ versioningManager.create(itemId, requestedVersion, VersionCreationMethod.major);
+ Assert.assertNotNull(version);
+ Assert.assertEquals(version.getName(), versionName);
+
+ verify(versionDaoMock).create(itemId, requestedVersion);
+ verify(itemManagerMock).updateVersionStatus(itemId, Draft, null);
+ verify(versionDaoMock).publish(eq(itemId), eq(requestedVersion), anyString());
+ }
+
+ @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp =
+ "Item itemId: create version failed, a version with the name 2.0 already exist")
+ public void testCreateWithExistingName() throws Exception {
+ String itemId = "itemId";
+ Version version = new Version();
+ version.setBaseId("baseVersionId");
+
+ Version baseVersion = createVersion(version.getBaseId(), Certified, UpToDate, false);
+ // TODO: 12/13/2017 fix to eq(new Version("baseVersionId")) when version.equals will be fixed
+ doReturn(Optional.of(baseVersion)).when(versionDaoMock).get(eq(itemId), any(Version.class));
+
+ String versionName = "2.0";
+ doReturn(versionName)
+ .when(versionCalculatorMock).calculate(baseVersion.getName(), VersionCreationMethod.major);
+
+ doReturn(Stream.of(createVersion("1", null, null, false),
+ createVersion("2", null, null, false),
+ createVersion("3", null, null, false)).collect(Collectors.toList()))
+ .when(versionDaoMock).list(itemId);
+
+ versioningManager.create(itemId, version, VersionCreationMethod.major);
+ }
+
+ @Test(expectedExceptions = CoreException.class, expectedExceptionsMessageRegExp =
+ "Item itemId: submit version failed, version versionId is already Certified")
+ public void testSubmitCertified() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ Version returnedVersion = createVersion(versionId, Certified, UpToDate, false);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, version);
+
+ versioningManager.submit(itemId, version, "Submit message");
+ }
+
+ @Test
+ public void testSubmit() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ ArgumentCaptor<Version> versionArgumentCaptor = ArgumentCaptor.forClass(Version.class);
+
+ Version returnedVersion = createVersion(versionId, Draft, UpToDate, false);
+ doReturn(Optional.of(returnedVersion)).when(versionDaoMock).get(itemId, version);
+
+ String submitDescription = "Submit message";
+ versioningManager.submit(itemId, version, submitDescription);
+
+ verify(versionDaoMock).update(eq(itemId), versionArgumentCaptor.capture());
+ Assert.assertEquals(Certified, versionArgumentCaptor.getValue().getStatus());
+ verify(versionDaoMock).publish(itemId, version, submitDescription);
+ verify(itemManagerMock).updateVersionStatus(itemId, Certified, Draft);
+ }
+
+ @Test
+ public void testPublish() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+ String publishDescription = "Publish message";
+
+ versioningManager.publish(itemId, version, publishDescription);
+
+ verify(versionDaoMock).publish(itemId, version, publishDescription);
+ }
+
+ @Test
+ public void testSync() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ versioningManager.sync(itemId, version);
+
+ verify(versionDaoMock).sync(itemId, version);
+ }
+
+ @Test
+ public void testForceSync() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ versioningManager.forceSync(itemId, version);
+
+ verify(versionDaoMock).forceSync(itemId, version);
+ }
+
+ @Test
+ public void testRevert() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+ String revisionId = "revisionId";
+
+ versioningManager.revert(itemId, version, revisionId);
+
+ verify(versionDaoMock).revert(itemId, version, revisionId);
+ }
+
+ @Test
+ public void testListRevisions() throws Exception {
+ String itemId = "itemId";
+ String versionId = "versionId";
+ Version version = new Version(versionId);
+
+ List<Revision> returnedRevisions =
+ Stream.of(new Revision(), new Revision()).collect(Collectors.toList());
+ doReturn(returnedRevisions)
+ .when(versionDaoMock).listRevisions(itemId, version);
+
+ List<Revision> revisions = versioningManager.listRevisions(itemId, version);
+ Assert.assertEquals(revisions, returnedRevisions);
+ }
+
+ private Version createVersion(String id, VersionStatus status,
+ SynchronizationState syncState, boolean dirty) {
+ Version version = new Version(id);
+ version.setName(id + ".0");
+ version.setDescription(id + " desc");
+ version.setStatus(status);
+
+ VersionState state = new VersionState();
+ state.setSynchronizationState(syncState);
+ state.setDirty(dirty);
+ version.setState(state);
+ return version;
+ }
+
+/*
private static final String USR1 = "usr1";
private static final String USR2 = "usr2";
private static final String TYPE1 = "Type1";
-/* private static final String TYPE2 = "Type2";*/
+*/
+/* private static final String TYPE2 = "Type2";*//*
+
private static final String ID1 = "Id1";
+*/
/* private static final String ID2 = "Id2";
private static final String ID3 = "Id3";
private static final String TYPE1_TABLE_NAME = "vendor_license_model";
@@ -61,17 +348,20 @@ public class VersioningManagerImplTest {
private static final String TYPE1_VERSION_NAME = "version";
private static final String TYPE2_TABLE_NAME = "feature_group";
private static final String TYPE2_ID_NAME = "vlm_id";
- private static final String TYPE2_VERSION_NAME = "version";*/
+ private static final String TYPE2_VERSION_NAME = "version";*//*
+
private static final Version VERSION0 = new Version(0, 0);
private static final Version VERSION01 = new Version(0, 1);
private static final Version VERSION02 = new Version(0, 2);
private static final Version VERSION10 = new Version(1, 0);
private static final Version VERSION11 = new Version(1, 1);
- /* private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
+ */
+/* private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
private static UDTMapper<Version> versionMapper =
- noSqlDb.getMappingManager().udtMapper(Version.class);*/
+ noSqlDb.getMappingManager().udtMapper(Version.class);*//*
+
@Mock
private VersionInfoDao versionInfoDaoMock;
@Mock
@@ -87,7 +377,8 @@ public class VersioningManagerImplTest {
MockitoAnnotations.initMocks(this);
}
- /* @BeforeClass
+ */
+/* @BeforeClass
private void init() {
versionInfoDaoMock.delete(new VersionInfoEntity(TYPE1, ID1));
versionInfoDaoMock.delete(new VersionInfoEntity(TYPE1, ID2));
@@ -103,8 +394,10 @@ public class VersioningManagerImplTest {
new VersionableEntityMetadata(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME));
versioningManager.register(TYPE2,
new VersionableEntityMetadata(TYPE2_TABLE_NAME, TYPE2_ID_NAME, TYPE2_VERSION_NAME));
- }*/
+ }*//*
+
+*/
/* @Test
public void testRegister() throws Exception {
VersionableEntityMetadata entityMetadata =
@@ -116,7 +409,8 @@ public class VersioningManagerImplTest {
Set<VersionableEntityMetadata> type1Entities = versionableEntities.get(TYPE1);
Assert.assertNotNull(type1Entities);
Assert.assertTrue(type1Entities.contains(entityMetadata));
- }*/
+ }*//*
+
@Test(expectedExceptions = CoreException.class)
public void testCreateAlreadyExisting() {
@@ -129,8 +423,10 @@ public class VersioningManagerImplTest {
Version version = versioningManager.create(TYPE1, ID1, USR1);
Assert.assertEquals(version, VERSION01);
+*/
/* createVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
- version);*/
+ version);*//*
+
verify(versionInfoDaoMock).create(versionInfoEntityArg.capture());
VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue();
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, new Version(0, 0), VERSION01, USR1,
@@ -152,7 +448,7 @@ public class VersioningManagerImplTest {
@Test
public void testDelete() {
VersionInfoEntity versionInfoEntity = new VersionInfoEntity();
- versionInfoEntity.setStatus(VersionStatus.Available);
+ versionInfoEntity.setStatus(VersionStatus.Draft);
doReturn(versionInfoEntity).when(versionInfoDaoMock).get(anyObject());
versioningManager.delete(TYPE1, ID1, USR1);
@@ -171,13 +467,14 @@ public class VersioningManagerImplTest {
@Test
public void testUndoDelete() {
VersionInfoDeletedEntity versionInfoDeletedEntity = new VersionInfoDeletedEntity();
- versionInfoDeletedEntity.setStatus(VersionStatus.Available);
+ versionInfoDeletedEntity.setStatus(VersionStatus.Draft);
doReturn(versionInfoDeletedEntity).when(versionInfoDeletedDaoMock).get(anyObject());
versioningManager.undoDelete(TYPE1, ID1, USR1);
verify(versionInfoDeletedDaoMock).delete(versionInfoDeletedEntity);
verify(versionInfoDaoMock).create(versionInfoEntityArg.capture());
+*/
/*
VersionInfoDeletedEntity versionInfoDeletedEntity =
versionInfoDeletedDaoMock.get(new VersionInfoDeletedEntity(TYPE1, ID1));
@@ -190,7 +487,8 @@ public class VersioningManagerImplTest {
Assert.assertNull(versionInfoEntity);
versioningManager.undoDelete(TYPE1, ID1, USR1);
versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1));
- Assert.assertNotNull(versionInfoEntity);*/
+ Assert.assertNotNull(versionInfoEntity);*//*
+
}
@Test(expectedExceptions = CoreException.class)
@@ -216,7 +514,7 @@ public class VersioningManagerImplTest {
public void testCheckoutOnFinalized() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION10);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions,
VERSION10);
Version version = versioningManager.checkout(TYPE1, ID1, USR1);
@@ -225,18 +523,20 @@ public class VersioningManagerImplTest {
VersionInfoEntity versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1));
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION10, VERSION11, USR1,
VersionStatus.Locked, viewableVersions, VERSION10);
+*/
/*
ResultSet results =
loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
VERSION11);
- Assert.assertTrue(results.iterator().hasNext());*/
+ Assert.assertTrue(results.iterator().hasNext());*//*
+
}
@Test
public void testCheckout() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION01);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions,
null);
Version version = versioningManager.checkout(TYPE1, ID1, USR1);
@@ -248,10 +548,12 @@ public class VersioningManagerImplTest {
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, VERSION02, USR1,
VersionStatus.Locked, viewableVersions, null);
+*/
/* ResultSet results =
loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
VERSION02);
- Assert.assertTrue(results.iterator().hasNext());*/
+ Assert.assertTrue(results.iterator().hasNext());*//*
+
}
@Test(expectedExceptions = CoreException.class)
@@ -263,7 +565,7 @@ public class VersioningManagerImplTest {
public void testUndoCheckoutOnAvailable() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION01);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions,
null);
versioningManager.undoCheckout(TYPE1, ID1, USR1);
@@ -273,7 +575,7 @@ public class VersioningManagerImplTest {
public void testUndoCheckouOnFinalized() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION10);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions,
VERSION10);
versioningManager.undoCheckout(TYPE1, ID1, USR2);
}
@@ -298,12 +600,14 @@ public class VersioningManagerImplTest {
VersionInfoEntity versionInfoEntity = versionInfoDaoMock.get(new VersionInfoEntity(TYPE1, ID1));
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, null, null,
- VersionStatus.Available, viewableVersions, null);
+ VersionStatus.Draft, viewableVersions, null);
+*/
/* ResultSet results =
loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
VERSION02);
- Assert.assertFalse(results.iterator().hasNext());*/
+ Assert.assertFalse(results.iterator().hasNext());*//*
+
}
@Test(expectedExceptions = CoreException.class)
@@ -315,7 +619,7 @@ public class VersioningManagerImplTest {
public void testCheckinOnAvailable() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION01);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions,
null);
versioningManager.checkin(TYPE1, ID1, USR1, "fail checkin");
@@ -326,7 +630,7 @@ public class VersioningManagerImplTest {
public void testCheckinOnFinalized() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION10);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions,
VERSION10);
versioningManager.checkin(TYPE1, ID1, USR1, "failed checkin");
@@ -354,7 +658,7 @@ public class VersioningManagerImplTest {
viewableVersions.add(VERSION01);
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, null, null,
- VersionStatus.Available, viewableVersions, null);
+ VersionStatus.Draft, viewableVersions, null);
}
@Test(expectedExceptions = CoreException.class)
@@ -374,7 +678,7 @@ public class VersioningManagerImplTest {
public void testSubmitOnFinalized() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION10);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Final, VERSION10, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Certified, VERSION10, null, viewableVersions,
VERSION10);
versioningManager.submit(TYPE1, ID1, USR2, "failed submit");
}
@@ -390,7 +694,7 @@ public class VersioningManagerImplTest {
viewableVersions.add(new Version(3, 0));
viewableVersions.add(new Version(3, 1));
viewableVersions.add(version32);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, version32, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, version32, null, viewableVersions,
new Version(3, 0));
Version version = versioningManager.submit(TYPE1, ID1, USR1, "submit msg");
@@ -403,12 +707,14 @@ public class VersioningManagerImplTest {
VersionInfoEntity versionInfoEntity = versionInfoEntityArg.getValue();
assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, version40, null, null,
- VersionStatus.Final, viewableVersions, version40);
+ VersionStatus.Certified, viewableVersions, version40);
+*/
/* ResultSet results =
loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
VERSION10);
- Assert.assertTrue(results.iterator().hasNext());*/
+ Assert.assertTrue(results.iterator().hasNext());*//*
+
}
@Test(expectedExceptions = CoreException.class)
@@ -420,12 +726,12 @@ public class VersioningManagerImplTest {
public void testGetVersionInfoForReadOnAvailable() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION01);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions,
null);
VersionInfo versionInfo =
versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Read);
- assertVersionInfo(versionInfo, VERSION01, VersionStatus.Available, null,
+ assertVersionInfo(versionInfo, VERSION01, VersionStatus.Draft, null,
viewableVersions, null);
}
@@ -433,7 +739,7 @@ public class VersioningManagerImplTest {
public void testGetVersionInfoForWriteOnAvailable() {
Set<Version> viewableVersions = new HashSet<>();
viewableVersions.add(VERSION01);
- mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Available, VERSION01, null, viewableVersions,
+ mockVersionInfoEntity(TYPE1, ID1, VersionStatus.Draft, VERSION01, null, viewableVersions,
null);
versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Write);
@@ -488,6 +794,7 @@ public class VersioningManagerImplTest {
assertVersionInfo(versionInfo, VERSION02, VersionStatus.Locked, USR1, viewableVersions, null);
}
+*/
/* private void createVersionableEntityRecord(String tableName, String idName, String versionName,
String id, Version version) {
noSqlDb.execute(
@@ -500,7 +807,8 @@ public class VersioningManagerImplTest {
return noSqlDb.execute(
String.format("select * from %s where %s=? and %s=?", tableName, idName, versionName), id,
versionMapper.toUDT(version));
- }*/
+ }*//*
+
private static void assretVersionInfoEntity(VersionInfoEntity actual, String entityType,
@@ -553,4 +861,5 @@ public class VersioningManagerImplTest {
doReturn(mock).when(versionInfoDaoMock).get(anyObject());
return mock;
}
+*/
}