2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalapp.uebhandler;
22 import java.text.DateFormat;
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25 import java.util.List;
27 import org.openecomp.portalapp.portal.domain.EPApp;
28 import org.openecomp.portalapp.portal.domain.EPUser;
29 import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog;
30 import org.openecomp.portalapp.portal.service.EPAppService;
31 import org.openecomp.portalapp.portal.service.SearchService;
32 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
33 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
34 import org.openecomp.portalsdk.core.onboarding.ueb.UebException;
35 import org.openecomp.portalsdk.core.onboarding.ueb.UebManager;
36 import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.context.annotation.EnableAspectJAutoProxy;
39 import org.springframework.scheduling.annotation.Async;
40 import org.springframework.stereotype.Component;
43 @org.springframework.context.annotation.Configuration
44 @EnableAspectJAutoProxy
46 public class WidgetNotificationHandler {
47 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetNotificationHandler.class);
49 final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
55 SearchService searchSvc;
58 public WidgetNotificationHandler()
63 public void handleWidgetNotification(UebMsg requestMsg)
65 if (requestMsg.getUserId() != null) {
66 logger.debug(EELFLoggerDelegate.debugLogger, "handleWidgetNotification: getting widgets/apps for user = " + requestMsg.getUserId());
67 EPUser user = searchSvc.searchUserByUserId(requestMsg.getUserId());
68 if (user != null && (appSvc != null)) {
69 logger.debug(EELFLoggerDelegate.debugLogger, "Debug mytag: " + appSvc);
70 List<EPApp> apps = appSvc.getUserApps(user);
71 for (EPApp app : apps) {
72 if (app.getUebTopicName() != null) {
73 UebMsg widgetMsg = new UebMsg();
74 widgetMsg.putSourceTopicName(app.getUebTopicName());
75 logger.debug(EELFLoggerDelegate.debugLogger, "app.getUebTopicName was invoked");
76 widgetMsg.putPayload(requestMsg.getPayload());
78 logger.debug(EELFLoggerDelegate.debugLogger, "Sending widget notification from " + requestMsg.getSourceTopicName() + " to " + app.getUebTopicName());
79 UebManager.getInstance().publishEP(widgetMsg, app.getUebTopicName());
80 } catch (UebException e) {
81 logger.error(EELFLoggerDelegate.errorLogger, "handleWidgetNotification publishEP exception" + EcompPortalUtils.getStackTrace(e));
86 logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "handleWidgetNotification: user " +
87 requestMsg.getUserId() + " not found" + " source = " + requestMsg.getSourceTopicName() +
88 ". This widget notification cannot be posted to other widgets");