2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.client.cds;
23 import static org.onap.so.client.cds.ConfigureInstanceParamsUtil.applyParamsToObject;
24 import com.google.gson.JsonObject;
25 import org.onap.so.client.exception.PayloadGenerationException;
26 import org.onap.so.serviceinstancebeans.Service;
27 import org.onap.so.serviceinstancebeans.Pnfs;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Component;
30 import java.util.List;
32 import java.util.Optional;
35 public class ConfigureInstanceParamsForPnf {
37 private ExtractServiceFromUserParameters extractServiceFromUserParameters;
40 public ConfigureInstanceParamsForPnf(ExtractServiceFromUserParameters extractServiceFromUserParameters) {
41 this.extractServiceFromUserParameters = extractServiceFromUserParameters;
45 * Read instance parameters for PNF and put into JsonObject.
47 * @param jsonObject - JsonObject which will hold the payload to send to CDS.
48 * @param userParamsFromRequest - User parameters.
49 * @param modelCustomizationUuid - Unique ID for Pnf.
50 * @throws PayloadGenerationException if it doesn't able to populate instance parameters from SO payload.
52 public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest,
53 String modelCustomizationUuid) throws PayloadGenerationException {
55 Optional<Service> service =
56 extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest);
58 if (service.isPresent()) {
59 List<Map<String, String>> instanceParamsList =
60 getInstanceParamForPnf(service.get(), modelCustomizationUuid);
62 applyParamsToObject(instanceParamsList, jsonObject);
64 } catch (Exception exception) {
65 throw new PayloadGenerationException("Failed to resolve instance parameters", exception);
69 private List<Map<String, String>> getInstanceParamForPnf(Service service, String genericPnfModelCustomizationUuid)
70 throws PayloadGenerationException {
71 Optional<Pnfs> foundedPnfs = service.getResources().getPnfs().stream()
72 .filter(pnfs -> pnfs.getModelInfo().getModelCustomizationId().equals(genericPnfModelCustomizationUuid))
74 if (foundedPnfs.isPresent()) {
75 return foundedPnfs.get().getInstanceParams();
77 throw new PayloadGenerationException(String.format(
78 "Can not find pnf for genericPnfModelCustomizationUuid: %s", genericPnfModelCustomizationUuid));