Fix checkstyle violations in sdc/jtosca
[sdc/sdc-tosca.git] / src / main / java / org / onap / sdc / toscaparser / api / SubstitutionMappings.java
index 1dec80a..a622a9a 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
@@ -39,55 +39,55 @@ public class SubstitutionMappings {
     // SubstitutionMappings exports the topology template as an
     // implementation of a Node type.
 
-       private static final String NODE_TYPE = "node_type";
-       private static final String REQUIREMENTS = "requirements";
-       private static final String CAPABILITIES = "capabilities";
-
-       private static final String SECTIONS[] = {NODE_TYPE, REQUIREMENTS, CAPABILITIES};
-
-       private static final String OPTIONAL_OUTPUTS[] = {"tosca_id", "tosca_name", "state"};
-       
-       private LinkedHashMap<String,Object> subMappingDef;
-       private ArrayList<NodeTemplate> nodetemplates;
-       private ArrayList<Input> inputs;
-       private ArrayList<Output> outputs;
-       private ArrayList<Group> groups;
-       private NodeTemplate subMappedNodeTemplate;
-       private LinkedHashMap<String,Object> customDefs;
-       private LinkedHashMap<String,Object> _capabilities;
-       private LinkedHashMap<String,Object> _requirements;
-       
-       public SubstitutionMappings(LinkedHashMap<String,Object> smsubMappingDef,
-                                                               ArrayList<NodeTemplate> smnodetemplates,
-                                                               ArrayList<Input> sminputs,
-                                                               ArrayList<Output> smoutputs,
-                                                               ArrayList<Group> smgroups,
-                                                               NodeTemplate smsubMappedNodeTemplate,
-                                                               LinkedHashMap<String,Object> smcustomDefs) {
-               
+    private static final String NODE_TYPE = "node_type";
+    private static final String REQUIREMENTS = "requirements";
+    private static final String CAPABILITIES = "capabilities";
+
+    private static final String SECTIONS[] = {NODE_TYPE, REQUIREMENTS, CAPABILITIES};
+
+    private static final String OPTIONAL_OUTPUTS[] = {"tosca_id", "tosca_name", "state"};
+
+    private LinkedHashMap<String, Object> subMappingDef;
+    private ArrayList<NodeTemplate> nodetemplates;
+    private ArrayList<Input> inputs;
+    private ArrayList<Output> outputs;
+    private ArrayList<Group> groups;
+    private NodeTemplate subMappedNodeTemplate;
+    private LinkedHashMap<String, Object> customDefs;
+    private LinkedHashMap<String, Object> _capabilities;
+    private LinkedHashMap<String, Object> _requirements;
+
+    public SubstitutionMappings(LinkedHashMap<String, Object> smsubMappingDef,
+                                ArrayList<NodeTemplate> smnodetemplates,
+                                ArrayList<Input> sminputs,
+                                ArrayList<Output> smoutputs,
+                                ArrayList<Group> smgroups,
+                                NodeTemplate smsubMappedNodeTemplate,
+                                LinkedHashMap<String, Object> smcustomDefs) {
+
         subMappingDef = smsubMappingDef;
         nodetemplates = smnodetemplates;
         inputs = sminputs != null ? sminputs : new ArrayList<Input>();
         outputs = smoutputs != null ? smoutputs : new ArrayList<Output>();
         groups = smgroups != null ? smgroups : new ArrayList<Group>();
         subMappedNodeTemplate = smsubMappedNodeTemplate;
-        customDefs = smcustomDefs != null ? smcustomDefs : new LinkedHashMap<String,Object>();
+        customDefs = smcustomDefs != null ? smcustomDefs : new LinkedHashMap<String, Object>();
         _validate();
 
         _capabilities = null;
         _requirements = null;
-       }
-
-       public String getType() {
-               if(subMappingDef != null) {
-                       return (String)subMappingDef.get(NODE_TYPE);
-               }
-               return null;
-       }
-       
-       public ArrayList<NodeTemplate> getNodeTemplates() {
-               return nodetemplates;
-       }
+    }
+
+    public String getType() {
+        if (subMappingDef != null) {
+            return (String) subMappingDef.get(NODE_TYPE);
+        }
+        return null;
+    }
+
+    public ArrayList<NodeTemplate> getNodeTemplates() {
+        return nodetemplates;
+    }
 
        /*
     @classmethod
@@ -95,39 +95,39 @@ public class SubstitutionMappings {
         if isinstance(sub_mapping_def, dict):
             return sub_mapping_def.get(cls.NODE_TYPE)
        */
-       
-       public static String stGetNodeType(LinkedHashMap<String,Object> _subMappingDef) {
-               if(_subMappingDef instanceof LinkedHashMap) {
-                       return (String)_subMappingDef.get(NODE_TYPE);
-               }
-               return null;
-       }
-
-       public String getNodeType() {
-        return (String)subMappingDef.get(NODE_TYPE);
-       }
-       
-       public ArrayList<Input> getInputs() {
-               return inputs;
-       }
-       
-       public ArrayList<Group> getGroups() {
-               return groups;
-       }
-       
-       public LinkedHashMap<String,Object> getCapabilities() {
-               return (LinkedHashMap<String,Object>)subMappingDef.get(CAPABILITIES);
-       }
-
-       public LinkedHashMap<String,Object> getRequirements() {
-               return (LinkedHashMap<String,Object>)subMappingDef.get(REQUIREMENTS);
-       }
-
-       public NodeType getNodeDefinition() {
-               return new NodeType(getNodeType(), customDefs);
-       }
-
-       private void _validate() {
+
+    public static String stGetNodeType(LinkedHashMap<String, Object> _subMappingDef) {
+        if (_subMappingDef instanceof LinkedHashMap) {
+            return (String) _subMappingDef.get(NODE_TYPE);
+        }
+        return null;
+    }
+
+    public String getNodeType() {
+        return (String) subMappingDef.get(NODE_TYPE);
+    }
+
+    public ArrayList<Input> getInputs() {
+        return inputs;
+    }
+
+    public ArrayList<Group> getGroups() {
+        return groups;
+    }
+
+    public LinkedHashMap<String, Object> getCapabilities() {
+        return (LinkedHashMap<String, Object>) subMappingDef.get(CAPABILITIES);
+    }
+
+    public LinkedHashMap<String, Object> getRequirements() {
+        return (LinkedHashMap<String, Object>) subMappingDef.get(REQUIREMENTS);
+    }
+
+    public NodeType getNodeDefinition() {
+        return new NodeType(getNodeType(), customDefs);
+    }
+
+    private void _validate() {
         // Basic validation
         _validateKeys();
         _validateType();
@@ -137,149 +137,149 @@ public class SubstitutionMappings {
         _validateCapabilities();
         _validateRequirements();
         _validateOutputs();
-       }
-       
-       private void _validateKeys() {
-               // validate the keys of substitution mappings
-               for(String key: subMappingDef.keySet()) {
-                       boolean bFound = false;
-                       for(String s: SECTIONS) {
-                               if(s.equals(key)) {
-                                       bFound = true;
-                                       break;
-                               }
-                       }
-                       if(!bFound) {
-                   ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE232", String.format(
-                       "UnknownFieldError: SubstitutionMappings contain unknown field \"%s\"",
-                       key))); 
-                       }
-               }
-       }
-
-       private void _validateType() {
+    }
+
+    private void _validateKeys() {
+        // validate the keys of substitution mappings
+        for (String key : subMappingDef.keySet()) {
+            boolean bFound = false;
+            for (String s : SECTIONS) {
+                if (s.equals(key)) {
+                    bFound = true;
+                    break;
+                }
+            }
+            if (!bFound) {
+                ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE232", String.format(
+                        "UnknownFieldError: SubstitutionMappings contain unknown field \"%s\"",
+                        key)));
+            }
+        }
+    }
+
+    private void _validateType() {
         // validate the node_type of substitution mappings
-        String nodeType = (String)subMappingDef.get(NODE_TYPE);
-        if(nodeType == null) {
+        String nodeType = (String) subMappingDef.get(NODE_TYPE);
+        if (nodeType == null) {
             ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE233", String.format(
-                "MissingRequiredFieldError: SubstitutionMappings used in topology_template is missing required field \"%s\"",
-                NODE_TYPE))); 
+                    "MissingRequiredFieldError: SubstitutionMappings used in topology_template is missing required field \"%s\"",
+                    NODE_TYPE)));
         }
         Object nodeTypeDef = customDefs.get(nodeType);
-        if(nodeTypeDef == null) {
+        if (nodeTypeDef == null) {
             ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE234", String.format(
-                "InvalidNodeTypeError: \"%s\" is invalid",nodeType))); 
+                    "InvalidNodeTypeError: \"%s\" is invalid", nodeType)));
         }
-       }
+    }
 
-       private void _validateInputs() {
+    private void _validateInputs() {
         // validate the inputs of substitution mappings.
 
         // The inputs defined by the topology template have to match the
         // properties of the node type or the substituted node. If there are
         // more inputs than the substituted node has properties, default values
         //must be defined for those inputs.
-               
-               HashSet<String> allInputs = new HashSet<>();
-               for(Input inp: inputs) {
-                       allInputs.add(inp.getName());
-               }
-               HashSet<String> requiredProperties = new HashSet<>();
-               for(PropertyDef pd: getNodeDefinition().getPropertiesDefObjects()) {
-                       if(pd.isRequired() && pd.getDefault() == null) {
-                               requiredProperties.add(pd.getName());
-                       }
-               }
+
+        HashSet<String> allInputs = new HashSet<>();
+        for (Input inp : inputs) {
+            allInputs.add(inp.getName());
+        }
+        HashSet<String> requiredProperties = new HashSet<>();
+        for (PropertyDef pd : getNodeDefinition().getPropertiesDefObjects()) {
+            if (pd.isRequired() && pd.getDefault() == null) {
+                requiredProperties.add(pd.getName());
+            }
+        }
         // Must provide inputs for required properties of node type.
-        for(String property: requiredProperties) {
+        for (String property : requiredProperties) {
             // Check property which is 'required' and has no 'default' value
-            if(!allInputs.contains(property)) {
+            if (!allInputs.contains(property)) {
                 ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE235", String.format(
-                    "MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing required input \"%s\"",
-                    getNodeType(),property))); 
+                        "MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing required input \"%s\"",
+                        getNodeType(), property)));
             }
         }
         // If the optional properties of node type need to be customized by
         // substituted node, it also is necessary to define inputs for them,
         // otherwise they are not mandatory to be defined.
-         HashSet<String> customizedParameters = new HashSet<>();
-         if(subMappedNodeTemplate != null) {
-                customizedParameters.addAll(subMappedNodeTemplate.getProperties().keySet());
-         }
-         HashSet<String> allProperties = new HashSet<String>(
-                        getNodeDefinition().getPropertiesDef().keySet());
-         HashSet<String> diffset = customizedParameters;
-         diffset.removeAll(allInputs);
-         for(String parameter: diffset) {
-                if(allProperties.contains(parameter)) {
-                 ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE236", String.format(
-                     "MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing required input \"%s\"",
-                     getNodeType(),parameter))); 
-                }
-         }
-           // Additional inputs are not in the properties of node type must
-           // provide default values. Currently the scenario may not happen
-           // because of parameters validation in nodetemplate, here is a
-           // guarantee.
-           for(Input inp: inputs) {
-               diffset = allInputs;
-               diffset.removeAll(allProperties);
-               if(diffset.contains(inp.getName()) && inp.getDefault() == null) {
-                   ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE237", String.format(
-                            "MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing rquired input \"%s\"",
-                            getNodeType(),inp.getName()))); 
-               }
-           }
-       }
-       
-       private void _validateCapabilities() {
+        HashSet<String> customizedParameters = new HashSet<>();
+        if (subMappedNodeTemplate != null) {
+            customizedParameters.addAll(subMappedNodeTemplate.getProperties().keySet());
+        }
+        HashSet<String> allProperties = new HashSet<String>(
+                getNodeDefinition().getPropertiesDef().keySet());
+        HashSet<String> diffset = customizedParameters;
+        diffset.removeAll(allInputs);
+        for (String parameter : diffset) {
+            if (allProperties.contains(parameter)) {
+                ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE236", String.format(
+                        "MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing required input \"%s\"",
+                        getNodeType(), parameter)));
+            }
+        }
+        // Additional inputs are not in the properties of node type must
+        // provide default values. Currently the scenario may not happen
+        // because of parameters validation in nodetemplate, here is a
+        // guarantee.
+        for (Input inp : inputs) {
+            diffset = allInputs;
+            diffset.removeAll(allProperties);
+            if (diffset.contains(inp.getName()) && inp.getDefault() == null) {
+                ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE237", String.format(
+                        "MissingRequiredInputError: SubstitutionMappings with node_type \"%s\" is missing rquired input \"%s\"",
+                        getNodeType(), inp.getName())));
+            }
+        }
+    }
+
+    private void _validateCapabilities() {
         // validate the capabilities of substitution mappings
 
         // The capabilities must be in node template which be mapped.
-               LinkedHashMap<String,Object> tplsCapabilities = 
-                               (LinkedHashMap<String,Object>)subMappingDef.get(CAPABILITIES);
-               List<CapabilityAssignment> nodeCapabilities = null;
-               if(subMappedNodeTemplate != null) {
-                       nodeCapabilities = subMappedNodeTemplate.getCapabilities().getAll();
-               }
-               if(nodeCapabilities != null) {
-                       for(CapabilityAssignment cap: nodeCapabilities) {
-                               if(tplsCapabilities != null && tplsCapabilities.get(cap.getName()) == null) {
-                       ; //pass
-                       // ValidationIssueCollector.appendException(
-                       //    UnknownFieldError(what='SubstitutionMappings',
-                       //                      field=cap))
-                               }
-                       }
-               }
-       }
-       private void _validateRequirements() {
+        LinkedHashMap<String, Object> tplsCapabilities =
+                (LinkedHashMap<String, Object>) subMappingDef.get(CAPABILITIES);
+        List<CapabilityAssignment> nodeCapabilities = null;
+        if (subMappedNodeTemplate != null) {
+            nodeCapabilities = subMappedNodeTemplate.getCapabilities().getAll();
+        }
+        if (nodeCapabilities != null) {
+            for (CapabilityAssignment cap : nodeCapabilities) {
+                if (tplsCapabilities != null && tplsCapabilities.get(cap.getName()) == null) {
+                    ; //pass
+                    // ValidationIssueCollector.appendException(
+                    //    UnknownFieldError(what='SubstitutionMappings',
+                    //                      field=cap))
+                }
+            }
+        }
+    }
+
+    private void _validateRequirements() {
         // validate the requirements of substitution mappings
-               //*****************************************************
-               //TO-DO - Different from Python code!! one is a bug...
-               //*****************************************************
+        //*****************************************************
+        //TO-DO - Different from Python code!! one is a bug...
+        //*****************************************************
         // The requirements must be in node template which be mapped.
-               LinkedHashMap<String,Object> tplsRequirements = 
-                               (LinkedHashMap<String,Object>)subMappingDef.get(REQUIREMENTS);
-               List<RequirementAssignment> nodeRequirements = null;
-               if(subMappedNodeTemplate != null) {
-                       nodeRequirements = subMappedNodeTemplate.getRequirements().getAll();
-               }
-               if(nodeRequirements != null) {
-                       for(RequirementAssignment ro: nodeRequirements) {
-                               String cap = ro.getName();
-                               if(tplsRequirements != null && tplsRequirements.get(cap) == null) {
-                       ; //pass
-                       // ValidationIssueCollector.appendException(
-                       //    UnknownFieldError(what='SubstitutionMappings',
-                       //                      field=cap))
-                               }
-                       }
-               }
-       }
-       
-       private void _validateOutputs() {
+        LinkedHashMap<String, Object> tplsRequirements =
+                (LinkedHashMap<String, Object>) subMappingDef.get(REQUIREMENTS);
+        List<RequirementAssignment> nodeRequirements = null;
+        if (subMappedNodeTemplate != null) {
+            nodeRequirements = subMappedNodeTemplate.getRequirements().getAll();
+        }
+        if (nodeRequirements != null) {
+            for (RequirementAssignment ro : nodeRequirements) {
+                String cap = ro.getName();
+                if (tplsRequirements != null && tplsRequirements.get(cap) == null) {
+                    ; //pass
+                    // ValidationIssueCollector.appendException(
+                    //    UnknownFieldError(what='SubstitutionMappings',
+                    //                      field=cap))
+                }
+            }
+        }
+    }
+
+    private void _validateOutputs() {
         // validate the outputs of substitution mappings.
 
         // The outputs defined by the topology template have to match the
@@ -292,46 +292,46 @@ public class SubstitutionMappings {
         // attributes of the node type according to the specification, but
         // it's reasonable that there are more inputs than the node type
         // has properties, the specification will be amended?
-               
-        for(Output output: outputs) {
-               Object ado = getNodeDefinition().getAttributesDef();
-               if(ado != null && ((LinkedHashMap<String,Object>)ado).get(output.getName()) == null) {
+
+        for (Output output : outputs) {
+            Object ado = getNodeDefinition().getAttributesDef();
+            if (ado != null && ((LinkedHashMap<String, Object>) ado).get(output.getName()) == null) {
                 ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE238", String.format(
-                    "UnknownOutputError: Unknown output \"%s\" in SubstitutionMappings with node_type \"%s\"",
-                    output.getName(),getNodeType()))); 
-               }
+                        "UnknownOutputError: Unknown output \"%s\" in SubstitutionMappings with node_type \"%s\"",
+                        output.getName(), getNodeType())));
+            }
         }
-       }
+    }
 
-       @Override
-       public String toString() {
-               return "SubstitutionMappings{" +
+    @Override
+    public String toString() {
+        return "SubstitutionMappings{" +
 //                             "subMappingDef=" + subMappingDef +
 //                             ", nodetemplates=" + nodetemplates +
 //                             ", inputs=" + inputs +
 //                             ", outputs=" + outputs +
 //                             ", groups=" + groups +
-                               ", subMappedNodeTemplate=" + (subMappedNodeTemplate==null?"":subMappedNodeTemplate.getName()) +
+                ", subMappedNodeTemplate=" + (subMappedNodeTemplate == null ? "" : subMappedNodeTemplate.getName()) +
 //                             ", customDefs=" + customDefs +
 //                             ", _capabilities=" + _capabilities +
 //                             ", _requirements=" + _requirements +
-                               '}';
-       }
-
-       @Deprecated
-       public String toLimitedString() {
-               return "SubstitutionMappings{" +
-                               "subMappingDef=" + subMappingDef +
-                               ", nodetemplates=" + nodetemplates +
-                               ", inputs=" + inputs +
-                               ", outputs=" + outputs +
-                               ", groups=" + groups +
-                               ", subMappedNodeTemplate=" + (subMappedNodeTemplate==null?"":subMappedNodeTemplate.getName()) +
-                               ", customDefs=" + customDefs +
-                               ", _capabilities=" + _capabilities +
-                               ", _requirements=" + _requirements +
-                               '}';
-       }
+                '}';
+    }
+
+    @Deprecated
+    public String toLimitedString() {
+        return "SubstitutionMappings{" +
+                "subMappingDef=" + subMappingDef +
+                ", nodetemplates=" + nodetemplates +
+                ", inputs=" + inputs +
+                ", outputs=" + outputs +
+                ", groups=" + groups +
+                ", subMappedNodeTemplate=" + (subMappedNodeTemplate == null ? "" : subMappedNodeTemplate.getName()) +
+                ", customDefs=" + customDefs +
+                ", _capabilities=" + _capabilities +
+                ", _requirements=" + _requirements +
+                '}';
+    }
 }