Removal of dead code
[clamp.git] / src / main / java / org / onap / clamp / clds / client / OperationalPolicyDelegate.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * Modifications copyright (c) 2018 Nokia
21  * ===================================================================
22  *
23  */
24
25 package org.onap.clamp.clds.client;
26
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29
30 import java.io.UnsupportedEncodingException;
31 import java.util.Map;
32
33 import org.apache.camel.Exchange;
34 import org.apache.camel.Handler;
35 import org.onap.clamp.clds.client.req.policy.OperationalPolicyAttributesConstructor;
36 import org.onap.clamp.clds.client.req.policy.PolicyClient;
37 import org.onap.clamp.clds.config.ClampProperties;
38 import org.onap.clamp.clds.model.properties.ModelProperties;
39 import org.onap.clamp.clds.model.properties.Policy;
40 import org.onap.clamp.clds.model.properties.PolicyChain;
41 import org.onap.clamp.clds.util.LoggingUtils;
42 import org.onap.policy.api.AttributeType;
43 import org.onap.policy.controlloop.policy.builder.BuilderException;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.stereotype.Component;
46
47 /**
48  * Send Operational Policy info to policy api. It uses the policy code to define
49  * the model and communicate with it. See also the PolicyClient class.
50  */
51 @Component
52 public class OperationalPolicyDelegate {
53
54     protected static final EELFLogger logger = EELFManager.getInstance().getLogger(OperationalPolicyDelegate.class);
55     protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
56     private final PolicyClient policyClient;
57     private final ClampProperties refProp;
58
59     @Autowired
60     public OperationalPolicyDelegate(PolicyClient policyClient, ClampProperties refProp) {
61         this.policyClient = policyClient;
62         this.refProp = refProp;
63     }
64
65     /**
66      * Perform activity. Send Operational Policy info to policy api.
67      *
68      * @param camelExchange
69      *            The Camel Exchange object containing the properties
70      * @throws BuilderException
71      *             In case of issues with OperationalPolicyRequestAttributesConstructor
72      * @throws UnsupportedEncodingException
73      *             In case of issues with the Charset encoding
74      */
75     @Handler
76     public void execute(Exchange camelExchange) throws BuilderException, UnsupportedEncodingException {
77         String responseMessage = null;
78         ModelProperties prop = ModelProperties.create(camelExchange);
79         Policy policy = prop.getType(Policy.class);
80         if (policy.isFound()) {
81             for (PolicyChain policyChain : prop.getType(Policy.class).getPolicyChains()) {
82                 Map<AttributeType, Map<String, String>> attributes = OperationalPolicyAttributesConstructor.formatAttributes(refProp,
83                     prop, prop.getType(Policy.class).getId(), policyChain);
84                 responseMessage = policyClient.sendBrmsPolicy(attributes, prop, LoggingUtils.getRequestId());
85             }
86             if (responseMessage != null) {
87                 camelExchange.setProperty("operationalPolicyResponseMessage", responseMessage.getBytes());
88             }
89         }
90     }
91 }