-
- // Match for policyName
- allOfOne.getMatch().add(createMatch("PolicyName", name));
-
- AllOfType allOf = new AllOfType();
-
- // Adding the matches to AllOfType element Match for Onap
- allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
- if (matchMap==null || matchMap.isEmpty()){
- // Match for ConfigName
- allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
- // Match for Service
- allOf.getMatch().add(createDynamicMatch("service", policyAdapter.getServiceType()));
- // Match for uuid
- allOf.getMatch().add(createDynamicMatch("uuid", policyAdapter.getUuid()));
- // Match for location
- allOf.getMatch().add(createDynamicMatch("location", policyAdapter.getLocation()));
- }else {
- for (Entry<String, String> matchValue : matchMap.entrySet()){
- String value = matchValue.getValue();
- String key = matchValue.getKey().trim();
- if (value.contains("matching-true")){
- if (mapAttribute.containsKey(key)){
- allOf.getMatch().add(createDynamicMatch(key, mapAttribute.get(key)));
- }
- }
- }
- }
- // Match for riskType
- allOf.getMatch().add(
- createDynamicMatch("RiskType", policyAdapter.getRiskType()));
- // Match for riskLevel
- allOf.getMatch().add(
- createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
- // Match for riskguard
- allOf.getMatch().add(
- createDynamicMatch("guard", policyAdapter.getGuard()));
- // Match for ttlDate
- allOf.getMatch().add(
- createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
-
- AnyOfType anyOf = new AnyOfType();
- anyOf.getAllOf().add(allOfOne);
- anyOf.getAllOf().add(allOf);
-
- TargetType target = new TargetType();
- ((TargetType) target).getAnyOf().add(anyOf);
-
- // Adding the target to the policy element
- configPolicy.setTarget((TargetType) target);
-
- RuleType rule = new RuleType();
- rule.setRuleId(policyAdapter.getRuleID());
-
- rule.setEffect(EffectType.PERMIT);
-
- // Create Target in Rule
- AllOfType allOfInRule = new AllOfType();
-
- // Creating match for ACCESS in rule target
- MatchType accessMatch = new MatchType();
- AttributeValueType accessAttributeValue = new AttributeValueType();
- accessAttributeValue.setDataType(STRING_DATATYPE);
- accessAttributeValue.getContent().add("ACCESS");
- accessMatch.setAttributeValue(accessAttributeValue);
- AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
- URI accessURI = null;
- try {
- accessURI = new URI(ACTION_ID);
- } catch (URISyntaxException e) {
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating ACCESS URI");
- }
- accessAttributeDesignator.setCategory(CATEGORY_ACTION);
- accessAttributeDesignator.setDataType(STRING_DATATYPE);
- accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
- accessMatch.setAttributeDesignator(accessAttributeDesignator);
- accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
- // Creating Config Match in rule Target
- MatchType configMatch = new MatchType();
- AttributeValueType configAttributeValue = new AttributeValueType();
- configAttributeValue.setDataType(STRING_DATATYPE);
- configAttributeValue.getContent().add("Config");
- configMatch.setAttributeValue(configAttributeValue);
- AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
- URI configURI = null;
- try {
- configURI = new URI(RESOURCE_ID);
- } catch (URISyntaxException e) {
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating Config URI");
- }
- configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
- configAttributeDesignator.setDataType(STRING_DATATYPE);
- configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
- configMatch.setAttributeDesignator(configAttributeDesignator);
- configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
- allOfInRule.getMatch().add(accessMatch);
- allOfInRule.getMatch().add(configMatch);
-
- AnyOfType anyOfInRule = new AnyOfType();
- anyOfInRule.getAllOf().add(allOfInRule);
-
- TargetType targetInRule = new TargetType();
- targetInRule.getAnyOf().add(anyOfInRule);
-
- rule.setTarget(targetInRule);
- rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
-
- configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
- policyAdapter.setPolicyData(configPolicy);
-
- } else {
- PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
- }
- setPreparedToSave(true);
- return true;
- }
-
+
+ // Match for policyName
+ allOfOne.getMatch().add(createMatch("PolicyName", name));
+
+ AllOfType allOf = new AllOfType();
+
+ // Adding the matches to AllOfType element Match for Onap
+ allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
+ if (matchMap == null || matchMap.isEmpty()) {
+ // Match for ConfigName
+ allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
+ // Match for Service
+ allOf.getMatch().add(createDynamicMatch("service", policyAdapter.getServiceType()));
+ // Match for uuid
+ allOf.getMatch().add(createDynamicMatch("uuid", policyAdapter.getUuid()));
+ // Match for location
+ allOf.getMatch().add(createDynamicMatch("location", policyAdapter.getLocation()));
+ } else {
+ for (Entry<String, String> matchValue : matchMap.entrySet()) {
+ String value = matchValue.getValue();
+ String key = matchValue.getKey().trim();
+ if (value.contains("matching-true")) {
+ if (mapAttribute.containsKey(key)) {
+ allOf.getMatch().add(createDynamicMatch(key, mapAttribute.get(key)));
+ }
+ }
+ }
+ }
+ // Match for riskType
+ allOf.getMatch().add(createDynamicMatch("RiskType", policyAdapter.getRiskType()));
+ // Match for riskLevel
+ allOf.getMatch().add(createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
+ // Match for riskguard
+ allOf.getMatch().add(createDynamicMatch("guard", policyAdapter.getGuard()));
+ // Match for ttlDate
+ allOf.getMatch().add(createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
+
+ AnyOfType anyOf = new AnyOfType();
+ anyOf.getAllOf().add(allOfOne);
+ anyOf.getAllOf().add(allOf);
+
+ TargetType target = new TargetType();
+ ((TargetType) target).getAnyOf().add(anyOf);
+
+ // Adding the target to the policy element
+ configPolicy.setTarget((TargetType) target);
+
+ RuleType rule = new RuleType();
+ rule.setRuleId(policyAdapter.getRuleID());
+
+ rule.setEffect(EffectType.PERMIT);
+
+ // Create Target in Rule
+ AllOfType allOfInRule = new AllOfType();
+
+ // Creating match for ACCESS in rule target
+ MatchType accessMatch = new MatchType();
+ AttributeValueType accessAttributeValue = new AttributeValueType();
+ accessAttributeValue.setDataType(STRING_DATATYPE);
+ accessAttributeValue.getContent().add("ACCESS");
+ accessMatch.setAttributeValue(accessAttributeValue);
+ AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
+ URI accessURI = null;
+ try {
+ accessURI = new URI(ACTION_ID);
+ } catch (URISyntaxException e) {
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy",
+ "Exception creating ACCESS URI");
+ }
+ accessAttributeDesignator.setCategory(CATEGORY_ACTION);
+ accessAttributeDesignator.setDataType(STRING_DATATYPE);
+ accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
+ accessMatch.setAttributeDesignator(accessAttributeDesignator);
+ accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+ // Creating Config Match in rule Target
+ MatchType configMatch = new MatchType();
+ AttributeValueType configAttributeValue = new AttributeValueType();
+ configAttributeValue.setDataType(STRING_DATATYPE);
+ configAttributeValue.getContent().add("Config");
+ configMatch.setAttributeValue(configAttributeValue);
+ AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
+ URI configURI = null;
+ try {
+ configURI = new URI(RESOURCE_ID);
+ } catch (URISyntaxException e) {
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy",
+ "Exception creating Config URI");
+ }
+ configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
+ configAttributeDesignator.setDataType(STRING_DATATYPE);
+ configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
+ configMatch.setAttributeDesignator(configAttributeDesignator);
+ configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+ allOfInRule.getMatch().add(accessMatch);
+ allOfInRule.getMatch().add(configMatch);
+
+ AnyOfType anyOfInRule = new AnyOfType();
+ anyOfInRule.getAllOf().add(allOfInRule);
+
+ TargetType targetInRule = new TargetType();
+ targetInRule.getAnyOf().add(anyOfInRule);
+
+ rule.setTarget(targetInRule);
+ rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
+
+ configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
+ policyAdapter.setPolicyData(configPolicy);
+
+ } else {
+ PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
+ }
+ setPreparedToSave(true);
+ return true;
+ }
+