Fix Sdc Controller
[clamp.git] / src / main / java / org / onap / clamp / clds / client / CldsEventDelegate.java
index 4886b0d..ce2169f 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP CLAMP
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
  *                             reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +18,7 @@
  * limitations under the License.
  * ============LICENSE_END============================================
  * ===================================================================
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * 
  */
 
 package org.onap.clamp.clds.client;
@@ -26,40 +26,59 @@ package org.onap.clamp.clds.client;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 
-import org.camunda.bpm.engine.delegate.DelegateExecution;
-import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.apache.camel.Exchange;
+import org.apache.camel.Handler;
+import org.onap.clamp.clds.config.ClampProperties;
 import org.onap.clamp.clds.dao.CldsDao;
 import org.onap.clamp.clds.model.CldsEvent;
+import org.onap.clamp.clds.model.CldsModel;
+import org.onap.clamp.clds.model.properties.ModelProperties;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
 
 /**
  * Create CLDS Event.
  */
-public class CldsEventDelegate implements JavaDelegate {
-    protected static final EELFLogger logger        = EELFManager.getInstance().getLogger(CldsEventDelegate.class);
+@Component
+public class CldsEventDelegate {
+
+    protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsEventDelegate.class);
     protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
     @Autowired
-    private CldsDao                   cldsDao;
+    private CldsDao cldsDao;
+    @Autowired
+    private ClampProperties refProp;
 
     /**
      * Insert event using process variables.
      *
-     * @param execution
+     * @param camelExchange
+     *            The Camel Exchange object containing the properties
      */
-    @Override
-    public void execute(DelegateExecution execution) {
-        String controlName = (String) execution.getVariable("controlName");
-        String actionCd = (String) execution.getVariable("actionCd");
-        String actionStateCd = (String) execution.getVariable("actionStateCd");
+    @Handler
+    public void execute(Exchange camelExchange) {
+        String controlName = (String) camelExchange.getProperty("controlName");
+        String actionCd = (String) camelExchange.getProperty("actionCd");
+        String actionStateCd = (String) camelExchange.getProperty("actionStateCd");
         // Flag indicate whether it is triggered by Validation Test button from
         // UI
-        boolean isTest = (boolean) execution.getVariable("isTest");
-        boolean isInsertTestEvent = (boolean) execution.getVariable("isInsertTestEvent");
-        String userid = (String) execution.getVariable("userid");
+        boolean isTest = (boolean) camelExchange.getProperty("isTest");
+        boolean isInsertTestEvent = (boolean) camelExchange.getProperty("isInsertTestEvent");
+        String userid = (String) camelExchange.getProperty("userid");
         // do not insert events for test actions unless flag set to insert them
         if (!isTest || isInsertTestEvent) {
             // won't really have userid here...
-            CldsEvent.insEvent(cldsDao, controlName, userid, actionCd, actionStateCd, execution.getProcessInstanceId());
+            CldsEvent.insEvent(cldsDao, controlName, userid, actionCd, actionStateCd, camelExchange.getExchangeId());
         }
+        generateAutoPolicyId(camelExchange);
+    }
+
+    private void generateAutoPolicyId(Exchange camelExchange) {
+        ModelProperties prop = ModelProperties.create(camelExchange);
+        ;
+        CldsModel cldsModel = CldsModel.retrieve(cldsDao, (String) camelExchange.getProperty("modelName"), false);
+        cldsModel.setPropText(cldsModel.getPropText().replaceAll("AUTO_GENERATED_POLICY_ID_AT_SUBMIT",
+                prop.getPolicyNameForDcaeDeploy(refProp)));
+        cldsModel.save(cldsDao, (String) camelExchange.getProperty("userid"));
     }
 }