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
45 * Application: ONAP - Blueprint Generator
46 * Common ONAP Service used by ONAP and DMAAP Blueprint to add Policy Node
50 @Service("onapPolicyNodeService")
51 public class PolicyNodeService {
54 private BlueprintHelperService blueprintHelperService;
56 // Method to add Policy Nodes and Inputs
57 public void addPolicyNodesAndInputs(OnapComponentSpec onapComponentSpec, Map<String, Node> nodeTemplate, Map<String, LinkedHashMap<String, Object>> inputs) {
58 List<TypePolicy> policyList = onapComponentSpec.getPolicyInfo().getTypePolicyList();
59 for(TypePolicy policy: policyList){
60 addPolicyNodesToNodeTemplate(policy, nodeTemplate);
61 addPolicyInputs(policy, inputs);
65 private void addPolicyInputs(TypePolicy policy, Map<String, LinkedHashMap<String, Object>> inputs) {
66 String defaultValue = policy.getPolicy_id();
67 defaultValue = defaultValue != null ? defaultValue : "";
68 inputs.put(policy.getNode_label() + "_policy_id", blueprintHelperService.createStringInput("policy_id", defaultValue));
71 private void addPolicyNodesToNodeTemplate(TypePolicy policy, Map<String, Node> nodeTemplate) {
72 PolicyNode policyNode = new PolicyNode();
73 policyNode.setType(Constants.POLICY_NODE_TYPE);
74 policyNode.setPolicyNodeProperties(getPolicyNodeProperties(policy));
75 nodeTemplate.put(policy.getNode_label(), policyNode);
78 private PolicyNodeProperties getPolicyNodeProperties(TypePolicy policy) {
79 PolicyNodeProperties policyNodeProperties = new PolicyNodeProperties();
80 GetInput policyIdGetInput = new GetInput();
81 policyIdGetInput.setBpInputName(policy.getNode_label() + "_policy_id");
82 policyNodeProperties.setPolicyId(policyIdGetInput);
83 policyNodeProperties.setPolicyModelId(policy.getPolicy_model_id());
84 return policyNodeProperties;
87 // Method to add Policy Relationships
88 public List<Map<String, String>> getPolicyRelationships(OnapComponentSpec onapComponentSpec) {
89 List<Map<String, String>> relationships = new ArrayList<>();
90 List<TypePolicy> policyList = onapComponentSpec.getPolicyInfo().getTypePolicyList();
91 for(TypePolicy policy: policyList){
92 Map<String, String> relationship = new LinkedHashMap<>();
93 relationship.put("type", Constants.POLICY_RELATIONSHIP_TYPE);
94 relationship.put("target", policy.getNode_label());
95 relationships.add(relationship);