summaryrefslogtreecommitdiffstats
path: root/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java
diff options
context:
space:
mode:
Diffstat (limited to 'services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java')
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java291
1 files changed, 0 insertions, 291 deletions
diff --git a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java b/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java
deleted file mode 100644
index 44383734e8..0000000000
--- a/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java
+++ /dev/null
@@ -1,291 +0,0 @@
-/*
- * Copyright © 2016-2017 European Support Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openecomp.activityspec.be.impl;
-
-import static org.openecomp.activityspec.api.rest.types.ActivitySpecAction.CERTIFY;
-import static org.openecomp.activityspec.api.rest.types.ActivitySpecAction.DELETE;
-import static org.openecomp.activityspec.api.rest.types.ActivitySpecAction.DEPRECATE;
-import static org.openecomp.activityspec.utils.ActivitySpecConstant.ACTIVITY_SPEC_NOT_FOUND;
-import static org.openecomp.activityspec.utils.ActivitySpecConstant.INVALID_STATE;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Certified;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deleted;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Deprecated;
-import static org.openecomp.sdc.versioning.dao.types.VersionStatus.Draft;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.function.Predicate;
-import org.openecomp.activityspec.api.rest.types.ActivitySpecAction;
-import org.openecomp.activityspec.be.ActivitySpecManager;
-import org.openecomp.activityspec.be.dao.ActivitySpecDao;
-import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity;
-import org.openecomp.activityspec.be.datatypes.ItemType;
-import org.openecomp.activityspec.errors.ActivitySpecNotFoundException;
-import org.openecomp.activityspec.utils.ActivitySpecConstant;
-import org.openecomp.core.dao.UniqueValueDao;
-import org.openecomp.core.util.UniqueValueUtil;
-import org.openecomp.sdc.common.errors.CoreException;
-import org.openecomp.sdc.common.errors.ErrorCategory;
-import org.openecomp.sdc.common.errors.ErrorCode;
-import org.openecomp.sdc.common.errors.SdcRuntimeException;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.versioning.ItemManager;
-import org.openecomp.sdc.versioning.VersioningManager;
-import org.openecomp.sdc.versioning.dao.types.Version;
-import org.openecomp.sdc.versioning.dao.types.VersionStatus;
-import org.openecomp.sdc.versioning.types.Item;
-import org.openecomp.sdc.versioning.types.VersionCreationMethod;
-
-public class ActivitySpecManagerImpl implements ActivitySpecManager {
-
- private static final Map<VersionStatus, Transition> TRANSITIONS;
-
- static {
- TRANSITIONS = new EnumMap<>(VersionStatus.class);
- TRANSITIONS.put(Certified, new Transition("Certify", Draft));
- TRANSITIONS.put(Deprecated, new Transition("Deprecate", Certified));
- TRANSITIONS.put(Deleted, new Transition("Delete", Deprecated));
- }
-
- private final ItemManager itemManager;
- private final VersioningManager versioningManager;
- private final ActivitySpecDao activitySpecDao;
- private final UniqueValueUtil uniqueValueUtil;
- private static final String ACTIVITY_SPEC_NAME = "ActivitySpec.Name";
- private static final Logger LOGGER =
- LoggerFactory.getLogger(ActivitySpecManagerImpl.class);
-
- public ActivitySpecManagerImpl(ItemManager itemManager,
- VersioningManager versioningManager,
- ActivitySpecDao activitySpecDao,
- UniqueValueDao uniqueValueDao) {
- this.itemManager = itemManager;
- this.versioningManager = versioningManager;
- this.activitySpecDao = activitySpecDao;
- this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao);
- }
-
- @Override
- public ActivitySpecEntity createActivitySpec(ActivitySpecEntity activitySpecEntity) {
-
- validateUniqueValue(activitySpecEntity);
-
- Item item = getActivitySpecItem(activitySpecEntity);
- item = itemManager.create(item);
-
- Version version = getActivitySpecVersion(activitySpecEntity);
- versioningManager.create(item.getId(), version, VersionCreationMethod.major);
-
- enrichActivitySpec(item, version, activitySpecEntity);
- activitySpecDao.create(activitySpecEntity);
-
- uniqueValueUtil.createUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName());
- return activitySpecEntity;
- }
-
- private void validateUniqueValue(ActivitySpecEntity activitySpecEntity) {
- try {
- uniqueValueUtil.validateUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName());
- } catch (CoreException exception) {
- LOGGER.debug("Unique value error for activity spec name :" + activitySpecEntity.getName(), exception);
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId(exception.code().id())
- .withMessage("name already in use").build());
- }
- }
-
- private Version getActivitySpecVersion(ActivitySpecEntity activitySpecEntity) {
- return activitySpecEntity.getVersion() == null ? new Version()
- : activitySpecEntity.getVersion();
-
- }
-
- @Override
- public ActivitySpecEntity get(ActivitySpecEntity activitySpec) {
- activitySpec.setVersion(calculateLatestVersion(activitySpec.getId(),activitySpec.getVersion()));
- ActivitySpecEntity retrieved;
- try {
- retrieved = activitySpecDao.get(activitySpec);
- } catch (SdcRuntimeException runtimeException) {
- LOGGER.debug("Failed to retrieve activity spec for activitySpecId: " + activitySpec.getId()
- + " and version: " + activitySpec.getVersion().getId(), runtimeException);
- throw new ActivitySpecNotFoundException(ACTIVITY_SPEC_NOT_FOUND, runtimeException);
- }
- if (retrieved != null) {
- final Version retrievedVersion = versioningManager.get(activitySpec.getId(),
- activitySpec.getVersion());
- retrieved.setStatus(Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus().name()
- : null);
- }
- return retrieved;
- }
-
- @Override
- public void update(ActivitySpecEntity activitySpec) {
-
- ActivitySpecEntity previousActivitySpec = get(activitySpec);
-
- if (!activitySpec.getName().equals(previousActivitySpec.getName())) {
- validateUniqueValue(activitySpec);
- }
-
- activitySpecDao.update(activitySpec);
-
- if (!activitySpec.getName().equals(previousActivitySpec.getName())) {
- uniqueValueUtil.createUniqueValue(ACTIVITY_SPEC_NAME, activitySpec.getName());
- itemManager.updateName(activitySpec.getId(), activitySpec.getName());
- uniqueValueUtil.deleteUniqueValue(ACTIVITY_SPEC_NAME, previousActivitySpec.getName());
- }
- }
-
- @Override
- public void actOnAction(String activitySpecId, String versionId, ActivitySpecAction action) {
- Version version = new Version(versionId);
- version = calculateLatestVersion(activitySpecId, version);
- if (action == CERTIFY) {
- version.setStatus(Certified);
- }
- if (action == DEPRECATE) {
- version.setStatus(Deprecated);
- }
- if (action == DELETE) {
- version.setStatus(Deleted);
- }
-
- updateVersionStatus(activitySpecId, action, version);
- if (action == DELETE) {
- ActivitySpecEntity entity = new ActivitySpecEntity();
- entity.setId(activitySpecId);
- entity.setVersion(version);
- final ActivitySpecEntity activitySpecEntity = get(entity);
- uniqueValueUtil.deleteUniqueValue(ACTIVITY_SPEC_NAME, activitySpecEntity.getName());
- }
- }
-
- private void updateVersionStatus(String activitySpecId, ActivitySpecAction action,
- Version version) {
- VersionStatus prevVersionStatus = null;
- Version retrievedVersion;
- try {
- retrievedVersion = versioningManager.get(activitySpecId, version);
- } catch (SdcRuntimeException exception) {
- LOGGER.debug("Failed to get version for activitySpecId: " + activitySpecId
- + " and version: " + version.getId(), exception);
- throw new ActivitySpecNotFoundException(ACTIVITY_SPEC_NOT_FOUND, exception);
-
- }
-
- VersionStatus status = version.getStatus();
- Transition transition = TRANSITIONS.get(status);
- if (transition != null) {
-
- VersionStatus retrievedStatus = Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus() : null;
- if (retrievedStatus != transition.prevStatus) {
- LOGGER.debug("Failed to " + version.getStatus() + " since activity spec is in "
- + retrievedStatus);
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withMessage(INVALID_STATE).build());
- }
- prevVersionStatus = transition.prevStatus;
- }
-
- if (Objects.nonNull(retrievedVersion)) {
- retrievedVersion.setStatus(status);
- versioningManager.updateVersion(activitySpecId, retrievedVersion);
- itemManager.updateVersionStatus(activitySpecId, status, prevVersionStatus);
- versioningManager.publish(activitySpecId, retrievedVersion, "actionOnActivitySpec :"
- + action.name());
- }
- }
-
- private Version calculateLatestVersion(String activitySpecId, Version version) {
- if (ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE.equalsIgnoreCase(version.getId())) {
- List<Version> list;
- try {
- list = versioningManager.list(activitySpecId);
- } catch (SdcRuntimeException runtimeException) {
- LOGGER.debug("Failed to list versions for activitySpecId "
- + activitySpecId, runtimeException);
- throw new ActivitySpecNotFoundException(ACTIVITY_SPEC_NOT_FOUND, runtimeException);
- }
- if (Objects.nonNull(list) && !list.isEmpty()) {
- return list.get(0);
- }
- }
- return version;
- }
-
- @Override
- public Collection<Item> list(String versionStatus) {
- Predicate<Item> itemPredicate;
- if (Objects.nonNull(versionStatus)) {
-
- VersionStatus statusEnumValue;
-
- try {
- statusEnumValue = VersionStatus.valueOf(versionStatus);
- } catch (IllegalArgumentException e) {
- LOGGER.debug("Unexpected value of VersionStatus {}", versionStatus);
- return Collections.emptyList();
- }
-
- itemPredicate = item -> ItemType.ACTIVITYSPEC.name().equals(item.getType())
- && item.getVersionStatusCounters().containsKey(statusEnumValue);
-
- } else {
- itemPredicate = item -> ItemType.ACTIVITYSPEC.name().equals(item.getType());
- }
-
- return itemManager.list(itemPredicate);
- }
-
- private void enrichActivitySpec(Item item, Version version,
- ActivitySpecEntity activitySpecEntity) {
- activitySpecEntity.setId(item.getId());
- activitySpecEntity.setVersion(version);
- }
-
- private Item getActivitySpecItem(ActivitySpecEntity activitySpecEntity) {
- Item item = new Item();
- item.setType(ItemType.ACTIVITYSPEC.name());
- item.setName(activitySpecEntity.getName());
- if (activitySpecEntity.getId() != null) {
- item.setId(activitySpecEntity.getId());
- }
- item.addProperty(ActivitySpecConstant.CATEGORY_ATTRIBUTE_NAME,
- activitySpecEntity.getCategoryList());
- return item;
- }
-
- private static class Transition {
-
- private final String action;
- private final VersionStatus prevStatus;
-
- private Transition(String action, VersionStatus prevStatus) {
- this.action = action;
- this.prevStatus = prevStatus;
- }
- }
-
-}