Enable ControllerExecutionBB for service scope
[so.git] / bpmn / MSOCommonBPMN / src / main / java / org / onap / so / client / cds / ExtractServiceFromUserParameters.java
index 43fabd3..53e1da4 100644 (file)
@@ -20,6 +20,7 @@
 package org.onap.so.client.cds;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import java.util.Optional;
 import org.onap.so.client.exception.PayloadGenerationException;
 import org.onap.so.serviceinstancebeans.Service;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,10 +36,13 @@ public class ExtractServiceFromUserParameters {
     @Autowired
     private ObjectMapper objectMapper;
 
-    public Service getServiceFromRequestUserParams(List<Map<String, Object>> userParams) throws Exception {
-        Map<String, Object> serviceMap = userParams.stream().filter(key -> key.containsKey(SERVICE_KEY)).findFirst()
-                .orElseThrow(() -> new Exception("Can not find service in userParams section in generalBuildingBlock"));
-        return getServiceObjectFromServiceMap(serviceMap);
+    public Optional<Service> getServiceFromRequestUserParams(List<Map<String, Object>> userParams) throws Exception {
+        Optional<Map<String, Object>> serviceMap =
+                userParams.stream().filter(key -> key.containsKey(SERVICE_KEY)).findFirst();
+        if (serviceMap.isPresent()) {
+            return Optional.of(getServiceObjectFromServiceMap(serviceMap.get()));
+        }
+        return Optional.empty();
     }
 
     private Service getServiceObjectFromServiceMap(Map<String, Object> serviceMap) throws PayloadGenerationException {