summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src')
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculator.java8
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculatorFactory.java7
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/ItemDaoFactoryImpl.java13
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionDaoFactoryImpl.java13
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDaoFactoryImpl.java12
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDaoImpl.java61
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDeletedDaoFactoryImpl.java17
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDeletedDaoImpl.java54
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java203
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoFactoryImpl.java43
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java79
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java180
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java312
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/convertor/ItemVersionToVersionConvertor.java57
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerFactoryImpl.java17
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImpl.java1057
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerFactoryImpl.java16
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerImpl.java67
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerFactoryImpl.java13
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java141
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorFactoryImpl.java12
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImpl.java69
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorFactoryImpl.java13
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java97
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java14
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java285
26 files changed, 1308 insertions, 1552 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculator.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculator.java
index 2d64355d48..445632af3f 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculator.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculator.java
@@ -19,13 +19,13 @@
*/
package org.openecomp.sdc.versioning;
+import java.util.Set;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.types.VersionCreationMethod;
-import java.util.Set;
-
public interface VersionCalculator {
- String calculate(String baseVersion, VersionCreationMethod creationMethod);
- void injectAdditionalInfo(Version version, Set<String> existingVersions);
+ String calculate(String baseVersion, VersionCreationMethod creationMethod);
+
+ void injectAdditionalInfo(Version version, Set<String> existingVersions);
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculatorFactory.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculatorFactory.java
index 85f02cd267..0e6558564e 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculatorFactory.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/VersionCalculatorFactory.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.versioning;
import org.openecomp.core.factory.api.AbstractComponentFactory;
@@ -25,7 +24,7 @@ import org.openecomp.core.factory.api.AbstractFactory;
public abstract class VersionCalculatorFactory extends AbstractComponentFactory<VersionCalculator> {
- public static VersionCalculatorFactory getInstance() {
- return AbstractFactory.getInstance(VersionCalculatorFactory.class);
- }
+ public static VersionCalculatorFactory getInstance() {
+ return AbstractFactory.getInstance(VersionCalculatorFactory.class);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/ItemDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/ItemDaoFactoryImpl.java
index 0f9c9065d4..d75cc35050 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/ItemDaoFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/ItemDaoFactoryImpl.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.versioning.dao.impl;
import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
@@ -26,11 +25,11 @@ import org.openecomp.sdc.versioning.dao.ItemDaoFactory;
import org.openecomp.sdc.versioning.dao.impl.zusammen.ItemZusammenDaoImpl;
public class ItemDaoFactoryImpl extends ItemDaoFactory {
- private static ItemDao INSTANCE =
- new ItemZusammenDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface());
- @Override
- public ItemDao createInterface() {
- return INSTANCE;
- }
+ private static ItemDao INSTANCE = new ItemZusammenDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface());
+
+ @Override
+ public ItemDao createInterface() {
+ return INSTANCE;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionDaoFactoryImpl.java
index f8b0d71eb7..80a385fd4b 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionDaoFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionDaoFactoryImpl.java
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.versioning.dao.impl;
import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
@@ -26,11 +25,11 @@ import org.openecomp.sdc.versioning.dao.VersionDaoFactory;
import org.openecomp.sdc.versioning.dao.impl.zusammen.VersionZusammenDaoImpl;
public class VersionDaoFactoryImpl extends VersionDaoFactory {
- private static VersionDao INSTANCE =
- new VersionZusammenDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface());
- @Override
- public VersionDao createInterface() {
- return INSTANCE;
- }
+ private static VersionDao INSTANCE = new VersionZusammenDaoImpl(ZusammenAdaptorFactory.getInstance().createInterface());
+
+ @Override
+ public VersionDao createInterface() {
+ return INSTANCE;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/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
index f26164a9d3..5e63a97a92 100644
--- 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
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.versioning.dao.impl;
import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
@@ -21,10 +20,11 @@ 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(NoSqlDbFactory.getInstance().createInterface());
- @Override
- public VersionInfoDao createInterface() {
- return INSTANCE;
- }
+ private static VersionInfoDao INSTANCE = new VersionInfoDaoImpl(NoSqlDbFactory.getInstance().createInterface());
+
+ @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
index 4df67735be..e9bb17efd2 100644
--- 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
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.versioning.dao.impl;
import com.datastax.driver.extras.codecs.enums.EnumNameCodec;
@@ -21,50 +20,46 @@ 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 java.util.Collection;
-
import org.openecomp.core.dao.impl.CassandraBaseDao;
import org.openecomp.core.nosqldb.api.NoSqlDb;
import org.openecomp.sdc.versioning.dao.VersionInfoDao;
import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-public class VersionInfoDaoImpl extends CassandraBaseDao<VersionInfoEntity>
- implements VersionInfoDao {
+public class VersionInfoDaoImpl extends CassandraBaseDao<VersionInfoEntity> implements VersionInfoDao {
+ private final NoSqlDb noSqlDb;
+ private final Mapper<VersionInfoEntity> mapper;
+ private final VersionInfoAccessor accessor;
- private final NoSqlDb noSqlDb;
- private final Mapper<VersionInfoEntity> mapper;
- private final VersionInfoAccessor accessor;
-
-
- public VersionInfoDaoImpl(NoSqlDb noSqlDb) {
- this.noSqlDb = noSqlDb;
- this.mapper = this.noSqlDb.getMappingManager().mapper(VersionInfoEntity.class);
- this.accessor = this.noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class);
- this.noSqlDb.getMappingManager().getSession().getCluster().getConfiguration().getCodecRegistry()
+ public VersionInfoDaoImpl(NoSqlDb noSqlDb) {
+ this.noSqlDb = noSqlDb;
+ this.mapper = this.noSqlDb.getMappingManager().mapper(VersionInfoEntity.class);
+ this.accessor = this.noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class);
+ this.noSqlDb.getMappingManager().getSession().getCluster().getConfiguration().getCodecRegistry()
.register(new EnumNameCodec<>(VersionStatus.class));
- }
+ }
+
+ @Override
+ protected Mapper<VersionInfoEntity> getMapper() {
+ return mapper;
+ }
- @Override
- protected Mapper<VersionInfoEntity> getMapper() {
- return mapper;
- }
+ @Override
+ protected Object[] getKeys(VersionInfoEntity entity) {
+ return new Object[]{entity.getEntityType(), entity.getEntityId()};
+ }
- @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();
+ }
- @Override
- public Collection<VersionInfoEntity> list(VersionInfoEntity entity) {
- return accessor.getAll(entity.getEntityType()).all();
- }
+ @Accessor
+ interface VersionInfoAccessor {
- @Accessor
- interface VersionInfoAccessor {
- @Query("select * from version_info where entity_type=?")
- Result<VersionInfoEntity> getAll(String entityType);
- }
+ @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
index 9163018a85..fb7c8131e4 100644
--- 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
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,18 +17,17 @@
* 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;
- }
+ 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
index af6b20252e..02945be400 100644
--- 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
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,50 +17,44 @@
* 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 java.util.Collection;
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 {
+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);
+ 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 Mapper<VersionInfoDeletedEntity> getMapper() {
- return mapper;
- }
+ @Override
+ protected Object[] getKeys(VersionInfoDeletedEntity entity) {
+ return new Object[]{entity.getEntityType(), entity.getEntityId()};
+ }
- @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();
+ }
- @Override
- public Collection<VersionInfoDeletedEntity> list(VersionInfoDeletedEntity entity) {
- return accessor.getAll(entity.getEntityType()).all();
- }
+ @Accessor
+ interface VersionInfoAccessor {
- @Accessor
- interface VersionInfoAccessor {
- @Query("select * from version_info_deleted where entity_type=?")
- Result<VersionInfoDeletedEntity> getAll(String entityType);
- }
+ @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
index 19c62ab43c..fcbbaf77aa 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,12 +17,17 @@
* 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 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;
import org.openecomp.core.dao.UniqueValueDao;
import org.openecomp.core.nosqldb.api.NoSqlDb;
import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
@@ -35,135 +40,103 @@ import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.types.UniqueValueMetadata;
import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
-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 final UniqueValueUtil uniqueValueUtil;
- private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
- private static Logger Logger =
- (Logger) LoggerFactory.getLogger(VersionableEntityDaoCassandraImpl.class);
-
- public VersionableEntityDaoCassandraImpl(
- UniqueValueDao uniqueValueDao) {
- this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao);
- }
+ private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
+ private static Logger Logger = (Logger) LoggerFactory.getLogger(VersionableEntityDaoCassandraImpl.class);
+ private final UniqueValueUtil uniqueValueUtil;
- 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('?');
+ public VersionableEntityDaoCassandraImpl(UniqueValueDao uniqueValueDao) {
+ this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao);
}
- return sb.toString();
- }
+ 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)
+ @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(newVersion);
- columnNameToValue.put(columnName, newVersion.toString());
- } else {
- Object value = row.getObject(columnName);
- columnValues.add(value);
- columnNameToValue.put(columnName, value);
+ 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(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());
}
- }
-
- initRowUniqueValues(metadata.getUniqueValuesMetadata(), columnNameToValue);
-
- noSqlDb.execute(insertCql, columnValues.toArray());
}
- }
-
- @Override
- public void deleteVersion(VersionableEntityMetadata metadata, String entityId,
- Version versionToDelete, Version backToVersion) {
- 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, versionToDelete);
- }
-
- @Override
- public void closeVersion(VersionableEntityMetadata versionableTableMetadata, String entityId,
- Version versionToClose) {
- // redundant in cassandra impl.
- }
- 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);
+ @Override
+ public void deleteVersion(VersionableEntityMetadata metadata, String entityId, Version versionToDelete, Version backToVersion) {
+ 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, versionToDelete);
+ }
- return noSqlDb.execute(selectCql, entityId, version);
- }
+ @Override
+ public void closeVersion(VersionableEntityMetadata versionableTableMetadata, String entityId, Version versionToClose) {
+ // redundant in cassandra impl.
+ }
- 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 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, version);
}
- }
- 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 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 deleteRowsUniqueValues(VersionableEntityMetadata metadata, String entityId,
- Version version) {
- if (metadata.getUniqueValuesMetadata().isEmpty()) {
- return;
+ 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()]));
+ }
}
- 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);
+ 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
index d9300a007b..806d77ecd2 100644
--- 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
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.versioning.dao.impl;
import org.openecomp.core.dao.UniqueValueDaoFactory;
@@ -27,26 +26,26 @@ import org.openecomp.sdc.versioning.dao.VersionableEntityDaoFactory;
import org.openecomp.sdc.versioning.types.VersionableEntityStoreType;
public class VersionableEntityDaoFactoryImpl extends VersionableEntityDaoFactory {
- private static VersionableEntityDao CASSANDRA_INSTANCE = new VersionableEntityDaoCassandraImpl(
- UniqueValueDaoFactory.getInstance().createInterface());
- private static VersionableEntityDao ZUSAMMEN_INSTANCE =
- new VersionableEntityDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface());
- @Override
- public VersionableEntityDao createInterface() {
- throw new UnsupportedOperationException
- ("Please use createInterface api with VersionableEntityStoreType argument.");
- }
+ private static VersionableEntityDao CASSANDRA_INSTANCE = new VersionableEntityDaoCassandraImpl(
+ UniqueValueDaoFactory.getInstance().createInterface());
+ private static VersionableEntityDao ZUSAMMEN_INSTANCE = new VersionableEntityDaoZusammenImpl(
+ ZusammenAdaptorFactory.getInstance().createInterface());
+
+ @Override
+ public VersionableEntityDao createInterface() {
+ throw new UnsupportedOperationException("Please use createInterface api with VersionableEntityStoreType argument.");
+ }
- @Override
- public VersionableEntityDao createInterface(VersionableEntityStoreType storeType) {
- switch (storeType) {
- case Cassandra:
- return CASSANDRA_INSTANCE;
- case Zusammen:
- return ZUSAMMEN_INSTANCE;
- default:
- throw new IllegalArgumentException("Unssported state store");
+ @Override
+ public VersionableEntityDao createInterface(VersionableEntityStoreType storeType) {
+ switch (storeType) {
+ case Cassandra:
+ return CASSANDRA_INSTANCE;
+ case Zusammen:
+ return ZUSAMMEN_INSTANCE;
+ default:
+ throw new IllegalArgumentException("Unssported state store");
+ }
}
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java
index f90ef79290..f8c479eb5b 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.versioning.dao.impl;
import com.amdocs.zusammen.datatypes.Id;
@@ -32,53 +31,47 @@ import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
public class VersionableEntityDaoZusammenImpl implements VersionableEntityDao {
- private ZusammenAdaptor zusammenAdaptor;
+ private ZusammenAdaptor zusammenAdaptor;
- public VersionableEntityDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
- this.zusammenAdaptor = zusammenAdaptor;
- }
+ public VersionableEntityDaoZusammenImpl(ZusammenAdaptor zusammenAdaptor) {
+ this.zusammenAdaptor = zusammenAdaptor;
+ }
- @Override
- public void initVersion(VersionableEntityMetadata versionableTableMetadata, String entityId,
- Version baseVersion, Version newVersion) {
- // redundant in zusammen impl.
- }
+ private static Comparator<ItemVersion> getVersionModificationTimeDescComparator() {
+ return (o1, o2) -> Integer.compare(o2.getId().getValue().length(), o1.getId().getValue().length());
+ }
- @Override
- public void deleteVersion(VersionableEntityMetadata versionableTableMetadata, String entityId,
- Version versionToDelete, Version backToVersion) {
- SessionContext context = ZusammenUtil.createSessionContext();
- Id itemId = new Id(entityId);
- Id versionId = getItemVersionId(itemId, context);
- zusammenAdaptor.resetVersionHistory(context, itemId, versionId, backToVersion.toString());
- }
+ @Override
+ public void initVersion(VersionableEntityMetadata versionableTableMetadata, String entityId, Version baseVersion, Version newVersion) {
+ // redundant in zusammen impl.
+ }
- @Override
- public void closeVersion(VersionableEntityMetadata versionableTableMetadata, String entityId,
- Version versionToClose) {
- SessionContext context = ZusammenUtil.createSessionContext();
- Id itemId = new Id(entityId);
- Id versionId = getItemVersionId(itemId, context);
- zusammenAdaptor
- .tagVersion(context, itemId, versionId, new Tag(versionToClose.toString(), null));
- }
+ @Override
+ public void deleteVersion(VersionableEntityMetadata versionableTableMetadata, String entityId, Version versionToDelete, Version backToVersion) {
+ SessionContext context = ZusammenUtil.createSessionContext();
+ Id itemId = new Id(entityId);
+ Id versionId = getItemVersionId(itemId, context);
+ zusammenAdaptor.resetVersionHistory(context, itemId, versionId, backToVersion.toString());
+ }
- // TODO: 3/19/2017 move to a common util
- private Id getItemVersionId(Id itemId, SessionContext context) {
- Optional<ItemVersion> itemVersionOptional = getFirstVersion(context, itemId);
- ItemVersion itemVersion = itemVersionOptional.orElseThrow(() ->
- new RuntimeException(String.format("No version was found for item %s.", itemId)));
- return itemVersion.getId();
- }
+ @Override
+ public void closeVersion(VersionableEntityMetadata versionableTableMetadata, String entityId, Version versionToClose) {
+ SessionContext context = ZusammenUtil.createSessionContext();
+ Id itemId = new Id(entityId);
+ Id versionId = getItemVersionId(itemId, context);
+ zusammenAdaptor.tagVersion(context, itemId, versionId, new Tag(versionToClose.toString(), null));
+ }
- private Optional<ItemVersion> getFirstVersion(SessionContext context, Id itemId) {
- Collection<ItemVersion> versions = zusammenAdaptor.listPublicVersions(context, itemId);
- return CollectionUtils.isEmpty(versions)
- ? Optional.empty()
- : versions.stream().min(getVersionModificationTimeDescComparator());
- }
+ // TODO: 3/19/2017 move to a common util
+ private Id getItemVersionId(Id itemId, SessionContext context) {
+ Optional<ItemVersion> itemVersionOptional = getFirstVersion(context, itemId);
+ ItemVersion itemVersion = itemVersionOptional
+ .orElseThrow(() -> new RuntimeException(String.format("No version was found for item %s.", itemId)));
+ return itemVersion.getId();
+ }
- private static Comparator<ItemVersion> getVersionModificationTimeDescComparator() {
- return (o1, o2) -> Integer.compare(o2.getId().getValue().length(), o1.getId().getValue().length());
- }
+ private Optional<ItemVersion> getFirstVersion(SessionContext context, Id itemId) {
+ Collection<ItemVersion> versions = zusammenAdaptor.listPublicVersions(context, itemId);
+ return CollectionUtils.isEmpty(versions) ? Optional.empty() : versions.stream().min(getVersionModificationTimeDescComparator());
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java
index b631663813..6ac18d9ff9 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java
@@ -21,6 +21,9 @@ package org.openecomp.sdc.versioning.dao.impl.zusammen;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.item.Info;
+import java.util.Collection;
+import java.util.Map;
+import java.util.stream.Collectors;
import org.openecomp.core.zusammen.api.ZusammenAdaptor;
import org.openecomp.core.zusammen.api.ZusammenUtil;
import org.openecomp.sdc.versioning.dao.ItemDao;
@@ -28,120 +31,103 @@ import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.types.Item;
import org.openecomp.sdc.versioning.types.ItemStatus;
-import java.util.Collection;
-import java.util.Map;
-import java.util.stream.Collectors;
-
public class ItemZusammenDaoImpl implements ItemDao {
- private ZusammenAdaptor zusammenAdaptor;
-
- public ItemZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) {
- this.zusammenAdaptor = zusammenAdaptor;
- }
-
- @Override
- public Collection<Item> list() {
- return zusammenAdaptor.listItems(ZusammenUtil.createSessionContext())
- .stream().map(this::mapFromZusammenItem)
- .collect(Collectors.toList());
- }
-
- @Override
- public Item get(Item item) {
- return mapFromZusammenItem(
- zusammenAdaptor.getItem(ZusammenUtil.createSessionContext(), new Id(item.getId())));
- }
-
- @Override
- public Item create(Item item) {
- Id itemId = zusammenAdaptor
- .createItem(ZusammenUtil.createSessionContext(), mapToZusammenItemInfo(item));
- item.setId(itemId.getValue());
- return item;
- }
+ private ZusammenAdaptor zusammenAdaptor;
- @Override
- public void delete(Item item){
- zusammenAdaptor.deleteItem(ZusammenUtil.createSessionContext(),new Id(item.getId()));
- }
+ public ItemZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) {
+ this.zusammenAdaptor = zusammenAdaptor;
+ }
- @Override
- public void update(Item item) {
- zusammenAdaptor
- .updateItem(ZusammenUtil.createSessionContext(), new Id(item.getId()),
- mapToZusammenItemInfo(item));
- }
+ @Override
+ public Collection<Item> list() {
+ return zusammenAdaptor.listItems(ZusammenUtil.createSessionContext()).stream().map(this::mapFromZusammenItem).collect(Collectors.toList());
+ }
- private Item mapFromZusammenItem(com.amdocs.zusammen.datatypes.item.Item zusammenItem) {
- if (zusammenItem == null) {
- return null;
+ @Override
+ public Item get(Item item) {
+ return mapFromZusammenItem(zusammenAdaptor.getItem(ZusammenUtil.createSessionContext(), new Id(item.getId())));
}
- Item item = new Item();
- item.setId(zusammenItem.getId().getValue());
- item.setName(zusammenItem.getInfo().getName());
- item.setDescription(zusammenItem.getInfo().getDescription());
- zusammenItem.getInfo().getProperties().entrySet()
- .forEach(property -> addPropertyToItem(property.getKey(), property.getValue(), item));
+ @Override
+ public Item create(Item item) {
+ Id itemId = zusammenAdaptor.createItem(ZusammenUtil.createSessionContext(), mapToZusammenItemInfo(item));
+ item.setId(itemId.getValue());
+ return item;
+ }
- item.setCreationTime(zusammenItem.getCreationTime());
- item.setModificationTime(zusammenItem.getModificationTime());
+ @Override
+ public void delete(Item item) {
+ zusammenAdaptor.deleteItem(ZusammenUtil.createSessionContext(), new Id(item.getId()));
+ }
- if(item.getStatus() == null){
- item.setStatus(ItemStatus.ACTIVE);
- update(item);
+ @Override
+ public void update(Item item) {
+ zusammenAdaptor.updateItem(ZusammenUtil.createSessionContext(), new Id(item.getId()), mapToZusammenItemInfo(item));
}
- return item;
- }
+ private Item mapFromZusammenItem(com.amdocs.zusammen.datatypes.item.Item zusammenItem) {
+ if (zusammenItem == null) {
+ return null;
+ }
+ Item item = new Item();
+ item.setId(zusammenItem.getId().getValue());
+ item.setName(zusammenItem.getInfo().getName());
+ item.setDescription(zusammenItem.getInfo().getDescription());
+ zusammenItem.getInfo().getProperties().entrySet().forEach(property -> addPropertyToItem(property.getKey(), property.getValue(), item));
+ item.setCreationTime(zusammenItem.getCreationTime());
+ item.setModificationTime(zusammenItem.getModificationTime());
+ if (item.getStatus() == null) {
+ item.setStatus(ItemStatus.ACTIVE);
+ update(item);
+ }
+ return item;
+ }
- private void addPropertyToItem(String propertyKey, Object propertyValue, Item item) {
- switch (propertyKey) {
- case InfoPropertyName.ITEM_TYPE:
- item.setType((String) propertyValue);
- break;
- case InfoPropertyName.ITEM_OWNER:
- item.setOwner((String) propertyValue);
- break;
- case InfoPropertyName.ITEM_STATUS:
- item.setStatus(ItemStatus.valueOf((String)propertyValue));
- break;
- case InfoPropertyName.ITEM_VERSIONS_STATUSES:
- for (Map.Entry<String, Number> statusCounter :
- ((Map<String, Number>) propertyValue).entrySet()) {
- item.getVersionStatusCounters().put(VersionStatus.valueOf(statusCounter.getKey()),
- statusCounter.getValue().intValue());
+ private void addPropertyToItem(String propertyKey, Object propertyValue, Item item) {
+ switch (propertyKey) {
+ case InfoPropertyName.ITEM_TYPE:
+ item.setType((String) propertyValue);
+ break;
+ case InfoPropertyName.ITEM_OWNER:
+ item.setOwner((String) propertyValue);
+ break;
+ case InfoPropertyName.ITEM_STATUS:
+ item.setStatus(ItemStatus.valueOf((String) propertyValue));
+ break;
+ case InfoPropertyName.ITEM_VERSIONS_STATUSES:
+ for (Map.Entry<String, Number> statusCounter : ((Map<String, Number>) propertyValue).entrySet()) {
+ item.getVersionStatusCounters().put(VersionStatus.valueOf(statusCounter.getKey()), statusCounter.getValue().intValue());
+ }
+ break;
+ default:
+ item.addProperty(propertyKey, propertyValue);
}
- break;
- default:
- item.addProperty(propertyKey, propertyValue);
}
- }
- private Info mapToZusammenItemInfo(Item item) {
- Info info = new Info();
- info.setName(item.getName());
- info.setDescription(item.getDescription());
- info.addProperty(InfoPropertyName.ITEM_TYPE, item.getType());
- info.addProperty(InfoPropertyName.ITEM_OWNER,item.getOwner());
- if (item.getStatus() != null) {
- info.addProperty(InfoPropertyName.ITEM_STATUS, item.getStatus());
+ private Info mapToZusammenItemInfo(Item item) {
+ Info info = new Info();
+ info.setName(item.getName());
+ info.setDescription(item.getDescription());
+ info.addProperty(InfoPropertyName.ITEM_TYPE, item.getType());
+ info.addProperty(InfoPropertyName.ITEM_OWNER, item.getOwner());
+ if (item.getStatus() != null) {
+ info.addProperty(InfoPropertyName.ITEM_STATUS, item.getStatus());
+ }
+ info.addProperty(InfoPropertyName.ITEM_VERSIONS_STATUSES, item.getVersionStatusCounters());
+ item.getProperties().entrySet().forEach(property -> info.addProperty(property.getKey(), property.getValue()));
+ return info;
}
- info.addProperty(InfoPropertyName.ITEM_VERSIONS_STATUSES, item.getVersionStatusCounters());
- item.getProperties().entrySet()
- .forEach(property -> info.addProperty(property.getKey(), property.getValue()));
- return info;
- }
- private static final class InfoPropertyName {
- private static final String ITEM_TYPE = "item_type";
- private static final String ITEM_VERSIONS_STATUSES = "item_versions_statuses";
- private static final String ITEM_OWNER = "Owner";
- private static final String ITEM_STATUS = "status";
+ private static final class InfoPropertyName {
- private InfoPropertyName() {
- throw new IllegalStateException("Constants class");
+ private static final String ITEM_TYPE = "item_type";
+ private static final String ITEM_VERSIONS_STATUSES = "item_versions_statuses";
+ private static final String ITEM_OWNER = "Owner";
+ private static final String ITEM_STATUS = "status";
+
+ private InfoPropertyName() {
+ throw new IllegalStateException("Constants class");
+ }
}
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java
index dfefc7273d..044359a165 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/VersionZusammenDaoImpl.java
@@ -23,7 +23,11 @@ import static org.openecomp.core.zusammen.api.ZusammenUtil.createSessionContext;
import com.amdocs.zusammen.datatypes.Id;
import com.amdocs.zusammen.datatypes.SessionContext;
-import com.amdocs.zusammen.datatypes.item.*;
+import com.amdocs.zusammen.datatypes.item.Info;
+import com.amdocs.zusammen.datatypes.item.ItemVersion;
+import com.amdocs.zusammen.datatypes.item.ItemVersionData;
+import com.amdocs.zusammen.datatypes.item.ItemVersionStatus;
+import com.amdocs.zusammen.datatypes.item.SynchronizationStatus;
import com.amdocs.zusammen.datatypes.itemversion.ItemVersionRevisions;
import java.util.ArrayList;
import java.util.List;
@@ -42,168 +46,148 @@ import org.openecomp.sdc.versioning.dao.types.VersionState;
public class VersionZusammenDaoImpl implements VersionDao {
- public static final class ZusammenProperty {
- public static final String LABEL = "label";
- public static final String STATUS = "status";
-
- private ZusammenProperty() {
- throw new IllegalStateException("Constants class");
- }
- }
-
- private ZusammenAdaptor zusammenAdaptor;
-
- public VersionZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) {
- this.zusammenAdaptor = zusammenAdaptor;
- }
-
- @Override
- public List<Version> list(String itemId) {
- ItemVersionToVersionConvertor convertor = new ItemVersionToVersionConvertor();
- return zusammenAdaptor.listPublicVersions(createSessionContext(), new Id(itemId)).stream()
- .map(convertor::convert)
- .collect(Collectors.toList());
- }
-
- @Override
- public void create(String itemId, Version version) {
- Id versionId =
- zusammenAdaptor.createVersion(createSessionContext(), new Id(itemId),
- version.getBaseId() == null ? null : new Id(version.getBaseId()),
- mapToZusammenVersion(version));
-
- version.setId(versionId.getValue());
- }
-
- @Override
- public void update(String itemId, Version version) {
- zusammenAdaptor.updateVersion(createSessionContext(), new Id(itemId), new Id(version.getId()),
- mapToZusammenVersion(version));
- }
-
- @Override
- public Optional<Version> get(String itemId, Version version) {
- SessionContext context = createSessionContext();
- Id itemIdObj = new Id(itemId);
- Id versionId = new Id(version.getId());
- ItemVersion itemVersion = zusammenAdaptor.getVersion(context, itemIdObj, versionId);
-
- if (itemVersion == null) {
- return Optional.empty();
- }
-
- VersionState versionState =
- convertState(zusammenAdaptor.getVersionStatus(context, itemIdObj, versionId));
- updateVersionStatus(context, itemIdObj, versionId, versionState, itemVersion);
-
- Version result = new ItemVersionToVersionConvertor().convert(itemVersion);
- result.setState(versionState);
- return Optional.of(result);
- }
-
- @Override
- public void delete(String itemId, Version version) {
- throw new UnsupportedOperationException("Delete version operation is not yet supported.");
- }
-
- @Override
- public void publish(String itemId, Version version, String message) {
- zusammenAdaptor
- .publishVersion(createSessionContext(), new Id(itemId), new Id(version.getId()), message);
- }
-
- @Override
- public void sync(String itemId, Version version) {
- zusammenAdaptor
- .syncVersion(createSessionContext(), new Id(itemId), new Id(version.getId()));
- }
-
- @Override
- public void forceSync(String itemId, Version version) {
- zusammenAdaptor
- .forceSyncVersion(createSessionContext(), new Id(itemId), new Id(version.getId()));
- }
-
- @Override
- public void clean(String itemId, Version version) {
- zusammenAdaptor.cleanVersion(createSessionContext(), new Id(itemId), new Id(version.getId()));
- }
-
- @Override
- public void revert(String itemId, Version version, String revisionId) {
- zusammenAdaptor.revert(createSessionContext(), new Id(itemId), new Id(version.getId()),
- new Id(revisionId));
- }
-
- @Override
- public List<Revision> listRevisions(String itemId, Version version) {
- ItemVersionRevisions itemVersionRevisions = zusammenAdaptor
- .listRevisions(createSessionContext(), new Id(itemId), new Id(version.getId()));
-
- return itemVersionRevisions == null || itemVersionRevisions.getItemVersionRevisions() == null ||
- itemVersionRevisions.getItemVersionRevisions().isEmpty()
- ? new ArrayList<>()
- : itemVersionRevisions.getItemVersionRevisions().stream()
- .map(this::convertRevision)
- .sorted(this::compareRevisionsTime)
+ private ZusammenAdaptor zusammenAdaptor;
+
+ public VersionZusammenDaoImpl(ZusammenAdaptor zusammenAdaptor) {
+ this.zusammenAdaptor = zusammenAdaptor;
+ }
+
+ @Override
+ public List<Version> list(String itemId) {
+ ItemVersionToVersionConvertor convertor = new ItemVersionToVersionConvertor();
+ return zusammenAdaptor.listPublicVersions(createSessionContext(), new Id(itemId)).stream().map(convertor::convert)
.collect(Collectors.toList());
- }
-
- private void updateVersionStatus(SessionContext context, Id itemId, Id versionId,
- VersionState versionState, ItemVersion itemVersion) {
- if (versionState.getSynchronizationState() != SynchronizationState.UpToDate) {
- String versionStatus = zusammenAdaptor.getPublicVersion(context, itemId, versionId)
- .getData().getInfo().getProperty(ZusammenProperty.STATUS);
- itemVersion.getData().getInfo().addProperty(ZusammenProperty.STATUS, versionStatus);
- }
- }
-
- private ItemVersionData mapToZusammenVersion(Version version) {
- Info info = new Info();
- info.addProperty(ZusammenProperty.LABEL, version.toString());
- info.addProperty(ZusammenProperty.STATUS, version.getStatus().name());
- info.setName(version.getName());
- info.setDescription(version.getDescription());
-
- ItemVersionData itemVersionData = new ItemVersionData();
- itemVersionData.setInfo(info);
- return itemVersionData;
- }
-
- private VersionState convertState(ItemVersionStatus versionStatus) {
- VersionState state = new VersionState();
- state.setSynchronizationState(getSyncState(versionStatus.getSynchronizationStatus()));
- state.setDirty(versionStatus.isDirty());
- return state;
- }
-
- private SynchronizationState getSyncState(SynchronizationStatus synchronizationStatus) {
- switch (synchronizationStatus) {
- case UP_TO_DATE:
- return SynchronizationState.UpToDate;
- case OUT_OF_SYNC:
- return SynchronizationState.OutOfSync;
- case MERGING:
- return SynchronizationState.Merging;
- default:
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId("UNKNOWN_VERSION_STATE")
- .withMessage("Version state is unknown").build());
- }
- }
-
- private Revision convertRevision(
- com.amdocs.zusammen.datatypes.itemversion.Revision zusammenRevision) {
- Revision revision = new Revision();
- revision.setId(zusammenRevision.getRevisionId().getValue());
- revision.setTime(zusammenRevision.getTime());
- revision.setUser(zusammenRevision.getUser());
- revision.setMessage(zusammenRevision.getMessage());
- return revision;
- }
-
- private int compareRevisionsTime(Revision revision1, Revision revision2) {
- return revision1.getTime().before(revision2.getTime()) ? 1 : -1;
- }
+ }
+
+ @Override
+ public void create(String itemId, Version version) {
+ Id versionId = zusammenAdaptor
+ .createVersion(createSessionContext(), new Id(itemId), version.getBaseId() == null ? null : new Id(version.getBaseId()),
+ mapToZusammenVersion(version));
+ version.setId(versionId.getValue());
+ }
+
+ @Override
+ public void update(String itemId, Version version) {
+ zusammenAdaptor.updateVersion(createSessionContext(), new Id(itemId), new Id(version.getId()), mapToZusammenVersion(version));
+ }
+
+ @Override
+ public Optional<Version> get(String itemId, Version version) {
+ SessionContext context = createSessionContext();
+ Id itemIdObj = new Id(itemId);
+ Id versionId = new Id(version.getId());
+ ItemVersion itemVersion = zusammenAdaptor.getVersion(context, itemIdObj, versionId);
+ if (itemVersion == null) {
+ return Optional.empty();
+ }
+ VersionState versionState = convertState(zusammenAdaptor.getVersionStatus(context, itemIdObj, versionId));
+ updateVersionStatus(context, itemIdObj, versionId, versionState, itemVersion);
+ Version result = new ItemVersionToVersionConvertor().convert(itemVersion);
+ result.setState(versionState);
+ return Optional.of(result);
+ }
+
+ @Override
+ public void delete(String itemId, Version version) {
+ throw new UnsupportedOperationException("Delete version operation is not yet supported.");
+ }
+
+ @Override
+ public void publish(String itemId, Version version, String message) {
+ zusammenAdaptor.publishVersion(createSessionContext(), new Id(itemId), new Id(version.getId()), message);
+ }
+
+ @Override
+ public void sync(String itemId, Version version) {
+ zusammenAdaptor.syncVersion(createSessionContext(), new Id(itemId), new Id(version.getId()));
+ }
+
+ @Override
+ public void forceSync(String itemId, Version version) {
+ zusammenAdaptor.forceSyncVersion(createSessionContext(), new Id(itemId), new Id(version.getId()));
+ }
+
+ @Override
+ public void clean(String itemId, Version version) {
+ zusammenAdaptor.cleanVersion(createSessionContext(), new Id(itemId), new Id(version.getId()));
+ }
+
+ @Override
+ public void revert(String itemId, Version version, String revisionId) {
+ zusammenAdaptor.revert(createSessionContext(), new Id(itemId), new Id(version.getId()), new Id(revisionId));
+ }
+
+ @Override
+ public List<Revision> listRevisions(String itemId, Version version) {
+ ItemVersionRevisions itemVersionRevisions = zusammenAdaptor.listRevisions(createSessionContext(), new Id(itemId), new Id(version.getId()));
+ return
+ itemVersionRevisions == null || itemVersionRevisions.getItemVersionRevisions() == null || itemVersionRevisions.getItemVersionRevisions()
+ .isEmpty() ? new ArrayList<>()
+ : itemVersionRevisions.getItemVersionRevisions().stream().map(this::convertRevision).sorted(this::compareRevisionsTime)
+ .collect(Collectors.toList());
+ }
+
+ private void updateVersionStatus(SessionContext context, Id itemId, Id versionId, VersionState versionState, ItemVersion itemVersion) {
+ if (versionState.getSynchronizationState() != SynchronizationState.UpToDate) {
+ String versionStatus = zusammenAdaptor.getPublicVersion(context, itemId, versionId).getData().getInfo()
+ .getProperty(ZusammenProperty.STATUS);
+ itemVersion.getData().getInfo().addProperty(ZusammenProperty.STATUS, versionStatus);
+ }
+ }
+
+ private ItemVersionData mapToZusammenVersion(Version version) {
+ Info info = new Info();
+ info.addProperty(ZusammenProperty.LABEL, version.toString());
+ info.addProperty(ZusammenProperty.STATUS, version.getStatus().name());
+ info.setName(version.getName());
+ info.setDescription(version.getDescription());
+ ItemVersionData itemVersionData = new ItemVersionData();
+ itemVersionData.setInfo(info);
+ return itemVersionData;
+ }
+
+ private VersionState convertState(ItemVersionStatus versionStatus) {
+ VersionState state = new VersionState();
+ state.setSynchronizationState(getSyncState(versionStatus.getSynchronizationStatus()));
+ state.setDirty(versionStatus.isDirty());
+ return state;
+ }
+
+ private SynchronizationState getSyncState(SynchronizationStatus synchronizationStatus) {
+ switch (synchronizationStatus) {
+ case UP_TO_DATE:
+ return SynchronizationState.UpToDate;
+ case OUT_OF_SYNC:
+ return SynchronizationState.OutOfSync;
+ case MERGING:
+ return SynchronizationState.Merging;
+ default:
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId("UNKNOWN_VERSION_STATE")
+ .withMessage("Version state is unknown").build());
+ }
+ }
+
+ private Revision convertRevision(com.amdocs.zusammen.datatypes.itemversion.Revision zusammenRevision) {
+ Revision revision = new Revision();
+ revision.setId(zusammenRevision.getRevisionId().getValue());
+ revision.setTime(zusammenRevision.getTime());
+ revision.setUser(zusammenRevision.getUser());
+ revision.setMessage(zusammenRevision.getMessage());
+ return revision;
+ }
+
+ private int compareRevisionsTime(Revision revision1, Revision revision2) {
+ return revision1.getTime().before(revision2.getTime()) ? 1 : -1;
+ }
+
+ public static final class ZusammenProperty {
+
+ public static final String LABEL = "label";
+ public static final String STATUS = "status";
+
+ private ZusammenProperty() {
+ throw new IllegalStateException("Constants class");
+ }
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/convertor/ItemVersionToVersionConvertor.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/convertor/ItemVersionToVersionConvertor.java
index 2ebb95b33b..361b1bcbec 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/convertor/ItemVersionToVersionConvertor.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/convertor/ItemVersionToVersionConvertor.java
@@ -29,40 +29,37 @@ import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
public class ItemVersionToVersionConvertor extends ElementConvertor {
- @Override
- public Object convert(Element element) {
- return null;
- }
- @Override
- public Object convert(Item item) {
- return null;
- }
-
- @Override
- public Object convert(ElementInfo elementInfo) {
- return null;
- }
+ @Override
+ public Object convert(Element element) {
+ return null;
+ }
- @Override
- public Version convert(ItemVersion itemVersion) {
- if (itemVersion == null) {
- return null;
+ @Override
+ public Object convert(Item item) {
+ return null;
}
- Version version = Version.valueOf(
- itemVersion.getData().getInfo().getProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL));
- version.setStatus(VersionStatus.valueOf(itemVersion.getData().getInfo()
- .getProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS)));
- version.setName(itemVersion.getData().getInfo().getName());
- version.setDescription(itemVersion.getData().getInfo().getDescription());
- version.setId(itemVersion.getId().getValue());
- if (itemVersion.getBaseId() != null) {
- version.setBaseId(itemVersion.getBaseId().getValue());
+ @Override
+ public Object convert(ElementInfo elementInfo) {
+ return null;
}
- version.setCreationTime(itemVersion.getCreationTime());
- version.setModificationTime(itemVersion.getModificationTime());
- return version;
- }
+ @Override
+ public Version convert(ItemVersion itemVersion) {
+ if (itemVersion == null) {
+ return null;
+ }
+ Version version = Version.valueOf(itemVersion.getData().getInfo().getProperty(VersionZusammenDaoImpl.ZusammenProperty.LABEL));
+ version.setStatus(VersionStatus.valueOf(itemVersion.getData().getInfo().getProperty(VersionZusammenDaoImpl.ZusammenProperty.STATUS)));
+ version.setName(itemVersion.getData().getInfo().getName());
+ version.setDescription(itemVersion.getData().getInfo().getDescription());
+ version.setId(itemVersion.getId().getValue());
+ if (itemVersion.getBaseId() != null) {
+ version.setBaseId(itemVersion.getBaseId().getValue());
+ }
+ version.setCreationTime(itemVersion.getCreationTime());
+ version.setModificationTime(itemVersion.getModificationTime());
+ return version;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerFactoryImpl.java
index 054a569958..0de4af3ab8 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerFactoryImpl.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.versioning.impl;
import org.openecomp.sdc.versioning.ActionVersioningManager;
@@ -26,14 +25,10 @@ import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDaoFactory;
public class ActionVersioningManagerFactoryImpl extends ActionVersioningManagerFactory {
-
- @Override
- public ActionVersioningManager createInterface() {
- return new ActionVersioningManagerImpl(
- VersionInfoDaoFactory.getInstance().createInterface(),
- VersionInfoDeletedDaoFactory.getInstance().createInterface(),
- VersionDaoFactory.getInstance().createInterface(),
- VersionCalculatorFactory.getInstance().createInterface(),
- AsdcItemManagerFactory.getInstance().createInterface());
- }
+ @Override
+ public ActionVersioningManager createInterface() {
+ return new ActionVersioningManagerImpl(VersionInfoDaoFactory.getInstance().createInterface(),
+ VersionInfoDeletedDaoFactory.getInstance().createInterface(), VersionDaoFactory.getInstance().createInterface(),
+ VersionCalculatorFactory.getInstance().createInterface(), AsdcItemManagerFactory.getInstance().createInterface());
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImpl.java
index ef33beadab..a69e862582 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ActionVersioningManagerImpl.java
@@ -13,9 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.versioning.impl;
+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;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
@@ -28,585 +34,494 @@ import org.openecomp.sdc.versioning.dao.VersionDao;
import org.openecomp.sdc.versioning.dao.VersionInfoDao;
import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
import org.openecomp.sdc.versioning.dao.VersionableEntityDaoFactory;
-import org.openecomp.sdc.versioning.dao.types.*;
-import org.openecomp.sdc.versioning.errors.*;
+import org.openecomp.sdc.versioning.dao.types.Revision;
+import org.openecomp.sdc.versioning.dao.types.SynchronizationState;
+import org.openecomp.sdc.versioning.dao.types.UserCandidateVersion;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.dao.types.VersionInfoDeletedEntity;
+import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity;
+import org.openecomp.sdc.versioning.dao.types.VersionStatus;
+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.VersionCreationMethod;
import org.openecomp.sdc.versioning.types.VersionInfo;
import org.openecomp.sdc.versioning.types.VersionableEntityAction;
import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
-import java.util.stream.Collectors;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
public class ActionVersioningManagerImpl implements ActionVersioningManager {
- private static final Logger LOGGER = LoggerFactory.getLogger(ActionVersioningManagerImpl.class);
- private static final Version INITIAL_ACTIVE_VERSION = new Version(0, 0);
- private static final Map<String, Set<VersionableEntityMetadata>> VERSIONABLE_ENTITIES =
- new HashMap<>();
-
- private final VersionInfoDao versionInfoDao;
- private final VersionInfoDeletedDao versionInfoDeletedDao;
- private VersionDao versionDao;
- private VersionCalculator versionCalculator;
- private AsdcItemManager asdcItemManager;
-
- public ActionVersioningManagerImpl(VersionInfoDao versionInfoDao,
- VersionInfoDeletedDao versionInfoDeletedDao,
- VersionDao versionDao,
- VersionCalculator versionCalculator,
- AsdcItemManager asdcItemManager) {
- this.versionInfoDao = versionInfoDao;
- this.versionInfoDeletedDao = versionInfoDeletedDao;
- this.versionDao = versionDao;
- this.versionCalculator = versionCalculator;
- this.asdcItemManager = asdcItemManager;
- }
-
- 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();
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ActionVersioningManagerImpl.class);
+ private static final Version INITIAL_ACTIVE_VERSION = new Version(0, 0);
+ private static final Map<String, Set<VersionableEntityMetadata>> VERSIONABLE_ENTITIES = new HashMap<>();
+ private final VersionInfoDao versionInfoDao;
+ private final VersionInfoDeletedDao versionInfoDeletedDao;
+ private VersionDao versionDao;
+ private VersionCalculator versionCalculator;
+ private AsdcItemManager asdcItemManager;
+
+ public ActionVersioningManagerImpl(VersionInfoDao versionInfoDao, VersionInfoDeletedDao versionInfoDeletedDao, VersionDao versionDao,
+ VersionCalculator versionCalculator, AsdcItemManager asdcItemManager) {
+ this.versionInfoDao = versionInfoDao;
+ this.versionInfoDeletedDao = versionInfoDeletedDao;
+ this.versionDao = versionDao;
+ this.versionCalculator = versionCalculator;
+ this.asdcItemManager = asdcItemManager;
+ }
+
+ 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 {
- throw new CoreException(
- new EditOnEntityLockedByOtherErrorBuilder(entityType, entityId, candidate.getUser())
- .build());
+ if (candidate != null && user.equals(candidate.getUser())) {
+ activeVersion = candidate.getVersion();
+ } else {
+ activeVersion = activeVer;
+ }
}
- } 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.setStatus(status);
- activeVersion.setStatus(status);
- if (latestFinalVersion != null) {
- latestFinalVersion.setStatus(status);
- }
- if (viewableVersions != null) {
- viewableVersions.forEach(version -> version.setStatus(status));
- versionInfo.setViewableVersions(toSortedList(viewableVersions));
- versionInfo.setFinalVersions(getFinalVersions(viewableVersions));
- }
- versionInfo.setActiveVersion(activeVersion);
- versionInfo.setLatestFinalVersion(latestFinalVersion);
- if (candidate != null) {
- candidate.getVersion().setStatus(status);
- 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) -> 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::isFinal).collect(Collectors.toList());
- }
-
- @Override
- public void register(String entityType, VersionableEntityMetadata entityMetadata) {
- Set<VersionableEntityMetadata> entitiesMetadata =
- VERSIONABLE_ENTITIES.computeIfAbsent(entityType, k -> new HashSet<>());
- 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 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:
- //do nothing
- break;
- }
-
- doDelete(versionInfoEntity);
- }
-
- @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);
-}
+ VersionInfo versionInfo = new VersionInfo();
+ versionInfo.setStatus(status);
+ activeVersion.setStatus(status);
+ if (latestFinalVersion != null) {
+ latestFinalVersion.setStatus(status);
+ }
+ if (viewableVersions != null) {
+ viewableVersions.forEach(version -> version.setStatus(status));
+ versionInfo.setViewableVersions(toSortedList(viewableVersions));
+ versionInfo.setFinalVersions(getFinalVersions(viewableVersions));
+ }
+ versionInfo.setActiveVersion(activeVersion);
+ versionInfo.setLatestFinalVersion(latestFinalVersion);
+ if (candidate != null) {
+ candidate.getVersion().setStatus(status);
+ versionInfo.setLockingUser(candidate.getUser());
+ if (user.equals(candidate.getUser())) {
+ versionInfo.getViewableVersions().add(candidate.getVersion());
+ }
+ }
+ return versionInfo;
+ }
- @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 Certified:
- case Draft:
- checkoutVersion = doCheckout(versionInfoEntity, user);
- break;
- default:
- //do nothing
- break;
- }
-
- 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());
+ private static List<Version> toSortedList(
+ Set<Version> versions) { // changing the Set to List in DB will require migration...
+ return versions.stream().sorted((o1, o2) -> o1.getMajor() > o2.getMajor() ? 1
+ : o1.getMajor() == o2.getMajor() ? (o1.getMinor() > o2.getMinor() ? 1 : o1.getMinor() == o2.getMinor() ? 0 : -1) : -1)
+ .collect(Collectors.toList());
+ }
+
+ private static List<Version> getFinalVersions(Set<Version> versions) {
+ return versions.stream().filter(Version::isFinal).collect(Collectors.toList());
+ }
+
+ @Override
+ public void register(String entityType, VersionableEntityMetadata entityMetadata) {
+ Set<VersionableEntityMetadata> entitiesMetadata = VERSIONABLE_ENTITIES.computeIfAbsent(entityType, k -> new HashSet<>());
+ 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 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:
+ //do nothing
+ break;
+ }
+ doDelete(versionInfoEntity);
+ }
+
+ @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);
+ }
+
+ @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 Certified:
+ case Draft:
+ checkoutVersion = doCheckout(versionInfoEntity, user);
+ break;
+ default:
+ //do nothing
+ break;
+ }
+ 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 Certified:
+ case Draft:
+ throw new CoreException(new UndoCheckoutOnUnlockedEntityErrorBuilder(entityType, entityId).build());
+ default:
+ //do nothing
+ break;
+ }
+ return activeVersion;
+ }
+
+ private Version undoCheckout(VersionInfoEntity versionInfoEntity) {
+ deleteVersionFromEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(), versionInfoEntity.getCandidate().getVersion(),
+ versionInfoEntity.getActiveVersion());
+ versionInfoEntity.setStatus(versionInfoEntity.getActiveVersion().isFinal() ? VersionStatus.Certified : VersionStatus.Draft);
+ 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());
}
- activeVersion = undoCheckout(versionInfoEntity);
- break;
- case Certified:
- case Draft:
- throw new CoreException(
- new UndoCheckoutOnUnlockedEntityErrorBuilder(entityType, entityId).build());
- default:
- //do nothing
- break;
- }
-
- return activeVersion;
- }
-
- private Version undoCheckout(VersionInfoEntity versionInfoEntity) {
- deleteVersionFromEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(),
- versionInfoEntity.getCandidate().getVersion(), versionInfoEntity.getActiveVersion());
-
- versionInfoEntity
- .setStatus(versionInfoEntity.getActiveVersion().isFinal() ? VersionStatus.Certified
- : VersionStatus.Draft);
- 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 Draft:
- case Certified:
- 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());
+ Version checkedInVersion = null;
+ switch (versionInfoEntity.getStatus()) {
+ case Draft:
+ case Certified:
+ 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:
+ //do nothing
+ break;
+ }
+ 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 Certified:
+ throw new CoreException(new EntityAlreadyFinalizedErrorBuilder(entityType, entityId).build());
+ case Locked:
+ throw new CoreException(
+ new SubmitLockedEntityNotAllowedErrorBuilder(entityType, entityId, versionInfoEntity.getCandidate().getUser()).build());
+ case Draft:
+ submitVersion = doSubmit(versionInfoEntity, user, submitDescription);
+ break;
+ default:
+ //do nothing
+ break;
+ }
+ 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());
}
- checkedInVersion = doCheckin(versionInfoEntity, checkinDescription);
- break;
- default:
- //do nothing
- break;
- }
-
- 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 Certified:
- throw new CoreException(
- new EntityAlreadyFinalizedErrorBuilder(entityType, entityId).build());
- case Locked:
- throw new CoreException(new SubmitLockedEntityNotAllowedErrorBuilder(entityType, entityId,
- versionInfoEntity.getCandidate().getUser()).build());
- case Draft:
- submitVersion = doSubmit(versionInfoEntity, user, submitDescription);
- break;
- default:
- //do nothing
- break;
- }
-
- 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 List<Version> list(String itemId) {
-
- List<Version> versions = versionDao.list(itemId);
- Set<String> versionsNames = versions.stream().map(Version::getName).collect(Collectors.toSet());
- versions.forEach(version -> {
- version.setAdditionalInfo(new HashMap<>());
- versionCalculator.injectAdditionalInfo(version, versionsNames);
- });
- return versions;
- }
-
- @Override
- public Version get(String itemId, Version version) {
- return versionDao.get(itemId, version)
- .map(retrievedVersion -> getUpdateRetrievedVersion(itemId, retrievedVersion))
- .orElseGet(() -> getSyncedVersion(itemId, version));
- }
-
- private Version getUpdateRetrievedVersion(String itemId, Version version) {
- if (version.getStatus() == VersionStatus.Certified &&
- (version.getState().getSynchronizationState() == SynchronizationState.OutOfSync ||
- version.getState().isDirty())) {
- forceSync(itemId, version);
- LOGGER.info("Item Id {}, version Id {}: Force sync is done", itemId, version.getId());
- version = versionDao.get(itemId, version)
- .orElseThrow(() -> new IllegalStateException(
- "Get version after a successful force sync must return the version"));
- }
- return version;
- }
-
- private Version getSyncedVersion(String itemId, Version version) {
- sync(itemId, version);
- LOGGER.info("Item Id {}, version Id {}: First time sync is done", itemId, version.getId());
- return versionDao.get(itemId, version)
- .orElseThrow(() -> new IllegalStateException(
- "Get version after a successful sync must return the version"));
- }
-
- @Override
- public Version create(String itemId, Version version, VersionCreationMethod creationMethod) {
- String baseVersionName = null;
- if (version.getBaseId() == null) {
- version.setDescription("Initial version");
- } else {
- baseVersionName = get(itemId, new Version(version.getBaseId())).getName();
- }
- String versionName = versionCalculator.calculate(baseVersionName, creationMethod);
- validateVersionName(itemId, versionName);
- version.setName(versionName);
-
- versionDao.create(itemId, version);
- asdcItemManager.updateVersionStatus(itemId, VersionStatus.Draft, null);
-
- publish(itemId, version, String.format("Create version: %s", version.getName()));
- return version;
- }
-
- private void validateVersionName(String itemId, String versionName) {
- if (versionDao.list(itemId).stream()
- .anyMatch(version -> versionName.equals(version.getName()))) {
- String errorDescription = String
- .format("Item %s: create version failed, a version with the name %s already exist",
- itemId, versionName);
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId("VERSION_NAME_ALREADY_EXIST")
- .withMessage(errorDescription)
- .build());
- }
- }
-
- @Override
- public void submit(String itemId, Version version, String submitDescription) {
- version = get(itemId, version);
-
- validateSubmit(itemId, version);
-
- version.setStatus(VersionStatus.Certified);
- versionDao.update(itemId, version);
-
- publish(itemId, version, submitDescription);
-
- asdcItemManager.updateVersionStatus(itemId, VersionStatus.Certified, VersionStatus.Draft);
- }
-
- private void validateSubmit(String itemId, Version version) {
- if (version.getStatus() == VersionStatus.Certified) {
- String errorDescription = String
- .format("Item %s: submit version failed, version %s is already Certified", itemId,
- version.getId());
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId("VERSION_ALREADY_CERTIFIED")
- .withMessage(errorDescription)
- .build());
- }
- }
-
- @Override
- public void publish(String itemId, Version version, String message) {
- versionDao.publish(itemId, version, message);
- }
-
-
- @Override
- public void sync(String itemId, Version version) {
- versionDao.sync(itemId, version);
- }
-
- @Override
- public void forceSync(String itemId, Version version) {
- versionDao.forceSync(itemId, version);
- }
-
- @Override
- public void revert(String itemId, Version version, String revisionId) {
- versionDao.revert(itemId, version, revisionId);
- }
-
- @Override
- public List<Revision> listRevisions(String itemId, Version version) {
- return versionDao.listRevisions(itemId, version);
- }
-
- private void markAsCheckedOut(VersionInfoEntity versionInfoEntity, String checkingOutUser) {
- versionInfoEntity.setStatus(VersionStatus.Locked);
- versionInfoEntity.setCandidate(new UserCandidateVersion(checkingOutUser,
- 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) {
- 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) {
- 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.Draft);
-
- closeVersionOnEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(),
- versionInfoEntity.getActiveVersion());
-
- 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);
- closeVersionOnEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(),
- 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.Certified);
- versionInfoDao.update(versionInfoEntity);
-
- return finalVersion;
- }
-
- private void initVersionOnEntity(String entityType, String entityId, Version baseVersion,
- Version newVersion) {
- Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
- if (entityMetadatas != null) {
- for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
- VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
- .initVersion(entityMetadata, entityId, baseVersion, newVersion);
- }
- }
- }
-
- private void deleteVersionFromEntity(String entityType, String entityId,
- Version versionToDelete, Version backToVersion) {
- Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
- if (entityMetadatas != null) {
- for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
- VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
- .deleteVersion(entityMetadata, entityId, versionToDelete, backToVersion);
- }
- }
- }
-
- private void closeVersionOnEntity(String entityType, String entityId, Version versionToClose) {
- Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
- if (entityMetadatas != null) {
- for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
- VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
- .closeVersion(entityMetadata, entityId, versionToClose);
- }
- }
- }
+ 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 List<Version> list(String itemId) {
+ List<Version> versions = versionDao.list(itemId);
+ Set<String> versionsNames = versions.stream().map(Version::getName).collect(Collectors.toSet());
+ versions.forEach(version -> {
+ version.setAdditionalInfo(new HashMap<>());
+ versionCalculator.injectAdditionalInfo(version, versionsNames);
+ });
+ return versions;
+ }
+
+ @Override
+ public Version get(String itemId, Version version) {
+ return versionDao.get(itemId, version).map(retrievedVersion -> getUpdateRetrievedVersion(itemId, retrievedVersion))
+ .orElseGet(() -> getSyncedVersion(itemId, version));
+ }
+
+ private Version getUpdateRetrievedVersion(String itemId, Version version) {
+ if (version.getStatus() == VersionStatus.Certified && (version.getState().getSynchronizationState() == SynchronizationState.OutOfSync
+ || version.getState().isDirty())) {
+ forceSync(itemId, version);
+ LOGGER.info("Item Id {}, version Id {}: Force sync is done", itemId, version.getId());
+ version = versionDao.get(itemId, version)
+ .orElseThrow(() -> new IllegalStateException("Get version after a successful force sync must return the version"));
+ }
+ return version;
+ }
+
+ private Version getSyncedVersion(String itemId, Version version) {
+ sync(itemId, version);
+ LOGGER.info("Item Id {}, version Id {}: First time sync is done", itemId, version.getId());
+ return versionDao.get(itemId, version)
+ .orElseThrow(() -> new IllegalStateException("Get version after a successful sync must return the version"));
+ }
+
+ @Override
+ public Version create(String itemId, Version version, VersionCreationMethod creationMethod) {
+ String baseVersionName = null;
+ if (version.getBaseId() == null) {
+ version.setDescription("Initial version");
+ } else {
+ baseVersionName = get(itemId, new Version(version.getBaseId())).getName();
+ }
+ String versionName = versionCalculator.calculate(baseVersionName, creationMethod);
+ validateVersionName(itemId, versionName);
+ version.setName(versionName);
+ versionDao.create(itemId, version);
+ asdcItemManager.updateVersionStatus(itemId, VersionStatus.Draft, null);
+ publish(itemId, version, String.format("Create version: %s", version.getName()));
+ return version;
+ }
+
+ private void validateVersionName(String itemId, String versionName) {
+ if (versionDao.list(itemId).stream().anyMatch(version -> versionName.equals(version.getName()))) {
+ String errorDescription = String.format("Item %s: create version failed, a version with the name %s already exist", itemId, versionName);
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId("VERSION_NAME_ALREADY_EXIST")
+ .withMessage(errorDescription).build());
+ }
+ }
+
+ @Override
+ public void submit(String itemId, Version version, String submitDescription) {
+ version = get(itemId, version);
+ validateSubmit(itemId, version);
+ version.setStatus(VersionStatus.Certified);
+ versionDao.update(itemId, version);
+ publish(itemId, version, submitDescription);
+ asdcItemManager.updateVersionStatus(itemId, VersionStatus.Certified, VersionStatus.Draft);
+ }
+
+ private void validateSubmit(String itemId, Version version) {
+ if (version.getStatus() == VersionStatus.Certified) {
+ String errorDescription = String.format("Item %s: submit version failed, version %s is already Certified", itemId, version.getId());
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId("VERSION_ALREADY_CERTIFIED")
+ .withMessage(errorDescription).build());
+ }
+ }
+
+ @Override
+ public void publish(String itemId, Version version, String message) {
+ versionDao.publish(itemId, version, message);
+ }
+
+ @Override
+ public void sync(String itemId, Version version) {
+ versionDao.sync(itemId, version);
+ }
+
+ @Override
+ public void forceSync(String itemId, Version version) {
+ versionDao.forceSync(itemId, version);
+ }
+
+ @Override
+ public void revert(String itemId, Version version, String revisionId) {
+ versionDao.revert(itemId, version, revisionId);
+ }
+
+ @Override
+ public List<Revision> listRevisions(String itemId, Version version) {
+ return versionDao.listRevisions(itemId, version);
+ }
+
+ private void markAsCheckedOut(VersionInfoEntity versionInfoEntity, String checkingOutUser) {
+ versionInfoEntity.setStatus(VersionStatus.Locked);
+ versionInfoEntity.setCandidate(new UserCandidateVersion(checkingOutUser, 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) {
+ 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) {
+ 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.Draft);
+ closeVersionOnEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(), versionInfoEntity.getActiveVersion());
+ 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);
+ closeVersionOnEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(), 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.Certified);
+ versionInfoDao.update(versionInfoEntity);
+ return finalVersion;
+ }
+
+ private void initVersionOnEntity(String entityType, String entityId, Version baseVersion, Version newVersion) {
+ Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
+ if (entityMetadatas != null) {
+ for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
+ VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
+ .initVersion(entityMetadata, entityId, baseVersion, newVersion);
+ }
+ }
+ }
+
+ private void deleteVersionFromEntity(String entityType, String entityId, Version versionToDelete, Version backToVersion) {
+ Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
+ if (entityMetadatas != null) {
+ for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
+ VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
+ .deleteVersion(entityMetadata, entityId, versionToDelete, backToVersion);
+ }
+ }
+ }
+
+ private void closeVersionOnEntity(String entityType, String entityId, Version versionToClose) {
+ Set<VersionableEntityMetadata> entityMetadatas = VERSIONABLE_ENTITIES.get(entityType);
+ if (entityMetadatas != null) {
+ for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
+ VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
+ .closeVersion(entityMetadata, entityId, versionToClose);
+ }
+ }
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerFactoryImpl.java
index 090f042027..f071d5e500 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerFactoryImpl.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.versioning.impl;
import org.openecomp.sdc.itempermissions.PermissionsServicesFactory;
@@ -23,13 +22,12 @@ import org.openecomp.sdc.versioning.AsdcItemManagerFactory;
import org.openecomp.sdc.versioning.dao.ItemDaoFactory;
public class AsdcItemManagerFactoryImpl extends AsdcItemManagerFactory {
- private static final AsdcItemManager INSTANCE =
- new AsdcItemManagerImpl(ItemDaoFactory.getInstance().createInterface(),
- PermissionsServicesFactory.getInstance().createInterface(),
- SubscriptionServiceFactory.getInstance().createInterface());
- @Override
- public AsdcItemManager createInterface() {
- return INSTANCE;
- }
+ private static final AsdcItemManager INSTANCE = new AsdcItemManagerImpl(ItemDaoFactory.getInstance().createInterface(),
+ PermissionsServicesFactory.getInstance().createInterface(), SubscriptionServiceFactory.getInstance().createInterface());
+
+ @Override
+ public AsdcItemManager 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/AsdcItemManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerImpl.java
index 82d3ae5a61..a4741f57e3 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/AsdcItemManagerImpl.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.versioning.impl;
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
@@ -24,47 +23,39 @@ import org.openecomp.sdc.versioning.dao.ItemDao;
import org.openecomp.sdc.versioning.types.Item;
public class AsdcItemManagerImpl extends ItemManagerImpl implements AsdcItemManager {
- private static final String CREATE_ITEM = "Create_Item";
-
- private PermissionsServices permissionsServices;
- private SubscriptionService subscriptionService;
-
- public AsdcItemManagerImpl(ItemDao itemDao, PermissionsServices permissionsServices,
- SubscriptionService subscriptionService) {
- super(itemDao);
-
- this.permissionsServices = permissionsServices;
- this.subscriptionService = subscriptionService;
- }
-
- @Override
- public Item create(Item item) {
- Item createdItem = super.create(item);
- String userId = SessionContextProviderFactory.getInstance()
- .createInterface().get().getUser().getUserId();
- String itemId = createdItem.getId();
- permissionsServices.execute(itemId, userId, CREATE_ITEM);
- subscriptionService.subscribe(userId, itemId);
+ private static final String CREATE_ITEM = "Create_Item";
+ private PermissionsServices permissionsServices;
+ private SubscriptionService subscriptionService;
- return createdItem;
- }
-
-
- @Override
- public void updateOwner(String itemId, String owner) {
- Item item = get(itemId);
- if (item == null) {
- return;
+ public AsdcItemManagerImpl(ItemDao itemDao, PermissionsServices permissionsServices, SubscriptionService subscriptionService) {
+ super(itemDao);
+ this.permissionsServices = permissionsServices;
+ this.subscriptionService = subscriptionService;
}
- item.setOwner(owner);
- super.update(item);
- }
- @Override
- public void delete(Item item) {
- super.delete(item);
- }
+ @Override
+ public Item create(Item item) {
+ Item createdItem = super.create(item);
+ String userId = SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId();
+ String itemId = createdItem.getId();
+ permissionsServices.execute(itemId, userId, CREATE_ITEM);
+ subscriptionService.subscribe(userId, itemId);
+ return createdItem;
+ }
+ @Override
+ public void updateOwner(String itemId, String owner) {
+ Item item = get(itemId);
+ if (item == null) {
+ return;
+ }
+ item.setOwner(owner);
+ super.update(item);
+ }
+ @Override
+ public void delete(Item item) {
+ super.delete(item);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerFactoryImpl.java
index fbbc32e58e..77f4ef90c7 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerFactoryImpl.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.versioning.impl;
import org.openecomp.sdc.versioning.ItemManager;
@@ -21,11 +20,11 @@ import org.openecomp.sdc.versioning.ItemManagerFactory;
import org.openecomp.sdc.versioning.dao.ItemDaoFactory;
public class ItemManagerFactoryImpl extends ItemManagerFactory {
- private static final ItemManager instance =
- new ItemManagerImpl(ItemDaoFactory.getInstance().createInterface());
- @Override
- public ItemManager createInterface() {
- return instance;
- }
+ private static final ItemManager instance = new ItemManagerImpl(ItemDaoFactory.getInstance().createInterface());
+
+ @Override
+ public ItemManager createInterface() {
+ return instance;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
index 368eadad2c..8ef1fd2e04 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
@@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.versioning.impl;
+import java.util.Collection;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
@@ -25,98 +27,81 @@ import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.types.Item;
import org.openecomp.sdc.versioning.types.ItemStatus;
-import java.util.Collection;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
public class ItemManagerImpl implements ItemManager {
- private ItemDao itemDao;
-
-
- public ItemManagerImpl(ItemDao itemDao) {
- this.itemDao = itemDao;
-
- }
+ private ItemDao itemDao;
- @Override
- public Collection<Item> list(Predicate<Item> predicate) {
- return itemDao.list().stream().filter(predicate).collect(Collectors.toList());
- }
-
- @Override
- public Item get(String itemId) {
- Item item = new Item();
- item.setId(itemId);
- return itemDao.get(item);
- }
-
- @Override
- public Item create(Item item) {
- return itemDao.create(item);
- }
-
- @Override
- public void updateVersionStatus(String itemId, VersionStatus addedVersionStatus,
- VersionStatus removedVersionStatus) {
- Item item = get(itemId);
- if (item == null) {
- return;
+ public ItemManagerImpl(ItemDao itemDao) {
+ this.itemDao = itemDao;
}
- item.addVersionStatus(addedVersionStatus);
- if (removedVersionStatus != null) {
- item.removeVersionStatus(removedVersionStatus);
+ @Override
+ public Collection<Item> list(Predicate<Item> predicate) {
+ return itemDao.list().stream().filter(predicate).collect(Collectors.toList());
}
- itemDao.update(item);
- }
- @Override
- public void delete(Item item) {
- itemDao.delete(item);
- }
-
- @Override
- public void updateName(String itemId, String name) {
- Item item = get(itemId);
- if (item == null) {
- return;
+ @Override
+ public Item get(String itemId) {
+ Item item = new Item();
+ item.setId(itemId);
+ return itemDao.get(item);
}
- item.setName(name);
- itemDao.update(item);
- }
-
- @Override
- public void archive(Item item) {
+ @Override
+ public Item create(Item item) {
+ return itemDao.create(item);
+ }
- if (item.getStatus() == ItemStatus.ARCHIVED) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withMessage(String.format("Archive item failed, item %s is already Archived", item.getId()))
- .build());
+ @Override
+ public void updateVersionStatus(String itemId, VersionStatus addedVersionStatus, VersionStatus removedVersionStatus) {
+ Item item = get(itemId);
+ if (item == null) {
+ return;
+ }
+ item.addVersionStatus(addedVersionStatus);
+ if (removedVersionStatus != null) {
+ item.removeVersionStatus(removedVersionStatus);
+ }
+ itemDao.update(item);
}
- item.setStatus(ItemStatus.ARCHIVED);
- itemDao.update(item);
- }
+ @Override
+ public void delete(Item item) {
+ itemDao.delete(item);
+ }
- @Override
- public void restore(Item item) {
+ @Override
+ public void updateName(String itemId, String name) {
+ Item item = get(itemId);
+ if (item == null) {
+ return;
+ }
+ item.setName(name);
+ itemDao.update(item);
+ }
- if (item.getStatus() == ItemStatus.ACTIVE) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withMessage(String.format("Restore item failed, item %s is already Active", item.getId()))
- .build());
- }
+ @Override
+ public void archive(Item item) {
+ if (item.getStatus() == ItemStatus.ARCHIVED) {
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
+ .withMessage(String.format("Archive item failed, item %s is already Archived", item.getId())).build());
+ }
+ item.setStatus(ItemStatus.ARCHIVED);
+ itemDao.update(item);
+ }
- item.setStatus(ItemStatus.ACTIVE);
- itemDao.update(item);
+ @Override
+ public void restore(Item item) {
+ if (item.getStatus() == ItemStatus.ACTIVE) {
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION)
+ .withMessage(String.format("Restore item failed, item %s is already Active", item.getId())).build());
+ }
+ item.setStatus(ItemStatus.ACTIVE);
+ itemDao.update(item);
}
- @Override
- public void update(Item item) {
- itemDao.update(item);
- }
+ @Override
+ public void update(Item item) {
+ itemDao.update(item);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorFactoryImpl.java
index 8cb524c27c..ef3ca5059f 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorFactoryImpl.java
@@ -23,11 +23,11 @@ import org.openecomp.sdc.versioning.VersionCalculator;
import org.openecomp.sdc.versioning.VersionCalculatorFactory;
public class MajorVersionCalculatorFactoryImpl extends VersionCalculatorFactory {
- private static final VersionCalculator INSTANCE =
- new MajorVersionCalculatorImpl();
- @Override
- public VersionCalculator createInterface() {
- return INSTANCE;
- }
+ private static final VersionCalculator INSTANCE = new MajorVersionCalculatorImpl();
+
+ @Override
+ public VersionCalculator createInterface() {
+ return INSTANCE;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImpl.java
index 008d96713f..c5e69ce647 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/MajorVersionCalculatorImpl.java
@@ -19,54 +19,49 @@
*/
package org.openecomp.sdc.versioning.impl;
+import java.util.HashSet;
+import java.util.Set;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.sdc.versioning.VersionCalculator;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.types.VersionCreationMethod;
-import java.util.HashSet;
-import java.util.Set;
-
public class MajorVersionCalculatorImpl implements VersionCalculator {
- private static final String INITIAL_VERSION = "1.0";
- private static final String VERSION_STRING_VIOLATION_MSG =
- "Version string must be in the format of: {integer}.{integer}";
- @Override
- public String calculate(String baseVersion, VersionCreationMethod creationMethod) {
+ private static final String INITIAL_VERSION = "1.0";
+ private static final String VERSION_STRING_VIOLATION_MSG = "Version string must be in the format of: {integer}.{integer}";
- if (baseVersion == null) {
- return INITIAL_VERSION;
- }
-
- String[] versionLevels = baseVersion.split("\\.");
- if (versionLevels.length != 2) {
- throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
+ @Override
+ public String calculate(String baseVersion, VersionCreationMethod creationMethod) {
+ if (baseVersion == null) {
+ return INITIAL_VERSION;
+ }
+ String[] versionLevels = baseVersion.split("\\.");
+ if (versionLevels.length != 2) {
+ throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
+ }
+ int index = Integer.parseInt(versionLevels[0]);
+ index++;
+ versionLevels[0] = Integer.toString(index);
+ versionLevels[1] = "0";
+ return CommonMethods.arrayToSeparatedString(versionLevels, '.');
}
- int index = Integer.parseInt(versionLevels[0]);
- index++;
- versionLevels[0] = Integer.toString(index);
- versionLevels[1] = "0";
-
- return CommonMethods.arrayToSeparatedString(versionLevels, '.');
- }
-
- @Override
- public void injectAdditionalInfo(Version version, Set<String> existingVersions) {
- String optionalVersion;
- Set<VersionCreationMethod> optionalCreationMethods = new HashSet<>();
- if(version.getStatus().equals(VersionStatus.Certified)) {
- try {
- optionalVersion = calculate(version.getName(), VersionCreationMethod.major);
- if (!existingVersions.contains(optionalVersion)) {
- optionalCreationMethods.add(VersionCreationMethod.major);
+ @Override
+ public void injectAdditionalInfo(Version version, Set<String> existingVersions) {
+ String optionalVersion;
+ Set<VersionCreationMethod> optionalCreationMethods = new HashSet<>();
+ if (version.getStatus().equals(VersionStatus.Certified)) {
+ try {
+ optionalVersion = calculate(version.getName(), VersionCreationMethod.major);
+ if (!existingVersions.contains(optionalVersion)) {
+ optionalCreationMethods.add(VersionCreationMethod.major);
+ }
+ } catch (IllegalArgumentException iae) {
+ //not a valid creation method.
+ }
}
- } catch (IllegalArgumentException iae) {
- //not a valid creation method.
- }
+ version.getAdditionalInfo().put("OptionalCreationMethods", optionalCreationMethods);
}
- version.getAdditionalInfo().put("OptionalCreationMethods", optionalCreationMethods);
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorFactoryImpl.java
index 155aa9c5e6..9f2b9fbe58 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorFactoryImpl.java
@@ -17,18 +17,17 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.versioning.impl;
import org.openecomp.sdc.versioning.VersionCalculator;
import org.openecomp.sdc.versioning.VersionCalculatorFactory;
public class VersionCalculatorFactoryImpl extends VersionCalculatorFactory {
- private static final VersionCalculator INSTANCE =
- new VersionCalculatorImpl();
- @Override
- public VersionCalculator createInterface() {
- return INSTANCE;
- }
+ private static final VersionCalculator INSTANCE = new VersionCalculatorImpl();
+
+ @Override
+ public VersionCalculator createInterface() {
+ return INSTANCE;
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java
index 5fe48ff7ca..4e9f460f04 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersionCalculatorImpl.java
@@ -19,6 +19,8 @@
*/
package org.openecomp.sdc.versioning.impl;
+import java.util.HashSet;
+import java.util.Set;
import org.openecomp.core.utilities.CommonMethods;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
@@ -27,62 +29,55 @@ import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.dao.types.VersionStatus;
import org.openecomp.sdc.versioning.types.VersionCreationMethod;
-import java.util.HashSet;
-import java.util.Set;
-
public class VersionCalculatorImpl implements VersionCalculator {
- private static final Logger LOGGER = LoggerFactory.getLogger(VersionCalculatorImpl.class);
-
- private static final String INITIAL_VERSION = "1.0";
- private static final String VERSION_STRING_VIOLATION_MSG =
- "Version string must be in the format of: {integer}.{integer}";
- private static final String INVALID_CREATION_METHOD_MSG = "Invalid creation method";
- @Override
- public String calculate(String baseVersion, VersionCreationMethod creationMethod) {
+ private static final Logger LOGGER = LoggerFactory.getLogger(VersionCalculatorImpl.class);
+ private static final String INITIAL_VERSION = "1.0";
+ private static final String VERSION_STRING_VIOLATION_MSG = "Version string must be in the format of: {integer}.{integer}";
+ private static final String INVALID_CREATION_METHOD_MSG = "Invalid creation method";
- if (baseVersion == null) {
- return INITIAL_VERSION;
- }
-
- String[] versionLevels = baseVersion.split("\\.");
- if (versionLevels.length != 2) {
- throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
- }
-
- int index;
- switch (creationMethod) {
- case major:
- index = Integer.parseInt(versionLevels[0]);
- index++;
- versionLevels[0] = Integer.toString(index);
- versionLevels[1] = "0";
- break;
- case minor:
- index = Integer.parseInt(versionLevels[1]);
- index++;
- versionLevels[1] = Integer.toString(index);
- break;
+ @Override
+ public String calculate(String baseVersion, VersionCreationMethod creationMethod) {
+ if (baseVersion == null) {
+ return INITIAL_VERSION;
+ }
+ String[] versionLevels = baseVersion.split("\\.");
+ if (versionLevels.length != 2) {
+ throw new IllegalArgumentException(VERSION_STRING_VIOLATION_MSG);
+ }
+ int index;
+ switch (creationMethod) {
+ case major:
+ index = Integer.parseInt(versionLevels[0]);
+ index++;
+ versionLevels[0] = Integer.toString(index);
+ versionLevels[1] = "0";
+ break;
+ case minor:
+ index = Integer.parseInt(versionLevels[1]);
+ index++;
+ versionLevels[1] = Integer.toString(index);
+ break;
+ }
+ return CommonMethods.arrayToSeparatedString(versionLevels, '.');
}
- return CommonMethods.arrayToSeparatedString(versionLevels, '.');
- }
- @Override
- public void injectAdditionalInfo(Version version, Set<String> existingVersions) {
- String optionalVersion;
- Set<VersionCreationMethod> optionalCreationMethods = new HashSet<>();
- if(version.getStatus().equals(VersionStatus.Certified)) {
- for (VersionCreationMethod versionCreationMethod : VersionCreationMethod.values()) {
- try {
- optionalVersion = calculate(version.getName(), versionCreationMethod);
- if (!existingVersions.contains(optionalVersion)) {
- optionalCreationMethods.add(versionCreationMethod);
- }
- } catch (IllegalArgumentException iae) {
- LOGGER.error("{}:{}", INVALID_CREATION_METHOD_MSG, versionCreationMethod.name(), iae);
+ @Override
+ public void injectAdditionalInfo(Version version, Set<String> existingVersions) {
+ String optionalVersion;
+ Set<VersionCreationMethod> optionalCreationMethods = new HashSet<>();
+ if (version.getStatus().equals(VersionStatus.Certified)) {
+ for (VersionCreationMethod versionCreationMethod : VersionCreationMethod.values()) {
+ try {
+ optionalVersion = calculate(version.getName(), versionCreationMethod);
+ if (!existingVersions.contains(optionalVersion)) {
+ optionalCreationMethods.add(versionCreationMethod);
+ }
+ } catch (IllegalArgumentException iae) {
+ LOGGER.error("{}:{}", INVALID_CREATION_METHOD_MSG, versionCreationMethod.name(), iae);
+ }
+ }
}
- }
+ version.getAdditionalInfo().put("OptionalCreationMethods", optionalCreationMethods);
}
- version.getAdditionalInfo().put("OptionalCreationMethods", optionalCreationMethods);
- }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java
index 83f3d77ae3..a8aad15677 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.versioning.impl;
import org.openecomp.sdc.versioning.ItemManagerFactory;
@@ -24,12 +23,9 @@ import org.openecomp.sdc.versioning.dao.VersionDaoFactory;
public class VersioningManagerFactoryImpl extends VersioningManagerFactory {
-
- @Override
- public VersioningManager createInterface() {
- return new VersioningManagerImpl(
- VersionDaoFactory.getInstance().createInterface(),
- VersionCalculatorFactory.getInstance().createInterface(),
- ItemManagerFactory.getInstance().createInterface());
- }
+ @Override
+ public VersioningManager createInterface() {
+ return new VersioningManagerImpl(VersionDaoFactory.getInstance().createInterface(), VersionCalculatorFactory.getInstance().createInterface(),
+ ItemManagerFactory.getInstance().createInterface());
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
index 95779c232c..6f1a7c4e13 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
@@ -13,9 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.versioning.impl;
+import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
+import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
@@ -30,163 +36,128 @@ import org.openecomp.sdc.versioning.dao.types.SynchronizationState;
import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.types.VersionCreationMethod;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Set;
-import java.util.stream.Collectors;
+public class VersioningManagerImpl implements VersioningManager {
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft;
+ private static final Logger LOGGER = LoggerFactory.getLogger(VersioningManagerImpl.class);
+ private VersionDao versionDao;
+ private VersionCalculator versionCalculator;
+ private ItemManager itemManager;
-public class VersioningManagerImpl implements VersioningManager {
- private static final Logger LOGGER = LoggerFactory.getLogger(VersioningManagerImpl.class);
-
- private VersionDao versionDao;
- private VersionCalculator versionCalculator;
- private ItemManager itemManager;
-
- public VersioningManagerImpl(VersionDao versionDao,
- VersionCalculator versionCalculator,
- ItemManager itemManager) {
- this.versionDao = versionDao;
- this.versionCalculator = versionCalculator;
- this.itemManager = itemManager;
- }
-
-
- @Override
- public List<Version> list(String itemId) {
-
- List<Version> versions = versionDao.list(itemId);
- Set<String> versionsNames = versions.stream().map(Version::getName).collect(Collectors.toSet());
- versions.forEach(version -> {
- version.setAdditionalInfo(new HashMap<>());
- versionCalculator.injectAdditionalInfo(version, versionsNames);
- });
- return versions;
- }
-
- @Override
- public Version get(String itemId, Version version) {
- return versionDao.get(itemId, version)
- .map(retrievedVersion -> getUpdateRetrievedVersion(itemId, retrievedVersion))
- .orElseGet(() -> getSyncedVersion(itemId, version));
- }
-
- private Version getUpdateRetrievedVersion(String itemId, Version version) {
- if (version.getStatus() == Certified &&
- (version.getState().getSynchronizationState() == SynchronizationState.OutOfSync ||
- version.getState().isDirty())) {
- forceSync(itemId, version);
- LOGGER.info("Item Id {}, version Id {}: Force sync is done", itemId, version.getId());
- version = versionDao.get(itemId, version)
- .orElseThrow(() -> new IllegalStateException(
- "Get version after a successful force sync must return the version"));
- }
- return version;
- }
-
- private Version getSyncedVersion(String itemId, Version version) {
- sync(itemId, version);
- LOGGER.info("Item Id {}, version Id {}: First time sync is done", itemId, version.getId());
- return versionDao.get(itemId, version)
- .orElseThrow(() -> new IllegalStateException(
- "Get version after a successful sync must return the version"));
- }
-
- @Override
- public Version create(String itemId, Version version, VersionCreationMethod creationMethod) {
- String baseVersionName = null;
- if (version.getBaseId() == null) {
- version.setDescription("Initial version");
- } else {
- baseVersionName = get(itemId, new Version(version.getBaseId())).getName();
- }
- String versionName = versionCalculator.calculate(baseVersionName, creationMethod);
- validateVersionName(itemId, versionName);
- version.setName(versionName);
-
- versionDao.create(itemId, version);
- itemManager.updateVersionStatus(itemId, Draft, null);
-
- publish(itemId, version, String.format("Create version: %s", version.getName()));
- return version;
- }
-
- private void validateVersionName(String itemId, String versionName) {
- if (versionDao.list(itemId).stream()
- .anyMatch(version -> versionName.equals(version.getName()))) {
- String errorDescription = String
- .format("Item %s: create version failed, a version with the name %s already exist",
- itemId, versionName);
-
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withMessage(errorDescription)
- .build());
- }
- }
-
- @Override
- public void submit(String itemId, Version version, String submitDescription) {
- version = get(itemId, version);
-
- validateSubmit(itemId, version);
-
- version.setStatus(Certified);
- versionDao.update(itemId, version);
-
- publish(itemId, version, submitDescription);
-
- itemManager.updateVersionStatus(itemId, Certified, Draft);
- }
-
- private void validateSubmit(String itemId, Version version) {
- if (version.getStatus() == Certified) {
- String errorDescription = String
- .format("Item %s: submit version failed, version %s is already Certified", itemId,
- version.getId());
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId("VERSION_ALREADY_CERTIFIED")
- .withMessage(errorDescription)
- .build());
- }
- }
-
- @Override
- public void publish(String itemId, Version version, String message) {
- versionDao.publish(itemId, version, message);
- }
-
-
- @Override
- public void sync(String itemId, Version version) {
- versionDao.sync(itemId, version);
- }
-
- @Override
- public void forceSync(String itemId, Version version) {
- versionDao.forceSync(itemId, version);
- }
-
- @Override
- public void revert(String itemId, Version version, String revisionId) {
- versionDao.revert(itemId, version, revisionId);
- }
-
- @Override
- public List<Revision> listRevisions(String itemId, Version version) {
- return versionDao.listRevisions(itemId, version);
- }
-
- @Override
- public void updateVersion(String itemId, Version version) {
- versionDao.update(itemId, version);
- }
-
- @Override
- public void clean(String itemId, Version version) {
- versionDao.clean(itemId, version);
- }
+ public VersioningManagerImpl(VersionDao versionDao, VersionCalculator versionCalculator, ItemManager itemManager) {
+ this.versionDao = versionDao;
+ this.versionCalculator = versionCalculator;
+ this.itemManager = itemManager;
+ }
+
+ @Override
+ public List<Version> list(String itemId) {
+ List<Version> versions = versionDao.list(itemId);
+ Set<String> versionsNames = versions.stream().map(Version::getName).collect(Collectors.toSet());
+ versions.forEach(version -> {
+ version.setAdditionalInfo(new HashMap<>());
+ versionCalculator.injectAdditionalInfo(version, versionsNames);
+ });
+ return versions;
+ }
+
+ @Override
+ public Version get(String itemId, Version version) {
+ return versionDao.get(itemId, version).map(retrievedVersion -> getUpdateRetrievedVersion(itemId, retrievedVersion))
+ .orElseGet(() -> getSyncedVersion(itemId, version));
+ }
+
+ private Version getUpdateRetrievedVersion(String itemId, Version version) {
+ if (version.getStatus() == Certified && (version.getState().getSynchronizationState() == SynchronizationState.OutOfSync || version.getState()
+ .isDirty())) {
+ forceSync(itemId, version);
+ LOGGER.info("Item Id {}, version Id {}: Force sync is done", itemId, version.getId());
+ version = versionDao.get(itemId, version)
+ .orElseThrow(() -> new IllegalStateException("Get version after a successful force sync must return the version"));
+ }
+ return version;
+ }
+ private Version getSyncedVersion(String itemId, Version version) {
+ sync(itemId, version);
+ LOGGER.info("Item Id {}, version Id {}: First time sync is done", itemId, version.getId());
+ return versionDao.get(itemId, version)
+ .orElseThrow(() -> new IllegalStateException("Get version after a successful sync must return the version"));
+ }
+
+ @Override
+ public Version create(String itemId, Version version, VersionCreationMethod creationMethod) {
+ String baseVersionName = null;
+ if (version.getBaseId() == null) {
+ version.setDescription("Initial version");
+ } else {
+ baseVersionName = get(itemId, new Version(version.getBaseId())).getName();
+ }
+ String versionName = versionCalculator.calculate(baseVersionName, creationMethod);
+ validateVersionName(itemId, versionName);
+ version.setName(versionName);
+ versionDao.create(itemId, version);
+ itemManager.updateVersionStatus(itemId, Draft, null);
+ publish(itemId, version, String.format("Create version: %s", version.getName()));
+ return version;
+ }
+
+ private void validateVersionName(String itemId, String versionName) {
+ if (versionDao.list(itemId).stream().anyMatch(version -> versionName.equals(version.getName()))) {
+ String errorDescription = String.format("Item %s: create version failed, a version with the name %s already exist", itemId, versionName);
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withMessage(errorDescription).build());
+ }
+ }
+
+ @Override
+ public void submit(String itemId, Version version, String submitDescription) {
+ version = get(itemId, version);
+ validateSubmit(itemId, version);
+ version.setStatus(Certified);
+ versionDao.update(itemId, version);
+ publish(itemId, version, submitDescription);
+ itemManager.updateVersionStatus(itemId, Certified, Draft);
+ }
+
+ private void validateSubmit(String itemId, Version version) {
+ if (version.getStatus() == Certified) {
+ String errorDescription = String.format("Item %s: submit version failed, version %s is already Certified", itemId, version.getId());
+ throw new CoreException(new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).withId("VERSION_ALREADY_CERTIFIED")
+ .withMessage(errorDescription).build());
+ }
+ }
+
+ @Override
+ public void publish(String itemId, Version version, String message) {
+ versionDao.publish(itemId, version, message);
+ }
+
+ @Override
+ public void sync(String itemId, Version version) {
+ versionDao.sync(itemId, version);
+ }
+
+ @Override
+ public void forceSync(String itemId, Version version) {
+ versionDao.forceSync(itemId, version);
+ }
+
+ @Override
+ public void revert(String itemId, Version version, String revisionId) {
+ versionDao.revert(itemId, version, revisionId);
+ }
+
+ @Override
+ public List<Revision> listRevisions(String itemId, Version version) {
+ return versionDao.listRevisions(itemId, version);
+ }
+
+ @Override
+ public void updateVersion(String itemId, Version version) {
+ versionDao.update(itemId, version);
+ }
+
+ @Override
+ public void clean(String itemId, Version version) {
+ versionDao.clean(itemId, version);
+ }
}