* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import com.google.common.base.Strings;
import java.util.Collection;
import java.util.Map;
+import lombok.NoArgsConstructor;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+@NoArgsConstructor
public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator {
private static final Logger LOGGER = LoggerFactory.getLogger(StdCombinedPolicyResultsTranslator.class);
- public StdCombinedPolicyResultsTranslator() {
- super();
- }
-
@Override
- public PolicyType convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
+ public Object convertPolicy(ToscaPolicy toscaPolicy) throws ToscaPolicyConversionException {
//
// Sanity checks
//
//
// Get the policy Id
//
- String policyId = toscaPolicy.getMetadata().get(POLICY_ID);
+ String policyId = String.valueOf(toscaPolicy.getMetadata().get(POLICY_ID));
//
// Set it as the policy ID
//
- PolicyType newPolicyType = new PolicyType();
+ var newPolicyType = new PolicyType();
newPolicyType.setPolicyId(policyId);
//
// Optional description
//
// Generate the TargetType
//
- TargetType target = this.generateTargetType(policyId, toscaPolicy.getType(), toscaPolicy.getVersion());
+ var target = this.generateTargetType(policyId, toscaPolicy.getType(), toscaPolicy.getVersion());
newPolicyType.setTarget(target);
//
// Now create the Permit Rule
// No target since the policy has a target
// With obligations.
//
- RuleType rule = new RuleType();
+ var rule = new RuleType();
rule.setDescription("Default is to PERMIT if the policy matches.");
rule.setRuleId(policyId + ":rule");
rule.setEffect(EffectType.PERMIT);
//
// Now represent the policy as Json
//
- StandardCoder coder = new StandardCoder();
+ var coder = new StandardCoder();
String jsonPolicy;
try {
jsonPolicy = coder.encode(toscaPolicy);
* scanAdvice - not implemented in this class.
*
* @param advice Collection of advice objects
- * @param DecisionResponse DecisionResponse object
+ * @param decisionResponse DecisionResponse object
*/
@Override
protected void scanAdvice(Collection<Advice> advice, DecisionResponse decisionResponse) {
//
// Create our OnapObligation which will scan for attributes
//
- OnapObligation onapObligation = new OnapObligation(obligation);
+ var onapObligation = new OnapObligation(obligation);
//
// Get the attributes we care about
//
// Sanity check that we got the attributes we care about. NOTE: This translator
// ensures that these are set when convertPolicy is called.
//
- if (! Strings.isNullOrEmpty(policyId) && policyContent != null) {
+ if (! Strings.isNullOrEmpty(policyId) && !policyContent.isEmpty()) {
decisionResponse.getPolicies().put(policyId, policyContent);
} else {
LOGGER.error("Missing obligation policyId {} or policyContent {}", policyId,
//
// This is for the Policy Id
//
- MatchType matchPolicyId = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
+ var matchPolicyId = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
XACML3.ID_FUNCTION_STRING_EQUAL,
policyId,
XACML3.ID_DATATYPE_STRING,
//
// This is for the Policy Type
//
- MatchType matchPolicyType = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
+ var matchPolicyType = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
XACML3.ID_FUNCTION_STRING_EQUAL,
policyType,
XACML3.ID_DATATYPE_STRING,
//
// This is for the Policy Type version
//
- MatchType matchPolicyTypeVersion = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
+ var matchPolicyTypeVersion = ToscaPolicyTranslatorUtils.buildMatchTypeDesignator(
XACML3.ID_FUNCTION_STRING_EQUAL,
policyTypeVersion,
XACML3.ID_DATATYPE_STRING,
//
// This is our outer AnyOf - which is an OR
//
- AnyOfType anyOf = new AnyOfType();
+ var anyOf = new AnyOfType();
//
// Create AllOf (AND) of just Policy Id
//
// Now we can create the TargetType, add the top-level anyOf (OR),
// and return the value.
//
- TargetType target = new TargetType();
+ var target = new TargetType();
target.getAnyOf().add(anyOf);
return target;
}