summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler
diff options
context:
space:
mode:
authorKishore Reddy, Gujja (kg811t) <kg811t@research.att.com>2018-05-14 17:19:51 -0400
committerKishore Reddy, Gujja (kg811t) <kg811t@research.att.com>2018-05-25 13:39:38 -0400
commit2845910b34682056c1949f82e39d9205a26554e9 (patch)
tree825474a899dc5783e6ea8c4aefd26b6d4c881dfd /ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler
parent485296388748c1efb5737cf7ae9d4a8254681552 (diff)
Bulk upload changes and music health check apis
Issue-ID: PORTAL-290, PORTAL-291 Bulk upload changes and music health check apis Change-Id: I63d289d75420658ff4a14385a5106838fa8c32b2 Signed-off-by: Kishore Reddy, Gujja (kg811t) <kg811t@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler')
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/FunctionalMenuHandler.java133
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/InitUebHandler.java85
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/MainUebHandler.java125
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/WidgetNotificationHandler.java109
4 files changed, 452 insertions, 0 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/FunctionalMenuHandler.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/FunctionalMenuHandler.java
new file mode 100644
index 00000000..b366d0da
--- /dev/null
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/FunctionalMenuHandler.java
@@ -0,0 +1,133 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.uebhandler;
+
+import java.util.List;
+
+import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.logging.aop.EPAuditLog;
+import org.onap.portalapp.portal.service.AdminRolesService;
+import org.onap.portalapp.portal.service.FunctionalMenuService;
+import org.onap.portalapp.portal.service.SearchService;
+import org.onap.portalapp.portal.transport.FunctionalMenuItem;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.onboarding.ueb.UebException;
+import org.onap.portalsdk.core.onboarding.ueb.UebManager;
+import org.onap.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;
+
+import com.google.gson.Gson;
+
+@Component
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+@EPAuditLog
+public class FunctionalMenuHandler {
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(FunctionalMenuHandler.class);
+
+ @Autowired
+ private AdminRolesService adminRolesService;
+
+ @Autowired
+ private FunctionalMenuService functionalMenuService;
+
+ @Autowired
+ private SearchService searchSvc;
+
+ @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, "getFunctionalMenu failed on UEB exception", e);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getFunctionalMenu failed", e);
+ }
+
+ return true;
+ }
+}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/InitUebHandler.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/InitUebHandler.java
new file mode 100644
index 00000000..472be3fb
--- /dev/null
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/InitUebHandler.java
@@ -0,0 +1,85 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ *
+ */
+package org.onap.portalapp.uebhandler;
+
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.onboarding.ueb.UebManager;
+import org.onap.portalsdk.core.onboarding.ueb.UebMsg;
+import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+
+//
+// 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 {
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(InitUebHandler.class);
+
+ // @Autowired
+ private 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.info(EELFLoggerDelegate.errorLogger, "Not starting UEB listening thread because property could not be read " + PortalApiConstants.UEB_LISTENERS_ENABLE);
+ }
+ }
+}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/MainUebHandler.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/MainUebHandler.java
new file mode 100644
index 00000000..33647874
--- /dev/null
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/MainUebHandler.java
@@ -0,0 +1,125 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.uebhandler;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import org.onap.portalapp.portal.ueb.EPUebMsgTypes;
+import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.onboarding.ueb.UebMsg;
+import org.onap.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");
+ private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MainUebHandler.class);
+
+ private ConcurrentLinkedQueue<UebMsg> inboxQueue = null;
+
+ @Autowired
+ private FunctionalMenuHandler funcMenuHandler;
+
+ @Autowired
+ private 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(EPCommonSystemProperties.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, "runHandler interrupted", e);
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "runHandler failed", e);
+ }
+ }
+ }
+}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/WidgetNotificationHandler.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/WidgetNotificationHandler.java
new file mode 100644
index 00000000..f91647e6
--- /dev/null
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/uebhandler/WidgetNotificationHandler.java
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software 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.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * 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.
+ *
+ * ============LICENSE_END============================================
+ *
+ *
+ */
+package org.onap.portalapp.uebhandler;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.List;
+
+import org.onap.portalapp.portal.domain.EPApp;
+import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
+import org.onap.portalapp.portal.service.EPAppService;
+import org.onap.portalapp.portal.service.SearchService;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.onboarding.ueb.UebException;
+import org.onap.portalsdk.core.onboarding.ueb.UebManager;
+import org.onap.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 {
+ private 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 failed", e);
+ }
+ }
+ }
+ } else {
+ logger.error(EELFLoggerDelegate.errorLogger,
+ "handleWidgetNotification: user " + requestMsg.getUserId() + " not found, source = "
+ + requestMsg.getSourceTopicName()
+ + ". This widget notification cannot be posted to other widgets");
+ }
+ }
+ }
+
+}