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;
@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 {