From 280f8015d06af1f41a3ef12e8300801c7a5e0d54 Mon Sep 17 00:00:00 2001 From: AviZi Date: Fri, 9 Jun 2017 02:39:56 +0300 Subject: [SDC-29] Amdocs OnBoard 1707 initial commit. Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370 Signed-off-by: AviZi --- .../openecomp-sdc-action-core/pom.xml | 18 +- .../pom.xml.versionsBackup | 30 ++ .../dao/impl/ActionArtifactDaoFactoryImpl.java | 3 +- .../sdc/action/dao/impl/ActionArtifactDaoImpl.java | 14 +- .../sdc/action/dao/impl/ActionDaoFactoryImpl.java | 3 +- .../sdc/action/dao/impl/ActionDaoImpl.java | 403 ++++++++++----------- 6 files changed, 246 insertions(+), 225 deletions(-) create mode 100644 openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/pom.xml.versionsBackup (limited to 'openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core') diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/pom.xml b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/pom.xml index 465e36a5e2..40092e9131 100644 --- a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/pom.xml @@ -1,9 +1,11 @@ - 4.0.0 + org.openecomp.sdc + openecomp-sdc-action-core org.openecomp.sdc @@ -11,11 +13,6 @@ 1.1.0-SNAPSHOT - - openecomp-sdc-action-core - - - org.openecomp.sdc @@ -27,11 +24,6 @@ openecomp-sdc-versioning-api ${project.version} - - org.openecomp.sdc.sdc_common - openecomp-logging-api - ${project.version} - - \ No newline at end of file + diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/pom.xml.versionsBackup new file mode 100644 index 0000000000..274bdb04c7 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/pom.xml.versionsBackup @@ -0,0 +1,30 @@ + + + 4.0.0 + + org.openecomp.sdc + openecomp-sdc-action-core + 1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-sdc-action-lib + 1.0-SNAPSHOT + + + + + org.openecomp.sdc + openecomp-sdc-action-api + 1.0-SNAPSHOT + + + org.openecomp.sdc + openecomp-sdc-versioning-api + 1.0-SNAPSHOT + + + + \ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoFactoryImpl.java index 2767c9eeca..51f3cac607 100644 --- a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoFactoryImpl.java @@ -23,8 +23,9 @@ package org.openecomp.sdc.action.dao.impl; import org.openecomp.sdc.action.dao.ActionArtifactDao; import org.openecomp.sdc.action.dao.ActionArtifactDaoFactory; + public class ActionArtifactDaoFactoryImpl extends ActionArtifactDaoFactory { - private static final ActionArtifactDao INSTANCE = new ActionArtifactDaoImpl(); + private static ActionArtifactDao INSTANCE = new ActionArtifactDaoImpl(); @Override public ActionArtifactDao createInterface() { diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoImpl.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoImpl.java index 3e884c24e3..bfa5830b8d 100644 --- a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionArtifactDaoImpl.java @@ -25,7 +25,6 @@ import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE; import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_QUERY_FAILURE_CODE; import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_QUERY_FAILURE_MSG; -import static org.openecomp.sdc.action.util.ActionUtil.actionLogPostProcessor; import com.datastax.driver.core.exceptions.NoHostAvailableException; import com.datastax.driver.mapping.Mapper; @@ -33,8 +32,8 @@ import com.datastax.driver.mapping.Result; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; import org.openecomp.core.dao.impl.CassandraBaseDao; -import org.openecomp.core.logging.api.Logger; -import org.openecomp.core.logging.api.LoggerFactory; +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.sdc.action.dao.ActionArtifactDao; @@ -49,12 +48,13 @@ import org.openecomp.sdc.action.util.ActionUtil; import java.util.Collection; import java.util.List; + public class ActionArtifactDaoImpl extends CassandraBaseDao implements ActionArtifactDao { - private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static final Mapper mapper = + private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static Mapper mapper = noSqlDb.getMappingManager().mapper(ActionArtifactEntity.class); - private static final ActionArtifactAccessor accessor = + private static ActionArtifactAccessor accessor = noSqlDb.getMappingManager().createAccessor(ActionArtifactAccessor.class); private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); @@ -97,7 +97,7 @@ public class ActionArtifactDaoImpl extends CassandraBaseDao result; + Result result = null; result = accessor.getArtifactByUuId(effectiveVersion, artifactUuId); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); log.metrics(""); diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoFactoryImpl.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoFactoryImpl.java index 66bd20687d..7ecda7844d 100644 --- a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoFactoryImpl.java +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoFactoryImpl.java @@ -23,8 +23,9 @@ package org.openecomp.sdc.action.dao.impl; import org.openecomp.sdc.action.dao.ActionDao; import org.openecomp.sdc.action.dao.ActionDaoFactory; + public class ActionDaoFactoryImpl extends ActionDaoFactory { - private static final ActionDao INSTANCE = new ActionDaoImpl(); + private static ActionDao INSTANCE = new ActionDaoImpl(); @Override public ActionDao createInterface() { diff --git a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoImpl.java b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoImpl.java index 29b5171470..b7f4b5c926 100644 --- a/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoImpl.java +++ b/openecomp-be/lib/openecomp-sdc-action-lib/openecomp-sdc-action-core/src/main/java/org/openecomp/sdc/action/dao/impl/ActionDaoImpl.java @@ -24,7 +24,25 @@ import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; import static com.datastax.driver.core.querybuilder.QueryBuilder.in; import static com.datastax.driver.core.querybuilder.QueryBuilder.set; import static org.openecomp.core.nosqldb.impl.cassandra.CassandraSessionFactory.getSession; -import static org.openecomp.sdc.action.util.ActionUtil.actionLogPostProcessor; +import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_CATEGORY; +import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_OPEN_ECOMP_COMPONENT; +import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_MODEL; +import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_NAME; +import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_NONE; +import static org.openecomp.sdc.action.ActionConstants.FILTER_TYPE_VENDOR; +import static org.openecomp.sdc.action.ActionConstants.STATUS; +import static org.openecomp.sdc.action.ActionConstants.TARGET_ENTITY; +import static org.openecomp.sdc.action.ActionConstants.TARGET_ENTITY_DB; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_NOT_EXIST; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_NOT_LOCKED_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_NOT_LOCKED_MSG; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_QUERY_FAILURE_CODE; +import static org.openecomp.sdc.action.errors.ActionErrorConstants.ACTION_QUERY_FAILURE_MSG; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; @@ -38,23 +56,22 @@ import com.datastax.driver.mapping.UDTMapper; import com.datastax.driver.mapping.annotations.Accessor; import com.datastax.driver.mapping.annotations.Query; import org.openecomp.core.dao.impl.CassandraBaseDao; -import org.openecomp.core.logging.api.Logger; -import org.openecomp.core.logging.api.LoggerFactory; +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.utilities.json.JsonUtil; import org.openecomp.sdc.action.ActionConstants; import org.openecomp.sdc.action.dao.ActionDao; import org.openecomp.sdc.action.dao.types.ActionEntity; -import org.openecomp.sdc.action.dao.types.EcompComponentEntity; -import org.openecomp.sdc.action.errors.ActionErrorConstants; +import org.openecomp.sdc.action.dao.types.OpenEcompComponentEntity; import org.openecomp.sdc.action.errors.ActionException; import org.openecomp.sdc.action.logging.CategoryLogLevel; import org.openecomp.sdc.action.logging.StatusCode; import org.openecomp.sdc.action.types.Action; import org.openecomp.sdc.action.types.ActionStatus; import org.openecomp.sdc.action.types.ActionSubOperation; -import org.openecomp.sdc.action.types.EcompComponent; +import org.openecomp.sdc.action.types.OpenEcompComponent; import org.openecomp.sdc.action.util.ActionUtil; import org.openecomp.sdc.versioning.VersioningManagerFactory; import org.openecomp.sdc.versioning.dao.VersionInfoDao; @@ -76,22 +93,22 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; + public class ActionDaoImpl extends CassandraBaseDao implements ActionDao { - private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); - private static final Mapper mapper = + private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static Mapper mapper = noSqlDb.getMappingManager().mapper(ActionEntity.class); - private static final ActionAccessor accessor = + private static ActionAccessor accessor = noSqlDb.getMappingManager().createAccessor(ActionAccessor.class); - private static final UDTMapper versionMapper = + private static UDTMapper versionMapper = noSqlDb.getMappingManager().udtMapper(Version.class); - private static final VersionInfoDao versionInfoDao = + private static VersionInfoDao versionInfoDao = VersionInfoDaoFactory.getInstance().createInterface(); - private static final VersionInfoDeletedDao versionInfoDeletedDao = + private static VersionInfoDeletedDao versionInfoDeletedDao = VersionInfoDeletedDaoFactory.getInstance().createInterface(); private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName()); - @Override public void registerVersioning(String versionableEntityType) { VersioningManagerFactory.getInstance().createInterface() @@ -102,62 +119,58 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act } @Override - public Action createAction(Action actionDto) { + public Action createAction(Action action) { try { - ActionUtil.actionLogPreProcessor( - ActionSubOperation.CREATE_ACTION_ENTITY, ActionConstants.TARGET_ENTITY_DB); - this.create(actionDto.toEntity()); + ActionUtil.actionLogPreProcessor(ActionSubOperation.CREATE_ACTION_ENTITY, TARGET_ENTITY_DB); + this.create(action.toEntity()); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); log.metrics(""); - return actionDto; - } catch (NoHostAvailableException noHostAvailableException) { - logGenericException(noHostAvailableException); - throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, - ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + return action; + } catch (NoHostAvailableException exception) { + logGenericException(exception); + throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); } } @Override - public Action updateAction(Action actionDto) { + public Action updateAction(Action action) { try { - log.debug(" entering updateAction with actionUUID= " + actionDto.getActionUuId()); - ActionUtil - .actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION, - ActionConstants.TARGET_ENTITY_DB); - this.update(actionDto.toEntity()); + log.debug(" entering updateAction with actionUUID= " + action.getActionUuId()); + ActionUtil.actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION, TARGET_ENTITY_DB); + this.update(action.toEntity()); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); log.metrics(""); - log.debug(" exit updateAction with actionUUID= " + actionDto.getActionUuId()); - return actionDto; - } catch (NoHostAvailableException noHostAvailableException) { - logGenericException(noHostAvailableException); - throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, - ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + log.debug(" exit updateAction with actionUUID= " + action.getActionUuId()); + return action; + } catch (NoHostAvailableException exception) { + logGenericException(exception); + throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); } } @Override public void deleteAction(String actionInvariantUuId) { try { - log.debug("entering deleteAction with actionInvariantUUID = " + actionInvariantUuId); - ActionUtil - .actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, - ActionConstants.TARGET_ENTITY_DB); + log.debug("entering deleteAction with actionInvariantUuId = " + actionInvariantUuId); + ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_DB); VersionInfoDeletedEntity activeVersionEntity = versionInfoDeletedDao.get( new VersionInfoDeletedEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, actionInvariantUuId)); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); log.metrics(""); + Version activeVersion = activeVersionEntity.getActiveVersion(); Statement getNameFromInvUuId = QueryBuilder.select().column("name").from("dox", "Action") .where(eq("actioninvariantuuid", actionInvariantUuId)) .and(in("version", versionMapper.toUDT(activeVersion))); ActionUtil - .actionLogPreProcessor(ActionSubOperation.GET_NAME_BY_ACTIONINVID, - ActionConstants.TARGET_ENTITY_DB); + .actionLogPreProcessor(ActionSubOperation.GET_NAME_BY_ACTIONINVID, TARGET_ENTITY_DB); ResultSet results = getSession().execute(getNameFromInvUuId); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); log.metrics(""); + if (!results.isExhausted()) { String name = results.one().getString("name"); List versions = getVersionsByName(name); @@ -165,96 +178,12 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act } } catch (NoHostAvailableException noHostAvailableException) { logGenericException(noHostAvailableException); - throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, - ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); } log.debug("exit deleteAction"); } - - @Override - public List getActionsByActionInvariantUuId(String actionInvariantUuId) { - List actions = new ArrayList<>(); - try { - log.debug(" entering getActionsByActionInvariantUUID with actionInvariantUUID= " - + actionInvariantUuId); - Set viewableVersions = new HashSet<>(); - VersionPredicate filter = new VersionPredicate(); - ActionUtil - .actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, - ActionConstants.TARGET_ENTITY_DB); - VersionInfoEntity versionInfoEntity = versionInfoDao - .get(new VersionInfoEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, actionInvariantUuId)); - if (versionInfoEntity == null) { - //Check for action in the Delete version info table - VersionInfoDeletedEntity versionInfoDeletedEntity = versionInfoDeletedDao.get( - new VersionInfoDeletedEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, - actionInvariantUuId)); - if (versionInfoDeletedEntity != null) { - viewableVersions = versionInfoDeletedEntity.getViewableVersions(); - //Remove intermediate minor versions from viewable versions - if (versionInfoDeletedEntity.getActiveVersion() != null) { - filter.activeVersion = versionInfoDeletedEntity.getActiveVersion(); - filter.finalVersion = versionInfoDeletedEntity.getLatestFinalVersion(); - viewableVersions.removeIf(filter::isIntermediateMinorVersion); - } - } - } else { - viewableVersions = versionInfoEntity.getViewableVersions(); - //Remove intermediate minor versions from viewable versions - if (versionInfoEntity.getActiveVersion() != null) { - filter.activeVersion = versionInfoEntity.getActiveVersion(); - filter.finalVersion = versionInfoEntity.getLatestFinalVersion(); - viewableVersions.removeIf(filter::isIntermediateMinorVersion); - } - //Add candidate version if available - if (versionInfoEntity.getCandidate() != null) { - viewableVersions.add(versionInfoEntity.getCandidate().getVersion()); - } - } - MDC.put(ActionConstants.TARGET_ENTITY, ActionConstants.TARGET_ENTITY_DB); - ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); - log.metrics(""); - - log.debug( - "Found " + viewableVersions + " viewable version for action with actionInvariantUUID " - + actionInvariantUuId); - - //Fetch action data for the viewable versions - if (!viewableVersions.isEmpty()) { - ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONINVID, - ActionConstants.TARGET_ENTITY_DB); - Result result = - accessor.getActionsByInvId(actionInvariantUuId, viewableVersions); - ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); - log.metrics(""); - if (result != null) { - actions - .addAll(result.all().stream().map(ActionEntity::toDto).collect(Collectors.toList())); - } - } - } catch (NoHostAvailableException noHostAvailableException) { - logGenericException(noHostAvailableException); - throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, - ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); - } - log.debug( - " exit getActionsByActionInvariantUUID with actionInvariantUUID= " + actionInvariantUuId); - return actions; - } - - private void logGenericException(Exception exception) { - ActionUtil - .actionLogPostProcessor(StatusCode.ERROR, ActionErrorConstants.ACTION_QUERY_FAILURE_CODE, - ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG, false); - log.metrics(""); - ActionUtil.actionErrorLogProcessor( - CategoryLogLevel.FATAL, ActionErrorConstants.ACTION_QUERY_FAILURE_CODE, - ActionErrorConstants.ACTION_QUERY_FAILURE_MSG); - log.error(exception.getMessage()); - } - - @Override public List getFilteredActions(String filterType, String filterId) { List actions = new ArrayList<>(); @@ -263,48 +192,45 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act " entering getFilteredActions By filterType = " + filterType + " With value = " + filterId); try { switch (filterType) { - case ActionConstants.FILTER_TYPE_VENDOR: + case FILTER_TYPE_VENDOR: ActionUtil .actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_VENDOR, - ActionConstants.TARGET_ENTITY_DB); + TARGET_ENTITY_DB); result = accessor.getActionsByVendor(filterId); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); log.metrics(""); break; - case ActionConstants.FILTER_TYPE_CATEGORY: + case FILTER_TYPE_CATEGORY: ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_CATEGORY, - ActionConstants.TARGET_ENTITY_DB); + TARGET_ENTITY_DB); result = accessor.getActionsByCategory(filterId); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); log.metrics(""); break; - case ActionConstants.FILTER_TYPE_MODEL: + case FILTER_TYPE_MODEL: ActionUtil .actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_MODEL, - ActionConstants.TARGET_ENTITY_DB); + TARGET_ENTITY_DB); result = accessor.getActionsByModel(filterId); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); log.metrics(""); break; - case ActionConstants.FILTER_TYPE_ECOMP_COMPONENT: + case FILTER_TYPE_OPEN_ECOMP_COMPONENT: ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_COMPONENT, - ActionConstants.TARGET_ENTITY_DB); - result = accessor.getActionsByEcompComponent(filterId); + TARGET_ENTITY_DB); + result = accessor.getActionsByOpenEcompComponent(filterId); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); log.metrics(""); break; - case ActionConstants.FILTER_TYPE_NONE: - ActionUtil - .actionLogPreProcessor(ActionSubOperation.GET_ALL_ACTIONS, - ActionConstants.TARGET_ENTITY_DB); + case FILTER_TYPE_NONE: + ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ALL_ACTIONS, TARGET_ENTITY_DB); result = accessor.getAllActions(); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); log.metrics(""); break; - case ActionConstants.FILTER_TYPE_NAME: + case FILTER_TYPE_NAME: ActionUtil - .actionLogPreProcessor(ActionSubOperation.GET_ACTIONINVID_BY_NAME, - ActionConstants.TARGET_ENTITY_DB); + .actionLogPreProcessor(ActionSubOperation.GET_ACTIONINVID_BY_NAME, TARGET_ENTITY_DB); result = accessor.getInvIdByName(filterId); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE); log.metrics(""); @@ -328,69 +254,135 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act " exit getFilteredActions By filterType = " + filterType + " With value = " + filterId); } catch (NoHostAvailableException noHostAvailableException) { logGenericException(noHostAvailableException); - throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, - ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); } return actions; } @Override - public List getEcompComponents() { - List ecompComponents = new ArrayList<>(); - Result result; + public Action getActionsByActionUuId(String actionUuId) { try { - log.debug(" entering getECOMPComponents "); - ActionUtil - .actionLogPreProcessor(ActionSubOperation.GET_ECOMP_COMPONENTS_ENTITY, - ActionConstants.TARGET_ENTITY_DB); - result = accessor.getEcompComponents(); + log.debug(" entering getActionsByActionUuId with actionUUID= " + actionUuId); + ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONUUID, + TARGET_ENTITY_DB); + Result result = accessor.actionInvariantUuId(actionUuId); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); log.metrics(""); if (result != null) { - ecompComponents.addAll( - result.all().stream().map(EcompComponentEntity::toDto).collect(Collectors.toList())); + log.debug(" exit getActionsByActionUuId with actionUUID= " + actionUuId); + ActionEntity entity = result.one(); + if (entity != null) { + return entity.toDto(); + } } + log.debug(" exit getActionsByActionUuId with actionUUID= " + actionUuId); + return null; } catch (NoHostAvailableException noHostAvailableException) { logGenericException(noHostAvailableException); - throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, - ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); } - log.debug(" exit getECOMPComponents "); - return ecompComponents; } @Override - public Action getActionsByActionUuId(String uniqueId) { + public List getOpenEcompComponents() { + List openEcompComponents = new ArrayList<>(); + Result result; try { - log.debug(" entering getActionsByActionUUID with actionUUID= " + uniqueId); + log.debug(" entering getOpenEcompComponents "); ActionUtil - .actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONUUID, - ActionConstants.TARGET_ENTITY_DB); - Result result = accessor.actionInvariantUuId(uniqueId); + .actionLogPreProcessor(ActionSubOperation.GET_OPEN_ECOMP_COMPONENTS_ENTITY, TARGET_ENTITY_DB); + result = accessor.getOpenEcompComponents(); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); log.metrics(""); if (result != null) { - log.debug(" exit getActionsByActionUUID with actionUUID= " + uniqueId); - ActionEntity entity = result.one(); - if (entity != null) { - return entity.toDto(); + openEcompComponents.addAll( + result.all().stream().map(OpenEcompComponentEntity::toDto).collect(Collectors.toList())); + } + } catch (NoHostAvailableException noHostAvailableException) { + logGenericException(noHostAvailableException); + throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + } + log.debug(" exit getOpenEcompComponents "); + return openEcompComponents; + } + + @Override + public List getActionsByActionInvariantUuId(String actionInvariantUuId) { + List actions = new ArrayList(); + try { + log.debug(" entering getActionsByActionInvariantUuId with actionInvariantUuId= " + + actionInvariantUuId); + Set viewableVersions = new HashSet<>(); + VersionPredicate filter = new VersionPredicate(); + ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_DB); + VersionInfoEntity versionInfoEntity = versionInfoDao + .get(new VersionInfoEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, actionInvariantUuId)); + if (versionInfoEntity == null) { + //Check for action in the Delete version info table + VersionInfoDeletedEntity versionInfoDeletedEntity = versionInfoDeletedDao.get( + new VersionInfoDeletedEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, + actionInvariantUuId)); + if (versionInfoDeletedEntity != null) { + viewableVersions = versionInfoDeletedEntity.getViewableVersions(); + //Remove intermediate minor versions from viewable versions + if (versionInfoDeletedEntity.getActiveVersion() != null) { + filter.activeVersion = versionInfoDeletedEntity.getActiveVersion(); + filter.finalVersion = versionInfoDeletedEntity.getLatestFinalVersion(); + viewableVersions.removeIf(filter::isIntermediateMinorVersion); + } + } + } else { + viewableVersions = versionInfoEntity.getViewableVersions(); + //Remove intermediate minor versions from viewable versions + if (versionInfoEntity.getActiveVersion() != null) { + filter.activeVersion = versionInfoEntity.getActiveVersion(); + filter.finalVersion = versionInfoEntity.getLatestFinalVersion(); + viewableVersions.removeIf(filter::isIntermediateMinorVersion); + } + //Add candidate version if available + if (versionInfoEntity.getCandidate() != null) { + viewableVersions.add(versionInfoEntity.getCandidate().getVersion()); + } + } + + MDC.put(TARGET_ENTITY, TARGET_ENTITY_DB); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + + log.debug( + "Found " + viewableVersions + " viewable version for action with actionInvariantUuId " + + actionInvariantUuId); + + //Fetch action data for the viewable versions + if (!viewableVersions.isEmpty()) { + ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONINVID, + TARGET_ENTITY_DB); + Result result = + accessor.getActionsByInvId(actionInvariantUuId, viewableVersions); + ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); + log.metrics(""); + if (result != null) { + actions + .addAll(result.all().stream().map(ActionEntity::toDto).collect(Collectors.toList())); } } - log.debug(" exit getActionsByActionUUID with actionUUID= " + uniqueId); - return null; } catch (NoHostAvailableException noHostAvailableException) { logGenericException(noHostAvailableException); - throw new ActionException(ActionErrorConstants.ACTION_INTERNAL_SERVER_ERR_CODE, - ActionErrorConstants.ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); + throw new ActionException(ACTION_INTERNAL_SERVER_ERR_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG); } + log.debug( + " exit getActionsByActionInvariantUuId with actionInvariantUuId= " + actionInvariantUuId); + return actions; } @Override public Action getLockedAction(String actionInvariantUuId, String user) throws ActionException { - log.debug(" entering getLockedAction with actionInvariantUUID= " + actionInvariantUuId); - ActionUtil - .actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, - ActionConstants.TARGET_ENTITY_DB); + log.debug(" entering getLockedAction with actionInvariantUuId= " + actionInvariantUuId); + ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_DB); Action action = null; VersionInfoEntity versionInfoEntity = versionInfoDao .get(new VersionInfoEntity(ActionConstants.ACTION_VERSIONABLE_TYPE, actionInvariantUuId)); @@ -403,7 +395,7 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act Set versions = new HashSet<>(); versions.add(versionInfoEntity.getCandidate().getVersion()); ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTIONENTITY_BY_ACTIONINVID, - ActionConstants.TARGET_ENTITY_DB); + TARGET_ENTITY_DB); Result result = accessor.getActionsByInvId(actionInvariantUuId, versions); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); log.metrics(""); @@ -412,22 +404,27 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act action = actionEntity != null ? actionEntity.toDto() : null; } } else { - throw new ActionException(ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE, - String - .format(ActionErrorConstants.ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER, actionUser)); + throw new ActionException(ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER_CODE, + String.format(ACTION_ARTIFACT_DEL_LOCKED_OTHER_USER, actionUser)); } } else { - throw new ActionException( - ActionErrorConstants.ACTION_NOT_LOCKED_CODE, - ActionErrorConstants.ACTION_NOT_LOCKED_MSG); + throw new ActionException(ACTION_NOT_LOCKED_CODE, ACTION_NOT_LOCKED_MSG); } } else { - throw new ActionException(ActionErrorConstants.ACTION_ENTITY_NOT_EXIST_CODE, - ActionErrorConstants.ACTION_ENTITY_NOT_EXIST); + throw new ActionException(ACTION_ENTITY_NOT_EXIST_CODE, ACTION_ENTITY_NOT_EXIST); } return action; } + private void logGenericException(Exception exception) { + ActionUtil.actionLogPostProcessor(StatusCode.ERROR, ACTION_QUERY_FAILURE_CODE, + ACTION_ENTITY_INTERNAL_SERVER_ERROR_MSG, false); + log.metrics(""); + ActionUtil.actionErrorLogProcessor(CategoryLogLevel.FATAL, ACTION_QUERY_FAILURE_CODE, + ACTION_QUERY_FAILURE_MSG); + log.error(exception.getMessage()); + } + @Override protected Mapper getMapper() { return mapper; @@ -445,19 +442,20 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act } /** - * param actionInvariantUuId. param versions. + * + * @param actionInvariantUUID. + * @param versions. */ private void updateActionStatusForDelete(String actionInvariantUuId, List versions) { log.debug( - "entering updateActionStatusForDelete with actionInvariantUUID = " + actionInvariantUuId + "entering updateActionStatusForDelete with actionInvariantUuId = " + actionInvariantUuId + " for versions " + versions); List versionUdt = new ArrayList<>(); + for (Version v : versions) { + versionUdt.add(versionMapper.toUDT(v)); + } - versions.forEach(v -> versionMapper.toUDT(v)); - ActionUtil - .actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION_STATUS, - ActionConstants.TARGET_ENTITY_DB); - + ActionUtil.actionLogPreProcessor(ActionSubOperation.UPDATE_ACTION_STATUS, TARGET_ENTITY_DB); //Update the status column of action table Statement updateStatusStatement = QueryBuilder.update("dox", "Action").with(set("status", ActionStatus.Deleted.name())) @@ -467,7 +465,7 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act log.metrics(""); //Update the status in the data field of action table updateStatusInActionData(actionInvariantUuId, versions, ActionStatus.Deleted); - log.debug("exit updateActionStatusForDelete with actionInvariantUUID = " + actionInvariantUuId + log.debug("exit updateActionStatusForDelete with actionInvariantUuId = " + actionInvariantUuId + " for versions " + versions); } @@ -480,13 +478,13 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act */ private void updateStatusInActionData(String actionInvariantUuId, List versions, ActionStatus status) { - log.debug("entering updateStatusInActionData for actionInvariantUUID = " + actionInvariantUuId - + " and status = " + status + " for versions " + versions); + log.debug("entering updateStatusInActionData for actionInvariantUuId = " + actionInvariantUuId + + " and status = " + status + " for versions " + versions); for (Version v : versions) { ActionEntity entity = this.get(new ActionEntity(actionInvariantUuId, v)); String currentData = entity.getData(); Map currentDataMap = JsonUtil.json2Object(currentData, LinkedHashMap.class); - currentDataMap.put(ActionConstants.STATUS, status); + currentDataMap.put(STATUS, status); String updatedActionData = JsonUtil.object2Json(currentDataMap); entity.setData(updatedActionData); this.updateAction(entity.toDto()); @@ -497,19 +495,18 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act /** * Get list of all major and minor version values for a given action by action name. * - * @param name Name of the action - * @return List of {@link Version} objects for the action + * @param name Name of the action. + * @return List of {@link Version} objects for the action. */ private List getVersionsByName(String name) { log.debug("entering getVersionsByName for Action Name = " + name); - ActionUtil - .actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, - ActionConstants.TARGET_ENTITY_DB); + ActionUtil.actionLogPreProcessor(ActionSubOperation.GET_ACTION_VERSION, TARGET_ENTITY_DB); Statement statement = QueryBuilder.select().column("version").from("dox", "Action").where(eq("name", name)); ResultSet results = getSession().execute(statement); ActionUtil.actionLogPostProcessor(StatusCode.COMPLETE, null, "", false); log.metrics(""); + List versionList = new ArrayList<>(); for (Row row : results) { Version version = versionMapper.fromUDT((UDTValue) row.getObject("version")); @@ -532,7 +529,7 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act Result getActionsByModel(String resource); @Query("SELECT * FROM Action where supportedComponents CONTAINS ?") - Result getActionsByEcompComponent(String resource); + Result getActionsByOpenEcompComponent(String resource); @Query("SELECT * FROM Action where vendor_list CONTAINS ?") Result getActionsByVendor(String vendor); @@ -543,8 +540,8 @@ public class ActionDaoImpl extends CassandraBaseDao implements Act @Query("SELECT actionInvariantUuId FROM Action where name = ? limit 1") Result getInvIdByName(String name); - @Query("SELECT * FROM ECOMPComponent") - Result getEcompComponents(); + @Query("SELECT * FROM EcompComponent") + Result getOpenEcompComponents(); @Query("SELECT * FROM Action where actionUUID = ?") Result actionInvariantUuId(String actionUuId); -- cgit 1.2.3-korg