diff options
author | st782s <statta@research.att.com> | 2017-05-04 07:48:42 -0400 |
---|---|---|
committer | st782s <statta@research.att.com> | 2017-05-04 12:28:17 -0400 |
commit | b54df0ddd0c6a0372327c5aa3668e5a6458fcd64 (patch) | |
tree | e69cfa9b314a801bd187cf0145d1d4306436229c /ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler | |
parent | 39d1e62c84041831bfc52cca73b5ed5efaf57d27 (diff) |
[PORTAL-7] Rebase
This rebasing includes common libraries and common overlays projects
abstraction of components
Change-Id: I9a24a338665c7cd058978e8636bc412d9e2fdce8
Signed-off-by: st782s <statta@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler')
4 files changed, 409 insertions, 0 deletions
diff --git a/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/FunctionalMenuHandler.java b/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/FunctionalMenuHandler.java new file mode 100644 index 00000000..0a360500 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/FunctionalMenuHandler.java @@ -0,0 +1,126 @@ +/*- + * ================================================================================ + * ECOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.uebhandler; + +import java.util.List; + +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.logging.aop.EPAuditLog; +import org.openecomp.portalapp.portal.service.AdminRolesService; +import org.openecomp.portalapp.portal.service.FunctionalMenuService; +import org.openecomp.portalapp.portal.service.SearchService; +import org.openecomp.portalapp.portal.transport.FunctionalMenuItem; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.ueb.UebException; +import org.openecomp.portalsdk.core.onboarding.ueb.UebManager; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import com.google.gson.Gson; + +@Component +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPAuditLog +public class FunctionalMenuHandler { + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuHandler.class); + + @Autowired + AdminRolesService adminRolesService; + + @Autowired + FunctionalMenuService functionalMenuService; + + @Autowired + SearchService searchSvc; + + @Autowired + DataAccessService dataAccessService; + + @Async + public Boolean getFunctionalMenu(UebMsg requestMsg) + { + UebMsg returnMsg = new UebMsg(); + + if (requestMsg == null) + { + logger.error(EELFLoggerDelegate.errorLogger, "handleMenuRequest received null message"); + return false; + } + else if (requestMsg.getSourceTopicName() == null) + { + logger.error(EELFLoggerDelegate.errorLogger, "A source topic name is required and not found in this msg:" + requestMsg.toString()); + return false; + } + else if (requestMsg.getUserId() == null) + { + logger.debug(EELFLoggerDelegate.debugLogger, "Error getting functional menu. A userId is required and not found in this msg: " + requestMsg.toString()); + returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response + returnMsg.putPayload("Error: A userId is required. Call msg.putUserId() with an userId"); + } + else + { + logger.debug(EELFLoggerDelegate.debugLogger, "Getting functional menu for user = " + requestMsg.getUserId()); + EPUser user = searchSvc.searchUserByUserId(requestMsg.getUserId()); + + List<FunctionalMenuItem> menuItems = null; + if (user == null) + { + logger.debug(EELFLoggerDelegate.debugLogger, "Error getting functional menu. userId not found in directory or is guest: " + requestMsg.toString()); + } + else if (adminRolesService.isSuperAdmin(user)) + { + logger.debug(EELFLoggerDelegate.debugLogger, "FunctionalMenuHandler: SuperUser, about to call getFunctionalMenuItems()"); + menuItems = functionalMenuService.getFunctionalMenuItems(); + } + else + { + logger.debug(EELFLoggerDelegate.debugLogger, "getMenuItemsForAuthUser: about to call getFunctionalMenuItemsForUser()"); + menuItems = functionalMenuService.getFunctionalMenuItemsForUser(requestMsg.getUserId()); + } + + if ( menuItems != null ) + { + String functionalMenuJsonString = new Gson().toJson(menuItems); + logger.debug(EELFLoggerDelegate.debugLogger, "returning functional menu : " + functionalMenuJsonString); + returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response + returnMsg.putPayload(functionalMenuJsonString); + } else { + returnMsg.putMsgId(requestMsg.getMsgId()); // echo tells requester this is a response + returnMsg.putPayload("Error: Not found for userId = " + requestMsg.getUserId()); + } + } + + try { + UebManager.getInstance().publishReplyEP(returnMsg, requestMsg.getSourceTopicName()); + } catch (UebException e) { + logger.error(EELFLoggerDelegate.errorLogger, "UebException occurred while responding to the Ueb message, Details:" + EcompPortalUtils.getStackTrace(e)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred while responding to the Ueb message, Details:" + EcompPortalUtils.getStackTrace(e)); + } + + return true; + } +} diff --git a/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java b/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java new file mode 100644 index 00000000..2ba27549 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/InitUebHandler.java @@ -0,0 +1,75 @@ +/*- + * ================================================================================ + * ECOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.uebhandler; + +import java.util.concurrent.ConcurrentLinkedQueue; + +import javax.annotation.PostConstruct; + +import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants; +import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties; +import org.openecomp.portalsdk.core.onboarding.ueb.UebManager; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +// +// Adding this class for the sole purpose of insuring that the MainUebHandler really +// honors @Async and kicks off a thread. For more info google @Async and read about +// @Async only working if called from different class. +// +//@Configuration +//@EnableAspectJAutoProxy +//@EPMetricsLog +public class InitUebHandler { + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(InitUebHandler.class); + + //@Autowired + MainUebHandler mainUebHandler; + + public InitUebHandler() { + + } + + //@PostConstruct + public void initUeb() { + + try { + String enableListenerThread = PortalApiProperties.getProperty(PortalApiConstants.UEB_LISTENERS_ENABLE); + if (enableListenerThread.equalsIgnoreCase("true")) { + ConcurrentLinkedQueue<UebMsg> inboxQueue = new ConcurrentLinkedQueue<UebMsg>(); + UebManager.getInstance().initListener(inboxQueue); + mainUebHandler.runHandler(inboxQueue); + logger.info(EELFLoggerDelegate.errorLogger, "Returned from initiating mainUebHandler..."); + } + else { + logger.info(EELFLoggerDelegate.errorLogger, "Not starting UEB listening thread because ueb_listeners_enable is not set to true in the properties file."); + } + } + catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e)); + logger.info(EELFLoggerDelegate.errorLogger, "Not starting UEB listening thread because property could not be read " + PortalApiConstants.UEB_LISTENERS_ENABLE + e.getMessage()); + } + } +} diff --git a/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java b/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java new file mode 100644 index 00000000..5edf04b4 --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/MainUebHandler.java @@ -0,0 +1,115 @@ +/*- + * ================================================================================ + * ECOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.uebhandler; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.concurrent.ConcurrentLinkedQueue; + +import org.openecomp.portalapp.portal.ueb.EPUebMsgTypes; +import org.openecomp.portalapp.portal.utils.EPSystemProperties; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsgTypes; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +import com.att.eelf.configuration.Configuration; + + +//------------------------------------------------------------------------- +// Listens for received UEB messages and handles the messages +// +// Note: To implement a synchronous reply call getMsgId on the request +// and putMsgId on the reply (echoing the request MsgId). +// +//------------------------------------------------------------------------- +@Component("MainUebHandler") +public class MainUebHandler +{ + final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MainUebHandler.class); + + ConcurrentLinkedQueue<UebMsg> inboxQueue = null; + + @Autowired + FunctionalMenuHandler funcMenuHandler; + + @Autowired + WidgetNotificationHandler widgetNotificationHandler; + + @Async + public void runHandler(ConcurrentLinkedQueue<UebMsg> queue) + { + inboxQueue = queue; + logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "==> MainUebHandler started"); + while (true) + { + UebMsg msg = null; + while ((msg = inboxQueue.poll()) != null) + { + if ((msg.getMsgType() != null) && (!msg.getMsgType().equalsIgnoreCase(EPUebMsgTypes.UEB_MSG_TYPE_HEALTH_CHECK))) + { + // TODO: switch this back to debug + logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== Received UEB message : " + msg.toString()); + logger.info(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== Received UEB message : " + msg.toString()); + MDC.put(EPSystemProperties.PARTNER_NAME, msg.getSourceTopicName()); + MDC.put(Configuration.MDC_SERVICE_NAME, msg.getMsgType().toString()); + switch(msg.getMsgType()) + { + case UebMsgTypes.UEB_MSG_TYPE_GET_FUNC_MENU: + { + funcMenuHandler.getFunctionalMenu(msg); + break; + } + case UebMsgTypes.UEB_MSG_TYPE_WIDGET_NOTIFICATION: + { + widgetNotificationHandler.handleWidgetNotification(msg); + break; + } + default: + { + logger.info(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "Unknown UEB message type " + msg.toString()); + break; + } + } + } + } + + if (Thread.interrupted()) + { + logger.info(EELFLoggerDelegate.errorLogger, "==> UebMainHandler exiting"); + break; + } + + try { + Thread.sleep(10); + } catch (InterruptedException e) { + logger.error(EELFLoggerDelegate.errorLogger, "UebMainHandler interrupted during sleep" + EcompPortalUtils.getStackTrace(e)); + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "Exception occurred during sleep" + EcompPortalUtils.getStackTrace(e)); + } + } + } +} diff --git a/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java b/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java new file mode 100644 index 00000000..e6f3089c --- /dev/null +++ b/ecomp-portal-BE-os/src/main/java/org/openecomp/portalapp/uebhandler/WidgetNotificationHandler.java @@ -0,0 +1,93 @@ +/*- + * ================================================================================ + * ECOMP Portal + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +package org.openecomp.portalapp.uebhandler; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; + +import org.openecomp.portalapp.portal.domain.EPApp; +import org.openecomp.portalapp.portal.domain.EPUser; +import org.openecomp.portalapp.portal.logging.aop.EPMetricsLog; +import org.openecomp.portalapp.portal.service.EPAppService; +import org.openecomp.portalapp.portal.service.SearchService; +import org.openecomp.portalapp.portal.utils.EcompPortalUtils; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.onboarding.ueb.UebException; +import org.openecomp.portalsdk.core.onboarding.ueb.UebManager; +import org.openecomp.portalsdk.core.onboarding.ueb.UebMsg; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +@Component +@org.springframework.context.annotation.Configuration +@EnableAspectJAutoProxy +@EPMetricsLog +public class WidgetNotificationHandler { + EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetNotificationHandler.class); + + final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + + @Autowired + EPAppService appSvc; + + @Autowired + SearchService searchSvc; + + + public WidgetNotificationHandler() + { + } + + @Async + public void handleWidgetNotification(UebMsg requestMsg) + { + if (requestMsg.getUserId() != null) { + logger.debug(EELFLoggerDelegate.debugLogger, "handleWidgetNotification: getting widgets/apps for user = " + requestMsg.getUserId()); + EPUser user = searchSvc.searchUserByUserId(requestMsg.getUserId()); + if (user != null && (appSvc != null)) { + logger.debug(EELFLoggerDelegate.debugLogger, "Debug mytag: " + appSvc); + List<EPApp> apps = appSvc.getUserApps(user); + for (EPApp app : apps) { + if (app.getUebTopicName() != null) { + UebMsg widgetMsg = new UebMsg(); + widgetMsg.putSourceTopicName(app.getUebTopicName()); + logger.debug(EELFLoggerDelegate.debugLogger, "app.getUebTopicName was invoked"); + widgetMsg.putPayload(requestMsg.getPayload()); + try { + logger.debug(EELFLoggerDelegate.debugLogger, "Sending widget notification from " + requestMsg.getSourceTopicName() + " to " + app.getUebTopicName()); + UebManager.getInstance().publishEP(widgetMsg, app.getUebTopicName()); + } catch (UebException e) { + logger.error(EELFLoggerDelegate.errorLogger, "handleWidgetNotification publishEP exception" + EcompPortalUtils.getStackTrace(e)); + } + } + } + } else { + logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "handleWidgetNotification: user " + + requestMsg.getUserId() + " not found" + " source = " + requestMsg.getSourceTopicName() + + ". This widget notification cannot be posted to other widgets"); + } + } + } + +} |