X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fclient%2FOperationalPolicyDelegate.java;h=307c8e511038dd0f5f79d867651aa15e9bb1dead;hb=09bc8450b2b0c4f60eb4a241efc548d13c5c9912;hp=e2d16c56c8e893cfb783b5ecc5669e11ea18b5ca;hpb=9dc1bebdf768fe33b5c9b983c8072ba5cb16f8a8;p=clamp.git diff --git a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java index e2d16c56..307c8e51 100644 --- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java +++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java @@ -17,8 +17,9 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ + * Modifications copyright (c) 2018 Nokia * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.clamp.clds.client; @@ -29,62 +30,61 @@ import com.att.eelf.configuration.EELFManager; import java.io.UnsupportedEncodingException; import java.util.Map; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.camunda.bpm.engine.delegate.JavaDelegate; -import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq; +import org.apache.camel.Exchange; +import org.apache.camel.Handler; +import org.onap.clamp.clds.client.req.policy.OperationalPolicyAttributesConstructor; import org.onap.clamp.clds.client.req.policy.PolicyClient; -import org.onap.clamp.clds.model.prop.ModelProperties; -import org.onap.clamp.clds.model.prop.Policy; -import org.onap.clamp.clds.model.prop.PolicyChain; -import org.onap.clamp.clds.model.refprop.RefProp; +import org.onap.clamp.clds.config.ClampProperties; +import org.onap.clamp.clds.model.properties.ModelProperties; +import org.onap.clamp.clds.model.properties.Policy; +import org.onap.clamp.clds.model.properties.PolicyChain; import org.onap.clamp.clds.util.LoggingUtils; import org.onap.policy.api.AttributeType; import org.onap.policy.controlloop.policy.builder.BuilderException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; /** * Send Operational Policy info to policy api. It uses the policy code to define * the model and communicate with it. See also the PolicyClient class. - * */ -public class OperationalPolicyDelegate implements JavaDelegate { - protected static final EELFLogger logger = EELFManager.getInstance() - .getLogger(OperationalPolicyDelegate.class); +@Component +public class OperationalPolicyDelegate { + + protected static final EELFLogger logger = EELFManager.getInstance().getLogger(OperationalPolicyDelegate.class); protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); - /** - * Automatically injected by Spring, define in CldsConfiguration as a bean. - */ - @Autowired - private PolicyClient policyClient; - /** - * Automatically injected by Spring, define in CldsConfiguration as a bean. - */ + private final PolicyClient policyClient; + private final ClampProperties refProp; + @Autowired - private RefProp refProp; + public OperationalPolicyDelegate(PolicyClient policyClient, ClampProperties refProp) { + this.policyClient = policyClient; + this.refProp = refProp; + } /** * Perform activity. Send Operational Policy info to policy api. * - * @param execution - * The DelegateExecution + * @param camelExchange + * The Camel Exchange object containing the properties * @throws BuilderException - * In case of issues with OperationalPolicyReq + * In case of issues with OperationalPolicyRequestAttributesConstructor * @throws UnsupportedEncodingException * In case of issues with the Charset encoding */ - @Override - public void execute(DelegateExecution execution) throws BuilderException, UnsupportedEncodingException { + @Handler + public void execute(Exchange camelExchange) throws BuilderException, UnsupportedEncodingException { String responseMessage = null; - ModelProperties prop = ModelProperties.create(execution); + ModelProperties prop = ModelProperties.create(camelExchange); Policy policy = prop.getType(Policy.class); if (policy.isFound()) { for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) { - Map> attributes = OperationalPolicyReq.formatAttributes(refProp, - prop, prop.getType(Policy.class).getId(), policyChain); + Map> attributes = OperationalPolicyAttributesConstructor + .formatAttributes(refProp,prop, prop.getType(Policy.class).getId(), policyChain); responseMessage = policyClient.sendBrmsPolicy(attributes, prop, LoggingUtils.getRequestId()); } if (responseMessage != null) { - execution.setVariable("operationalPolicyResponseMessage", responseMessage.getBytes()); + camelExchange.setProperty("operationalPolicyResponseMessage", responseMessage.getBytes()); } } }