aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-versioning-lib
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-02-19 12:35:04 +0200
committerMichael Lando <ml636r@att.com>2017-02-19 12:35:04 +0200
commitf5f13c4f6b6fe3b4d98e349dfd7db59339803436 (patch)
tree72caffc93fab394ffa3b761505775331f1c559b9 /openecomp-be/lib/openecomp-sdc-versioning-lib
parent451a3400b76511393c62a444f588a4ed15f4a549 (diff)
push addional code
Change-Id: Ia427bb3460cda3a896f8faced2de69eaf3807b74 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib')
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/pom.xml71
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManager.java57
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManagerFactory.java31
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningUtil.java187
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionHistoryDao.java27
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionHistoryDaoFactory.java30
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDao.java28
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDaoFactory.java30
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDeletedDao.java29
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDeletedDaoFactory.java32
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableDao.java25
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableEntityDao.java34
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableEntityDaoFactory.java31
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/UserCandidateVersion.java56
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/Version.java119
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionHistoryEntity.java90
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionInfoDeletedEntity.java126
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionInfoEntity.java126
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionStatus.java28
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionType.java26
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionableEntity.java43
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionableEntityId.java53
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckinOnEntityLockedByOtherErrorBuilder.java52
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckinOnUnlockedEntityErrorBuilder.java46
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckoutOnLockedEntityErrorBuilder.java51
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/DeleteOnLockedEntityErrorBuilder.java49
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EditOnEntityLockedByOtherErrorBuilder.java50
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EditOnUnlockedEntityErrorBuilder.java48
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityAlreadyExistErrorBuilder.java46
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityAlreadyFinalizedErrorBuilder.java51
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityNotExistErrorBuilder.java46
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/RequestedVersionInvalidErrorBuilder.java40
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/SubmitLockedEntityNotAllowedErrorBuilder.java49
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/UndoCheckoutOnEntityLockedByOtherErrorBuilder.java53
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/UndoCheckoutOnUnlockedEntityErrorBuilder.java50
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/VersionableSubEntityNotFoundErrorBuilder.java77
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/VersioningErrorCodes.java43
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/UniqueValueMetadata.java49
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionInfo.java97
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionableEntityAction.java26
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionableEntityMetadata.java78
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/resources/factoryConfiguration.json7
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml61
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryCassandraDaoImpl.java69
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryDaoFactoryImpl.java33
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDaoFactoryImpl.java33
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDaoImpl.java66
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDeletedDaoFactoryImpl.java34
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDeletedDaoImpl.java65
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java159
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoFactoryImpl.java33
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java33
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java468
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/VersioningManagerTest.java364
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/pom.xml23
55 files changed, 3728 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/pom.xml b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/pom.xml
new file mode 100644
index 0000000000..180410dcf0
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/pom.xml
@@ -0,0 +1,71 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-lib</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../..</relativePath>
+ </parent>
+
+ <artifactId>openecomp-sdc-versioning-api</artifactId>
+ <name>openecomp-sdc-versioning-api</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-facade-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-facade-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.core</groupId>
+ <artifactId>openecomp-nosqldb-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-validator</artifactId>
+ <version>${hibernate.validator.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>javax.el-api</artifactId>
+ <version>${javax.el-api.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.web</groupId>
+ <artifactId>javax.el</artifactId>
+ <version>2.2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ <version>1.10.19</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ <version>6.8.5</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>snakeyaml</artifactId>
+ <groupId>org.yaml</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ <version>RELEASE</version>
+ </dependency>
+ </dependencies>
+</project> \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManager.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManager.java
new file mode 100644
index 0000000000..7fab25456c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManager.java
@@ -0,0 +1,57 @@
+/*-
+ * ============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.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.types.VersionInfo;
+import org.openecomp.sdc.versioning.types.VersionableEntityAction;
+import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
+
+import java.util.Map;
+
+public interface VersioningManager {
+
+ void register(String entityType, VersionableEntityMetadata entityMetadata);
+
+ Version create(String entityType, String entityId, String user);
+
+ void delete(String entityType, String entityId, String user);
+
+ void undoDelete(String entityType, String entityId, String user);
+
+ Version checkout(String entityType, String entityId, String user);
+
+ Version undoCheckout(String entityType, String entityId, String user);
+
+ Version checkin(String entityType, String entityId, String user, String checkinDescription);
+
+ Version submit(String entityType, String entityId, String user, String submitDescription);
+
+ VersionInfo getEntityVersionInfo(String entityType, String entityId, String user,
+ VersionableEntityAction action);
+
+ Map<String, VersionInfo> listEntitiesVersionInfo(String entityType, String user,
+ VersionableEntityAction action);
+
+ Map<String, VersionInfo> listDeletedEntitiesVersionInfo(String entityType, String user,
+ VersionableEntityAction action);
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManagerFactory.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManagerFactory.java
new file mode 100644
index 0000000000..089777bbe6
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningManagerFactory.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 VersioningManagerFactory extends AbstractComponentFactory<VersioningManager> {
+
+ public static VersioningManagerFactory getInstance() {
+ return AbstractFactory.getInstance(VersioningManagerFactory.class);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningUtil.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningUtil.java
new file mode 100644
index 0000000000..d51f8c0a2b
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/VersioningUtil.java
@@ -0,0 +1,187 @@
+/*-
+ * ============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.dao.BaseDao;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionableEntity;
+import org.openecomp.sdc.versioning.errors.RequestedVersionInvalidErrorBuilder;
+import org.openecomp.sdc.versioning.errors.VersionableSubEntityNotFoundErrorBuilder;
+import org.openecomp.sdc.versioning.types.VersionInfo;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * The type Versioning util.
+ */
+public class VersioningUtil {
+
+ /**
+ * Validate entity existence.
+ *
+ * @param <T> the type parameter
+ * @param retrievedEntity the retrieved entity
+ * @param inputEntity the input entity
+ * @param firstClassCitizenType the first class citizen type
+ */
+ public static <T extends VersionableEntity> void validateEntityExistence(Object retrievedEntity,
+ T inputEntity,
+ String firstClassCitizenType) {
+ if (retrievedEntity == null) {
+ throw new CoreException(new VersionableSubEntityNotFoundErrorBuilder(
+ inputEntity.getEntityType(),
+ inputEntity.getId(),
+ firstClassCitizenType,
+ inputEntity.getFirstClassCitizenId(),
+ inputEntity.getVersion()).build());
+ }
+ }
+
+ /**
+ * Validate entities existence.
+ *
+ * @param <T> the type parameter
+ * @param <D> the type parameter
+ * @param entityIds the entity ids
+ * @param entity the entity
+ * @param entityDao the entity dao
+ * @param firstClassCitizenType the first class citizen type
+ */
+ public static <T extends VersionableEntity, D extends BaseDao<T>> void validateEntitiesExistence(
+ Set<String> entityIds, T entity, D entityDao, String firstClassCitizenType) {
+ if (entityIds == null) {
+ return;
+ }
+
+ List<String> nonExistingIds = new ArrayList<>();
+ for (String entityId : entityIds) {
+ entity.setId(entityId);
+ if (entityDao.get(entity) == null) {
+ nonExistingIds.add(entityId);
+ }
+ }
+
+ if (nonExistingIds.size() > 0) {
+ if (nonExistingIds.size() == 1) {
+ throw new CoreException(new VersionableSubEntityNotFoundErrorBuilder(
+ entity.getEntityType(),
+ nonExistingIds.get(0),
+ firstClassCitizenType,
+ entity.getFirstClassCitizenId(),
+ entity.getVersion()).build());
+ }
+ throw new CoreException(new VersionableSubEntityNotFoundErrorBuilder(
+ entity.getEntityType(),
+ nonExistingIds,
+ firstClassCitizenType,
+ entity.getFirstClassCitizenId(),
+ entity.getVersion()).build());
+ }
+ }
+
+ /**
+ * Validate contained entities existence.
+ *
+ * @param <T> the type parameter
+ * @param containedEntityType the contained entity type
+ * @param inputContainedEntityIds the input contained entity ids
+ * @param containingEntity the containing entity
+ * @param retrievedContainedEntityIds the retrieved contained entity ids
+ */
+ public static <T extends VersionableEntity> void validateContainedEntitiesExistence(
+ String containedEntityType, Set<String> inputContainedEntityIds, T containingEntity,
+ Set<String> retrievedContainedEntityIds) {
+ if (inputContainedEntityIds == null) {
+ return;
+ }
+
+ List<String> nonExistingIds = inputContainedEntityIds.stream()
+ .filter(entityId -> !retrievedContainedEntityIds.contains(entityId))
+ .collect(Collectors.toList());
+
+ if (nonExistingIds.size() > 0) {
+ if (nonExistingIds.size() == 1) {
+ throw new CoreException(new VersionableSubEntityNotFoundErrorBuilder(
+ containedEntityType,
+ nonExistingIds.get(0),
+ containingEntity.getEntityType(),
+ containingEntity.getId(),
+ containingEntity.getVersion()).build());
+ }
+ throw new CoreException(new VersionableSubEntityNotFoundErrorBuilder(
+ containedEntityType,
+ nonExistingIds,
+ containingEntity.getEntityType(),
+ containingEntity.getId(),
+ containingEntity.getVersion()).build());
+ }
+ }
+
+ /**
+ * Resolve version version.
+ *
+ * @param requestedVersion the requested version
+ * @param versionInfo the version info
+ * @param finalOnly the final only
+ * @return the version
+ */
+ public static Version resolveVersion(Version requestedVersion, VersionInfo versionInfo,
+ boolean finalOnly) {
+ if (requestedVersion == null) {
+ if (finalOnly) {
+ if (versionInfo.getLatestFinalVersion() == null) {
+ throw new CoreException(new RequestedVersionInvalidErrorBuilder().build());
+ }
+ requestedVersion = versionInfo.getLatestFinalVersion();
+ } else {
+ requestedVersion = versionInfo.getActiveVersion();
+ }
+ } else {
+ if ((finalOnly && !requestedVersion.isFinal())
+ || !versionInfo.getViewableVersions().contains(requestedVersion)) {
+ throw new CoreException(new RequestedVersionInvalidErrorBuilder().build());
+ }
+ }
+ return requestedVersion;
+ }
+
+ /**
+ * Resolve version version.
+ *
+ * @param requestedVersion the requested version
+ * @param versionInfo the version info
+ * @return the version
+ */
+ public static Version resolveVersion(Version requestedVersion, VersionInfo versionInfo) {
+ if (requestedVersion == null) {
+ requestedVersion = versionInfo.getActiveVersion();
+ } else {
+ if (!versionInfo.getViewableVersions().contains(requestedVersion)) {
+ throw new CoreException(new RequestedVersionInvalidErrorBuilder().build());
+ }
+ }
+ return requestedVersion;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionHistoryDao.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionHistoryDao.java
new file mode 100644
index 0000000000..f90265aeb6
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionHistoryDao.java
@@ -0,0 +1,27 @@
+/*-
+ * ============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;
+
+import org.openecomp.core.dao.BaseDao;
+import org.openecomp.sdc.versioning.dao.types.VersionHistoryEntity;
+
+public interface VersionHistoryDao extends BaseDao<VersionHistoryEntity> {
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionHistoryDaoFactory.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionHistoryDaoFactory.java
new file mode 100644
index 0000000000..9ea8d714b0
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionHistoryDaoFactory.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.versioning.dao;
+
+import org.openecomp.core.factory.api.AbstractComponentFactory;
+import org.openecomp.core.factory.api.AbstractFactory;
+
+public abstract class VersionHistoryDaoFactory extends AbstractComponentFactory<VersionHistoryDao> {
+ public static VersionHistoryDaoFactory getInstance() {
+ return AbstractFactory.getInstance(VersionHistoryDaoFactory.class);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDao.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDao.java
new file mode 100644
index 0000000000..260214eb07
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDao.java
@@ -0,0 +1,28 @@
+/*-
+ * ============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;
+
+import org.openecomp.core.dao.BaseDao;
+import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
+
+public interface VersionInfoDao extends BaseDao<VersionInfoEntity> {
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDaoFactory.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDaoFactory.java
new file mode 100644
index 0000000000..ebdb1a590b
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDaoFactory.java
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.versioning.dao;
+
+import org.openecomp.core.factory.api.AbstractComponentFactory;
+import org.openecomp.core.factory.api.AbstractFactory;
+
+public abstract class VersionInfoDaoFactory extends AbstractComponentFactory<VersionInfoDao> {
+ public static VersionInfoDaoFactory getInstance() {
+ return AbstractFactory.getInstance(VersionInfoDaoFactory.class);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDeletedDao.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDeletedDao.java
new file mode 100644
index 0000000000..cb6c050520
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDeletedDao.java
@@ -0,0 +1,29 @@
+/*-
+ * ============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;
+
+
+import org.openecomp.core.dao.BaseDao;
+import org.openecomp.sdc.versioning.dao.types.VersionInfoDeletedEntity;
+
+public interface VersionInfoDeletedDao extends BaseDao<VersionInfoDeletedEntity> {
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDeletedDaoFactory.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDeletedDaoFactory.java
new file mode 100644
index 0000000000..d14cbfeb0b
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionInfoDeletedDaoFactory.java
@@ -0,0 +1,32 @@
+/*-
+ * ============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;
+
+
+import org.openecomp.core.factory.api.AbstractComponentFactory;
+import org.openecomp.core.factory.api.AbstractFactory;
+
+public abstract class VersionInfoDeletedDaoFactory
+ extends AbstractComponentFactory<VersionInfoDeletedDao> {
+ public static VersionInfoDeletedDaoFactory getInstance() {
+ return AbstractFactory.getInstance(VersionInfoDeletedDaoFactory.class);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableDao.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableDao.java
new file mode 100644
index 0000000000..12cef62f44
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableDao.java
@@ -0,0 +1,25 @@
+/*-
+ * ============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;
+
+public interface VersionableDao {
+ void registerVersioning(String versionableEntityType);
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableEntityDao.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableEntityDao.java
new file mode 100644
index 0000000000..8709a983a3
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableEntityDao.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.dao;
+
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
+
+public interface VersionableEntityDao {
+
+ void initVersion(VersionableEntityMetadata versionableTableMetadata, String entityId,
+ Version baseVersion, Version newVersion);
+
+ void deleteVersion(VersionableEntityMetadata versionableTableMetadata, String entityId,
+ Version versionToDelete);
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableEntityDaoFactory.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableEntityDaoFactory.java
new file mode 100644
index 0000000000..be3c635be2
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/VersionableEntityDaoFactory.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.dao;
+
+import org.openecomp.core.factory.api.AbstractComponentFactory;
+import org.openecomp.core.factory.api.AbstractFactory;
+
+public abstract class VersionableEntityDaoFactory
+ extends AbstractComponentFactory<VersionableEntityDao> {
+ public static VersionableEntityDaoFactory getInstance() {
+ return AbstractFactory.getInstance(VersionableEntityDaoFactory.class);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/UserCandidateVersion.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/UserCandidateVersion.java
new file mode 100644
index 0000000000..ca044142de
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/UserCandidateVersion.java
@@ -0,0 +1,56 @@
+/*-
+ * ============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.types;
+
+import com.datastax.driver.mapping.annotations.Frozen;
+import com.datastax.driver.mapping.annotations.UDT;
+
+@UDT(name = "user_candidate_version", keyspace = "dox")
+public class UserCandidateVersion {
+
+ @Frozen
+ private Version version;
+ private String user;
+
+ public UserCandidateVersion() {
+ }
+
+ public UserCandidateVersion(String user, Version candidateVersion) {
+ this.user = user;
+ this.version = candidateVersion;
+ }
+
+ public Version getVersion() {
+ return version;
+ }
+
+ public void setVersion(Version version) {
+ this.version = version;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/Version.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/Version.java
new file mode 100644
index 0000000000..e6ac799fd4
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/Version.java
@@ -0,0 +1,119 @@
+/*-
+ * ============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.types;
+
+import com.datastax.driver.mapping.annotations.UDT;
+
+@UDT(name = "version", keyspace = "dox")
+public class Version {
+ public static final String VERSION_REGEX = "^\\d+\\.\\d+$";
+ public static final String VERSION_STRING_VIOLATION_MSG =
+ "Version string must be in the format of: {integer}.{integer}";
+
+ private int major;
+ private int minor;
+
+ public Version() {
+ }
+
+ public Version(int major, int minor) {
+ this.major = major;
+ this.minor = minor;
+ }
+
+ /**
+ * Value of version.
+ *
+ * @param versionString the version string
+ * @return the version
+ */
+ public static Version valueOf(String versionString) {
+ if (versionString == null) {
+ return null;
+ }
+ String[] versionLevels = versionString.split("\\.");
+ Version version;
+ if (versionLevels.length != 2) {
+ throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
+ }
+ try {
+ version = new Version(Integer.parseInt(versionLevels[0]), Integer.parseInt(versionLevels[1]));
+ } catch (Exception exception) {
+ throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
+ }
+
+ return version;
+ }
+
+ public int getMajor() {
+ return major;
+ }
+
+ public void setMajor(int major) {
+ this.major = major;
+ }
+
+ public int getMinor() {
+ return minor;
+ }
+
+ public void setMinor(int minor) {
+ this.minor = minor;
+ }
+
+ public Version calculateNextCandidate() {
+ return new Version(major, minor + 1);
+ }
+
+ public Version calculateNextFinal() {
+ return new Version(major + 1, 0);
+ }
+
+ public boolean isFinal() {
+ return major != 0 && minor == 0;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+
+ Version version = (Version) obj;
+
+ return major == version.major && minor == version.minor;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = major;
+ result = 31 * result + minor;
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return major + "." + minor;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionHistoryEntity.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionHistoryEntity.java
new file mode 100644
index 0000000000..e97e177f52
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionHistoryEntity.java
@@ -0,0 +1,90 @@
+/*-
+ * ============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.types;
+
+import com.datastax.driver.mapping.annotations.Column;
+import com.datastax.driver.mapping.annotations.Frozen;
+import com.datastax.driver.mapping.annotations.PartitionKey;
+import com.datastax.driver.mapping.annotations.Table;
+
+@Table(keyspace = "dox", name = "version_history")
+public class VersionHistoryEntity {
+
+ @PartitionKey
+ @Column(name = "entity_id")
+ @Frozen
+ private VersionableEntityId entityId;
+
+ @Column(name = "active_version")
+ @Frozen
+ private Version version;
+
+ private String user;
+ private String description;
+ private VersionType type;
+
+ public VersionHistoryEntity() {
+ }
+
+ public VersionHistoryEntity(VersionableEntityId entityId) {
+ this.entityId = entityId;
+ }
+
+ public VersionableEntityId getEntityId() {
+ return entityId;
+ }
+
+ public void setEntityId(VersionableEntityId entityId) {
+ this.entityId = entityId;
+ }
+
+ public Version getVersion() {
+ return version;
+ }
+
+ public void setVersion(Version version) {
+ this.version = version;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public VersionType getType() {
+ return type;
+ }
+
+ public void setType(VersionType type) {
+ this.type = type;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionInfoDeletedEntity.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionInfoDeletedEntity.java
new file mode 100644
index 0000000000..9a60aa3b4a
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionInfoDeletedEntity.java
@@ -0,0 +1,126 @@
+/*-
+ * ============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.types;
+
+import com.datastax.driver.mapping.annotations.ClusteringColumn;
+import com.datastax.driver.mapping.annotations.Column;
+import com.datastax.driver.mapping.annotations.Enumerated;
+import com.datastax.driver.mapping.annotations.Frozen;
+import com.datastax.driver.mapping.annotations.FrozenValue;
+import com.datastax.driver.mapping.annotations.PartitionKey;
+import com.datastax.driver.mapping.annotations.Table;
+
+import java.util.HashSet;
+import java.util.Set;
+
+@Table(keyspace = "dox", name = "version_info_deleted")
+public class VersionInfoDeletedEntity {
+
+ @PartitionKey
+ @Column(name = "entity_type")
+ private String entityType;
+
+ @ClusteringColumn
+ @Column(name = "entity_id")
+ private String entityId;
+
+ @Column(name = "active_version")
+ @Frozen
+ private Version activeVersion;
+
+ @Enumerated
+ private VersionStatus status;
+
+ @Frozen
+ private UserCandidateVersion candidate;
+
+ @Column(name = "viewable_versions")
+ @FrozenValue
+ private Set<Version> viewableVersions = new HashSet<>();
+
+ @Column(name = "latest_final_version")
+ @Frozen
+ private Version latestFinalVersion;
+
+ public VersionInfoDeletedEntity() {
+ }
+
+ public VersionInfoDeletedEntity(String entityType, String entityId) {
+ this.entityType = entityType;
+ this.entityId = entityId;
+ }
+
+ public String getEntityType() {
+ return entityType;
+ }
+
+ public void setEntityType(String entityType) {
+ this.entityType = entityType;
+ }
+
+ public String getEntityId() {
+ return entityId;
+ }
+
+ public void setEntityId(String entityId) {
+ this.entityId = entityId;
+ }
+
+ public Version getActiveVersion() {
+ return activeVersion;
+ }
+
+ public void setActiveVersion(Version activeVersion) {
+ this.activeVersion = activeVersion;
+ }
+
+ public VersionStatus getStatus() {
+ return status;
+ }
+
+ public void setStatus(VersionStatus status) {
+ this.status = status;
+ }
+
+ public UserCandidateVersion getCandidate() {
+ return candidate;
+ }
+
+ public void setCandidate(UserCandidateVersion candidate) {
+ this.candidate = candidate;
+ }
+
+ public Set<Version> getViewableVersions() {
+ return viewableVersions;
+ }
+
+ public void setViewableVersions(Set<Version> viewableVersions) {
+ this.viewableVersions = viewableVersions;
+ }
+
+ public Version getLatestFinalVersion() {
+ return latestFinalVersion;
+ }
+
+ public void setLatestFinalVersion(Version latestFinalVersion) {
+ this.latestFinalVersion = latestFinalVersion;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionInfoEntity.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionInfoEntity.java
new file mode 100644
index 0000000000..35ab4056f9
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionInfoEntity.java
@@ -0,0 +1,126 @@
+/*-
+ * ============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.types;
+
+import com.datastax.driver.mapping.annotations.ClusteringColumn;
+import com.datastax.driver.mapping.annotations.Column;
+import com.datastax.driver.mapping.annotations.Enumerated;
+import com.datastax.driver.mapping.annotations.Frozen;
+import com.datastax.driver.mapping.annotations.FrozenValue;
+import com.datastax.driver.mapping.annotations.PartitionKey;
+import com.datastax.driver.mapping.annotations.Table;
+
+import java.util.HashSet;
+import java.util.Set;
+
+@Table(keyspace = "dox", name = "version_info")
+public class VersionInfoEntity {
+
+ @PartitionKey
+ @Column(name = "entity_type")
+ private String entityType;
+
+ @ClusteringColumn
+ @Column(name = "entity_id")
+ private String entityId;
+
+ @Column(name = "active_version")
+ @Frozen
+ private Version activeVersion;
+
+ @Enumerated
+ private VersionStatus status;
+
+ @Frozen
+ private UserCandidateVersion candidate;
+
+ @Column(name = "viewable_versions")
+ @FrozenValue
+ private Set<Version> viewableVersions = new HashSet<>();
+
+ @Column(name = "latest_final_version")
+ @Frozen
+ private Version latestFinalVersion;
+
+ public VersionInfoEntity() {
+ }
+
+ public VersionInfoEntity(String entityType, String entityId) {
+ this.entityType = entityType;
+ this.entityId = entityId;
+ }
+
+ public String getEntityType() {
+ return entityType;
+ }
+
+ public void setEntityType(String entityType) {
+ this.entityType = entityType;
+ }
+
+ public String getEntityId() {
+ return entityId;
+ }
+
+ public void setEntityId(String entityId) {
+ this.entityId = entityId;
+ }
+
+ public Version getActiveVersion() {
+ return activeVersion;
+ }
+
+ public void setActiveVersion(Version activeVersion) {
+ this.activeVersion = activeVersion;
+ }
+
+ public VersionStatus getStatus() {
+ return status;
+ }
+
+ public void setStatus(VersionStatus status) {
+ this.status = status;
+ }
+
+ public UserCandidateVersion getCandidate() {
+ return candidate;
+ }
+
+ public void setCandidate(UserCandidateVersion candidate) {
+ this.candidate = candidate;
+ }
+
+ public Set<Version> getViewableVersions() {
+ return viewableVersions;
+ }
+
+ public void setViewableVersions(Set<Version> viewableVersions) {
+ this.viewableVersions = viewableVersions;
+ }
+
+ public Version getLatestFinalVersion() {
+ return latestFinalVersion;
+ }
+
+ public void setLatestFinalVersion(Version latestFinalVersion) {
+ this.latestFinalVersion = latestFinalVersion;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionStatus.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionStatus.java
new file mode 100644
index 0000000000..1fb68540d6
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionStatus.java
@@ -0,0 +1,28 @@
+/*-
+ * ============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.types;
+
+public enum VersionStatus {
+ Available,
+ Locked,
+ Final
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionType.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionType.java
new file mode 100644
index 0000000000..5a395c6172
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionType.java
@@ -0,0 +1,26 @@
+/*-
+ * ============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.types;
+
+public enum VersionType {
+ Draft,
+ Finalized
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionableEntity.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionableEntity.java
new file mode 100644
index 0000000000..d909af86a3
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionableEntity.java
@@ -0,0 +1,43 @@
+/*-
+ * ============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.types;
+
+public interface VersionableEntity {
+
+ String getEntityType();
+
+ String getFirstClassCitizenId();
+
+ String getId();
+
+ void setId(String id);
+
+ Version getVersion();
+
+ void setVersion(Version version);
+
+ default String getVersionUuId() {
+ return "";
+ }
+
+ default void setVersionUuId(String uuId) {
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionableEntityId.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionableEntityId.java
new file mode 100644
index 0000000000..78dc1b8811
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/dao/types/VersionableEntityId.java
@@ -0,0 +1,53 @@
+/*-
+ * ============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.types;
+
+import com.datastax.driver.mapping.annotations.UDT;
+
+@UDT(name = "versionable_entity_id", keyspace = "dox")
+public class VersionableEntityId {
+ private String type;
+ private String id;
+
+ public VersionableEntityId() {
+ }
+
+ public VersionableEntityId(String type, String id) {
+ this.type = type;
+ this.id = id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckinOnEntityLockedByOtherErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckinOnEntityLockedByOtherErrorBuilder.java
new file mode 100644
index 0000000000..829ce2691b
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckinOnEntityLockedByOtherErrorBuilder.java
@@ -0,0 +1,52 @@
+/*-
+ * ============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.errors;
+
+import static org.openecomp.sdc.versioning.errors.VersioningErrorCodes
+ .CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Checkin on entity locked by other error builder.
+ */
+public class CheckinOnEntityLockedByOtherErrorBuilder extends BaseErrorBuilder {
+
+ private static final String CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER_MSG =
+ "Can not check in versionable entity %s with id %s since it is "
+ + "checked out by other user: %s.";
+
+ /**
+ * Instantiates a new Checkin on entity locked by other error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ * @param lockingUser the locking user
+ */
+ public CheckinOnEntityLockedByOtherErrorBuilder(String entityType, String entityId,
+ String lockingUser) {
+ getErrorCodeBuilder().withId(CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(String
+ .format(CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER_MSG, entityType, entityId, lockingUser));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckinOnUnlockedEntityErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckinOnUnlockedEntityErrorBuilder.java
new file mode 100644
index 0000000000..4628febe2b
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckinOnUnlockedEntityErrorBuilder.java
@@ -0,0 +1,46 @@
+/*-
+ * ============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.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Checkin on unlocked entity error builder.
+ */
+public class CheckinOnUnlockedEntityErrorBuilder extends BaseErrorBuilder {
+
+ private static final String CHECKIN_ON_UNLOCKED_ENTITY_MSG =
+ "Can not check in versionable entity %s with id %s since it is not checked out.";
+
+ /**
+ * Instantiates a new Checkin on unlocked entity error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ */
+ public CheckinOnUnlockedEntityErrorBuilder(String entityType, String entityId) {
+ getErrorCodeBuilder().withId(VersioningErrorCodes.CHECKIN_ON_UNLOCKED_ENTITY);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder()
+ .withMessage(String.format(CHECKIN_ON_UNLOCKED_ENTITY_MSG, entityType, entityId));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckoutOnLockedEntityErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckoutOnLockedEntityErrorBuilder.java
new file mode 100644
index 0000000000..60c02474ad
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/CheckoutOnLockedEntityErrorBuilder.java
@@ -0,0 +1,51 @@
+/*-
+ * ============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.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Checkout on locked entity error builder.
+ */
+public class CheckoutOnLockedEntityErrorBuilder extends BaseErrorBuilder {
+
+ private static final String CHECKOT_ON_LOCKED_ENTITY_MSG =
+ "Can not check out versionable entity %s with id %s since it is "
+ + "checked out by other user: %s.";
+
+ /**
+ * Instantiates a new Checkout on locked entity error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ * @param lockingUser the locking user
+ */
+ public CheckoutOnLockedEntityErrorBuilder(String entityType, String entityId,
+ String lockingUser) {
+ getErrorCodeBuilder().withId(VersioningErrorCodes.CHECKOT_ON_LOCKED_ENTITY);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(
+ String.format(CHECKOT_ON_LOCKED_ENTITY_MSG, entityType, entityId, lockingUser));
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/DeleteOnLockedEntityErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/DeleteOnLockedEntityErrorBuilder.java
new file mode 100644
index 0000000000..a431e92ba4
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/DeleteOnLockedEntityErrorBuilder.java
@@ -0,0 +1,49 @@
+/*-
+ * ============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.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Delete on locked entity error builder.
+ */
+public class DeleteOnLockedEntityErrorBuilder extends BaseErrorBuilder {
+
+ private static final String DELETE_ON_LOCKED_ENTITY_MSG =
+ "Can not delete versionable entity %s with id %s since it is checked out by other user: %s.";
+
+ /**
+ * Instantiates a new Delete on locked entity error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ * @param lockingUser the locking user
+ */
+ public DeleteOnLockedEntityErrorBuilder(String entityType, String entityId, String lockingUser) {
+ getErrorCodeBuilder().withId(VersioningErrorCodes.DELETE_ON_LOCKED_ENTITY);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder()
+ .withMessage(String.format(DELETE_ON_LOCKED_ENTITY_MSG, entityType, entityId, lockingUser));
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EditOnEntityLockedByOtherErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EditOnEntityLockedByOtherErrorBuilder.java
new file mode 100644
index 0000000000..2c41bdeab1
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EditOnEntityLockedByOtherErrorBuilder.java
@@ -0,0 +1,50 @@
+/*-
+ * ============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.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Edit on entity locked by other error builder.
+ */
+public class EditOnEntityLockedByOtherErrorBuilder extends BaseErrorBuilder {
+
+ private static final String EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER_MSG =
+ "Versionable entity %s with id %s can not be edited since it is locked by other user %s.";
+
+ /**
+ * Instantiates a new Edit on entity locked by other error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ * @param lockingUser the locking user
+ */
+ public EditOnEntityLockedByOtherErrorBuilder(String entityType, String entityId,
+ String lockingUser) {
+ getErrorCodeBuilder().withId(VersioningErrorCodes.EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(
+ String.format(EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER_MSG, entityType, entityId, lockingUser));
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EditOnUnlockedEntityErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EditOnUnlockedEntityErrorBuilder.java
new file mode 100644
index 0000000000..fb61cce1f0
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EditOnUnlockedEntityErrorBuilder.java
@@ -0,0 +1,48 @@
+/*-
+ * ============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.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Edit on unlocked entity error builder.
+ */
+public class EditOnUnlockedEntityErrorBuilder extends BaseErrorBuilder {
+
+ private static final String EDIT_ON_UNLOCKED_ENTITY_MSG =
+ "Can not edit versionable entity %s with id %s since it is not checked out.";
+
+ /**
+ * Instantiates a new Edit on unlocked entity error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ */
+ public EditOnUnlockedEntityErrorBuilder(String entityType, String entityId) {
+ getErrorCodeBuilder().withId(VersioningErrorCodes.EDIT_ON_UNLOCKED_ENTITY);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder()
+ .withMessage(String.format(EDIT_ON_UNLOCKED_ENTITY_MSG, entityType, entityId));
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityAlreadyExistErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityAlreadyExistErrorBuilder.java
new file mode 100644
index 0000000000..8f80f6e14e
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityAlreadyExistErrorBuilder.java
@@ -0,0 +1,46 @@
+/*-
+ * ============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.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Entity already exist error builder.
+ */
+public class EntityAlreadyExistErrorBuilder extends BaseErrorBuilder {
+
+ private static final String VERSIONABLE_ENTITY_ALREADY_EXIST_MSG =
+ "Versionable entity %s with id %s already exist.";
+
+ /**
+ * Instantiates a new Entity already exist error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ */
+ public EntityAlreadyExistErrorBuilder(String entityType, String entityId) {
+ getErrorCodeBuilder().withId(VersioningErrorCodes.VERSIONABLE_ENTITY_ALREADY_EXIST);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder()
+ .withMessage(String.format(VERSIONABLE_ENTITY_ALREADY_EXIST_MSG, entityType, entityId));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityAlreadyFinalizedErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityAlreadyFinalizedErrorBuilder.java
new file mode 100644
index 0000000000..22643ddc26
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityAlreadyFinalizedErrorBuilder.java
@@ -0,0 +1,51 @@
+/*-
+ * ============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.errors;
+
+import static org.openecomp.sdc.versioning.errors.VersioningErrorCodes
+ .SUBMIT_FINALIZED_ENTITY_NOT_ALLOWED;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Entity already finalized error builder.
+ */
+public class EntityAlreadyFinalizedErrorBuilder extends BaseErrorBuilder {
+
+ private static final String SUBMIT_FINALIZED_ENTITY_NOT_ALLOWED_MSG =
+ "Versionable entity %s with id %s can not be submitted since it is already final.";
+
+ /**
+ * Instantiates a new Entity already finalized error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ */
+ public EntityAlreadyFinalizedErrorBuilder(String entityType, String entityId) {
+ getErrorCodeBuilder().withId(SUBMIT_FINALIZED_ENTITY_NOT_ALLOWED);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder()
+ .withMessage(String.format(SUBMIT_FINALIZED_ENTITY_NOT_ALLOWED_MSG, entityType, entityId));
+ }
+
+
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityNotExistErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityNotExistErrorBuilder.java
new file mode 100644
index 0000000000..806557f935
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/EntityNotExistErrorBuilder.java
@@ -0,0 +1,46 @@
+/*-
+ * ============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.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Entity not exist error builder.
+ */
+public class EntityNotExistErrorBuilder extends BaseErrorBuilder {
+
+ private static final String VERSIONABLE_ENTITY_NOT_EXIST_MSG =
+ "Versionable entity %s with id %s does not exist.";
+
+ /**
+ * Instantiates a new Entity not exist error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ */
+ public EntityNotExistErrorBuilder(String entityType, String entityId) {
+ getErrorCodeBuilder().withId(VersioningErrorCodes.VERSIONABLE_ENTITY_NOT_EXIST);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder()
+ .withMessage(String.format(VERSIONABLE_ENTITY_NOT_EXIST_MSG, entityType, entityId));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/RequestedVersionInvalidErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/RequestedVersionInvalidErrorBuilder.java
new file mode 100644
index 0000000000..7d3afcb94a
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/RequestedVersionInvalidErrorBuilder.java
@@ -0,0 +1,40 @@
+/*-
+ * ============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.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Requested version invalid error builder.
+ */
+public class RequestedVersionInvalidErrorBuilder extends BaseErrorBuilder {
+ private static final String REQUESTED_VERSION_INVALID_MSG = "Invalid requested version.";
+
+ /**
+ * Instantiates a new Requested version invalid error builder.
+ */
+ public RequestedVersionInvalidErrorBuilder() {
+ getErrorCodeBuilder().withId(VersioningErrorCodes.REQUESTED_VERSION_INVALID);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(REQUESTED_VERSION_INVALID_MSG);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/SubmitLockedEntityNotAllowedErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/SubmitLockedEntityNotAllowedErrorBuilder.java
new file mode 100644
index 0000000000..3f4fc81b76
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/SubmitLockedEntityNotAllowedErrorBuilder.java
@@ -0,0 +1,49 @@
+/*-
+ * ============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.errors;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Submit locked entity not allowed error builder.
+ */
+public class SubmitLockedEntityNotAllowedErrorBuilder extends BaseErrorBuilder {
+
+ private static final String SUBMIT_LOCKED_ENTITY_NOT_ALLOWED_MSG =
+ "Versionable entity %s with id %s can not be submitted since it is currently "
+ + "locked by user %s.";
+
+ /**
+ * Instantiates a new Submit locked entity not allowed error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ * @param lockingUser the locking user
+ */
+ public SubmitLockedEntityNotAllowedErrorBuilder(String entityType, String entityId,
+ String lockingUser) {
+ getErrorCodeBuilder().withId(VersioningErrorCodes.SUBMIT_LOCKED_ENTITY_NOT_ALLOWED);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(
+ String.format(SUBMIT_LOCKED_ENTITY_NOT_ALLOWED_MSG, entityType, entityId, lockingUser));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/UndoCheckoutOnEntityLockedByOtherErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/UndoCheckoutOnEntityLockedByOtherErrorBuilder.java
new file mode 100644
index 0000000000..5e2be13d61
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/UndoCheckoutOnEntityLockedByOtherErrorBuilder.java
@@ -0,0 +1,53 @@
+/*-
+ * ============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.errors;
+
+import static org.openecomp.sdc.versioning.errors.VersioningErrorCodes
+ .UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+/**
+ * The type Undo checkout on entity locked by other error builder.
+ */
+public class UndoCheckoutOnEntityLockedByOtherErrorBuilder extends BaseErrorBuilder {
+
+ private static final String UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER_MSG =
+ "Can not undo checkout on versionable entity %s with id %s since it is checked out by "
+ + "other user: %s.";
+
+ /**
+ * Instantiates a new Undo checkout on entity locked by other error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ * @param lockingUser the locking user
+ */
+ public UndoCheckoutOnEntityLockedByOtherErrorBuilder(String entityType, String entityId,
+ String lockingUser) {
+ getErrorCodeBuilder().withId(UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(String
+ .format(UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER_MSG, entityType, entityId,
+ lockingUser));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/UndoCheckoutOnUnlockedEntityErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/UndoCheckoutOnUnlockedEntityErrorBuilder.java
new file mode 100644
index 0000000000..36ca5b5c41
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/UndoCheckoutOnUnlockedEntityErrorBuilder.java
@@ -0,0 +1,50 @@
+/*-
+ * ============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.errors;
+
+import static org.openecomp.sdc.versioning.errors.VersioningErrorCodes
+ .UNDO_CHECKOUT_ON_UNLOCKED_ENTITY;
+
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+
+
+/**
+ * The type Undo checkout on unlocked entity error builder.
+ */
+public class UndoCheckoutOnUnlockedEntityErrorBuilder extends BaseErrorBuilder {
+
+ private static final String UNDO_CHECKOUT_ON_UNLOCKED_ENTITY_MSG =
+ "Can not undo checkout on versionable entity %s with id %s since it is not checked out.";
+
+ /**
+ * Instantiates a new Undo checkout on unlocked entity error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ */
+ public UndoCheckoutOnUnlockedEntityErrorBuilder(String entityType, String entityId) {
+ getErrorCodeBuilder().withId(UNDO_CHECKOUT_ON_UNLOCKED_ENTITY);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder()
+ .withMessage(String.format(UNDO_CHECKOUT_ON_UNLOCKED_ENTITY_MSG, entityType, entityId));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/VersionableSubEntityNotFoundErrorBuilder.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/VersionableSubEntityNotFoundErrorBuilder.java
new file mode 100644
index 0000000000..77be83f427
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/VersionableSubEntityNotFoundErrorBuilder.java
@@ -0,0 +1,77 @@
+/*-
+ * ============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.errors;
+
+import org.openecomp.core.utilities.CommonMethods;
+import org.openecomp.sdc.common.errors.BaseErrorBuilder;
+import org.openecomp.sdc.common.errors.ErrorCategory;
+import org.openecomp.sdc.versioning.dao.types.Version;
+
+import java.util.List;
+
+/**
+ * The type Versionable sub entity not found error builder.
+ */
+public class VersionableSubEntityNotFoundErrorBuilder extends BaseErrorBuilder {
+
+ private static final String SUB_ENTITY_NOT_FOUND_MSG =
+ "%s with Id %s does not exist for %s with id %s and version %s";
+ private static final String SUB_ENTITIES_NOT_FOUND_MSG =
+ "%ss with Ids %s do not exist for %s with id %s and version %s";
+
+ /**
+ * Instantiates a new Versionable sub entity not found error builder.
+ *
+ * @param entityType the entity type
+ * @param entityId the entity id
+ * @param containingEntityType the containing entity type
+ * @param containingEntityId the containing entity id
+ * @param version the version
+ */
+ public VersionableSubEntityNotFoundErrorBuilder(String entityType, String entityId,
+ String containingEntityType,
+ String containingEntityId, Version version) {
+ getErrorCodeBuilder().withId(VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(String
+ .format(SUB_ENTITY_NOT_FOUND_MSG, entityType, entityId, containingEntityType,
+ containingEntityId, version.toString()));
+ }
+
+ /**
+ * Instantiates a new Versionable sub entity not found error builder.
+ *
+ * @param entityType the entity type
+ * @param entityIds the entity ids
+ * @param containingEntityType the containing entity type
+ * @param containingEntityId the containing entity id
+ * @param version the version
+ */
+ public VersionableSubEntityNotFoundErrorBuilder(String entityType, List<String> entityIds,
+ String containingEntityType,
+ String containingEntityId, Version version) {
+ getErrorCodeBuilder().withId(VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND);
+ getErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION);
+ getErrorCodeBuilder().withMessage(String.format(SUB_ENTITIES_NOT_FOUND_MSG, entityType,
+ CommonMethods.listToSeparatedString(entityIds, ','), containingEntityType,
+ containingEntityId, version.toString()));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/VersioningErrorCodes.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/VersioningErrorCodes.java
new file mode 100644
index 0000000000..c1c6b96bfd
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/errors/VersioningErrorCodes.java
@@ -0,0 +1,43 @@
+/*-
+ * ============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.errors;
+
+public class VersioningErrorCodes {
+
+ public static final String REQUESTED_VERSION_INVALID = "REQUESTED_VERSION_INVALID";
+ public static final String CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER =
+ "CHECKIN_ON_ENTITY_LOCKED_BY_OTHER_USER";
+ public static final String CHECKIN_ON_UNLOCKED_ENTITY = "CHECKIN_ON_UNLOCKED_ENTITY";
+ public static final String CHECKOT_ON_LOCKED_ENTITY = "CHECKOT_ON_LOCKED_ENTITY";
+ public static final String DELETE_ON_LOCKED_ENTITY = "DELETE_ON_LOCKED_ENTITY";
+ public static final String EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER =
+ "EDIT_ON_ENTITY_LOCKED_BY_OTHER_USER";
+ public static final String EDIT_ON_UNLOCKED_ENTITY = "EDIT_ON_UNLOCKED_ENTITY";
+ public static final String VERSIONABLE_ENTITY_ALREADY_EXIST = "VERSIONABLE_ENTITY_ALREADY_EXIST";
+ public static final String SUBMIT_FINALIZED_ENTITY_NOT_ALLOWED =
+ "SUBMIT_FINALIZED_ENTITY_NOT_ALLOWED";
+ public static final String VERSIONABLE_ENTITY_NOT_EXIST = "VERSIONABLE_ENTITY_NOT_EXIST";
+ public static final String VERSIONABLE_SUB_ENTITY_NOT_FOUND = "VERSIONABLE_SUB_ENTITY_NOT_FOUND";
+ public static final String SUBMIT_LOCKED_ENTITY_NOT_ALLOWED = "SUBMIT_LOCKED_ENTITY_NOT_ALLOWED";
+ public static final String UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER =
+ "UNDO_CHECKOUT_ON_ENTITY_LOCKED_BY_OTHER_USER";
+ public static final String UNDO_CHECKOUT_ON_UNLOCKED_ENTITY = "UNDO_CHECKOUT_ON_UNLOCKED_ENTITY";
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/UniqueValueMetadata.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/UniqueValueMetadata.java
new file mode 100644
index 0000000000..21d42299fa
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/UniqueValueMetadata.java
@@ -0,0 +1,49 @@
+/*-
+ * ============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.types;
+
+import java.util.List;
+
+public class UniqueValueMetadata {
+ private String type;
+ private List<String> uniqueConstraintIdentifiers;
+
+ public UniqueValueMetadata(String type, List<String> contextIdentifierNames) {
+ this.type = type;
+ this.uniqueConstraintIdentifiers = contextIdentifierNames;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public List<String> getUniqueConstraintIdentifiers() {
+ return uniqueConstraintIdentifiers;
+ }
+
+ public void setUniqueConstraintIdentifiers(List<String> uniqueConstraintIdentifiers) {
+ this.uniqueConstraintIdentifiers = uniqueConstraintIdentifiers;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionInfo.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionInfo.java
new file mode 100644
index 0000000000..02b5aaa3bd
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionInfo.java
@@ -0,0 +1,97 @@
+/*-
+ * ============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.types;
+
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class VersionInfo {
+ private Version activeVersion;
+ private Version latestFinalVersion;
+ private List<Version> viewableVersions = new ArrayList<>();
+ private List<Version> finalVersions = new ArrayList<>();
+ private VersionStatus status;
+ private String lockingUser;
+
+ public Version getActiveVersion() {
+ return activeVersion;
+ }
+
+ public void setActiveVersion(Version activeVersion) {
+ this.activeVersion = activeVersion;
+ }
+
+ public Version getLatestFinalVersion() {
+ return latestFinalVersion;
+ }
+
+ public void setLatestFinalVersion(Version latestFinalVersion) {
+ this.latestFinalVersion = latestFinalVersion;
+ }
+
+ public List<Version> getViewableVersions() {
+ return viewableVersions;
+ }
+
+ public void setViewableVersions(List<Version> viewableVersions) {
+ this.viewableVersions = viewableVersions;
+ }
+
+ public List<Version> getFinalVersions() {
+ return finalVersions;
+ }
+
+ public void setFinalVersions(List<Version> finalVersions) {
+ this.finalVersions = finalVersions;
+ }
+
+ public VersionStatus getStatus() {
+ return status;
+ }
+
+ public void setStatus(VersionStatus status) {
+ this.status = status;
+ }
+
+ public String getLockingUser() {
+ return lockingUser;
+ }
+
+ public void setLockingUser(String lockingUser) {
+ this.lockingUser = lockingUser;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder("VersionInfo{");
+ sb.append("activeVersion=").append(activeVersion);
+ sb.append(", latestFinalVersion=").append(latestFinalVersion);
+ sb.append(", viewableVersions=").append(viewableVersions);
+ sb.append(", finalVersions=").append(finalVersions);
+ sb.append(", status=").append(status);
+ sb.append(", lockingUser='").append(lockingUser).append('\'');
+ sb.append('}');
+ return sb.toString();
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionableEntityAction.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionableEntityAction.java
new file mode 100644
index 0000000000..c7413858e5
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionableEntityAction.java
@@ -0,0 +1,26 @@
+/*-
+ * ============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.types;
+
+public enum VersionableEntityAction {
+ Read,
+ Write
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionableEntityMetadata.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionableEntityMetadata.java
new file mode 100644
index 0000000000..161221abe3
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/VersionableEntityMetadata.java
@@ -0,0 +1,78 @@
+/*-
+ * ============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.types;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class VersionableEntityMetadata {
+
+ private String name;
+ private String identifierName;
+ private String versionIdentifierName;
+ private List<UniqueValueMetadata> uniqueValuesMetadata = new ArrayList<>();
+
+ /**
+ * Instantiates a new Versionable entity metadata.
+ *
+ * @param name the name
+ * @param identifierName the identifier name
+ * @param versionIdentifierName the version identifier name
+ */
+ public VersionableEntityMetadata(String name, String identifierName,
+ String versionIdentifierName) {
+ this.name = name;
+ this.identifierName = identifierName;
+ this.versionIdentifierName = versionIdentifierName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getIdentifierName() {
+ return identifierName;
+ }
+
+ public void setIdentifierName(String idColumnName) {
+ this.identifierName = idColumnName;
+ }
+
+ public String getVersionIdentifierName() {
+ return versionIdentifierName;
+ }
+
+ public void setVersionIdentifierName(String versionColumnName) {
+ this.versionIdentifierName = versionColumnName;
+ }
+
+ public List<UniqueValueMetadata> getUniqueValuesMetadata() {
+ return uniqueValuesMetadata;
+ }
+
+ public void setUniqueValuesMetadata(List<UniqueValueMetadata> uniqueValuesMetadata) {
+ this.uniqueValuesMetadata = uniqueValuesMetadata;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/resources/factoryConfiguration.json
new file mode 100644
index 0000000000..f36c2d5a43
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/resources/factoryConfiguration.json
@@ -0,0 +1,7 @@
+{
+ "org.openecomp.sdc.versioning.VersioningManagerFactory": "org.openecomp.sdc.versioning.impl.VersioningManagerFactoryImpl",
+ "org.openecomp.sdc.versioning.dao.VersionableEntityDaoFactory" : "org.openecomp.sdc.versioning.dao.impl.VersionableEntityDaoFactoryImpl",
+ "org.openecomp.sdc.versioning.dao.VersionInfoDaoFactory": "org.openecomp.sdc.versioning.dao.impl.VersionInfoDaoFactoryImpl",
+ "org.openecomp.sdc.versioning.dao.VersionInfoDeletedDaoFactory": "org.openecomp.sdc.versioning.dao.impl.VersionInfoDeletedDaoFactoryImpl"
+
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml
new file mode 100644
index 0000000000..9812a3e941
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/pom.xml
@@ -0,0 +1,61 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-lib</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../..</relativePath>
+ </parent>
+
+ <name>openecomp-sdc-versioning-core</name>
+ <artifactId>openecomp-sdc-versioning-core</artifactId>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-versioning-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.3.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.14</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ <version>1.10.19</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ <version>6.8.5</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>snakeyaml</artifactId>
+ <groupId>org.yaml</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ <version>RELEASE</version>
+ </dependency>
+ </dependencies>
+
+</project> \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryCassandraDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryCassandraDaoImpl.java
new file mode 100644
index 0000000000..a50a8b7beb
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryCassandraDaoImpl.java
@@ -0,0 +1,69 @@
+/*-
+ * ============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 com.datastax.driver.core.UDTValue;
+import com.datastax.driver.mapping.Mapper;
+import com.datastax.driver.mapping.Result;
+import com.datastax.driver.mapping.UDTMapper;
+import com.datastax.driver.mapping.annotations.Accessor;
+import com.datastax.driver.mapping.annotations.Query;
+import org.openecomp.core.dao.impl.CassandraBaseDao;
+import org.openecomp.core.nosqldb.api.NoSqlDb;
+import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
+import org.openecomp.sdc.versioning.dao.VersionHistoryDao;
+import org.openecomp.sdc.versioning.dao.types.VersionHistoryEntity;
+import org.openecomp.sdc.versioning.dao.types.VersionableEntityId;
+
+import java.util.Collection;
+
+public class VersionHistoryCassandraDaoImpl extends CassandraBaseDao<VersionHistoryEntity>
+ implements VersionHistoryDao {
+
+ private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
+ private static Mapper<VersionHistoryEntity> mapper =
+ noSqlDb.getMappingManager().mapper(VersionHistoryEntity.class);
+ private static VersionHistoryAccessor accessor =
+ noSqlDb.getMappingManager().createAccessor(VersionHistoryAccessor.class);
+ private static UDTMapper<VersionableEntityId> versionedEntityIdMapper =
+ noSqlDb.getMappingManager().udtMapper(VersionableEntityId.class);
+
+ @Override
+ protected Mapper<VersionHistoryEntity> getMapper() {
+ return mapper;
+ }
+
+ @Override
+ protected Object[] getKeys(VersionHistoryEntity entity) {
+ return new Object[]{versionedEntityIdMapper.toUDT(entity.getEntityId())};
+ }
+
+ @Override
+ public Collection<VersionHistoryEntity> list(VersionHistoryEntity entity) {
+ return accessor.getAll(versionedEntityIdMapper.toUDT(entity.getEntityId())).all();
+ }
+
+ @Accessor
+ interface VersionHistoryAccessor {
+ @Query("select * from version_history where entity_id=?")
+ Result<VersionHistoryEntity> getAll(UDTValue entityId);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryDaoFactoryImpl.java
new file mode 100644
index 0000000000..ac1c7e9634
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryDaoFactoryImpl.java
@@ -0,0 +1,33 @@
+/*-
+ * ============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.sdc.versioning.dao.VersionHistoryDao;
+import org.openecomp.sdc.versioning.dao.VersionHistoryDaoFactory;
+
+public class VersionHistoryDaoFactoryImpl extends VersionHistoryDaoFactory {
+ private static final VersionHistoryDao INSTANCE = new VersionHistoryCassandraDaoImpl();
+
+ @Override
+ public VersionHistoryDao 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/VersionInfoDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDaoFactoryImpl.java
new file mode 100644
index 0000000000..46c6a9d795
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDaoFactoryImpl.java
@@ -0,0 +1,33 @@
+/*-
+ * ============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.sdc.versioning.dao.VersionInfoDao;
+import org.openecomp.sdc.versioning.dao.VersionInfoDaoFactory;
+
+public class VersionInfoDaoFactoryImpl extends VersionInfoDaoFactory {
+ private static VersionInfoDao INSTANCE = new VersionInfoDaoImpl();
+
+ @Override
+ public VersionInfoDao 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/VersionInfoDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDaoImpl.java
new file mode 100644
index 0000000000..a45c211f94
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDaoImpl.java
@@ -0,0 +1,66 @@
+/*-
+ * ============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 com.datastax.driver.mapping.Mapper;
+import com.datastax.driver.mapping.Result;
+import com.datastax.driver.mapping.annotations.Accessor;
+import com.datastax.driver.mapping.annotations.Query;
+import org.openecomp.core.dao.impl.CassandraBaseDao;
+import org.openecomp.core.nosqldb.api.NoSqlDb;
+import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
+import org.openecomp.sdc.versioning.dao.VersionInfoDao;
+import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
+
+import java.util.Collection;
+
+public class VersionInfoDaoImpl extends CassandraBaseDao<VersionInfoEntity>
+ implements VersionInfoDao {
+
+ private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
+ private static Mapper<VersionInfoEntity> mapper =
+ noSqlDb.getMappingManager().mapper(VersionInfoEntity.class);
+ private static VersionInfoAccessor accessor =
+ noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class);
+ //private static UDTMapper<VersionableEntityId> versionedEntityIdMapper = noSqlDb
+ //.getMappingManager().udtMapper(VersionableEntityId.class);
+
+ @Override
+ protected Mapper<VersionInfoEntity> getMapper() {
+ return mapper;
+ }
+
+ @Override
+ protected Object[] getKeys(VersionInfoEntity entity) {
+ return new Object[]{entity.getEntityType(), entity.getEntityId()};
+ }
+
+ @Override
+ public Collection<VersionInfoEntity> list(VersionInfoEntity entity) {
+ return accessor.getAll(entity.getEntityType()).all();
+ }
+
+ @Accessor
+ interface VersionInfoAccessor {
+ @Query("select * from version_info where entity_type=?")
+ Result<VersionInfoEntity> getAll(String entityType);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDeletedDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDeletedDaoFactoryImpl.java
new file mode 100644
index 0000000000..9163018a85
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDeletedDaoFactoryImpl.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.dao.impl;
+
+
+import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
+import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDaoFactory;
+
+public class VersionInfoDeletedDaoFactoryImpl extends VersionInfoDeletedDaoFactory {
+ private static VersionInfoDeletedDao INSTANCE = new VersionInfoDeletedDaoImpl();
+
+ @Override
+ public VersionInfoDeletedDao 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/VersionInfoDeletedDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDeletedDaoImpl.java
new file mode 100644
index 0000000000..82e4edcd80
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDeletedDaoImpl.java
@@ -0,0 +1,65 @@
+/*-
+ * ============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 com.datastax.driver.mapping.Mapper;
+import com.datastax.driver.mapping.Result;
+import com.datastax.driver.mapping.annotations.Accessor;
+import com.datastax.driver.mapping.annotations.Query;
+import org.openecomp.core.dao.impl.CassandraBaseDao;
+import org.openecomp.core.nosqldb.api.NoSqlDb;
+import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
+import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
+import org.openecomp.sdc.versioning.dao.types.VersionInfoDeletedEntity;
+
+import java.util.Collection;
+
+public class VersionInfoDeletedDaoImpl extends CassandraBaseDao<VersionInfoDeletedEntity>
+ implements VersionInfoDeletedDao {
+
+ private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
+ private static Mapper<VersionInfoDeletedEntity> mapper =
+ noSqlDb.getMappingManager().mapper(VersionInfoDeletedEntity.class);
+ private static VersionInfoAccessor accessor =
+ noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class);
+
+
+ @Override
+ protected Mapper<VersionInfoDeletedEntity> getMapper() {
+ return mapper;
+ }
+
+ @Override
+ protected Object[] getKeys(VersionInfoDeletedEntity entity) {
+ return new Object[]{entity.getEntityType(), entity.getEntityId()};
+ }
+
+ @Override
+ public Collection<VersionInfoDeletedEntity> list(VersionInfoDeletedEntity entity) {
+ return accessor.getAll(entity.getEntityType()).all();
+ }
+
+ @Accessor
+ interface VersionInfoAccessor {
+ @Query("select * from version_info_deleted where entity_type=?")
+ Result<VersionInfoDeletedEntity> getAll(String entityType);
+ }
+}
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
new file mode 100644
index 0000000000..f02ea89e34
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java
@@ -0,0 +1,159 @@
+/*-
+ * ============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 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.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.versioning.dao.VersionableEntityDao;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.types.UniqueValueMetadata;
+import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
+
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+class VersionableEntityDaoCassandraImpl implements VersionableEntityDao {
+
+ private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
+ private static org.slf4j.Logger Logger =
+ LoggerFactory.getLogger(VersionableEntityDaoCassandraImpl.class);
+ private static UDTMapper<Version> versionMapper =
+ noSqlDb.getMappingManager().udtMapper(Version.class);
+
+ private static String commaSeparatedQuestionMarks(int size) {
+ StringBuilder sb = new StringBuilder(size * 2 - 1);
+ for (int i = 0; i < size; i++) {
+ if (i > 0) {
+ sb.append(',');
+ }
+ sb.append('?');
+ }
+ return sb.toString();
+
+ }
+
+ @Override
+ public void initVersion(VersionableEntityMetadata metadata, String entityId, Version baseVersion,
+ Version newVersion) {
+ ResultSet rows = loadVersionRows(metadata, entityId, baseVersion);
+ List<String> columnNames =
+ rows.getColumnDefinitions().asList().stream().map(ColumnDefinitions.Definition::getName)
+ .collect(Collectors.toList());
+
+ String insertCql = String.format("insert into %s (%s) values (%s)", metadata.getName(),
+ CommonMethods.listToSeparatedString(columnNames, ','),
+ commaSeparatedQuestionMarks(columnNames.size()));
+ Logger.debug("insertCql", insertCql);
+
+ for (Row row : rows) {
+ List<Object> columnValues = new ArrayList<>();
+ Map<String, Object> columnNameToValue = new HashMap<>();
+
+ for (String columnName : columnNames) {
+ if (metadata.getVersionIdentifierName().equals(columnName)) {
+ columnValues.add(versionMapper.toUDT(newVersion));
+ columnNameToValue.put(columnName, newVersion.toString());
+ } else {
+ Object value = row.getObject(columnName);
+ columnValues.add(value);
+ columnNameToValue.put(columnName, value);
+ }
+ }
+
+ initRowUniqueValues(metadata.getUniqueValuesMetadata(), columnNameToValue);
+
+ noSqlDb.execute(insertCql, columnValues.toArray());
+ }
+ }
+
+ private ResultSet loadVersionRows(VersionableEntityMetadata metadata, String entityId,
+ Version version) {
+ String selectCql = String.format("select * from %s where %s=? and %s=?", metadata.getName(),
+ metadata.getIdentifierName(), metadata.getVersionIdentifierName());
+ Logger.debug("selectCql", selectCql);
+ Logger.debug("entityId", entityId);
+ Logger.debug("version", version);
+
+ return noSqlDb.execute(selectCql, entityId, versionMapper.toUDT(version));
+ }
+
+ @Override
+ public void deleteVersion(VersionableEntityMetadata metadata, String entityId,
+ Version versionToDelete) {
+ deleteRowsUniqueValues(metadata, entityId, versionToDelete);
+
+ String deleteCql = String.format("delete from %s where %s=? and %s=?", metadata.getName(),
+ metadata.getIdentifierName(), metadata.getVersionIdentifierName());
+ noSqlDb.execute(deleteCql, entityId, versionMapper.toUDT(versionToDelete));
+ }
+
+ private void initRowUniqueValues(List<UniqueValueMetadata> metadata,
+ Map<String, Object> columnNameToValue) {
+ for (UniqueValueMetadata uniqueMetadata : metadata) {
+ List<String> uniqueValueCombination = uniqueMetadata.getUniqueConstraintIdentifiers().stream()
+ .map(colName -> (String) columnNameToValue.get(colName)).collect(Collectors.toList());
+ UniqueValueUtil.createUniqueValue(uniqueMetadata.getType(),
+ uniqueValueCombination.toArray(new String[uniqueValueCombination.size()]));
+ }
+ }
+
+ private void deleteRowUniqueValues(List<UniqueValueMetadata> metadata,
+ Map<String, Object> columnNameToValue) {
+ for (UniqueValueMetadata uniqueMetadata : metadata) {
+ List<String> uniqueValueCombination = uniqueMetadata.getUniqueConstraintIdentifiers().stream()
+ .map(colName -> (String) columnNameToValue.get(colName)).collect(Collectors.toList());
+ UniqueValueUtil.deleteUniqueValue(uniqueMetadata.getType(),
+ uniqueValueCombination.toArray(new String[uniqueValueCombination.size()]));
+ }
+ }
+
+ private void deleteRowsUniqueValues(VersionableEntityMetadata metadata, String entityId,
+ Version version) {
+ if (metadata.getUniqueValuesMetadata().isEmpty()) {
+ return;
+ }
+ ResultSet rows = loadVersionRows(metadata, entityId, version);
+ List<String> columnNames =
+ rows.getColumnDefinitions().asList().stream().map(ColumnDefinitions.Definition::getName)
+ .collect(Collectors.toList());
+
+ for (Row row : rows) {
+ Map<String, Object> columnNameToValue =
+ columnNames.stream().filter(name -> row.getObject(name) != null).collect(Collectors
+ .toMap(Function.identity(),
+ columnName -> metadata.getVersionIdentifierName().equals(columnName) ? version
+ .toString() : row.getObject(columnName)));
+ deleteRowUniqueValues(metadata.getUniqueValuesMetadata(), columnNameToValue);
+ }
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoFactoryImpl.java
new file mode 100644
index 0000000000..8ec0814fc9
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoFactoryImpl.java
@@ -0,0 +1,33 @@
+/*-
+ * ============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.sdc.versioning.dao.VersionableEntityDao;
+import org.openecomp.sdc.versioning.dao.VersionableEntityDaoFactory;
+
+public class VersionableEntityDaoFactoryImpl extends VersionableEntityDaoFactory {
+ private static VersionableEntityDao INSTANCE = new VersionableEntityDaoCassandraImpl();
+
+ @Override
+ public VersionableEntityDao 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/VersioningManagerFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java
new file mode 100644
index 0000000000..f7065cfda4
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java
@@ -0,0 +1,33 @@
+/*-
+ * ============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.VersioningManager;
+import org.openecomp.sdc.versioning.VersioningManagerFactory;
+
+public class VersioningManagerFactoryImpl extends VersioningManagerFactory {
+ private static final VersioningManager INSTANCE = new VersioningManagerImpl();
+
+ @Override
+ public VersioningManager 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/VersioningManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
new file mode 100644
index 0000000000..6aa2a9f63c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
@@ -0,0 +1,468 @@
+/*-
+ * ============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.common.errors.CoreException;
+import org.openecomp.sdc.versioning.VersioningManager;
+import org.openecomp.sdc.versioning.dao.VersionInfoDao;
+import org.openecomp.sdc.versioning.dao.VersionInfoDaoFactory;
+import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
+import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDaoFactory;
+import org.openecomp.sdc.versioning.dao.VersionableEntityDao;
+import org.openecomp.sdc.versioning.dao.VersionableEntityDaoFactory;
+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;
+import org.openecomp.sdc.versioning.errors.DeleteOnLockedEntityErrorBuilder;
+import org.openecomp.sdc.versioning.errors.EditOnEntityLockedByOtherErrorBuilder;
+import org.openecomp.sdc.versioning.errors.EditOnUnlockedEntityErrorBuilder;
+import org.openecomp.sdc.versioning.errors.EntityAlreadyExistErrorBuilder;
+import org.openecomp.sdc.versioning.errors.EntityAlreadyFinalizedErrorBuilder;
+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.VersionInfo;
+import org.openecomp.sdc.versioning.types.VersionableEntityAction;
+import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class VersioningManagerImpl implements VersioningManager {
+
+ private static final Version INITIAL_ACTIVE_VERSION = new Version(0, 0);
+ private static VersionInfoDao versionInfoDao =
+ VersionInfoDaoFactory.getInstance().createInterface();
+ private static VersionInfoDeletedDao versionInfoDeletedDao =
+ VersionInfoDeletedDaoFactory.getInstance().createInterface();
+ private static VersionableEntityDao versionableEntityDao =
+ VersionableEntityDaoFactory.getInstance().createInterface();
+
+ private static Map<String, Set<VersionableEntityMetadata>> versionableEntities = new HashMap<>();
+
+ private static VersionInfo getVersionInfo(VersionInfoEntity versionInfoEntity, String user,
+ VersionableEntityAction action) {
+ return getVersionInfo(versionInfoEntity.getEntityId(),
+ versionInfoEntity.getEntityType(),
+ versionInfoEntity.getActiveVersion(),
+ versionInfoEntity.getCandidate(),
+ versionInfoEntity.getStatus(),
+ versionInfoEntity.getLatestFinalVersion(),
+ versionInfoEntity.getViewableVersions(),
+ action,
+ user);
+ }
+
+ private static VersionInfo getVersionInfo(VersionInfoDeletedEntity versionInfoEntity, String user,
+ VersionableEntityAction action) {
+ return getVersionInfo(versionInfoEntity.getEntityId(),
+ versionInfoEntity.getEntityType(),
+ versionInfoEntity.getActiveVersion(),
+ versionInfoEntity.getCandidate(),
+ versionInfoEntity.getStatus(),
+ versionInfoEntity.getLatestFinalVersion(),
+ versionInfoEntity.getViewableVersions(),
+ action,
+ user);
+ }
+
+ private static VersionInfo getVersionInfo(String entityId, String entityType, Version activeVer,
+ UserCandidateVersion candidate, VersionStatus status,
+ Version latestFinalVersion,
+ Set<Version> viewableVersions,
+ VersionableEntityAction action, String user) {
+ Version activeVersion;
+
+ if (action == VersionableEntityAction.Write) {
+ if (candidate != null) {
+ if (user.equals(candidate.getUser())) {
+ activeVersion = candidate.getVersion();
+ } else {
+ throw new CoreException(
+ new EditOnEntityLockedByOtherErrorBuilder(entityType, entityId, candidate.getUser())
+ .build());
+ }
+ } else {
+ throw new CoreException(new EditOnUnlockedEntityErrorBuilder(entityType, entityId).build());
+ }
+ } else {
+ if (candidate != null && user.equals(candidate.getUser())) {
+ activeVersion = candidate.getVersion();
+ } else {
+ activeVersion = activeVer;
+ }
+ }
+
+ VersionInfo versionInfo = new VersionInfo();
+ versionInfo.setActiveVersion(activeVersion);
+ versionInfo.setLatestFinalVersion(latestFinalVersion);
+ versionInfo.setViewableVersions(toSortedList(viewableVersions));
+ versionInfo.setFinalVersions(getFinalVersions(viewableVersions));
+ versionInfo.setStatus(status);
+ if (candidate != null) {
+ versionInfo.setLockingUser(candidate.getUser());
+ if (user.equals(candidate.getUser())) {
+ versionInfo.getViewableVersions().add(candidate.getVersion());
+ }
+ }
+ return versionInfo;
+ }
+
+ 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());
+ }
+
+ private static List<Version> getFinalVersions(Set<Version> versions) {
+ return versions.stream().filter(version -> version.isFinal()).collect(Collectors.toList());
+ }
+
+ @Override
+ public void register(String entityType, VersionableEntityMetadata entityMetadata) {
+ Set<VersionableEntityMetadata> entitiesMetadata = versionableEntities.get(entityType);
+ if (entitiesMetadata == null) {
+ entitiesMetadata = new HashSet<>();
+ versionableEntities.put(entityType, entitiesMetadata);
+ }
+ entitiesMetadata.add(entityMetadata);
+ }
+
+ @Override
+ public Version create(String entityType, String entityId, String user) {
+ VersionInfoEntity versionInfoEntity =
+ versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
+ if (versionInfoEntity != null) {
+ throw new CoreException(new EntityAlreadyExistErrorBuilder(entityType, entityId).build());
+ }
+
+ versionInfoEntity = new VersionInfoEntity(entityType, entityId);
+ versionInfoEntity.setActiveVersion(INITIAL_ACTIVE_VERSION);
+ markAsCheckedOut(versionInfoEntity, user);
+ versionInfoDao.create(versionInfoEntity);
+
+ return versionInfoEntity.getCandidate().getVersion();
+ }
+
+ @Override
+ public Version checkout(String entityType, String entityId, String user) {
+ VersionInfoEntity versionInfoEntity =
+ versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
+ if (versionInfoEntity == null) {
+ throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
+ }
+
+ Version checkoutVersion = null;
+ switch (versionInfoEntity.getStatus()) {
+ case Locked:
+ throw new CoreException(new CheckoutOnLockedEntityErrorBuilder(entityType, entityId,
+ versionInfoEntity.getCandidate().getUser()).build());
+ case Final:
+ case Available:
+ checkoutVersion = doCheckout(versionInfoEntity, user);
+ break;
+ default:
+ }
+ return checkoutVersion;
+ }
+
+ @Override
+ public Version undoCheckout(String entityType, String entityId, String user) {
+ VersionInfoEntity versionInfoEntity =
+ versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
+ if (versionInfoEntity == null) {
+ throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
+ }
+
+ Version activeVersion = null;
+ switch (versionInfoEntity.getStatus()) {
+ case Locked:
+ if (!user.equals(versionInfoEntity.getCandidate().getUser())) {
+ throw new CoreException(
+ new UndoCheckoutOnEntityLockedByOtherErrorBuilder(entityType, entityId,
+ versionInfoEntity.getCandidate().getUser()).build());
+ }
+ activeVersion = undoCheckout(versionInfoEntity);
+ break;
+ case Final:
+ case Available:
+ throw new CoreException(
+ new UndoCheckoutOnUnlockedEntityErrorBuilder(entityType, entityId).build());
+ default:
+ }
+ return activeVersion;
+ }
+
+ private Version undoCheckout(VersionInfoEntity versionInfoEntity) {
+ deleteVersionFromEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(),
+ versionInfoEntity.getCandidate().getVersion());
+
+ versionInfoEntity.setStatus(versionInfoEntity.getActiveVersion().isFinal() ? VersionStatus.Final
+ : VersionStatus.Available);
+ versionInfoEntity.setCandidate(null);
+ versionInfoDao.update(versionInfoEntity);
+ return versionInfoEntity.getActiveVersion();
+ }
+
+ @Override
+ public Version checkin(String entityType, String entityId, String user,
+ String checkinDescription) {
+ VersionInfoEntity versionInfoEntity =
+ versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
+ if (versionInfoEntity == null) {
+ throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
+ }
+
+ Version checkedInVersion = null;
+ switch (versionInfoEntity.getStatus()) {
+ case Available:
+ case Final:
+ throw new CoreException(
+ new CheckinOnUnlockedEntityErrorBuilder(entityType, entityId).build());
+ case Locked:
+ if (!user.equals(versionInfoEntity.getCandidate().getUser())) {
+ throw new CoreException(new CheckinOnEntityLockedByOtherErrorBuilder(entityType, entityId,
+ versionInfoEntity.getCandidate().getUser()).build());
+ }
+ checkedInVersion = doCheckin(versionInfoEntity, checkinDescription);
+ break;
+ default:
+ }
+ return checkedInVersion;
+ }
+
+ @Override
+ public Version submit(String entityType, String entityId, String user, String submitDescription) {
+ VersionInfoEntity versionInfoEntity =
+ versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
+ if (versionInfoEntity == null) {
+ throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
+ }
+
+ Version submitVersion = null;
+ switch (versionInfoEntity.getStatus()) {
+ case Final:
+ throw new CoreException(
+ new EntityAlreadyFinalizedErrorBuilder(entityType, entityId).build());
+ case Locked:
+ throw new CoreException(new SubmitLockedEntityNotAllowedErrorBuilder(entityType, entityId,
+ versionInfoEntity.getCandidate().getUser()).build());
+ case Available:
+ submitVersion = doSubmit(versionInfoEntity, user, submitDescription);
+ break;
+ default:
+ }
+ return submitVersion;
+ }
+
+ @Override
+ public VersionInfo getEntityVersionInfo(String entityType, String entityId, String user,
+ VersionableEntityAction action) {
+ VersionInfoEntity versionInfoEntity =
+ versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
+ if (versionInfoEntity == null) {
+ throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
+ }
+ return getVersionInfo(versionInfoEntity, user, action);
+ }
+
+ @Override
+ public Map<String, VersionInfo> listEntitiesVersionInfo(String entityType, String user,
+ VersionableEntityAction action) {
+ Collection<VersionInfoEntity> versionInfoEntities =
+ versionInfoDao.list(new VersionInfoEntity(entityType, null));
+ Map<String, VersionInfo> activeVersions = new HashMap<>();
+ for (VersionInfoEntity versionInfoEntity : versionInfoEntities) {
+ activeVersions
+ .put(versionInfoEntity.getEntityId(), getVersionInfo(versionInfoEntity, user, action));
+ }
+ return activeVersions;
+ }
+
+ @Override
+ public Map<String, VersionInfo> listDeletedEntitiesVersionInfo(String entityType, String user,
+ VersionableEntityAction action) {
+ Collection<VersionInfoDeletedEntity> versionInfoDeletedEntities =
+ versionInfoDeletedDao.list(new VersionInfoDeletedEntity(entityType, null));
+ Map<String, VersionInfo> activeVersions = new HashMap<>();
+
+
+ for (VersionInfoDeletedEntity versionInfoDeletedEntity : versionInfoDeletedEntities) {
+ activeVersions.put(versionInfoDeletedEntity.getEntityId(),
+ getVersionInfo(versionInfoDeletedEntity, user, action));
+ }
+ return activeVersions;
+ }
+
+ @Override
+ public void delete(String entityType, String entityId, String user) {
+ VersionInfoEntity versionInfoEntity =
+ versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
+ if (versionInfoEntity == null) {
+ throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
+ }
+
+ switch (versionInfoEntity.getStatus()) {
+ case Locked:
+ throw new CoreException(new DeleteOnLockedEntityErrorBuilder(entityType, entityId,
+ versionInfoEntity.getCandidate().getUser()).build());
+ default:
+ }
+
+ doDelete(versionInfoEntity, user);
+ }
+
+ @Override
+ public void undoDelete(String entityType, String entityId, String user) {
+ VersionInfoDeletedEntity versionInfoDeletedEntity =
+ versionInfoDeletedDao.get(new VersionInfoDeletedEntity(entityType, entityId));
+ if (versionInfoDeletedEntity == null) {
+ throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
+ }
+
+ doUndoDelete(versionInfoDeletedEntity, user);
+ }
+
+ private void markAsCheckedOut(VersionInfoEntity versionInfoEntity, String checkingOutUser) {
+ versionInfoEntity.setStatus(VersionStatus.Locked);
+ versionInfoEntity.setCandidate(new UserCandidateVersion(checkingOutUser,
+ versionInfoEntity.getActiveVersion().calculateNextCandidate()));
+ }
+
+ private Version doCheckout(VersionInfoEntity versionInfoEntity, String user) {
+ markAsCheckedOut(versionInfoEntity, user);
+ versionInfoDao.update(versionInfoEntity);
+
+ initVersionOnEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(),
+ versionInfoEntity.getActiveVersion(), versionInfoEntity.getCandidate().getVersion());
+
+ return versionInfoEntity.getCandidate().getVersion();
+ }
+
+ private void doDelete(VersionInfoEntity versionInfoEntity, String user) {
+
+ VersionInfoDeletedEntity versionInfoDeletedEntity = new VersionInfoDeletedEntity();
+ versionInfoDeletedEntity.setStatus(versionInfoEntity.getStatus());
+ versionInfoDeletedEntity.setViewableVersions(versionInfoEntity.getViewableVersions());
+ versionInfoDeletedEntity.setActiveVersion(versionInfoEntity.getActiveVersion());
+ versionInfoDeletedEntity.setCandidate(versionInfoEntity.getCandidate());
+ versionInfoDeletedEntity.setEntityId(versionInfoEntity.getEntityId());
+ versionInfoDeletedEntity.setEntityType(versionInfoEntity.getEntityType());
+ versionInfoDeletedEntity.setLatestFinalVersion(versionInfoEntity.getLatestFinalVersion());
+ versionInfoDeletedDao.create(versionInfoDeletedEntity);
+ versionInfoDao.delete(versionInfoEntity);
+
+ }
+
+ private void doUndoDelete(VersionInfoDeletedEntity versionInfoDeletedEntity, String user) {
+
+ VersionInfoEntity versionInfoEntity = new VersionInfoEntity();
+ versionInfoEntity.setStatus(versionInfoDeletedEntity.getStatus());
+ versionInfoEntity.setViewableVersions(versionInfoDeletedEntity.getViewableVersions());
+ versionInfoEntity.setActiveVersion(versionInfoDeletedEntity.getActiveVersion());
+ versionInfoEntity.setCandidate(versionInfoDeletedEntity.getCandidate());
+ versionInfoEntity.setEntityId(versionInfoDeletedEntity.getEntityId());
+ versionInfoEntity.setEntityType(versionInfoDeletedEntity.getEntityType());
+ versionInfoEntity.setLatestFinalVersion(versionInfoDeletedEntity.getLatestFinalVersion());
+ versionInfoDao.create(versionInfoEntity);
+ versionInfoDeletedDao.delete(versionInfoDeletedEntity);
+
+ }
+
+ private Version doCheckin(VersionInfoEntity versionInfoEntity, String checkinDescription) {
+ UserCandidateVersion userCandidateVersion = versionInfoEntity.getCandidate();
+ versionInfoEntity.setCandidate(null);
+ versionInfoEntity.setActiveVersion(userCandidateVersion.getVersion());
+ versionInfoEntity.getViewableVersions().add(versionInfoEntity.getActiveVersion());
+ versionInfoEntity.setStatus(VersionStatus.Available);
+ versionInfoDao.update(versionInfoEntity);
+
+ return versionInfoEntity.getActiveVersion();
+ }
+
+ private Version doSubmit(VersionInfoEntity versionInfoEntity, String submittingUser,
+ String submitDescription) {
+ Version finalVersion = versionInfoEntity.getActiveVersion().calculateNextFinal();
+ initVersionOnEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(),
+ versionInfoEntity.getActiveVersion(), finalVersion);
+
+ Set<Version> viewableVersions = new HashSet<>();
+ for (Version version : versionInfoEntity.getViewableVersions()) {
+ if (version.isFinal()) {
+ viewableVersions.add(version);
+ }
+ }
+ viewableVersions.add(finalVersion);
+ versionInfoEntity.setViewableVersions(viewableVersions);
+ versionInfoEntity.setActiveVersion(finalVersion);
+ versionInfoEntity.setLatestFinalVersion(finalVersion);
+ versionInfoEntity.setStatus(VersionStatus.Final);
+ 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);
+ }
+
+ private void initVersionOnEntity(String entityType, String entityId, Version baseVersion,
+ Version newVersion) {
+ Set<VersionableEntityMetadata> entityMetadatas = versionableEntities.get(entityType);
+ if (entityMetadatas != null) {
+ for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
+ versionableEntityDao.initVersion(entityMetadata, entityId, baseVersion, newVersion);
+ }
+ }
+ }
+
+ private void deleteVersionFromEntity(String entityType, String entityId,
+ Version versionToDelete) {
+ Set<VersionableEntityMetadata> entityMetadatas = versionableEntities.get(entityType);
+ if (entityMetadatas != null) {
+ for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
+ versionableEntityDao.deleteVersion(entityMetadata, entityId, versionToDelete);
+ }
+ }
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/VersioningManagerTest.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/VersioningManagerTest.java
new file mode 100644
index 0000000000..3695f9ef2d
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/test/java/org/openecomp/sdc/versioning/VersioningManagerTest.java
@@ -0,0 +1,364 @@
+package org.openecomp.sdc.versioning;
+
+
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.versioning.dao.VersionInfoDao;
+import org.openecomp.sdc.versioning.dao.VersionInfoDaoFactory;
+import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
+import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDaoFactory;
+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.VersionStatus;
+import org.openecomp.sdc.versioning.types.VersionInfo;
+import org.openecomp.sdc.versioning.types.VersionableEntityAction;
+import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
+import org.openecomp.core.nosqldb.api.NoSqlDb;
+import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.mapping.UDTMapper;
+
+import org.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class VersioningManagerTest {
+ private static final VersioningManager versioningManager =
+ VersioningManagerFactory.getInstance().createInterface();
+ private static final VersionInfoDao versionInfoDao =
+ VersionInfoDaoFactory.getInstance().createInterface();
+ private static final VersionInfoDeletedDao versionInfoDeletedDao =
+ VersionInfoDeletedDaoFactory.getInstance().createInterface();
+ private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
+ private static final String USR1 = "usr1";
+ private static final String USR2 = "usr2";
+ private static final String USR3 = "usr3";
+ private static final String TYPE1 = "Type1";
+ 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";
+ private static final String TYPE1_ID_NAME = "vlm_id";
+ 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 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 UDTMapper<Version> versionMapper =
+ noSqlDb.getMappingManager().udtMapper(Version.class);
+ private static Set<Version> expectedViewableVersionsType1Id1 = new HashSet<>();
+
+ private static void assretVersionInfoEntity(VersionInfoEntity actual, String entityType,
+ String entityId, Version activeVersion,
+ Version candidateVersion, String candidateUser,
+ VersionStatus status, Set<Version> viewbleVersions,
+ Version latestFinalVersion) {
+ Assert.assertNotNull(actual);
+ Assert.assertEquals(actual.getEntityType(), entityType);
+ Assert.assertEquals(actual.getEntityId(), entityId);
+ Assert.assertEquals(actual.getActiveVersion(), activeVersion);
+ if (candidateVersion != null && candidateUser != null) {
+ Assert.assertEquals(actual.getCandidate().getVersion(), candidateVersion);
+ Assert.assertEquals(actual.getCandidate().getUser(), candidateUser);
+ } else {
+ Assert.assertNull(actual.getCandidate());
+ }
+ Assert.assertEquals(actual.getStatus(), status);
+ Assert.assertEquals(actual.getViewableVersions().size(), viewbleVersions.size());
+ Assert.assertEquals(actual.getViewableVersions(), viewbleVersions);
+ Assert.assertEquals(actual.getLatestFinalVersion(), latestFinalVersion);
+ }
+
+ private static void assretVersionInfo(VersionInfo actual, Version activeVersion,
+ VersionStatus status, String lockingUser,
+ Set<Version> viewableVersions, Version latestFinalVersion) {
+ Assert.assertNotNull(actual);
+ Assert.assertEquals(actual.getActiveVersion(), activeVersion);
+ Assert.assertEquals(actual.getStatus(), status);
+ Assert.assertEquals(actual.getLockingUser(), lockingUser);
+ Assert.assertEquals(actual.getViewableVersions().size(), viewableVersions.size());
+ Assert.assertEquals(actual.getViewableVersions(), viewableVersions);
+ Assert.assertEquals(actual.getLatestFinalVersion(), latestFinalVersion);
+ }
+
+// @BeforeClass
+ private void init() {
+ versionInfoDao.delete(new VersionInfoEntity(TYPE1, ID1));
+ versionInfoDao.delete(new VersionInfoEntity(TYPE1, ID2));
+ versionInfoDao.delete(new VersionInfoEntity(TYPE2, ID3));
+ String deleteFromType1 = String
+ .format("delete from %s where %s=? and %s=?", TYPE1_TABLE_NAME, TYPE1_ID_NAME,
+ TYPE1_VERSION_NAME);
+ noSqlDb.execute(deleteFromType1, ID1, versionMapper.toUDT(VERSION01));
+ noSqlDb.execute(deleteFromType1, ID1, versionMapper.toUDT(VERSION02));
+ noSqlDb.execute(deleteFromType1, ID1, versionMapper.toUDT(VERSION11));
+
+ versioningManager.register(TYPE1,
+ 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 createTest() {
+ Version version = versioningManager.create(TYPE1, ID1, USR1);
+ createVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
+ version);
+
+ VersionInfoEntity versionInfoEntity = versionInfoDao.get(new VersionInfoEntity(TYPE1, ID1));
+ assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, new Version(0, 0), VERSION01, USR1,
+ VersionStatus.Locked, expectedViewableVersionsType1Id1, null);
+ }
+
+// @Test(dependsOnMethods = "createTest")
+ public void checkinTest() {
+ Version version = versioningManager.checkin(TYPE1, ID1, USR1, "checkin 0.1");
+ Assert.assertEquals(version, VERSION01);
+
+ VersionInfoEntity versionInfoEntity = versionInfoDao.get(new VersionInfoEntity(TYPE1, ID1));
+ expectedViewableVersionsType1Id1.add(VERSION01);
+ assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, null, null,
+ VersionStatus.Available, expectedViewableVersionsType1Id1, null);
+ }
+
+// @Test(dependsOnMethods = "checkinTest")
+ public void getVersionInfoForReadOnAvailableTest() {
+ VersionInfo versionInfo =
+ versioningManager.getEntityVersionInfo(TYPE1, ID1, USR2, VersionableEntityAction.Read);
+ assretVersionInfo(versionInfo, VERSION01, VersionStatus.Available, null,
+ expectedViewableVersionsType1Id1, null);
+ }
+
+// @Test(dependsOnMethods = "getVersionInfoForReadOnAvailableTest",
+// expectedExceptions = CoreException.class)
+ public void getVersionInfoForWriteOnAvailableTest() {
+ versioningManager.getEntityVersionInfo(TYPE1, ID1, USR2, VersionableEntityAction.Write);
+ }
+
+// @Test(dependsOnMethods = "getVersionInfoForWriteOnAvailableTest",
+// expectedExceptions = CoreException.class)
+ public void checkinOnAvailableTest() {
+ versioningManager.checkin(TYPE1, ID1, USR1, "fail checkin");
+ }
+
+// @Test(dependsOnMethods = "checkinOnAvailableTest", expectedExceptions = CoreException.class)
+ public void undoCheckoutOnAvailableTest() {
+ versioningManager.undoCheckout(TYPE1, ID1, USR1);
+ }
+
+// @Test(dependsOnMethods = "undoCheckoutOnAvailableTest")
+ public void checkoutTest() {
+ Version version = versioningManager.checkout(TYPE1, ID1, USR2);
+ Assert.assertEquals(version, VERSION02);
+
+ VersionInfoEntity versionInfoEntity = versionInfoDao.get(new VersionInfoEntity(TYPE1, ID1));
+ assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, VERSION02, USR2,
+ VersionStatus.Locked, expectedViewableVersionsType1Id1, null);
+
+ ResultSet results =
+ loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
+ VERSION02);
+ Assert.assertTrue(results.iterator().hasNext());
+ }
+
+// @Test(dependsOnMethods = "checkoutTest")
+ public void getVersionInfoForReadOnLockedSameUserTest() {
+ VersionInfo versionInfo =
+ versioningManager.getEntityVersionInfo(TYPE1, ID1, USR2, VersionableEntityAction.Read);
+ Set<Version> expectedViewableVersions = new HashSet<>();
+ expectedViewableVersions.addAll(expectedViewableVersionsType1Id1);
+ expectedViewableVersions.add(VERSION02);
+ assretVersionInfo(versionInfo, VERSION02, VersionStatus.Locked, USR2, expectedViewableVersions,
+ null);
+ }
+
+// @Test(dependsOnMethods = "getVersionInfoForReadOnLockedSameUserTest")
+ public void getVersionInfoForReadOnLockedOtherUserTest() {
+ VersionInfo entityVersionInfo =
+ versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Read);
+ Assert.assertEquals(entityVersionInfo.getActiveVersion(), VERSION01);
+ }
+
+// @Test(dependsOnMethods = "getVersionInfoForReadOnLockedOtherUserTest",
+// expectedExceptions = CoreException.class)
+ public void getVersionInfoForWriteOnLockedOtherUserTest() {
+ versioningManager.getEntityVersionInfo(TYPE1, ID1, USR1, VersionableEntityAction.Write)
+ .getActiveVersion();
+ }
+
+// @Test(dependsOnMethods = "getVersionInfoForWriteOnLockedOtherUserTest")
+ public void getVersionInfoForWriteOnLockedSameUserTest() {
+ Version activeVersion =
+ versioningManager.getEntityVersionInfo(TYPE1, ID1, USR2, VersionableEntityAction.Write)
+ .getActiveVersion();
+ Assert.assertEquals(activeVersion, VERSION02);
+ }
+
+// @Test(dependsOnMethods = "getVersionInfoForWriteOnLockedSameUserTest",
+// expectedExceptions = CoreException.class)
+ public void checkoutOnLockedSameUserTest() {
+ versioningManager.checkout(TYPE1, ID1, USR2);
+ }
+
+// @Test(dependsOnMethods = "checkoutOnLockedSameUserTest", expectedExceptions = CoreException.class)
+ public void checkoutOnLockedOtherUserTest() {
+ versioningManager.checkout(TYPE1, ID1, USR1);
+ }
+
+// @Test(dependsOnMethods = "checkoutOnLockedSameUserTest", expectedExceptions = CoreException.class)
+ public void undoCheckoutOnLockedOtherUserTest() {
+ versioningManager.undoCheckout(TYPE1, ID1, USR1);
+ }
+
+// @Test(dependsOnMethods = "undoCheckoutOnLockedOtherUserTest",
+// expectedExceptions = CoreException.class)
+ public void submitOnLockedTest() {
+ versioningManager.submit(TYPE1, ID1, USR2, "failed submit");
+ }
+
+// @Test(dependsOnMethods = "submitOnLockedTest")
+ public void undoCheckoutTest() {
+ Version version = versioningManager.undoCheckout(TYPE1, ID1, USR2);
+ Assert.assertEquals(version, VERSION01);
+
+ VersionInfoEntity versionInfoEntity = versionInfoDao.get(new VersionInfoEntity(TYPE1, ID1));
+ assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION01, null, null,
+ VersionStatus.Available, expectedViewableVersionsType1Id1, null);
+
+ ResultSet results =
+ loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
+ VERSION02);
+ Assert.assertFalse(results.iterator().hasNext());
+ }
+
+// @Test(dependsOnMethods = "undoCheckoutTest")
+ public void submitTest() {
+ Version version = versioningManager.submit(TYPE1, ID1, USR3, "submit msg");
+ Assert.assertEquals(version, VERSION10);
+ expectedViewableVersionsType1Id1 = new HashSet<>();
+ expectedViewableVersionsType1Id1.add(version);
+
+ VersionInfoEntity versionInfoEntity = versionInfoDao.get(new VersionInfoEntity(TYPE1, ID1));
+ assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION10, null, null,
+ VersionStatus.Final, expectedViewableVersionsType1Id1, VERSION10);
+
+ ResultSet results =
+ loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
+ VERSION10);
+ Assert.assertTrue(results.iterator().hasNext());
+ }
+
+// @Test(dependsOnMethods = "submitTest", expectedExceptions = CoreException.class)
+ public void checkinOnFinalizedTest() {
+ versioningManager.checkin(TYPE1, ID1, USR2, "failed checkin");
+ }
+
+// @Test(dependsOnMethods = "checkinOnFinalizedTest", expectedExceptions = CoreException.class)
+ public void undoCheckouOnFinalizedTest() {
+ versioningManager.undoCheckout(TYPE1, ID1, USR2);
+ }
+
+// @Test(dependsOnMethods = "undoCheckouOnFinalizedTest", expectedExceptions = CoreException.class)
+ public void submitOnFinalizedTest() {
+ versioningManager.submit(TYPE1, ID1, USR2, "failed submit");
+ }
+
+// @Test(dependsOnMethods = "submitOnFinalizedTest")
+ public void checkoutOnFinalizedTest() {
+ Version version = versioningManager.checkout(TYPE1, ID1, USR3);
+ Assert.assertEquals(version, VERSION11);
+
+ VersionInfoEntity versionInfoEntity = versionInfoDao.get(new VersionInfoEntity(TYPE1, ID1));
+ assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, VERSION10, VERSION11, USR3,
+ VersionStatus.Locked, expectedViewableVersionsType1Id1, VERSION10);
+
+ ResultSet results =
+ loadVersionableEntityRecord(TYPE1_TABLE_NAME, TYPE1_ID_NAME, TYPE1_VERSION_NAME, ID1,
+ VERSION11);
+ Assert.assertTrue(results.iterator().hasNext());
+ }
+
+// @Test(dependsOnMethods = "checkoutOnFinalizedTest")
+ public void viewableVersionsTest() {
+ versioningManager.checkin(TYPE1, ID1, USR3, "check in 1.1");
+ versioningManager.checkout(TYPE1, ID1, USR3);
+ versioningManager.checkin(TYPE1, ID1, USR3, "check in 1.2");
+ versioningManager.submit(TYPE1, ID1, USR3, "submit in 2.0");
+ versioningManager.checkout(TYPE1, ID1, USR3);
+ versioningManager.checkin(TYPE1, ID1, USR3, "check in 2.1");
+ versioningManager.submit(TYPE1, ID1, USR3, "submit in 3.0");
+ versioningManager.checkout(TYPE1, ID1, USR3);
+ versioningManager.checkin(TYPE1, ID1, USR3, "check in 3.1");
+ versioningManager.checkout(TYPE1, ID1, USR3);
+ versioningManager.checkin(TYPE1, ID1, USR3, "check in 3.2");
+ versioningManager.checkout(TYPE1, ID1, USR2);
+
+ VersionInfoEntity versionInfoEntity = versionInfoDao.get(new VersionInfoEntity(TYPE1, ID1));
+ HashSet<Version> expectedViewableVersions = new HashSet<>();
+ expectedViewableVersions.add(VERSION10);
+ expectedViewableVersions.add(new Version(2, 0));
+ expectedViewableVersions.add(new Version(3, 0));
+ expectedViewableVersions.add(new Version(3, 1));
+ expectedViewableVersions.add(new Version(3, 2));
+ assretVersionInfoEntity(versionInfoEntity, TYPE1, ID1, new Version(3, 2), new Version(3, 3),
+ USR2, VersionStatus.Locked, expectedViewableVersions, new Version(3, 0));
+ }
+
+// @Test(dependsOnMethods = "viewableVersionsTest")
+ public void listActiveVersionsTest() {
+ versioningManager.create(TYPE1, ID2, USR3);
+ versioningManager.checkin(TYPE1, ID2, USR3, "check in 0.1");
+
+ versioningManager.create(TYPE2, ID3, USR3);
+ versioningManager.checkin(TYPE2, ID3, USR3, "check in 0.1");
+
+ Map<String, VersionInfo> idToVersionInfo =
+ versioningManager.listEntitiesVersionInfo(TYPE1, USR2, VersionableEntityAction.Read);
+ Assert.assertEquals(idToVersionInfo.size(), 2);
+ Assert.assertEquals(idToVersionInfo.get(ID1).getActiveVersion(), new Version(3, 3));
+ Assert.assertEquals(idToVersionInfo.get(ID2).getActiveVersion(), VERSION01);
+ }
+
+// @Test(dependsOnMethods = "listActiveVersionsTest")
+ public void deleteTest() {
+ versioningManager.checkin(TYPE1, ID1, USR2, "check in for delete");
+ versioningManager.delete(TYPE1, ID1, USR1);
+
+ VersionInfoDeletedEntity versionInfoDeletedEntity =
+ versionInfoDeletedDao.get(new VersionInfoDeletedEntity(TYPE1, ID1));
+ Assert.assertNotNull(versionInfoDeletedEntity);
+
+ Map<String, VersionInfo> entitiesInfoMap =
+ versioningManager.listDeletedEntitiesVersionInfo(TYPE1, USR2, null);
+ Assert.assertEquals(entitiesInfoMap.size(), 1);
+ VersionInfoEntity versionInfoEntity = versionInfoDao.get(new VersionInfoEntity(TYPE1, ID1));
+ Assert.assertNull(versionInfoEntity);
+ versioningManager.undoDelete(TYPE1, ID1, USR1);
+ versionInfoEntity = versionInfoDao.get(new VersionInfoEntity(TYPE1, ID1));
+ Assert.assertNotNull(versionInfoEntity);
+
+
+ }
+
+ private void createVersionableEntityRecord(String tableName, String idName, String versionName,
+ String id, Version version) {
+ noSqlDb.execute(
+ String.format("insert into %s (%s,%s) values (?,?)", tableName, idName, versionName), id,
+ versionMapper.toUDT(version));
+ }
+
+ private ResultSet loadVersionableEntityRecord(String tableName, String idName, String versionName,
+ String id, Version version) {
+ return noSqlDb.execute(
+ String.format("select * from %s where %s=? and %s=?", tableName, idName, versionName), id,
+ versionMapper.toUDT(version));
+ }
+}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/pom.xml b/openecomp-be/lib/openecomp-sdc-versioning-lib/pom.xml
new file mode 100644
index 0000000000..b94d9a1cac
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/pom.xml
@@ -0,0 +1,23 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>openecomp-sdc-lib</artifactId>
+ <groupId>org.openecomp.sdc</groupId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>openecomp-sdc-versioning-lib</artifactId>
+ <packaging>pom</packaging>
+ <name>openecomp-sdc-versioning-lib</name>
+
+ <modules>
+ <module>openecomp-sdc-versioning-api</module>
+ <module>openecomp-sdc-versioning-core</module>
+ </modules>
+
+ <dependencies>
+
+ </dependencies>
+</project> \ No newline at end of file