- while (fieldsIterator.hasNext()) {
- Map.Entry<String, JsonNode> field = fieldsIterator.next();
- final String key = field.getKey();
- final JsonNode value = field.getValue();
- if (value.isContainerNode() && !value.isArray()) {
- pullMatchValue(value); // RECURSIVE CALL
- } else {
- newValue = StringUtils.replaceEach(value.toString(), new String[]{"[", "]", "\""}, new String[]{"", "", ""});
- mapAttribute.put(key, newValue);
- }
- }
-
- }
-
- private String getValueFromDictionary(String service){
- String ruleTemplate=null;
- String modelName = service.split("-v")[0];
- String modelVersion = service.split("-v")[1];
-
- CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
- List<Object> result = dbConnection.getDataById(OptimizationModels.class, "modelName:version", modelName+":"+modelVersion);
- if(result != null && !result.isEmpty()){
- OptimizationModels model = (OptimizationModels) result.get(0);
- ruleTemplate = model.getAnnotation();
- }
- return ruleTemplate;
- }
-
- // Data required for Advice part is setting here.
- private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
- AdviceExpressionsType advices = new AdviceExpressionsType();
- AdviceExpressionType advice = new AdviceExpressionType();
- advice.setAdviceId("OptimizationID");
- advice.setAppliesTo(EffectType.PERMIT);
-
- // For Configuration
- AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
- assignment1.setAttributeId("type");
- assignment1.setCategory(CATEGORY_RESOURCE);
- assignment1.setIssuer("");
-
- AttributeValueType configNameAttributeValue = new AttributeValueType();
- configNameAttributeValue.setDataType(STRING_DATATYPE);
- configNameAttributeValue.getContent().add("Configuration");
- assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
-
- advice.getAttributeAssignmentExpression().add(assignment1);
-
- // For Config file Url if configurations are provided.
- AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
- assignment2.setAttributeId("URLID");
- assignment2.setCategory(CATEGORY_RESOURCE);
- assignment2.setIssuer("");
-
- AttributeValueType attributeValue = new AttributeValueType();
- attributeValue.setDataType(URI_DATATYPE);
- String configName;
- if(policyName.endsWith(".xml")){
- configName = policyName.replace(".xml", "");
- }else{
- configName = policyName;
- }
- String content = CONFIG_URL +"/Config/" + configName + ".json";
- attributeValue.getContent().add(content);
- assignment2.setExpression(new ObjectFactory().createAttributeValue(attributeValue));
-
- advice.getAttributeAssignmentExpression().add(assignment2);
-
- //PolicyName Attribute Assignment
- AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
- assignment3.setAttributeId("PolicyName");
- assignment3.setCategory(CATEGORY_RESOURCE);
- assignment3.setIssuer("");
-
- AttributeValueType attributeValue3 = new AttributeValueType();
- attributeValue3.setDataType(STRING_DATATYPE);
- fileName = FilenameUtils.removeExtension(fileName);
- fileName = fileName + ".xml";
- String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
- if ((name == null) || (name.equals(""))) {
- name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
- }
- attributeValue3.getContent().add(name);
- assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
- advice.getAttributeAssignmentExpression().add(assignment3);
-
- //VersionNumber Attribute Assignment
- AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
- assignment4.setAttributeId("VersionNumber");
- assignment4.setCategory(CATEGORY_RESOURCE);
- assignment4.setIssuer("");
-
- AttributeValueType configNameAttributeValue4 = new AttributeValueType();
- configNameAttributeValue4.setDataType(STRING_DATATYPE);
- configNameAttributeValue4.getContent().add(Integer.toString(version));
- assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
-
- advice.getAttributeAssignmentExpression().add(assignment4);
-
- //OnapName Attribute Assignment
- AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
- assignment5.setAttributeId("matching:" + ONAPID);
- assignment5.setCategory(CATEGORY_RESOURCE);
- assignment5.setIssuer("");
-
- AttributeValueType configNameAttributeValue5 = new AttributeValueType();
- configNameAttributeValue5.setDataType(STRING_DATATYPE);
- configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
- assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
-
- advice.getAttributeAssignmentExpression().add(assignment5);
-
- //ServiceType Attribute Assignment
+ while (fieldsIterator.hasNext()) {
+ Map.Entry<String, JsonNode> field = fieldsIterator.next();
+ final String key = field.getKey();
+ final JsonNode value = field.getValue();
+ if (value.isContainerNode() && !value.isArray()) {
+ pullMatchValue(value); // RECURSIVE CALL
+ } else {
+ newValue =
+ StringUtils.replaceEach(value.toString(), new String[] {"[", "]", "\""}, new String[] {"", "", ""});
+ mapAttribute.put(key, newValue);
+ }
+ }
+
+ }
+
+ private String getValueFromDictionary(String service) {
+ String ruleTemplate = null;
+ String modelName = service.split("-v")[0];
+ String modelVersion = service.split("-v")[1];
+
+ CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
+ List<Object> result =
+ dbConnection.getDataById(OptimizationModels.class, "modelName:version", modelName + ":" + modelVersion);
+ if (result != null && !result.isEmpty()) {
+ OptimizationModels model = (OptimizationModels) result.get(0);
+ ruleTemplate = model.getAnnotation();
+ }
+ return ruleTemplate;
+ }
+
+ // Data required for Advice part is setting here.
+ protected AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
+ AdviceExpressionsType advices = new AdviceExpressionsType();
+ AdviceExpressionType advice = new AdviceExpressionType();
+ advice.setAdviceId("OptimizationID");
+ advice.setAppliesTo(EffectType.PERMIT);
+
+ // For Configuration
+ AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
+ assignment1.setAttributeId("type");
+ assignment1.setCategory(CATEGORY_RESOURCE);
+ assignment1.setIssuer("");
+
+ AttributeValueType configNameAttributeValue = new AttributeValueType();
+ configNameAttributeValue.setDataType(STRING_DATATYPE);
+ configNameAttributeValue.getContent().add("Configuration");
+ assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
+
+ advice.getAttributeAssignmentExpression().add(assignment1);
+
+ // For Config file Url if configurations are provided.
+ AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
+ assignment2.setAttributeId("URLID");
+ assignment2.setCategory(CATEGORY_RESOURCE);
+ assignment2.setIssuer("");
+
+ AttributeValueType attributeValue = new AttributeValueType();
+ attributeValue.setDataType(URI_DATATYPE);
+ String configName;
+ if (policyName.endsWith(".xml")) {
+ configName = policyName.replace(".xml", "");
+ } else {
+ configName = policyName;
+ }
+ String content = CONFIG_URL + "/Config/" + configName + ".json";
+ attributeValue.getContent().add(content);
+ assignment2.setExpression(new ObjectFactory().createAttributeValue(attributeValue));
+
+ advice.getAttributeAssignmentExpression().add(assignment2);
+
+ // PolicyName Attribute Assignment
+ AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
+ assignment3.setAttributeId("PolicyName");
+ assignment3.setCategory(CATEGORY_RESOURCE);
+ assignment3.setIssuer("");
+
+ AttributeValueType attributeValue3 = new AttributeValueType();
+ attributeValue3.setDataType(STRING_DATATYPE);
+ fileName = FilenameUtils.removeExtension(fileName);
+ fileName = fileName + ".xml";
+ String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
+ if ((name == null) || (name.equals(""))) {
+ name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
+ }
+ attributeValue3.getContent().add(name);
+ assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
+ advice.getAttributeAssignmentExpression().add(assignment3);
+
+ // VersionNumber Attribute Assignment
+ AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
+ assignment4.setAttributeId("VersionNumber");
+ assignment4.setCategory(CATEGORY_RESOURCE);
+ assignment4.setIssuer("");
+
+ AttributeValueType configNameAttributeValue4 = new AttributeValueType();
+ configNameAttributeValue4.setDataType(STRING_DATATYPE);
+ configNameAttributeValue4.getContent().add(Integer.toString(version));
+ assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
+
+ advice.getAttributeAssignmentExpression().add(assignment4);
+
+ // OnapName Attribute Assignment
+ AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
+ assignment5.setAttributeId("matching:" + ONAPID);
+ assignment5.setCategory(CATEGORY_RESOURCE);
+ assignment5.setIssuer("");
+
+ AttributeValueType configNameAttributeValue5 = new AttributeValueType();
+ configNameAttributeValue5.setDataType(STRING_DATATYPE);
+ configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
+ assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
+
+ advice.getAttributeAssignmentExpression().add(assignment5);
+
+ // ServiceType Attribute Assignment