-
- if(parameters.getPolicyClass()!=null && !"Config".equals(parameters.getPolicyClass().toString())){
-
- policyData.setPolicyType(parameters.getPolicyClass().toString());
-
- //Get Matching attribute values
- Map<AttributeType, Map<String, String>> attributes = parameters.getAttributes();
- Map<String, String> matching = null;
- if(attributes != null){
- matching = attributes.get(AttributeType.MATCHING);
- }
-
- if("Decision".equals(parameters.getPolicyClass().toString())){
-
- String ruleProvider = parameters.getRuleProvider().toString();
- policyData.setRuleProvider(ruleProvider);
-
- if("Rainy_Day".equals(ruleProvider)){
-
- // Set Matching attributes in RainyDayParams in adapter
- RainyDayParams rainyday = new RainyDayParams();
-
- if(matching != null) {
- rainyday.setServiceType(matching.get("ServiceType"));
- rainyday.setVnfType(matching.get("VNFType"));
- rainyday.setBbid(matching.get("BB_ID"));
- rainyday.setWorkstep(matching.get("WorkStep"));
- }
-
- Map<String, String> treatments = parameters.getTreatments();
- ArrayList<Object> treatmentsTableChoices = new ArrayList<>();
-
- for (String keyField : treatments.keySet()) {
- LinkedHashMap<String, String> treatmentMap = new LinkedHashMap<>();
- String errorcode = keyField;
- String treatment = treatments.get(errorcode);
- treatmentMap.put("errorcode", errorcode);
- treatmentMap.put("treatment", treatment);
- treatmentsTableChoices.add(treatmentMap);
- }
- rainyday.setTreatmentTableChoices(treatmentsTableChoices);
- policyData.setRainyday(rainyday);
-
- }else if("GUARD_YAML".equals(ruleProvider) || "GUARD_BL_YAML".equals(ruleProvider)) {
-
- // Set Matching attributes in YAMLParams in adapter
- YAMLParams yamlparams = new YAMLParams();
-
- if (matching != null) {
- yamlparams.setActor(matching.get("actor"));
- yamlparams.setRecipe(matching.get("recipe"));
- yamlparams.setGuardActiveStart(matching.get("guardActiveStart"));
- yamlparams.setGuardActiveEnd(matching.get("guardActiveEnd"));
-
- if("GUARD_YAML".equals(ruleProvider)){
- yamlparams.setLimit(matching.get("limit"));
- yamlparams.setTimeWindow(matching.get("timeWindow"));
- yamlparams.setTimeUnits(matching.get("timeUnits"));
- }else{
-
- List<String> blackList = new ArrayList<>();
-
- if(!Strings.isNullOrEmpty(matching.get("blackList"))){
- String[] blackListArray = matching.get("blackList").split(",");
- for(String element : blackListArray){
- blackList.add(element);
- }
- }
-
- yamlparams.setBlackList(blackList);
-
- }
- }
- policyData.setYamlparams(yamlparams);
- }
-
- } else if("Action".equals(parameters.getPolicyClass().toString())){
-
- ArrayList<Object> ruleAlgorithmChoices = new ArrayList<>();
-
- List<String> dynamicLabelRuleAlgorithms = parameters.getDynamicRuleAlgorithmLabels();
- List<String> dynamicFieldFunctionRuleAlgorithms = parameters.getDynamicRuleAlgorithmFunctions();
- List<String> dynamicFieldOneRuleAlgorithms = parameters.getDynamicRuleAlgorithmField1();
- List<String> dyrnamicFieldTwoRuleAlgorithms = parameters.getDynamicRuleAlgorithmField2();
-
- if (dynamicLabelRuleAlgorithms != null && !dynamicLabelRuleAlgorithms.isEmpty()) {
- int i = dynamicLabelRuleAlgorithms.size() - 1;
-
- for (String labelAttr : dynamicLabelRuleAlgorithms) {
- LinkedHashMap<String, String> ruleAlgorithm = new LinkedHashMap<>();
-
- String id = dynamicLabelRuleAlgorithms.get(i);
- String dynamicRuleAlgorithmField1 = dynamicFieldOneRuleAlgorithms.get(i);
- String dynamicRuleAlgorithmCombo = dynamicFieldFunctionRuleAlgorithms.get(i);
- String dynamicRuleAlgorithmField2 = dyrnamicFieldTwoRuleAlgorithms.get(i);
-
- ruleAlgorithm.put("id", id);
- ruleAlgorithm.put("dynamicRuleAlgorithmField1", dynamicRuleAlgorithmField1);
- ruleAlgorithm.put("dynamicRuleAlgorithmCombo", dynamicRuleAlgorithmCombo);
- ruleAlgorithm.put("dynamicRuleAlgorithmField2", dynamicRuleAlgorithmField2);
-
- ruleAlgorithmChoices.add(ruleAlgorithm);
-
- i--;
-
- }
- }
-
- policyData.setRuleAlgorithmschoices(ruleAlgorithmChoices);
-
- ArrayList<Object> attributeList = new ArrayList<>();
- if (matching != null) {
- for (String keyField : matching.keySet()) {
- LinkedHashMap<String, String> attributeMap = new LinkedHashMap<>();
- String key = keyField;
- String value = matching.get(keyField);
- attributeMap.put("key", key);
- attributeMap.put("value", value);
- attributeList.add(attributeMap);
- }
- }
-
- policyData.setAttributes(attributeList);
- policyData.setActionAttributeValue(parameters.getActionAttribute());
- policyData.setActionPerformer(parameters.getActionPerformer());
-
- }
- }else {
-
- policyData.setPolicyType("Config");
- policyData.setConfigPolicyType(parameters.getPolicyConfigType().toString());
-
- //Config Specific
- policyData.setConfigBodyData(parameters.getConfigBody()); //Base
- policyData.setConfigType((parameters.getConfigBodyType()!=null) ? parameters.getConfigBodyType().toString().toUpperCase(): null); //Base
-
- if("FW".equalsIgnoreCase(parameters.getPolicyConfigType().toString())){
-
- policyData.setConfigPolicyType("Firewall Config");
-
- // get values and attributes from the JsonObject
- if(json != null){
- if (json.get("securityZoneId")!=null){
- String securityZone = json.get("securityZoneId").toString().replace("\"", "");
- policyData.setSecurityZone(securityZone);
- }
- if (json.get(CONFIG_NAME)!=null){
- String configName = json.get(CONFIG_NAME).toString().replace("\"", "");
- policyData.setConfigName(configName);
- }
- }
-
- }else if("MS".equals(parameters.getPolicyConfigType().toString())){
-
- policyData.setConfigPolicyType("Micro Service");
-
- // get values and attributes from the JsonObject
- if(json != null){
- if (json.containsKey("content")){
- String content = json.get("content").toString();
- ObjectMapper mapper = new ObjectMapper();
- JsonNode policyJSON = null;
- try {
- policyJSON = mapper.readTree(content);
- } catch (IOException e) {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + parameters.getConfigBody();
- LOGGER.error(message, e);
- return null;
- }
- policyData.setPolicyJSON(policyJSON);
- }
- if (json.containsKey("service")){
- String serviceType = json.get("service").toString().replace("\"", "");
- policyData.setServiceType(serviceType);
- }
- if (json.containsKey("uuid")){
- String uuid = json.get("uuid").toString().replace("\"", "");
- policyData.setUuid(uuid);
- }
- if (json.containsKey("location")){
- String msLocation = json.get("location").toString().replace("\"", "");
- policyData.setMsLocation(msLocation);
- }
- if (json.containsKey(CONFIG_NAME)){
- String configName = json.get(CONFIG_NAME).toString().replace("\"", "");
- policyData.setConfigName(configName);
- }
- if(json.containsKey("priority")){
- String priority = json.get("priority").toString().replace("\"", "");
- policyData.setPriority(priority);
- }
- if(json.containsKey("version")){
- String version = json.get("version").toString().replace("\"", "");
- policyData.setVersion(version);
- }
- if(json.containsKey("policyScope")){
- String policyScope = json.get("policyScope").toString().replace("\"", "");
- policyData.setPolicyScope(policyScope);
- }
- if(json.containsKey("riskType")){
- String riskType = json.get("riskType").toString().replace("\"", "");
- policyData.setRiskType(riskType);
- }
- if(json.containsKey("riskLevel")){
- String riskLevel = json.get("riskLevel").toString().replace("\"", "");
- policyData.setRiskLevel(riskLevel);
- }
- if(json.containsKey("guard")){
- String guard = json.get("guard").toString().replace("\"", "");
- policyData.setGuard(guard);
- }
- } else {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + parameters.getConfigBody();
- LOGGER.error(message);
- return null;
- }
-
- } else if("Fault".equals(parameters.getPolicyConfigType().toString())){
-
- policyData.setConfigPolicyType("ClosedLoop_Fault");
- policyData.setApiflag("API");
-
- if(json != null){
- policyData.setJsonBody(json.toString());
- if (json.get("onapname")!=null){
- String onapName = json.get("onapname").toString().replace("\"", "");
- policyData.setOnapName(onapName);
- }
- }
-
- } else if("PM".equals(parameters.getPolicyConfigType().toString())){
-
- policyData.setConfigPolicyType("ClosedLoop_PM");
-
- if(json != null){
- policyData.setJsonBody(json.toString());
- if (json.get("onapname")!=null){
- String onapName = json.get("onapname").toString().replace("\"", "");
- policyData.setOnapName(onapName);
- }
- if (json.get("serviceTypePolicyName")!=null){
- String serviceType = json.get("serviceTypePolicyName").toString().replace("\"", "");
- LinkedHashMap<String, String> serviceTypePolicyName = new LinkedHashMap<>();
- serviceTypePolicyName.put("serviceTypePolicyName", serviceType);
- policyData.setServiceTypePolicyName(serviceTypePolicyName);
- }
- }
- } else if("BRMS_Param".equals(parameters.getPolicyConfigType().toString())){
- Map<AttributeType, Map<String, String>> drlRuleAndUIParams = parameters.getAttributes();
- Map<String, String> rule = drlRuleAndUIParams.get(AttributeType.RULE);
- policyData.setRuleName(rule.get("templateName"));
-
- }
- }
-
- return policyData;
-
- }
-
- private JsonObject stringToJsonObject(String value) {