import lombok.Setter;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
import org.onap.policy.rest.adapter.ClosedLoopSignatures;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
import org.onap.policy.rest.dao.CommonClassDao;
-import org.onap.policy.rest.jpa.OnapName;
import org.onap.policy.rest.jpa.PolicyEntity;
import org.onap.policy.rest.jpa.VarbindDictionary;
+import org.onap.policy.utils.PolicyUtils;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
private static final String CONNECT_TRAP_2 = "connectTrap2";
private static final String TRAP_COUNT_2 = "trapCount2";
private static final String TRIGGER_1 = "trigger1";
- private static final String ENC_UTF_8 = "UTF-8";
private static final String TRIGGER_2 = "trigger2";
protected PolicyRestAdapter policyAdapter = null;
} catch (NumberFormatException e) {
try {
trap1Attrib = getVarbindOid(trap1Attrib);
- attributesStr = attributesStr + "(" + URLEncoder.encode(trap1Attrib, ENC_UTF_8) + ")";
+ attributesStr = attributesStr + "(" + URLEncoder.encode(trap1Attrib,
+ PolicyUtils.CHARACTER_ENCODING) + ")";
} catch (UnsupportedEncodingException e1) {
policyLogger.error("Caused Exception while Encoding Varbind Dictionary Values", e1);
}
} else {
try {
trap1Attrib = getVarbindOid(trap1Attrib);
- attributesStr = attributesStr + "(" + URLEncoder.encode(trap1Attrib, ENC_UTF_8) + ")";
+ attributesStr = attributesStr + "(" + URLEncoder.encode(trap1Attrib,
+ PolicyUtils.CHARACTER_ENCODING) + ")";
} catch (UnsupportedEncodingException e) {
policyLogger.error("Caused Exception while Encoding Varbind Dictionary Values", e);
}
try {
varbindId =
(VarbindDictionary) commonclassdao.getEntityItem(VarbindDictionary.class, "varbindName", attrib);
- return varbindId.getVarbindOID();
+ return varbindId.getVarbindOid();
} catch (Exception e) {
policyLogger.error("Error during retrieving varbindName " + attrib, e);
return attrib;
* @param entity PolicyEntity
*/
public void prePopulateClosedLoopFaultPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
- if (policyAdapter.getPolicyData() instanceof PolicyType) {
- PolicyType policy = (PolicyType) policyAdapter.getPolicyData();
-
- // Set PolicyAdapter policyName, description
- setPolicyAdapterPolicyNameAndDescription(policyAdapter, policy);
-
- // Set PolicyAdapter JsonBodyData, timeout settings
- setClosedLoopJsonFile(policyAdapter, entity);
+ if (! (policyAdapter.getPolicyData() instanceof PolicyType)) {
+ return;
+ }
+ PolicyType policy = (PolicyType) policyAdapter.getPolicyData();
- // Get the target data under policy.
- TargetType target = policy.getTarget();
- if (target == null) {
- return;
- }
+ // Set PolicyAdapter policyName, description
+ setPolicyAdapterPolicyNameAndDescription(policyAdapter, policy);
- // Under target we have AnyOFType
- List<AnyOfType> anyOfList = target.getAnyOf();
- if (anyOfList == null) {
- return;
- }
+ // Set PolicyAdapter JsonBodyData, timeout settings
+ setClosedLoopJsonFile(policyAdapter, entity);
- // Set PolicyAdapter OnapNameField, riskType, riskLevel, guard, ttlDate from match attributes
- setPolicyAdapterMatchAttributes(policyAdapter, anyOfList);
+ // Get the target data under policy.
+ TargetType target = policy.getTarget();
+ if (target == null) {
+ return;
}
+
+ // Set PolicyAdapter OnapNameField, riskType, riskLevel, guard, ttlDate from match attributes
+ setPolicyAdapterMatchAttributes(policyAdapter, target.getAnyOf());
}
private void setPolicyAdapterMatchAttributes(PolicyRestAdapter policyAdapter, List<AnyOfType> anyOfList) {
.forEach(match -> {
// Under the match we have attribute value and
// attributeDesignator. So,finally down to the actual attribute.
- AttributeValueType attributeValue = match.getAttributeValue();
- String value = (String) attributeValue.getContent().get(0);
- AttributeDesignatorType designator = match.getAttributeDesignator();
- String attributeId = designator.getAttributeId();
- // First match in the target is OnapName, so set that value.
- if ("ONAPName".equals(attributeId)) {
- policyAdapter.setOnapName(value);
- OnapName onapName = new OnapName();
- onapName.setOnapName(value);
- policyAdapter.setOnapNameField(onapName);
- } else if ("RiskType".equals(attributeId)) {
- policyAdapter.setRiskType(value);
- } else if ("RiskLevel".equals(attributeId)) {
- policyAdapter.setRiskLevel(value);
- } else if ("guard".equals(attributeId)) {
- policyAdapter.setGuard(value);
- } else if ("TTLDate".equals(attributeId) && !value.contains("NA")) {
- PolicyController controller = new PolicyController();
- String newDate = controller.convertDate(value);
- policyAdapter.setTtlDate(newDate);
- }
+ policyAdapter.setupUsingAttribute(match.getAttributeDesignator().getAttributeId(),
+ (String) match.getAttributeValue().getContent().get(0));
}));
}