Widget microservices configuration change
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / uebhandler / WidgetNotificationHandler.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 package org.onap.portalapp.uebhandler;
39
40 import java.text.DateFormat;
41 import java.text.SimpleDateFormat;
42 import java.util.List;
43
44 import org.onap.portalapp.portal.domain.EPApp;
45 import org.onap.portalapp.portal.domain.EPUser;
46 import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
47 import org.onap.portalapp.portal.service.EPAppService;
48 import org.onap.portalapp.portal.service.SearchService;
49 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
50 import org.onap.portalsdk.core.onboarding.ueb.UebException;
51 import org.onap.portalsdk.core.onboarding.ueb.UebManager;
52 import org.onap.portalsdk.core.onboarding.ueb.UebMsg;
53 import org.springframework.beans.factory.annotation.Autowired;
54 import org.springframework.context.annotation.EnableAspectJAutoProxy;
55 import org.springframework.scheduling.annotation.Async;
56 import org.springframework.stereotype.Component;
57
58 @Component
59 @org.springframework.context.annotation.Configuration
60 @EnableAspectJAutoProxy
61 @EPMetricsLog
62 public class WidgetNotificationHandler {
63         private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetNotificationHandler.class);
64
65         final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
66
67         @Autowired
68         EPAppService appSvc;
69
70         @Autowired
71         SearchService searchSvc;
72
73         public WidgetNotificationHandler() {
74         }
75
76         @Async
77         public void handleWidgetNotification(UebMsg requestMsg) {
78                 if (requestMsg.getUserId() != null) {
79                         logger.debug(EELFLoggerDelegate.debugLogger,
80                                         "handleWidgetNotification: getting widgets/apps for user = " + requestMsg.getUserId());
81                         EPUser user = searchSvc.searchUserByUserId(requestMsg.getUserId());
82                         if (user != null && (appSvc != null)) {
83                                 logger.debug(EELFLoggerDelegate.debugLogger, "Debug mytag: " + appSvc);
84                                 List<EPApp> apps = appSvc.getUserApps(user);
85                                 for (EPApp app : apps) {
86                                         if (app.getUebTopicName() != null) {
87                                                 UebMsg widgetMsg = new UebMsg();
88                                                 widgetMsg.putSourceTopicName(app.getUebTopicName());
89                                                 logger.debug(EELFLoggerDelegate.debugLogger, "app.getUebTopicName was invoked");
90                                                 widgetMsg.putPayload(requestMsg.getPayload());
91                                                 try {
92                                                         logger.debug(EELFLoggerDelegate.debugLogger, "Sending widget notification from "
93                                                                         + requestMsg.getSourceTopicName() + " to " + app.getUebTopicName());
94                                                         UebManager.getInstance().publishEP(widgetMsg, app.getUebTopicName());
95                                                 } catch (UebException e) {
96                                                         logger.error(EELFLoggerDelegate.errorLogger, "handleWidgetNotification failed", e);
97                                                 }
98                                         }
99                                 }
100                         } else {
101                                 logger.error(EELFLoggerDelegate.errorLogger,
102                                                 "handleWidgetNotification: user " + requestMsg.getUserId() + " not found, source = "
103                                                                 + requestMsg.getSourceTopicName()
104                                                                 + ". This widget notification cannot be posted to other widgets");
105                         }
106                 }
107         }
108
109 }