3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * ================================================================================
8 * * Licensed under the Apache License, Version 2.0 (the "License");
9 * * you may not use this file except in compliance with the License.
10 * * You may obtain a copy of the License at
12 * * http://www.apache.org/licenses/LICENSE-2.0
14 * * Unless required by applicable law or agreed to in writing, software
15 * * distributed under the License is distributed on an "AS IS" BASIS,
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * * See the License for the specific language governing permissions and
18 * * limitations under the License.
19 * * ============LICENSE_END=========================================================
24 package org.onap.blueprintgenerator.service.common;
26 import org.onap.blueprintgenerator.constants.Constants;
27 import org.onap.blueprintgenerator.model.common.GetInput;
28 import org.onap.blueprintgenerator.model.common.Node;
29 import org.onap.blueprintgenerator.model.common.PolicyNode;
30 import org.onap.blueprintgenerator.model.common.PolicyNodeProperties;
31 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
32 import org.onap.blueprintgenerator.model.componentspec.TypePolicy;
33 import org.onap.blueprintgenerator.service.base.BlueprintHelperService;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Service;
37 import java.util.ArrayList;
38 import java.util.LinkedHashMap;
39 import java.util.List;
43 * @author : Ravi Mantena
44 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service to add Policy Node
46 @Service("onapPolicyNodeService")
47 public class PolicyNodeService {
50 private BlueprintHelperService blueprintHelperService;
53 * Creates Policy Nodes and Inputs
55 * @param onapComponentSpec OnapComponentSpec
56 * @param nodeTemplate Node Template
57 * @param inputs Inputs
60 public void addPolicyNodesAndInputs(
61 OnapComponentSpec onapComponentSpec,
62 Map<String, Node> nodeTemplate,
63 Map<String, LinkedHashMap<String, Object>> inputs) {
64 List<TypePolicy> policyList = onapComponentSpec.getPolicyInfo().getTypePolicyList();
65 for (TypePolicy policy : policyList) {
66 addPolicyNodesToNodeTemplate(policy, nodeTemplate);
67 addPolicyInputs(policy, inputs);
71 private void addPolicyInputs(
72 TypePolicy policy, Map<String, LinkedHashMap<String, Object>> inputs) {
73 String defaultValue = policy.getPolicy_id();
74 defaultValue = defaultValue != null ? defaultValue : "";
76 policy.getNode_label() + "_policy_id",
77 blueprintHelperService.createStringInput("policy_id", defaultValue));
80 private void addPolicyNodesToNodeTemplate(TypePolicy policy, Map<String, Node> nodeTemplate) {
81 PolicyNode policyNode = new PolicyNode();
82 policyNode.setType(Constants.POLICY_NODE_TYPE);
83 policyNode.setPolicyNodeProperties(getPolicyNodeProperties(policy));
84 nodeTemplate.put(policy.getNode_label(), policyNode);
87 private PolicyNodeProperties getPolicyNodeProperties(TypePolicy policy) {
88 PolicyNodeProperties policyNodeProperties = new PolicyNodeProperties();
89 GetInput policyIdGetInput = new GetInput();
90 policyIdGetInput.setBpInputName(policy.getNode_label() + "_policy_id");
91 policyNodeProperties.setPolicyId(policyIdGetInput);
92 policyNodeProperties.setPolicyModelId(policy.getPolicy_model_id());
93 return policyNodeProperties;
97 * Creates Policy Relationships
99 * @param onapComponentSpec OnapComponentSpec
102 public List<Map<String, String>> getPolicyRelationships(OnapComponentSpec onapComponentSpec) {
103 List<Map<String, String>> relationships = new ArrayList<>();
104 List<TypePolicy> policyList = onapComponentSpec.getPolicyInfo().getTypePolicyList();
105 for (TypePolicy policy : policyList) {
106 Map<String, String> relationship = new LinkedHashMap<>();
107 relationship.put("type", Constants.POLICY_RELATIONSHIP_TYPE);
108 relationship.put("target", policy.getNode_label());
109 relationships.add(relationship);
111 return relationships;