X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ONAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Frest%2Futil%2FMSModelUtils.java;h=3880b35d844a700fe580f3de80317200f5581753;hp=fa2c51d18d329db7b942f002ba5a9c5f1b9f1bfa;hb=401b48bc573561f097960a9ca7abe6d788456f28;hpb=9301fed7c290f52208922f780fdfe4b5a880b5aa diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java index fa2c51d18..3880b35d8 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/MSModelUtils.java @@ -86,7 +86,7 @@ public class MSModelUtils { }; - public HashMap processEpackage(String file, MODEL_TYPE model){ + public Map processEpackage(String file, MODEL_TYPE model){ if (model == MODEL_TYPE.XMI ){ processXMIEpackage(file); } @@ -97,8 +97,8 @@ public class MSModelUtils { private void processXMIEpackage(String xmiFile){ EPackage root = getEpackage(xmiFile); TreeIterator treeItr = root.eAllContents(); - String className = null; - String returnValue = null; + String className; + String returnValue; // Pulling out dependency from file while (treeItr.hasNext()) { @@ -151,15 +151,13 @@ public class MSModelUtils { private void UpdateMatching(HashMap tempAttribute, String key) { - Map newClass = null; - - newClass = classMap; + Map newClass = classMap; for (Entry updateClass : newClass.entrySet()){ - HashMap valueMap = updateClass.getValue().getMatchingSet(); + Map valueMap = updateClass.getValue().getMatchingSet(); String keymap = updateClass.getKey(); if (valueMap.containsKey(key)){ - HashMap modifyMap = classMap.get(keymap).getMatchingSet(); + Map modifyMap = classMap.get(keymap).getMatchingSet(); modifyMap.remove(key); modifyMap.putAll(tempAttribute); classMap.get(keymap).setMatchingSet(modifyMap); @@ -181,7 +179,7 @@ public class MSModelUtils { m.put("xmi", new XMIResourceFactoryImpl()); Resource resource = resSet.getResource(URI.createFileURI(xmiFile), true); try { - resource.load(Collections.EMPTY_MAP); + resource.load(Collections.emptyMap()); } catch (IOException e) { logger.error("Error loading Encore Resource for new Model" + e); } @@ -210,14 +208,14 @@ public class MSModelUtils { public void getAttributes(String className, String dependency, EPackage root) { List dpendList = new ArrayList<>(); if (dependency!=null){ - dpendList = new ArrayList(Arrays.asList(dependency.split(","))); + dpendList = new ArrayList<>(Arrays.asList(dependency.split(","))); } MSAttributeObject msAttributeObject = new MSAttributeObject(); msAttributeObject.setClassName(className); String extendClass = getSubTypes(root, className); - HashMap returnRefList = getRefAttributeList(root, className, extendClass); - HashMap returnAttributeList = getAttributeList(root, className, extendClass); - HashMap returnSubList = getSubAttributeList(root, className, extendClass); + Map returnRefList = getRefAttributeList(root, className, extendClass); + Map returnAttributeList = getAttributeList(root, className, extendClass); + Map returnSubList = getSubAttributeList(root, className, extendClass); HashMap returnAnnotation = getAnnotation(root, className, extendClass); msAttributeObject.setAttribute(returnAttributeList); msAttributeObject.setRefAttribute(returnRefList); @@ -234,9 +232,9 @@ public class MSModelUtils { boolean requiredAttribute = false; boolean requiredMatchAttribute = false; HashMap annotationSet = new HashMap<>(); - String matching = null; - String range = null; - String dictionary = null; + String matching; + String range; + String dictionary; // Pulling out dependency from file while (treeItr.hasNext()) { @@ -249,7 +247,7 @@ public class MSModelUtils { if (requiredAttribute){ if (obj instanceof EStructuralFeature) { EStructuralFeature eStrucClassifier = (EStructuralFeature) obj; - if (eStrucClassifier.getEAnnotations().size() != 0) { + if (!eStrucClassifier.getEAnnotations().isEmpty()) { matching = annotationValue(eStrucClassifier, ANNOTATION_TYPE.MATCHING, policy); if (matching!=null){ annotationSet.put(eStrucClassifier.getName(), matching); @@ -267,7 +265,7 @@ public class MSModelUtils { } else if (requiredMatchAttribute){ if (obj instanceof EStructuralFeature) { EStructuralFeature eStrucClassifier = (EStructuralFeature) obj; - if (eStrucClassifier.getEAnnotations().size() != 0) { + if (!eStrucClassifier.getEAnnotations().isEmpty()) { matching = annotationValue(eStrucClassifier, ANNOTATION_TYPE.MATCHING, policy); if (matching!=null){ if (obj instanceof EReference){ @@ -285,13 +283,13 @@ public class MSModelUtils { return annotationSet; } - private HashMap getSubAttributeList(EPackage root, String className , String superClass) { + private Map getSubAttributeList(EPackage root, String className , String superClass) { TreeIterator treeItr = root.eAllContents(); boolean requiredAttribute = false; - HashMap subAttribute = new HashMap(); + Map subAttribute = new HashMap<>(); int rollingCount = 0; int processClass = 0; - boolean annotation = false; + boolean annotation; // Pulling out dependency from file while (treeItr.hasNext() && rollingCount < 2) { @@ -312,7 +310,7 @@ public class MSModelUtils { if (requiredAttribute) { if (obj instanceof EStructuralFeature) { EStructuralFeature eStrucClassifier = (EStructuralFeature) obj; - if (eStrucClassifier.getEAnnotations().size() != 0) { + if (!eStrucClassifier.getEAnnotations().isEmpty()) { annotation = annotationTest(eStrucClassifier, configuration, onap); if (annotation && obj instanceof EReference) { EClass refType = ((EReference) obj).getEReferenceType(); @@ -348,7 +346,7 @@ public class MSModelUtils { return ":required-false"; } - public JSONObject buildJavaObject(HashMap map, String attributeType){ + public JSONObject buildJavaObject(Map map){ JSONObject returnValue = new JSONObject(map); @@ -356,14 +354,14 @@ public class MSModelUtils { } - public HashMap getRefAttributeList(EPackage root, String className, String superClass){ + public Map getRefAttributeList(EPackage root, String className, String superClass){ TreeIterator treeItr = root.eAllContents(); boolean requiredAttribute = false; HashMap refAttribute = new HashMap<>(); int rollingCount = 0; int processClass = 0; - boolean annotation = false; + boolean annotation; // Pulling out dependency from file while (treeItr.hasNext()) { EObject obj = treeItr.next(); @@ -382,7 +380,7 @@ public class MSModelUtils { if (requiredAttribute) { if (obj instanceof EStructuralFeature) { EStructuralFeature eStrucClassifier = (EStructuralFeature) obj; - if (eStrucClassifier.getEAnnotations().size() != 0) { + if (!eStrucClassifier.getEAnnotations().isEmpty()) { annotation = annotationTest(eStrucClassifier, configuration, onap); if ( annotation && obj instanceof EReference) { EClass refType = ((EReference) obj).getEReferenceType(); @@ -408,10 +406,10 @@ public class MSModelUtils { } private boolean annotationTest(EStructuralFeature eStrucClassifier, String annotation, String type) { - String annotationType = null; - EAnnotation eAnnotation = null; - String onapType = null; - String onapValue = null; + String annotationType; + EAnnotation eAnnotation; + String onapType; + String onapValue; EList value = eStrucClassifier.getEAnnotations(); @@ -432,9 +430,9 @@ public class MSModelUtils { private String annotationValue(EStructuralFeature eStrucClassifier, ANNOTATION_TYPE annotation, String type) { - String annotationType = null; - EAnnotation eAnnotation = null; - String onapType = null; + String annotationType; + EAnnotation eAnnotation; + String onapType; String onapValue = null; EList value = eStrucClassifier.getEAnnotations(); @@ -501,15 +499,15 @@ public class MSModelUtils { return returnSubTypes; } - public HashMap getAttributeList(EPackage root, String className, String superClass){ + public Map getAttributeList(EPackage root, String className, String superClass){ TreeIterator treeItr = root.eAllContents(); boolean requiredAttribute = false; HashMap refAttribute = new HashMap<>(); - boolean annotation = false; - boolean dictionaryTest = false; - String defaultValue = null; - String eType = null; + boolean annotation; + boolean dictionaryTest; + String defaultValue; + String eType; // Pulling out dependency from file while (treeItr.hasNext()) { @@ -526,7 +524,7 @@ public class MSModelUtils { if (requiredAttribute){ if (obj instanceof EStructuralFeature) { EStructuralFeature eStrucClassifier = (EStructuralFeature) obj; - if (eStrucClassifier.getEAnnotations().size() != 0) { + if (!eStrucClassifier.getEAnnotations().isEmpty()) { annotation = annotationTest(eStrucClassifier, configuration, onap); dictionaryTest = annotationTest(eStrucClassifier, dictionary, policy); EClassifier refType = ((EStructuralFeature) obj).getEType(); @@ -578,9 +576,9 @@ public class MSModelUtils { return returnValue; } - public Map buildSubList(HashMap subClassAttributes, HashMap classMap, String className){ + public Map buildSubList(Map subClassAttributes, Map classMap, String className){ Map missingValues = new HashMap<>(); - Map workingMap = new HashMap<>(); + Map workingMap; boolean enumType; for ( Entry map : classMap.get(className).getRefAttribute().entrySet()){ @@ -604,10 +602,10 @@ public class MSModelUtils { return missingValues; } - public Map> recursiveReference(HashMap classMap, String className){ + public Map> recursiveReference(Map classMap, String className){ - Map> returnObject = new HashMap<>(); - HashMap returnClass = getRefclass(classMap, className); + Map> returnObject = new HashMap<>(); + Map returnClass = getRefclass(classMap, className); returnObject.put(className, returnClass); for (Entry reAttribute :returnClass.entrySet()){ if (reAttribute.getValue().split(":")[1].contains("MANY")){ @@ -622,16 +620,16 @@ public class MSModelUtils { } - public String createJson(HashMap subClassAttributes, HashMap classMap, String className) { + public String createJson(Map subClassAttributes, Map classMap, String className) { boolean enumType; - Map> myObject = new HashMap<>(); + Map> myObject = new HashMap<>(); for ( Entry map : classMap.get(className).getRefAttribute().entrySet()){ String value = map.getValue().split(":")[0]; if (value!=null){ enumType = classMap.get(className).getEnumType().containsKey(value); if (!enumType){ if (map.getValue().split(":")[1].contains("MANY")){ - Map> testRecursive = recursiveReference(classMap, map.getValue().split(":")[0] ); + Map> testRecursive = recursiveReference(classMap, map.getValue().split(":")[0] ); myObject.putAll(testRecursive); } } @@ -644,7 +642,7 @@ public class MSModelUtils { return json; } - public HashMap getRefclass(HashMap classMap, String className){ + public Map getRefclass(Map classMap, String className){ HashMap missingValues = new HashMap<>(); if (classMap.get(className).getAttribute()!=null || !classMap.get(className).getAttribute().isEmpty()){ @@ -658,12 +656,12 @@ public class MSModelUtils { return missingValues; } - public String createSubAttributes(ArrayList dependency, HashMap classMap, String modelName) { + public String createSubAttributes(List dependency, Map classMap, String modelName) { HashMap workingMap = new HashMap<>(); - MSAttributeObject tempObject = new MSAttributeObject(); + MSAttributeObject tempObject; if (dependency!=null){ - if (dependency.size()==0){ + if (dependency.isEmpty()){ return "{}"; } dependency.add(modelName); @@ -679,15 +677,15 @@ public class MSModelUtils { return returnValue; } - public ArrayList getFullDependencyList(ArrayList dependency, HashMap classMap) { + public List getFullDependencyList(List dependency, Map classMap) { ArrayList returnList = new ArrayList<>(); - ArrayList workingList = new ArrayList<>(); + ArrayList workingList; returnList.addAll(dependency); for (String element : dependency ){ if (classMap.containsKey(element)){ MSAttributeObject value = classMap.get(element); String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""}); - workingList = new ArrayList(Arrays.asList(rawValue.split(","))); + workingList = new ArrayList<>(Arrays.asList(rawValue.split(","))); for(String depend : workingList){ if (!returnList.contains(depend) && !depend.isEmpty()){ returnList.add(depend.trim());