58843d9bffdb65d17e4ffe7ef5536d4a3f1b24a9
[clamp.git] / src / main / java / org / onap / clamp / clds / client / TcaPolicyDelegate.java
1 package org.onap.clamp.clds.client;
2
3 import java.util.UUID;
4 import java.util.logging.Logger;
5
6 import org.camunda.bpm.engine.delegate.DelegateExecution;
7 import org.camunda.bpm.engine.delegate.JavaDelegate;
8 import org.springframework.beans.factory.annotation.Autowired;
9
10 import org.onap.clamp.clds.client.req.TcaMPolicyReq;
11 import org.onap.clamp.clds.model.prop.ModelProperties;
12 import org.onap.clamp.clds.model.prop.Tca;
13 import org.onap.clamp.clds.model.refprop.RefProp;
14
15
16 /**
17  * Send Tca info to policy api. 
18  * 
19  *
20  */
21 public class TcaPolicyDelegate implements JavaDelegate {
22         // currently uses the java.util.logging.Logger like the Camunda engine
23         private static final Logger logger = Logger.getLogger(TcaPolicyDelegate.class.getName());
24         
25         @Autowired
26         private RefProp refProp;
27         
28         @Autowired PolicyClient policyClient;
29         
30         /**
31          * Perform activity.  Send Tca info to policy api.
32          * 
33          * @param execution
34          */
35         public void execute(DelegateExecution execution) throws Exception {             
36                 String tcaPolicyRequestUuid = UUID.randomUUID().toString();
37                 execution.setVariable("tcaPolicyRequestUuid", tcaPolicyRequestUuid);
38
39                 ModelProperties prop = ModelProperties.create(execution);
40                 Tca tca = prop.getTca();
41                 if(tca.isFound()){
42                         String policyJson = TcaMPolicyReq.formatTca(refProp, prop);
43                         String responseMessage = policyClient.sendMicroService(policyJson, prop, tcaPolicyRequestUuid);
44                         if(responseMessage != null)
45                         {
46                                 execution.setVariable("tcaPolicyResponseMessage", responseMessage.getBytes());          
47                         }
48                 }
49         }
50         
51         
52         
53 }