summaryrefslogtreecommitdiffstats
path: root/services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be
diff options
context:
space:
mode:
authorsheetalm <sheetal.mudholkar@amdocs.com>2018-04-02 18:12:54 +0530
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2018-04-10 14:37:17 +0000
commit40bd5b855df62e257e4cc2810a95248bc3426302 (patch)
tree518cff1b6aaf972a3f06066f8e47ac1a5e65bfee /services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be
parent7a9073719da3db83024e66a1da9ba14546cfd175 (diff)
Activity Spec - Change Error Response Structure
1 Added ActivitySpecNotFoundException to map to 404 Not Found response code 2 404 Not Found response code will only be returned in case activity spec does not exists irrespective of GET or PUT used in REST 3 Update flow test to check error messages 4 Error Response to have only "message" now 5 Use proper response code instead of EXPECTATION_FAILED Change-Id: I82fb3c0970f4e9416d9fe2577174dcaf0a4fef92 Issue-ID: SDC-1048 Signed-off-by: sheetalm <sheetal.mudholkar@amdocs.com>
Diffstat (limited to 'services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be')
-rw-r--r--services/activity-spec/activity-spec-web/activity-spec-service/src/main/java/org/openecomp/activityspec/be/impl/ActivitySpecManagerImpl.java58
1 files changed, 23 insertions, 35 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
index b4a735409c..44383734e8 100644
--- 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
@@ -19,6 +19,8 @@ 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;
@@ -36,6 +38,7 @@ 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;
@@ -103,6 +106,7 @@ public class ActivitySpecManagerImpl implements ActivitySpecManager {
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())
@@ -118,16 +122,14 @@ public class ActivitySpecManagerImpl implements ActivitySpecManager {
@Override
public ActivitySpecEntity get(ActivitySpecEntity activitySpec) {
- activitySpec.setVersion(calculateLatestVersion(activitySpec.getId(),activitySpec.getVersion()
- ));
- ActivitySpecEntity retrieved = null;
+ activitySpec.setVersion(calculateLatestVersion(activitySpec.getId(),activitySpec.getVersion()));
+ ActivitySpecEntity retrieved;
try {
retrieved = activitySpecDao.get(activitySpec);
} catch (SdcRuntimeException runtimeException) {
- LOGGER.error("Failed to retrieve activity spec for activitySpecId: " + activitySpec.getId()
- + " and version: "
- + activitySpec.getVersion().getId(), runtimeException);
- validateActivitySpecExistence(activitySpec.getId(), activitySpec.getVersion());
+ 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(),
@@ -183,23 +185,27 @@ public class ActivitySpecManagerImpl implements ActivitySpecManager {
private void updateVersionStatus(String activitySpecId, ActivitySpecAction action,
Version version) {
VersionStatus prevVersionStatus = null;
- Version retrievedVersion = null;
+ Version retrievedVersion;
try {
retrievedVersion = versioningManager.get(activitySpecId, version);
} catch (SdcRuntimeException exception) {
- LOGGER.error("Failed to get version for activitySpecId: " + activitySpecId
+ LOGGER.debug("Failed to get version for activitySpecId: " + activitySpecId
+ " and version: " + version.getId(), exception);
- validateActivitySpecExistence(activitySpecId, version);
+ throw new ActivitySpecNotFoundException(ACTIVITY_SPEC_NOT_FOUND, exception);
}
VersionStatus status = version.getStatus();
Transition transition = TRANSITIONS.get(status);
if (transition != null) {
- String errMsg = String.format("Activity Spec is in an invalid state",
- transition.action, activitySpecId, transition.prevStatus);
- validateStatus(Objects.nonNull(retrievedVersion) ? retrievedVersion.getStatus() : null,
- transition.prevStatus, errMsg);
+
+ 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;
}
@@ -212,33 +218,15 @@ public class ActivitySpecManagerImpl implements ActivitySpecManager {
}
}
- private void validateActivitySpecExistence(String activitySpecId, Version version) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId("ACTIVITYSPEC_NOT_FOUND")
- .withMessage("No Activity Spec found for the given identifiers")
- .build());
- }
-
- private void validateStatus(VersionStatus retrievedVersionStatus,
- VersionStatus expectedVersionStatus, String errorMessage) {
- if (retrievedVersionStatus != expectedVersionStatus) {
- throw new CoreException(new ErrorCode.ErrorCodeBuilder()
- .withCategory(ErrorCategory.APPLICATION)
- .withId("STATUS_NOT_" + expectedVersionStatus.name().toUpperCase())
- .withMessage(errorMessage).build());
- }
- }
-
private Version calculateLatestVersion(String activitySpecId, Version version) {
if (ActivitySpecConstant.VERSION_ID_DEFAULT_VALUE.equalsIgnoreCase(version.getId())) {
- List<Version> list = null;
+ List<Version> list;
try {
list = versioningManager.list(activitySpecId);
} catch (SdcRuntimeException runtimeException) {
- LOGGER.error("Failed to list versions for activitySpecId "
+ LOGGER.debug("Failed to list versions for activitySpecId "
+ activitySpecId, runtimeException);
- validateActivitySpecExistence(activitySpecId, version);
+ throw new ActivitySpecNotFoundException(ACTIVITY_SPEC_NOT_FOUND, runtimeException);
}
if (Objects.nonNull(list) && !list.isEmpty()) {
return list.get(0);