summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap
diff options
context:
space:
mode:
authorKuleshov, Elena <evn@att.com>2020-09-08 16:45:49 -0400
committerBenjamin, Max (mb388a) <mb388a@att.com>2020-09-08 16:45:49 -0400
commit27d4ba1bdde932efa07837743ebf9a0b2594e1fe (patch)
treef0f823baeb5f06ec97c6f1f21b280f504a30077c /mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap
parent36982a7db770806b0a3e12d07686b4e3a72a0871 (diff)
Populate serviceInstanceId from instanceMap on
Populate serviceInstanceId from instanceMap on validation error. Use Optional for return value for serviceInstanceId assist methods. Issue-ID: SO-3224 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: I36a44ae42bb89d621dec5a2f85266458ea0e0766
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java42
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java3
2 files changed, 33 insertions, 12 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java
index 87e5a2f23e..60e9c3b30a 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java
@@ -518,20 +518,16 @@ public class RequestHandlerUtils extends AbstractRestHandler {
}
protected String setServiceInstanceId(String requestScope, ServiceInstancesRequest sir) {
+ String serviceInstanceId = null;
if (sir.getServiceInstanceId() != null) {
- return sir.getServiceInstanceId();
- } else if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) {
- RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList();
- if (relatedInstances != null) {
- for (RelatedInstanceList relatedInstanceList : relatedInstances) {
- RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
- if (relatedInstance.getModelInfo().getModelType() == ModelType.service) {
- return relatedInstance.getInstanceId();
- }
- }
+ serviceInstanceId = sir.getServiceInstanceId();
+ } else {
+ Optional<String> serviceInstanceIdForInstance = getServiceInstanceIdForInstanceGroup(requestScope, sir);
+ if (serviceInstanceIdForInstance.isPresent()) {
+ serviceInstanceId = serviceInstanceIdForInstance.get();
}
}
- return null;
+ return serviceInstanceId;
}
private String requestScopeFromUri(String requestUri) {
@@ -916,6 +912,30 @@ public class RequestHandlerUtils extends AbstractRestHandler {
return null;
}
+ protected Optional<String> getServiceInstanceIdForValidationError(ServiceInstancesRequest sir,
+ HashMap<String, String> instanceIdMap, String requestScope) {
+ if (instanceIdMap != null && !instanceIdMap.isEmpty() && instanceIdMap.get("serviceInstanceId") != null) {
+ return Optional.of(instanceIdMap.get("serviceInstanceId"));
+ } else {
+ return getServiceInstanceIdForInstanceGroup(requestScope, sir);
+ }
+ }
+
+ protected Optional<String> getServiceInstanceIdForInstanceGroup(String requestScope, ServiceInstancesRequest sir) {
+ if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) {
+ RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList();
+ if (relatedInstances != null) {
+ for (RelatedInstanceList relatedInstanceList : relatedInstances) {
+ RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
+ if (relatedInstance.getModelInfo().getModelType() == ModelType.service) {
+ return Optional.ofNullable(relatedInstance.getInstanceId());
+ }
+ }
+ }
+ }
+ return Optional.empty();
+ }
+
private RecipeLookupResult getDefaultVnfUri(ServiceInstancesRequest sir, Actions action) {
String defaultSource = getDefaultModel(sir);
VnfRecipe vnfRecipe = catalogDbClient.getFirstVnfRecipeByNfRoleAndAction(defaultSource, action.toString());
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
index 107aa57974..2c8e92633c 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
@@ -829,7 +829,8 @@ public class ServiceInstances extends AbstractRestHandler {
requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action);
} catch (ApiException e) {
msoRequest.createErrorRequestRecord(Status.FAILED, requestId, e.getMessage(), action, requestScope,
- requestJSON, sir.getServiceInstanceId());
+ requestJSON, requestHandlerUtils
+ .getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).orElse(null));
throw e;
}