aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java
diff options
context:
space:
mode:
authorAviZi <avi.ziv@amdocs.com>2017-06-09 02:39:56 +0300
committerAviZi <avi.ziv@amdocs.com>2017-06-09 02:39:56 +0300
commit280f8015d06af1f41a3ef12e8300801c7a5e0d54 (patch)
tree9c1d3978c04cd28068f02073038c936bb49ca9e0 /openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java
parentfd3821dad11780d33c5373d74c957c442489945e (diff)
[SDC-29] Amdocs OnBoard 1707 initial commit.
Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370 Signed-off-by: AviZi <avi.ziv@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java')
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryCassandraDaoImpl.java3
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDaoImpl.java2
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionInfoDeletedDaoImpl.java1
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java34
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoFactoryImpl.java21
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java55
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerFactoryImpl.java7
-rw-r--r--openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java216
8 files changed, 261 insertions, 78 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryCassandraDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryCassandraDaoImpl.java
index a50a8b7beb..b364da0772 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryCassandraDaoImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionHistoryCassandraDaoImpl.java
@@ -36,7 +36,8 @@ import org.openecomp.sdc.versioning.dao.types.VersionableEntityId;
import java.util.Collection;
public class VersionHistoryCassandraDaoImpl extends CassandraBaseDao<VersionHistoryEntity>
- implements VersionHistoryDao {
+ implements
+ VersionHistoryDao {
private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
private static Mapper<VersionHistoryEntity> mapper =
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 a45c211f94..7bc73ce3d5 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
@@ -40,8 +40,6 @@ public class VersionInfoDaoImpl extends CassandraBaseDao<VersionInfoEntity>
noSqlDb.getMappingManager().mapper(VersionInfoEntity.class);
private static VersionInfoAccessor accessor =
noSqlDb.getMappingManager().createAccessor(VersionInfoAccessor.class);
- //private static UDTMapper<VersionableEntityId> versionedEntityIdMapper = noSqlDb
- //.getMappingManager().udtMapper(VersionableEntityId.class);
@Override
protected Mapper<VersionInfoEntity> getMapper() {
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 82e4edcd80..af6b20252e 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
@@ -20,6 +20,7 @@
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;
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 f02ea89e34..5673da7070 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoCassandraImpl.java
@@ -24,6 +24,8 @@ import com.datastax.driver.core.ColumnDefinitions;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.mapping.UDTMapper;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.core.nosqldb.api.NoSqlDb;
import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
import org.openecomp.core.util.UniqueValueUtil;
@@ -33,8 +35,6 @@ import org.openecomp.sdc.versioning.dao.types.Version;
import org.openecomp.sdc.versioning.types.UniqueValueMetadata;
import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
-import org.slf4j.LoggerFactory;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -45,8 +45,8 @@ import java.util.stream.Collectors;
class VersionableEntityDaoCassandraImpl implements VersionableEntityDao {
private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
- private static org.slf4j.Logger Logger =
- LoggerFactory.getLogger(VersionableEntityDaoCassandraImpl.class);
+ private static Logger Logger =
+ (Logger) LoggerFactory.getLogger(VersionableEntityDaoCassandraImpl.class);
private static UDTMapper<Version> versionMapper =
noSqlDb.getMappingManager().udtMapper(Version.class);
@@ -96,6 +96,22 @@ class VersionableEntityDaoCassandraImpl implements VersionableEntityDao {
}
}
+ @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, versionMapper.toUDT(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(),
@@ -107,16 +123,6 @@ class VersionableEntityDaoCassandraImpl implements VersionableEntityDao {
return noSqlDb.execute(selectCql, entityId, versionMapper.toUDT(version));
}
- @Override
- public void deleteVersion(VersionableEntityMetadata metadata, String entityId,
- Version versionToDelete) {
- deleteRowsUniqueValues(metadata, entityId, versionToDelete);
-
- String deleteCql = String.format("delete from %s where %s=? and %s=?", metadata.getName(),
- metadata.getIdentifierName(), metadata.getVersionIdentifierName());
- noSqlDb.execute(deleteCql, entityId, versionMapper.toUDT(versionToDelete));
- }
-
private void initRowUniqueValues(List<UniqueValueMetadata> metadata,
Map<String, Object> columnNameToValue) {
for (UniqueValueMetadata uniqueMetadata : metadata) {
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 8ec0814fc9..3ab6560c71 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
@@ -20,14 +20,31 @@
package org.openecomp.sdc.versioning.dao.impl;
+import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
import org.openecomp.sdc.versioning.dao.VersionableEntityDao;
import org.openecomp.sdc.versioning.dao.VersionableEntityDaoFactory;
+import org.openecomp.sdc.versioning.types.VersionableEntityStoreType;
public class VersionableEntityDaoFactoryImpl extends VersionableEntityDaoFactory {
- private static VersionableEntityDao INSTANCE = new VersionableEntityDaoCassandraImpl();
+ private static VersionableEntityDao CASSANDRA_INSTANCE = new VersionableEntityDaoCassandraImpl();
+ private static VersionableEntityDao ZUSAMMEN_INSTANCE =
+ new VersionableEntityDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface());
@Override
public VersionableEntityDao createInterface() {
- return INSTANCE;
+ 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");
+ }
}
}
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
new file mode 100644
index 0000000000..9e12d0dec9
--- /dev/null
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/VersionableEntityDaoZusammenImpl.java
@@ -0,0 +1,55 @@
+package org.openecomp.sdc.versioning.dao.impl;
+
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.item.ItemVersion;
+import com.amdocs.zusammen.datatypes.itemversion.Tag;
+import org.openecomp.core.zusammen.api.ZusammenAdaptor;
+import org.openecomp.core.zusammen.api.ZusammenUtil;
+import org.openecomp.sdc.versioning.dao.VersionableEntityDao;
+import org.openecomp.sdc.versioning.dao.types.Version;
+import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
+
+import java.util.Optional;
+
+public class VersionableEntityDaoZusammenImpl implements VersionableEntityDao {
+
+ private 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.
+ }
+
+ @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 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));
+ }
+
+ // TODO: 3/19/2017 move to a common util
+ private Id getItemVersionId(Id itemId, SessionContext context) {
+ Optional<ItemVersion> itemVersionOptional = zusammenAdaptor.getFirstVersion(context, itemId);
+ ItemVersion itemVersion = itemVersionOptional.orElseThrow(() ->
+ new RuntimeException(String.format("No version was found for item %s.", itemId)));
+ return itemVersion.getId();
+ }
+}
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 f7065cfda4..8ab5c608bf 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
@@ -22,9 +22,14 @@ package org.openecomp.sdc.versioning.impl;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.VersioningManagerFactory;
+import org.openecomp.sdc.versioning.dao.VersionInfoDaoFactory;
+import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDaoFactory;
public class VersioningManagerFactoryImpl extends VersioningManagerFactory {
- private static final VersioningManager INSTANCE = new VersioningManagerImpl();
+ private static final VersioningManager INSTANCE = new VersioningManagerImpl(
+ VersionInfoDaoFactory.getInstance().createInterface(),
+ VersionInfoDeletedDaoFactory.getInstance().createInterface()
+ );
@Override
public VersioningManager createInterface() {
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
index 6aa2a9f63c..0bbe3f81e7 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/VersioningManagerImpl.java
@@ -21,12 +21,16 @@
package org.openecomp.sdc.versioning.impl;
import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.datatypes.error.ErrorLevel;
+import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
+import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
+import org.openecomp.sdc.logging.types.LoggerConstants;
+import org.openecomp.sdc.logging.types.LoggerErrorCode;
+import org.openecomp.sdc.logging.types.LoggerErrorDescription;
+import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
import org.openecomp.sdc.versioning.VersioningManager;
import org.openecomp.sdc.versioning.dao.VersionInfoDao;
-import org.openecomp.sdc.versioning.dao.VersionInfoDaoFactory;
import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDao;
-import org.openecomp.sdc.versioning.dao.VersionInfoDeletedDaoFactory;
-import org.openecomp.sdc.versioning.dao.VersionableEntityDao;
import org.openecomp.sdc.versioning.dao.VersionableEntityDaoFactory;
import org.openecomp.sdc.versioning.dao.types.UserCandidateVersion;
import org.openecomp.sdc.versioning.dao.types.Version;
@@ -51,6 +55,7 @@ import org.openecomp.sdc.versioning.errors.UndoCheckoutOnUnlockedEntityErrorBuil
import org.openecomp.sdc.versioning.types.VersionInfo;
import org.openecomp.sdc.versioning.types.VersionableEntityAction;
import org.openecomp.sdc.versioning.types.VersionableEntityMetadata;
+import org.slf4j.MDC;
import java.util.Collection;
import java.util.HashMap;
@@ -63,15 +68,18 @@ import java.util.stream.Collectors;
public class VersioningManagerImpl implements VersioningManager {
private static final Version INITIAL_ACTIVE_VERSION = new Version(0, 0);
- private static VersionInfoDao versionInfoDao =
- VersionInfoDaoFactory.getInstance().createInterface();
- private static VersionInfoDeletedDao versionInfoDeletedDao =
- VersionInfoDeletedDaoFactory.getInstance().createInterface();
- private static VersionableEntityDao versionableEntityDao =
- VersionableEntityDaoFactory.getInstance().createInterface();
-
+ private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
private static Map<String, Set<VersionableEntityMetadata>> versionableEntities = new HashMap<>();
+ private VersionInfoDao versionInfoDao;
+ private VersionInfoDeletedDao versionInfoDeletedDao;
+
+ public VersioningManagerImpl(VersionInfoDao versionInfoDao,
+ VersionInfoDeletedDao versionInfoDeletedDao) {
+ this.versionInfoDao = versionInfoDao;
+ this.versionInfoDeletedDao = versionInfoDeletedDao;
+ }
+
private static VersionInfo getVersionInfo(VersionInfoEntity versionInfoEntity, String user,
VersionableEntityAction action) {
return getVersionInfo(versionInfoEntity.getEntityId(),
@@ -103,6 +111,10 @@ public class VersioningManagerImpl implements VersioningManager {
Version latestFinalVersion,
Set<Version> viewableVersions,
VersionableEntityAction action, String user) {
+
+
+ mdcDataDebugMessage.debugEntryMessage("entity Id", entityId);
+
Version activeVersion;
if (action == VersionableEntityAction.Write) {
@@ -110,11 +122,17 @@ public class VersioningManagerImpl implements VersioningManager {
if (user.equals(candidate.getUser())) {
activeVersion = candidate.getVersion();
} else {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.GET_VERSION_INFO, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't get entity version info");
throw new CoreException(
new EditOnEntityLockedByOtherErrorBuilder(entityType, entityId, candidate.getUser())
.build());
}
} else {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.GET_VERSION_INFO, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't get entity version info");
throw new CoreException(new EditOnUnlockedEntityErrorBuilder(entityType, entityId).build());
}
} else {
@@ -126,17 +144,23 @@ public class VersioningManagerImpl implements VersioningManager {
}
VersionInfo versionInfo = new VersionInfo();
+ versionInfo.setStatus(status);
+ activeVersion.setStatus(status);
+ if(latestFinalVersion!= null) latestFinalVersion.setStatus(status);
+ if(viewableVersions != null) viewableVersions.forEach(version->version.setStatus(status));
versionInfo.setActiveVersion(activeVersion);
versionInfo.setLatestFinalVersion(latestFinalVersion);
versionInfo.setViewableVersions(toSortedList(viewableVersions));
versionInfo.setFinalVersions(getFinalVersions(viewableVersions));
- versionInfo.setStatus(status);
if (candidate != null) {
+ candidate.getVersion().setStatus(status);
versionInfo.setLockingUser(candidate.getUser());
if (user.equals(candidate.getUser())) {
versionInfo.getViewableVersions().add(candidate.getVersion());
}
}
+
+ mdcDataDebugMessage.debugExitMessage("entity Id", entityId);
return versionInfo;
}
@@ -150,24 +174,24 @@ public class VersioningManagerImpl implements VersioningManager {
}
private static List<Version> getFinalVersions(Set<Version> versions) {
- return versions.stream().filter(version -> version.isFinal()).collect(Collectors.toList());
+ return versions.stream().filter(Version::isFinal).collect(Collectors.toList());
}
@Override
public void register(String entityType, VersionableEntityMetadata entityMetadata) {
- Set<VersionableEntityMetadata> entitiesMetadata = versionableEntities.get(entityType);
- if (entitiesMetadata == null) {
- entitiesMetadata = new HashSet<>();
- versionableEntities.put(entityType, entitiesMetadata);
- }
+ Set<VersionableEntityMetadata> entitiesMetadata =
+ versionableEntities.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));
+ VersionInfoEntity
+ versionInfoEntity = versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
if (versionInfoEntity != null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.CREATE_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't create versionable entity");
throw new CoreException(new EntityAlreadyExistErrorBuilder(entityType, entityId).build());
}
@@ -180,16 +204,63 @@ public class VersioningManagerImpl implements VersioningManager {
}
@Override
+ public void delete(String entityType, String entityId, String user) {
+ VersionInfoEntity versionInfoEntity =
+ versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
+ if (versionInfoEntity == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.DELETE_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't delete versionable entity");
+ throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
+ }
+
+ switch (versionInfoEntity.getStatus()) {
+ case Locked:
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.DELETE_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't delete versionable entity");
+ 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) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.UNDO_DELETE_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't undo delete for versionable entity");
+ 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));
+ MDC.put(LoggerConstants.TARGET_SERVICE_NAME, LoggerTragetServiceName.CHECKOUT_ENTITY);
if (versionInfoEntity == null) {
+ MDC.put(LoggerConstants.ERROR_CATEGORY, ErrorLevel.ERROR.name());
+ MDC.put(LoggerConstants.TARGET_ENTITY, LoggerConstants.TARGET_ENTITY_DB);
+ MDC.put(LoggerConstants.ERROR_DESCRIPTION, LoggerErrorDescription.CHECKOUT_ENTITY);
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
Version checkoutVersion = null;
switch (versionInfoEntity.getStatus()) {
case Locked:
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.CHECKOUT_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't checkout versionable entity");
throw new CoreException(new CheckoutOnLockedEntityErrorBuilder(entityType, entityId,
versionInfoEntity.getCandidate().getUser()).build());
case Final:
@@ -197,7 +268,10 @@ public class VersioningManagerImpl implements VersioningManager {
checkoutVersion = doCheckout(versionInfoEntity, user);
break;
default:
+ //do nothing
+ break;
}
+
return checkoutVersion;
}
@@ -206,6 +280,9 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfoEntity versionInfoEntity =
versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
if (versionInfoEntity == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.UNDO_CHECKOUT_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't undo checkout for versionable entity");
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
@@ -213,6 +290,10 @@ public class VersioningManagerImpl implements VersioningManager {
switch (versionInfoEntity.getStatus()) {
case Locked:
if (!user.equals(versionInfoEntity.getCandidate().getUser())) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.UNDO_CHECKOUT_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.PERMISSION_ERROR.getErrorCode(),
+ "Can't undo checkout for versionable entity");
throw new CoreException(
new UndoCheckoutOnEntityLockedByOtherErrorBuilder(entityType, entityId,
versionInfoEntity.getCandidate().getUser()).build());
@@ -221,16 +302,23 @@ public class VersioningManagerImpl implements VersioningManager {
break;
case Final:
case Available:
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.UNDO_CHECKOUT_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.PERMISSION_ERROR.getErrorCode(),
+ "Can't undo checkout for versionable entity");
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.getCandidate().getVersion(), versionInfoEntity.getActiveVersion());
versionInfoEntity.setStatus(versionInfoEntity.getActiveVersion().isFinal() ? VersionStatus.Final
: VersionStatus.Available);
@@ -245,6 +333,9 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfoEntity versionInfoEntity =
versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
if (versionInfoEntity == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.CHECKIN_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't checkin versionable entity");
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
@@ -252,17 +343,26 @@ public class VersioningManagerImpl implements VersioningManager {
switch (versionInfoEntity.getStatus()) {
case Available:
case Final:
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.CHECKIN_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't checkin versionable entity");
throw new CoreException(
new CheckinOnUnlockedEntityErrorBuilder(entityType, entityId).build());
case Locked:
if (!user.equals(versionInfoEntity.getCandidate().getUser())) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.CHECKIN_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't checkin versionable entity");
throw new CoreException(new CheckinOnEntityLockedByOtherErrorBuilder(entityType, entityId,
versionInfoEntity.getCandidate().getUser()).build());
}
checkedInVersion = doCheckin(versionInfoEntity, checkinDescription);
break;
default:
+ //do nothing
+ break;
}
+
return checkedInVersion;
}
@@ -271,22 +371,34 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfoEntity versionInfoEntity =
versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
if (versionInfoEntity == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't submit versionable entity");
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
Version submitVersion = null;
switch (versionInfoEntity.getStatus()) {
case Final:
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't submit versionable entity");
throw new CoreException(
new EntityAlreadyFinalizedErrorBuilder(entityType, entityId).build());
case Locked:
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't submit versionable entity");
throw new CoreException(new SubmitLockedEntityNotAllowedErrorBuilder(entityType, entityId,
versionInfoEntity.getCandidate().getUser()).build());
case Available:
submitVersion = doSubmit(versionInfoEntity, user, submitDescription);
break;
default:
+ //do nothing
+ break;
}
+
return submitVersion;
}
@@ -296,6 +408,9 @@ public class VersioningManagerImpl implements VersioningManager {
VersionInfoEntity versionInfoEntity =
versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
if (versionInfoEntity == null) {
+ MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
+ LoggerTragetServiceName.GET_VERSION_INFO, ErrorLevel.ERROR.name(),
+ LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't get entity version info");
throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
}
return getVersionInfo(versionInfoEntity, user, action);
@@ -329,35 +444,6 @@ public class VersioningManagerImpl implements VersioningManager {
return activeVersions;
}
- @Override
- public void delete(String entityType, String entityId, String user) {
- VersionInfoEntity versionInfoEntity =
- versionInfoDao.get(new VersionInfoEntity(entityType, entityId));
- if (versionInfoEntity == null) {
- throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
- }
-
- switch (versionInfoEntity.getStatus()) {
- case Locked:
- throw new CoreException(new DeleteOnLockedEntityErrorBuilder(entityType, entityId,
- versionInfoEntity.getCandidate().getUser()).build());
- default:
- }
-
- doDelete(versionInfoEntity, user);
- }
-
- @Override
- public void undoDelete(String entityType, String entityId, String user) {
- VersionInfoDeletedEntity versionInfoDeletedEntity =
- versionInfoDeletedDao.get(new VersionInfoDeletedEntity(entityType, entityId));
- if (versionInfoDeletedEntity == null) {
- throw new CoreException(new EntityNotExistErrorBuilder(entityType, entityId).build());
- }
-
- doUndoDelete(versionInfoDeletedEntity, user);
- }
-
private void markAsCheckedOut(VersionInfoEntity versionInfoEntity, String checkingOutUser) {
versionInfoEntity.setStatus(VersionStatus.Locked);
versionInfoEntity.setCandidate(new UserCandidateVersion(checkingOutUser,
@@ -374,8 +460,7 @@ public class VersioningManagerImpl implements VersioningManager {
return versionInfoEntity.getCandidate().getVersion();
}
- private void doDelete(VersionInfoEntity versionInfoEntity, String user) {
-
+ private void doDelete(VersionInfoEntity versionInfoEntity) {
VersionInfoDeletedEntity versionInfoDeletedEntity = new VersionInfoDeletedEntity();
versionInfoDeletedEntity.setStatus(versionInfoEntity.getStatus());
versionInfoDeletedEntity.setViewableVersions(versionInfoEntity.getViewableVersions());
@@ -386,11 +471,9 @@ public class VersioningManagerImpl implements VersioningManager {
versionInfoDeletedEntity.setLatestFinalVersion(versionInfoEntity.getLatestFinalVersion());
versionInfoDeletedDao.create(versionInfoDeletedEntity);
versionInfoDao.delete(versionInfoEntity);
-
}
- private void doUndoDelete(VersionInfoDeletedEntity versionInfoDeletedEntity, String user) {
-
+ private void doUndoDelete(VersionInfoDeletedEntity versionInfoDeletedEntity) {
VersionInfoEntity versionInfoEntity = new VersionInfoEntity();
versionInfoEntity.setStatus(versionInfoDeletedEntity.getStatus());
versionInfoEntity.setViewableVersions(versionInfoDeletedEntity.getViewableVersions());
@@ -401,7 +484,6 @@ public class VersioningManagerImpl implements VersioningManager {
versionInfoEntity.setLatestFinalVersion(versionInfoDeletedEntity.getLatestFinalVersion());
versionInfoDao.create(versionInfoEntity);
versionInfoDeletedDao.delete(versionInfoDeletedEntity);
-
}
private Version doCheckin(VersionInfoEntity versionInfoEntity, String checkinDescription) {
@@ -412,6 +494,9 @@ public class VersioningManagerImpl implements VersioningManager {
versionInfoEntity.setStatus(VersionStatus.Available);
versionInfoDao.update(versionInfoEntity);
+ closeVersionOnEntity(versionInfoEntity.getEntityType(), versionInfoEntity.getEntityId(),
+ versionInfoEntity.getActiveVersion());
+
return versionInfoEntity.getActiveVersion();
}
@@ -420,6 +505,8 @@ public class VersioningManagerImpl implements VersioningManager {
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()) {
@@ -444,6 +531,7 @@ public class VersioningManagerImpl implements VersioningManager {
versionHistory.setUser(user);
versionHistory.setDescription(description);
versionHistory.setType(type);
+ //versionHistoryDao.create(versionHistory);
}
private void initVersionOnEntity(String entityType, String entityId, Version baseVersion,
@@ -451,17 +539,29 @@ public class VersioningManagerImpl implements VersioningManager {
Set<VersionableEntityMetadata> entityMetadatas = versionableEntities.get(entityType);
if (entityMetadatas != null) {
for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
- versionableEntityDao.initVersion(entityMetadata, entityId, baseVersion, newVersion);
+ VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
+ .initVersion(entityMetadata, entityId, baseVersion, newVersion);
}
}
}
private void deleteVersionFromEntity(String entityType, String entityId,
- Version versionToDelete) {
+ Version versionToDelete, Version backToVersion) {
+ Set<VersionableEntityMetadata> entityMetadatas = versionableEntities.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 = versionableEntities.get(entityType);
if (entityMetadatas != null) {
for (VersionableEntityMetadata entityMetadata : entityMetadatas) {
- versionableEntityDao.deleteVersion(entityMetadata, entityId, versionToDelete);
+ VersionableEntityDaoFactory.getInstance().createInterface(entityMetadata.getStoreType())
+ .closeVersion(entityMetadata, entityId, versionToClose);
}
}
}