From 04f13ef80c6e79d8c0b7b3fa1faeeaa0def1584e Mon Sep 17 00:00:00 2001 From: Joanna Jeremicz Date: Wed, 30 Sep 2020 11:39:25 +0200 Subject: Adjust BP-gen to correctly support DFC component spec - types - Update relationshipsType and feedNode values in DmaapNode - Create a class for hardcoded values - Update unit tests Issue-ID: DCAEGEN2-2459 Signed-off-by: Joanna Jeremicz Change-Id: Ic5dc91844b4aefcf7d3d9d25c866a60e63875deb --- .../models/policymodel/PolicyModel.java | 229 ++++++++++----------- 1 file changed, 113 insertions(+), 116 deletions(-) (limited to 'mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java') diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java index 9c9bd51..81bc440 100644 --- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java +++ b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java @@ -1,37 +1,28 @@ -/**============LICENSE_START======================================================= - org.onap.dcae - ================================================================================ - Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. - ================================================================================ - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - ============LICENSE_END========================================================= +/*============LICENSE_START======================================================= + org.onap.dcae + ================================================================================ + Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + ================================================================================ + Modifications Copyright (c) 2020 Nokia. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.blueprintgenerator.models.policymodel; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.TreeMap; - -import org.onap.blueprintgenerator.models.blueprint.Node; -import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; -import org.onap.blueprintgenerator.models.componentspec.Parameters; +import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOSCA_SIMPLE_YAML; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonGenerationException; @@ -39,101 +30,107 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; - +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.TreeMap; import lombok.Getter; import lombok.Setter; +import org.onap.blueprintgenerator.models.componentspec.ComponentSpec; +import org.onap.blueprintgenerator.models.componentspec.Parameters; -@Getter @Setter +@Getter +@Setter @JsonInclude(JsonInclude.Include.NON_NULL) public class PolicyModel { - - private String tosca_definition_version; - private TreeMap node_types; - private TreeMap data_types; - - public ArrayList createPolicyModels(ComponentSpec cs, String filePath) { - ArrayList models = new ArrayList(); - Parameters[] params = cs.getParameters(); - - ArrayList groups = new ArrayList(); - groups = getModelGroups(params); - - for(String s: groups) { - PolicyModel model = new PolicyModel(); - model = model.createPolicyModel(s, params); - //models.add(model); - policyModelToYaml(filePath, model, s); - } - + + private String tosca_definition_version; + private TreeMap node_types; + private TreeMap data_types; + + public ArrayList createPolicyModels(ComponentSpec cs, String filePath) { + ArrayList models = new ArrayList(); + Parameters[] params = cs.getParameters(); + + ArrayList groups = new ArrayList(); + groups = getModelGroups(params); + + for (String s : groups) { + PolicyModel model = new PolicyModel(); + model = model.createPolicyModel(s, params); + //models.add(model); + policyModelToYaml(filePath, model, s); + } + // for(PolicyModel p: models) { // policyModelToYaml(filePath, p); // } - return models; - } - - public ArrayList getModelGroups(Parameters[] params) { - ArrayList groups = new ArrayList(); - - for(Parameters p: params) { - if(p.isPolicy_editable()) { - if(groups.isEmpty()) { - groups.add(p.getPolicy_group()); - } else { - if(!groups.contains(p.getPolicy_group())) { - groups.add(p.getPolicy_group()); - } - } - } - } - - return groups; - } - - public PolicyModel createPolicyModel(String s, Parameters[] params) { - PolicyModel model = new PolicyModel(); - model.setTosca_definition_version("tosca_simple_yaml_1_0_0"); - - PolicyModelNode node = new PolicyModelNode(); - String hasEntryScheme = node.createNodeType(s, params); - String nodeTypeName = "onap.policy." + s; - TreeMap nodeType = new TreeMap(); - nodeType.put(nodeTypeName, node); - model.setNode_types(nodeType); - - if(!hasEntryScheme.equals("")) { - PolicyModelNode data = new PolicyModelNode(); - TreeMap dataType = data.createDataTypes(hasEntryScheme, params); - model.setData_types(dataType); - } - - return model; - } - - public void policyModelToYaml(String path, PolicyModel p, String name) { - File outputFile; - String filePath = path + "/" + name + ".yml"; - File policyFile = new File(filePath); - ObjectMapper policyMapper = new ObjectMapper(new YAMLFactory().configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)); - outputFile = new File(path, name + ".yml"); - outputFile.getParentFile().mkdirs(); - - try { - PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile, true))); - } catch (IOException e) { - e.printStackTrace(); - } - - try { - policyMapper.writeValue(outputFile, p); - } catch (JsonGenerationException e) { - e.printStackTrace(); - } catch (JsonMappingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - System.out.println("model " + name + " created"); - } + return models; + } + + public ArrayList getModelGroups(Parameters[] params) { + ArrayList groups = new ArrayList(); + + for (Parameters p : params) { + if (p.isPolicy_editable()) { + if (groups.isEmpty()) { + groups.add(p.getPolicy_group()); + } else { + if (!groups.contains(p.getPolicy_group())) { + groups.add(p.getPolicy_group()); + } + } + } + } + + return groups; + } + + public PolicyModel createPolicyModel(String s, Parameters[] params) { + PolicyModel model = new PolicyModel(); + model.setTosca_definition_version(TOSCA_SIMPLE_YAML); + + PolicyModelNode node = new PolicyModelNode(); + String hasEntryScheme = node.createNodeType(s, params); + String nodeTypeName = "onap.policy." + s; + TreeMap nodeType = new TreeMap(); + nodeType.put(nodeTypeName, node); + model.setNode_types(nodeType); + + if (!hasEntryScheme.equals("")) { + PolicyModelNode data = new PolicyModelNode(); + TreeMap dataType = data.createDataTypes(hasEntryScheme, params); + model.setData_types(dataType); + } + + return model; + } + + public void policyModelToYaml(String path, PolicyModel p, String name) { + File outputFile; + String filePath = path + "/" + name + ".yml"; + File policyFile = new File(filePath); + ObjectMapper policyMapper = new ObjectMapper( + new YAMLFactory().configure(YAMLGenerator.Feature.MINIMIZE_QUOTES, true)); + outputFile = new File(path, name + ".yml"); + outputFile.getParentFile().mkdirs(); + + try { + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(outputFile, true))); + } catch (IOException e) { + e.printStackTrace(); + } + + try { + policyMapper.writeValue(outputFile, p); + } catch (IOException e) { + e.printStackTrace(); + } + System.out.println("model " + name + " created"); + } } -- cgit 1.2.3-korg