summaryrefslogtreecommitdiffstats
path: root/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel
diff options
context:
space:
mode:
Diffstat (limited to 'mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel')
-rw-r--r--mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java136
-rw-r--r--mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModelNode.java147
-rw-r--r--mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyProperties.java41
3 files changed, 0 insertions, 324 deletions
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
deleted file mode 100644
index 81bc440..0000000
--- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModel.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*============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 static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOSCA_SIMPLE_YAML;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.core.JsonGenerationException;
-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
-@JsonInclude(JsonInclude.Include.NON_NULL)
-
-public class PolicyModel {
-
- private String tosca_definition_version;
- private TreeMap<String, PolicyModelNode> node_types;
- private TreeMap<String, PolicyModelNode> data_types;
-
- public ArrayList<PolicyModel> createPolicyModels(ComponentSpec cs, String filePath) {
- ArrayList<PolicyModel> models = new ArrayList();
- Parameters[] params = cs.getParameters();
-
- ArrayList<String> groups = new ArrayList<String>();
- 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<String> getModelGroups(Parameters[] params) {
- ArrayList<String> 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<String, PolicyModelNode> nodeType = new TreeMap();
- nodeType.put(nodeTypeName, node);
- model.setNode_types(nodeType);
-
- if (!hasEntryScheme.equals("")) {
- PolicyModelNode data = new PolicyModelNode();
- TreeMap<String, PolicyModelNode> 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");
- }
-}
diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModelNode.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModelNode.java
deleted file mode 100644
index 89321de..0000000
--- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyModelNode.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*============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 static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOSCA_DATATYPES_ROOT;
-import static org.onap.blueprintgenerator.models.blueprint.BpConstants.TOSCA_NODES_ROOT;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.TreeMap;
-import lombok.Getter;
-import lombok.Setter;
-import org.onap.blueprintgenerator.models.componentspec.EntrySchemaObj;
-import org.onap.blueprintgenerator.models.componentspec.Parameters;
-import org.onap.blueprintgenerator.models.componentspec.PolicySchemaObj;
-
-@Getter
-@Setter
-@JsonInclude(JsonInclude.Include.NON_NULL)
-public class PolicyModelNode {
-
- private String derived_from;
- private TreeMap<String, PolicyProperties> properties;
-
- public String createNodeType(String policyName, Parameters[] params) {
- String hasEntrySchema = "";
-
- TreeMap<String, PolicyProperties> props = new TreeMap();
- for (Parameters p : params) {
- if (p.getPolicy_group() != null) {
- if (p.getPolicy_group().equals(policyName)) {
- String name = p.getName();
- String type = p.getType();
- PolicyProperties polProps = new PolicyProperties();
- if (p.getPolicy_schema() != null) {
- polProps.setType("map");
- HashMap<String, String> entrySchema = new HashMap();
- entrySchema.put("type", "onap.datatypes." + name);
- //ArrayList<String> entrySchema = new ArrayList<String>();
- //entrySchema.add("type: onap.data." + name);
- polProps.setEntry_schema(entrySchema);
- hasEntrySchema = name;
- props.put(name, polProps);
- } else {
- polProps.setType(type);
- props.put(name, polProps);
- }
- }
- }
- }
-
- this.setDerived_from(TOSCA_DATATYPES_ROOT);
- this.setProperties(props);
- return hasEntrySchema;
- }
-
- public TreeMap<String, PolicyModelNode> createDataTypes(String param, Parameters[] parameters) {
- TreeMap<String, PolicyModelNode> dataType = new TreeMap<String, PolicyModelNode>();
-
- PolicyModelNode node = new PolicyModelNode();
- node.setDerived_from(TOSCA_DATATYPES_ROOT);
-
- TreeMap<String, PolicyProperties> properties = new TreeMap();
-
- Parameters par = new Parameters();
- for (Parameters p : parameters) {
- if (p.getName().equals(param)) {
- par = p;
- break;
- }
- }
-
- for (PolicySchemaObj pol : par.getPolicy_schema()) {
- if (pol.getEntry_schema() != null) {
- PolicyProperties prop = new PolicyProperties();
- prop.setType("map");
- HashMap<String, String> schema = new HashMap();
- schema.put("type", "onap.datatypes." + pol.getName());
-// prop.setType("list");
-// ArrayList<String> schema = new ArrayList();
-// schema.add("type: onap.data." + pol.getName());
- prop.setEntry_schema(schema);
- properties.put(pol.getName(), prop);
- dataType = translateEntrySchema(dataType, pol.getEntry_schema(), pol.getName());
- } else {
- PolicyProperties prop = new PolicyProperties();
- prop.setType(pol.getType());
- properties.put(pol.getName(), prop);
- }
- }
-
- node.setProperties(properties);
- dataType.put("onap.datatypes." + param, node);
- return dataType;
- }
-
- private TreeMap<String, PolicyModelNode> translateEntrySchema(TreeMap<String, PolicyModelNode> dataType,
- EntrySchemaObj[] entry, String name) {
- TreeMap<String, PolicyModelNode> data = dataType;
- PolicyModelNode node = new PolicyModelNode();
- node.setDerived_from(TOSCA_NODES_ROOT);
- TreeMap<String, PolicyProperties> properties = new TreeMap<String, PolicyProperties>();
-
- for (EntrySchemaObj e : entry) {
- if (e.getEntry_schema() != null) {
- PolicyProperties prop = new PolicyProperties();
- prop.setType("list");
- ArrayList<String> schema = new ArrayList<String>();
- schema.add("type: onap.datatypes." + e.getName());
- prop.setEntry_schema(schema);
- properties.put(e.getName(), prop);
- data = translateEntrySchema(data, e.getEntry_schema(), e.getName());
- node.setProperties(properties);
- } else {
- PolicyProperties prop = new PolicyProperties();
- prop.setType(e.getType());
- properties.put(e.getName(), prop);
- node.setProperties(properties);
- }
- }
-
- dataType.put("onap.datatypes." + name, node);
- return data;
- }
-
-}
diff --git a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyProperties.java b/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyProperties.java
deleted file mode 100644
index 6faf78d..0000000
--- a/mod/bpgenerator/src/main/java/org/onap/blueprintgenerator/models/policymodel/PolicyProperties.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**============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=========================================================
-
-*/
-
-package org.onap.blueprintgenerator.models.policymodel;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.TreeMap;
-
-import org.onap.blueprintgenerator.models.blueprint.Node;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-
-import lombok.Getter;
-import lombok.Setter;
-
-@Getter @Setter
-@JsonInclude(JsonInclude.Include.NON_NULL)
-public class PolicyProperties {
-
- private String type;
- private Object entry_schema;
-
-}