Update the license for 2017-2018 license
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / util / StoreNotificationEvent.java
index 0ad33cb..375a2ad 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 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.
@@ -16,8 +16,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  */
 package org.onap.aai.util;
 
@@ -27,35 +25,70 @@ import java.util.UUID;
 
 import javax.xml.bind.Marshaller;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 import org.eclipse.persistence.dynamic.DynamicEntity;
 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
 import org.json.JSONException;
 import org.json.JSONObject;
+import org.onap.aai.config.SpringContextAware;
 import org.onap.aai.dmaap.AAIDmaapEventJMSProducer;
+import org.onap.aai.dmaap.JMSProducer;
+import org.onap.aai.dmaap.MessageProducer;
 import org.onap.aai.domain.notificationEvent.NotificationEvent;
 import org.onap.aai.exceptions.AAIException;
 import org.onap.aai.introspection.Introspector;
 import org.onap.aai.introspection.Loader;
 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
+import org.springframework.beans.factory.NoSuchBeanDefinitionException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.env.Environment;
 
 public class StoreNotificationEvent {
 
-       private AAIDmaapEventJMSProducer messageProducer;
+    private static final EELFLogger logger = EELFManager.getInstance().getLogger(StoreNotificationEvent.class);
+       private MessageProducer messageProducer;
        private String fromAppId = "";
        private String transId = "";
        private final String transactionId;
        private final String sourceOfTruth;
+
+       private ApplicationContext context;
+       private Environment env;
+
        /**
         * Instantiates a new store notification event.
         */
        public StoreNotificationEvent(String transactionId, String sourceOfTruth) {
-               this(new AAIDmaapEventJMSProducer(), transactionId, sourceOfTruth);
+               this.context         = SpringContextAware.getApplicationContext();
+               // If the context is null then this is being invoked from
+               // non spring context so creating the jms producer each time
+               // Otherwise, get the jms producer from the spring context so
+               // no need to create a instance of this each time
+        // Also check if the environment has the dmaap profile
+               // TODO - Add the constants for profile so do this when adding the https two-way ssl and one way with basic auth
+               if(this.context == null){
+                       this.messageProducer = new AAIDmaapEventJMSProducer();
+               } else {
+                   env = context.getEnvironment();
+                       if(env.acceptsProfiles("dmaap")){
+                               try {
+                                       this.messageProducer = (JMSProducer)context.getBean("jmsProducer");
+                               } catch(NoSuchBeanDefinitionException ex){
+                                       logger.error("Currently using the dmaap profile but still not able to find bean so check DmaapConfig", ex);
+                               }
+                       } else {
+                               this.messageProducer = new AAIDmaapEventJMSProducer();
+                       }
+               }
+        this.transactionId   = transactionId;
+        this.sourceOfTruth   = sourceOfTruth;
        }
-       
+
        public StoreNotificationEvent(AAIDmaapEventJMSProducer producer, String transactionId, String sourceOfTruth) {
-               this.messageProducer = producer;
-               this.transactionId = transactionId;
-               this.sourceOfTruth = sourceOfTruth;
+           this.messageProducer = producer;
+               this.transactionId   = transactionId;
+               this.sourceOfTruth   = sourceOfTruth;
        }
 
        /**