[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / controller / DashboardController.java
index 290a5ff..81a61d5 100644 (file)
-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-package org.openecomp.portalapp.portal.controller;\r
-\r
-import java.text.ParseException;\r
-import java.text.SimpleDateFormat;\r
-import java.util.ArrayList;\r
-import java.util.Date;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-\r
-import org.openecomp.portalapp.controller.EPRestrictedBaseController;\r
-import org.openecomp.portalapp.portal.domain.EPUser;\r
-import org.openecomp.portalapp.portal.domain.EcompAuditLog;\r
-import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;\r
-import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;\r
-import org.openecomp.portalapp.portal.ecomp.model.SearchResultItem;\r
-import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;\r
-import org.openecomp.portalapp.portal.logging.aop.EPEELFLoggerAdvice;\r
-import org.openecomp.portalapp.portal.logging.logic.EPLogUtil;\r
-import org.openecomp.portalapp.portal.service.DashboardSearchService;\r
-import org.openecomp.portalapp.portal.transport.CommonWidget;\r
-import org.openecomp.portalapp.portal.transport.CommonWidgetMeta;\r
-import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;\r
-import org.openecomp.portalapp.portal.utils.EcompPortalUtils;\r
-import org.openecomp.portalapp.util.EPUserUtils;\r
-import org.openecomp.portalsdk.core.domain.AuditLog;\r
-import org.openecomp.portalsdk.core.domain.support.CollaborateList;\r
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
-import org.openecomp.portalsdk.core.service.AuditService;\r
-import org.openecomp.portalsdk.core.util.SystemProperties;\r
-import org.slf4j.MDC;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.context.annotation.Configuration;\r
-import org.springframework.web.bind.annotation.RequestBody;\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-import org.springframework.web.bind.annotation.RequestMethod;\r
-import org.springframework.web.bind.annotation.RequestParam;\r
-import org.springframework.web.bind.annotation.RestController;\r
-\r
-/**\r
- * Controller supplies data to Angular services on the dashboard page.\r
- */\r
-@Configuration\r
-@RestController\r
-@RequestMapping("/portalApi/dashboard")\r
-public class DashboardController extends EPRestrictedBaseController {\r
-\r
-       private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DashboardController.class);\r
-\r
-       @Autowired\r
-       private DashboardSearchService searchService;\r
-       @Autowired\r
-       private AuditService auditService;\r
-       \r
-       public enum WidgetCategory {\r
-               EVENTS, NEWS, IMPORTANTRESOURCES;\r
-       }\r
-\r
-       /**\r
-        * Validates the resource type parameter.\r
-        * \r
-        * @param resourceType\r
-        * @return True if known in the enum WidgetCategory, else false.\r
-        */\r
-       private boolean isValidResourceType(String resourceType) {\r
-               if (resourceType == null)\r
-                       return false;\r
-               for (WidgetCategory wc : WidgetCategory.values())\r
-                       if (wc.name().equals(resourceType))\r
-                               return true;\r
-               return false;\r
-       }\r
-\r
-       /**\r
-        * Gets all widgets of the specified resource type. \r
-        * In iteration 41 (when widget will utilized service onboarding), this method can be removed, instead we will use CommonWidgetController.java (basic auth based)\r
-        * \r
-        * @param request\r
-        * @param resourceType\r
-        *            Request parameter.\r
-        * @return Rest response wrapped around a CommonWidgetMeta object.\r
-        */\r
-       @RequestMapping(value = "/widgetData", method = RequestMethod.GET, produces = "application/json")\r
-       public PortalRestResponse<CommonWidgetMeta> getWidgetData(HttpServletRequest request,\r
-                       @RequestParam String resourceType) {\r
-               if (!isValidResourceType(resourceType))\r
-                       return new PortalRestResponse<CommonWidgetMeta>(PortalRestStatusEnum.ERROR,\r
-                                       "Unexpected resource type " + resourceType, null);\r
-               return new PortalRestResponse<CommonWidgetMeta>(PortalRestStatusEnum.OK, "success",\r
-                               searchService.getWidgetData(resourceType));\r
-       }\r
-       \r
-       \r
-       /**\r
-        * Saves a batch of events, news or resources.\r
-        * \r
-        * @param commonWidgetMeta\r
-        *            read from POST body.\r
-        * @return Rest response wrapped around a String; e.g., "success" or "ERROR"\r
-        */\r
-       @RequestMapping(value = "/widgetDataBulk", method = RequestMethod.POST, produces = "application/json")\r
-       public PortalRestResponse<String> saveWidgetDataBulk(@RequestBody CommonWidgetMeta commonWidgetMeta) {\r
-               logger.debug(EELFLoggerDelegate.debugLogger, "saveWidgetDataBulk: argument is {}", commonWidgetMeta);\r
-               if (commonWidgetMeta.getCategory() == null || commonWidgetMeta.getCategory().trim().equals(""))\r
-                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "ERROR",\r
-                                       "Category cannot be null or empty");\r
-               if (!isValidResourceType(commonWidgetMeta.getCategory()))\r
-                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,\r
-                                       "Unexpected resource type " + commonWidgetMeta.getCategory(), null);\r
-               // validate dates\r
-               for (CommonWidget cw : commonWidgetMeta.getItems()) {\r
-                       String err = validateCommonWidget(cw);\r
-                       if (err != null)\r
-                               return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, err, null);\r
-               }\r
-               return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success",\r
-                               searchService.saveWidgetDataBulk(commonWidgetMeta));\r
-       }\r
-\r
-       /**\r
-        * Saves one: event, news or resource\r
-        * \r
-        * @param commonWidget\r
-        *            read from POST body\r
-        * @return Rest response wrapped around a String; e.g., "success" or "ERROR"\r
-        */\r
-       @RequestMapping(value = "/widgetData", method = RequestMethod.POST, produces = "application/json")\r
-       public PortalRestResponse<String> saveWidgetData(@RequestBody CommonWidget commonWidget) {\r
-               logger.debug(EELFLoggerDelegate.debugLogger, "saveWidgetData: argument is {}", commonWidget);\r
-               if (commonWidget.getCategory() == null || commonWidget.getCategory().trim().equals(""))\r
-                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "ERROR",\r
-                                       "Category cannot be null or empty");\r
-               String err = validateCommonWidget(commonWidget);\r
-               if (err != null)\r
-                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, err, null);\r
-               return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success",\r
-                               searchService.saveWidgetData(commonWidget));\r
-       }\r
-\r
-       /**\r
-        * Used by the validate function\r
-        */\r
-       private final SimpleDateFormat yearMonthDayFormat = new SimpleDateFormat("yyyy-MM-dd");\r
-\r
-       /**\r
-        * Validates the content of a common widget.\r
-        * \r
-        * @param cw\r
-        * @return null on success; an error message if validation fails.\r
-        * @throws Exception\r
-        */\r
-       private String validateCommonWidget(CommonWidget cw) {\r
-               if (!isValidResourceType(cw.getCategory()))\r
-                       return "Invalid category: " + cw.getCategory();\r
-               if (cw.getTitle() == null || cw.getTitle().trim().length() == 0)\r
-                       return "Title is missing";\r
-               if (cw.getHref() == null || cw.getHref().trim().length() == 0)\r
-                       return "HREF is missing";\r
-               if (!cw.getHref().toLowerCase().startsWith("http"))\r
-                       return "HREF does not start with http";\r
-               if (cw.getSortOrder() == null)\r
-                       return "Sort order is null";\r
-               if (WidgetCategory.EVENTS.name().equals(cw.getCategory())) {\r
-                       if (cw.getEventDate() == null || cw.getEventDate().trim().length() == 0)\r
-                               return "Date is missing";\r
-                       try {\r
-                               yearMonthDayFormat.setLenient(false);\r
-                               Date date = yearMonthDayFormat.parse(cw.getEventDate());\r
-                               if (date == null)\r
-                                       return "Failed to parse date " + cw.getEventDate();\r
-                       } catch (ParseException ex) {\r
-                               return ex.toString();\r
-                       }\r
-               }\r
-               return null;\r
-       }\r
-\r
-       /**\r
-        * Deletes one: event, news or resource\r
-        * \r
-        * @param commonWidget\r
-        *            read from POST body\r
-        * @return Rest response wrapped around a String; e.g., "success" or "ERROR"\r
-        */\r
-       @RequestMapping(value = "/deleteData", method = RequestMethod.POST, produces = "application/json")\r
-       public PortalRestResponse<String> deleteWidgetData(@RequestBody CommonWidget commonWidget) {\r
-               logger.debug(EELFLoggerDelegate.debugLogger, "deleteWidgetData: argument is {}", commonWidget);\r
-               return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success",\r
-                               searchService.deleteWidgetData(commonWidget));\r
-       }\r
-\r
-       /**\r
-        * Searches all portal for the input string.\r
-        * \r
-        * @param request\r
-        * @param searchString\r
-        * @return Rest response wrapped around a Map of String to List of Search\r
-        *         Result Item.\r
-        */\r
-       @EPAuditLog\r
-       @RequestMapping(value = "/search", method = RequestMethod.GET, produces = "application/json")\r
-       public PortalRestResponse<Map<String, List<SearchResultItem>>> searchPortal(HttpServletRequest request,\r
-                       @RequestParam String searchString) {\r
-\r
-               if (searchString != null)\r
-                       searchString = searchString.trim();\r
-               EPUser user = EPUserUtils.getUserSession(request);\r
-               try {\r
-                       if (user == null) {\r
-                               return new PortalRestResponse<>(PortalRestStatusEnum.ERROR,\r
-                                               "searchPortal: User object is null? - check logs",\r
-                                               new HashMap<String, List<SearchResultItem>>());\r
-                       } else if (searchString == null || searchString.length() == 0) {\r
-                               return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "searchPortal: String string is null",\r
-                                               new HashMap<String, List<SearchResultItem>>());\r
-                       } else {\r
-                               logger.debug(EELFLoggerDelegate.debugLogger, "searchPortal: user {}, search string '{}'",\r
-                                               user.getLoginId(), searchString);\r
-                               Map<String, List<SearchResultItem>> results = searchService.searchResults(user.getLoginId(),\r
-                                               searchString);\r
-                               /*Audit log the search*/\r
-                               AuditLog auditLog = new AuditLog();\r
-                               auditLog.setUserId(user.getId());\r
-                               auditLog.setActivityCode(EcompAuditLog.CD_ACTIVITY_SEARCH);\r
-                               auditLog.setComments(searchString);\r
-                               MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC());          \r
-                               auditService.logActivity(auditLog, null);\r
-                               MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC());\r
-                               EcompPortalUtils.calculateDateTimeDifferenceForLog(MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));\r
-                               logger.info(EELFLoggerDelegate.auditLogger, EPLogUtil.formatAuditLogMessage("DashboardController.PortalRestResponse", \r
-                                               EcompAuditLog.CD_ACTIVITY_SEARCH, user.getOrgUserId(), null, searchString));    \r
-                               MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);\r
-                               MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);\r
-                               MDC.remove(SystemProperties.MDC_TIMER);\r
-                               return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);\r
-                       }\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "searchPortal failed", e);\r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage() + " - check logs.",\r
-                                       new HashMap<String, List<SearchResultItem>>());\r
-               }\r
-       }\r
-\r
-       /**\r
-        * Gets all active users.\r
-        * \r
-        * TODO: should only the superuser be allowed to use this API?\r
-        * \r
-        * @param request\r
-        * @return Rest response wrapped around a list of String\r
-        */\r
-       @RequestMapping(value = "/activeUsers", method = RequestMethod.GET, produces = "application/json")\r
-       public List<String> getActiveUsers(HttpServletRequest request) {\r
-               List<String> activeUsers = null;\r
-               List<String> onlineUsers = new ArrayList<>();\r
-               try {\r
-                       EPUser user = EPUserUtils.getUserSession(request);\r
-                       String userId = user.getOrgUserId();\r
-\r
-                       activeUsers = searchService.getRelatedUsers(userId);\r
-                       HashSet<String> usersSet = CollaborateList.getInstance().getAllUserName();\r
-                       for (String users : activeUsers) {\r
-                               if (usersSet.contains(users)) {\r
-                                       onlineUsers.add(users);\r
-                               }\r
-                       }\r
-\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "getActiveUsers failed", e);\r
-               }\r
-               return onlineUsers;\r
-       }\r
-       \r
-       /**\r
-        * Gets the refresh interval and duration of a cycle of continuous refreshing for the online users side panel, both in milliseconds.\r
-        * \r
-        * @param request\r
-        * @return Rest response wrapped around a number that is the number of milliseconds.\r
-        */\r
-       @RequestMapping(value = "/onlineUserUpdateRate", method = RequestMethod.GET, produces = "application/json")\r
-       public PortalRestResponse<Map<String, String>> getOnlineUserUpdateRate(HttpServletRequest request) {\r
-               try {\r
-                       String updateRate = SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_RATE);     \r
-                       String updateDuration = SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_DURATION);                             \r
-                       Integer rateInMiliSec = Integer.valueOf(updateRate)*1000;\r
-                       Integer durationInMiliSec = Integer.valueOf(updateDuration)*1000;\r
-                       Map<String, String> results = new HashMap<String,String>();\r
-                       results.put("onlineUserUpdateRate", String.valueOf(rateInMiliSec));\r
-                       results.put("onlineUserUpdateDuration", String.valueOf(durationInMiliSec));                     \r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "getOnlineUserUpdateRate failed", e);\r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);\r
-               }               \r
-       }\r
-\r
-       /**\r
-        * Gets the window width threshold for collapsing right menu from system.properties.\r
-        * \r
-        * @param request\r
-        * @return Rest response wrapped around a number that is the window width threshold to collapse right menu.\r
-        */\r
-       @RequestMapping(value = "/windowWidthThresholdRightMenu", method = RequestMethod.GET, produces = "application/json")\r
-       public PortalRestResponse<Map<String, String>> getWindowWidthThresholdForRightMenu(HttpServletRequest request) {\r
-               try {\r
-                       String windowWidthString = SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_RIGHT_MENU);    \r
-                       Integer windowWidth = Integer.valueOf(windowWidthString);\r
-                       Map<String, String> results = new HashMap<String,String>();\r
-                       results.put("windowWidth", String.valueOf(windowWidth));\r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "getWindowWidthThresholdForRightMenu failed", e);\r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);\r
-               }               \r
-       }\r
-\r
-\r
-       /**\r
-        * Gets the window width threshold for collapsing left menu from system.properties.\r
-        * \r
-        * @param request\r
-        * @return Rest response wrapped around a number that is the window width threshold to collapse the left menu.\r
-        */\r
-       @RequestMapping(value = "/windowWidthThresholdLeftMenu", method = RequestMethod.GET, produces = "application/json")\r
-       public PortalRestResponse<Map<String, String>> getWindowWidthThresholdForLeftMenu(HttpServletRequest request) {\r
-               try {\r
-                       String windowWidthString = SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_LEFT_MENU);     \r
-                       Integer windowWidth = Integer.valueOf(windowWidthString);\r
-                       Map<String, String> results = new HashMap<String,String>();\r
-                       results.put("windowWidth", String.valueOf(windowWidth));\r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "getWindowWidthThresholdForLeftMenu failed", e);\r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);\r
-               }               \r
-       }\r
-       \r
-       /**\r
-        * Gets only those users that are 'related' to the currently logged-in user.\r
-        * \r
-        * @param request\r
-        * @return Rest response wrapped around a List of String\r
-        */\r
-       @RequestMapping(value = "/relatedUsers", method = RequestMethod.GET, produces = "application/json")\r
-       public PortalRestResponse<List<String>> activeUsers(HttpServletRequest request) {\r
-               EPUser user = EPUserUtils.getUserSession(request);\r
-               try {\r
-                       if (user == null) {\r
-                               return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "User object is null? - check logs",\r
-                                               new ArrayList<>());\r
-                       } else {\r
-                               logger.debug(EELFLoggerDelegate.debugLogger, "activeUsers: searching for user {}", user.getLoginId());\r
-                               return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success",\r
-                                               searchService.getRelatedUsers(user.getLoginId()));\r
-                       }\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "activeUsers failed", e);\r
-                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage() + " - check logs.",\r
-                                       new ArrayList<>());\r
-               }\r
-       }\r
-\r
-}\r
+/*-
+ * ================================================================================
+ * 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.portal.controller;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.openecomp.portalapp.controller.EPRestrictedBaseController;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.domain.EcompAuditLog;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.ecomp.model.SearchResultItem;
+import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
+import org.openecomp.portalapp.portal.logging.aop.EPEELFLoggerAdvice;
+import org.openecomp.portalapp.portal.logging.logic.EPLogUtil;
+import org.openecomp.portalapp.portal.service.DashboardSearchService;
+import org.openecomp.portalapp.portal.transport.CommonWidget;
+import org.openecomp.portalapp.portal.transport.CommonWidgetMeta;
+import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
+import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalsdk.core.domain.AuditLog;
+import org.openecomp.portalsdk.core.domain.support.CollaborateList;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.service.AuditService;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.slf4j.MDC;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * Controller supplies data to Angular services on the dashboard page.
+ */
+@Configuration
+@RestController
+@RequestMapping("/portalApi/dashboard")
+public class DashboardController extends EPRestrictedBaseController {
+
+       private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DashboardController.class);
+
+       @Autowired
+       private DashboardSearchService searchService;
+       @Autowired
+       private AuditService auditService;
+       
+       public enum WidgetCategory {
+               EVENTS, NEWS, IMPORTANTRESOURCES;
+       }
+
+       /**
+        * Validates the resource type parameter.
+        * 
+        * @param resourceType
+        * @return True if known in the enum WidgetCategory, else false.
+        */
+       private boolean isValidResourceType(String resourceType) {
+               if (resourceType == null)
+                       return false;
+               for (WidgetCategory wc : WidgetCategory.values())
+                       if (wc.name().equals(resourceType))
+                               return true;
+               return false;
+       }
+
+       /**
+        * Gets all widgets of the specified resource type. 
+        * In iteration 41 (when widget will utilized service onboarding), this method can be removed, instead we will use CommonWidgetController.java (basic auth based)
+        * 
+        * @param request
+        * @param resourceType
+        *            Request parameter.
+        * @return Rest response wrapped around a CommonWidgetMeta object.
+        */
+       @RequestMapping(value = "/widgetData", method = RequestMethod.GET, produces = "application/json")
+       public PortalRestResponse<CommonWidgetMeta> getWidgetData(HttpServletRequest request,
+                       @RequestParam String resourceType) {
+               if (!isValidResourceType(resourceType))
+                       return new PortalRestResponse<CommonWidgetMeta>(PortalRestStatusEnum.ERROR,
+                                       "Unexpected resource type " + resourceType, null);
+               return new PortalRestResponse<CommonWidgetMeta>(PortalRestStatusEnum.OK, "success",
+                               searchService.getWidgetData(resourceType));
+       }
+       
+       
+       /**
+        * Saves a batch of events, news or resources.
+        * 
+        * @param commonWidgetMeta
+        *            read from POST body.
+        * @return Rest response wrapped around a String; e.g., "success" or "ERROR"
+        */
+       @RequestMapping(value = "/widgetDataBulk", method = RequestMethod.POST, produces = "application/json")
+       public PortalRestResponse<String> saveWidgetDataBulk(@RequestBody CommonWidgetMeta commonWidgetMeta) {
+               logger.debug(EELFLoggerDelegate.debugLogger, "saveWidgetDataBulk: argument is {}", commonWidgetMeta);
+               if (commonWidgetMeta.getCategory() == null || commonWidgetMeta.getCategory().trim().equals(""))
+                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "ERROR",
+                                       "Category cannot be null or empty");
+               if (!isValidResourceType(commonWidgetMeta.getCategory()))
+                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR,
+                                       "Unexpected resource type " + commonWidgetMeta.getCategory(), null);
+               // validate dates
+               for (CommonWidget cw : commonWidgetMeta.getItems()) {
+                       String err = validateCommonWidget(cw);
+                       if (err != null)
+                               return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, err, null);
+               }
+               return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success",
+                               searchService.saveWidgetDataBulk(commonWidgetMeta));
+       }
+
+       /**
+        * Saves one: event, news or resource
+        * 
+        * @param commonWidget
+        *            read from POST body
+        * @return Rest response wrapped around a String; e.g., "success" or "ERROR"
+        */
+       @RequestMapping(value = "/widgetData", method = RequestMethod.POST, produces = "application/json")
+       public PortalRestResponse<String> saveWidgetData(@RequestBody CommonWidget commonWidget) {
+               logger.debug(EELFLoggerDelegate.debugLogger, "saveWidgetData: argument is {}", commonWidget);
+               if (commonWidget.getCategory() == null || commonWidget.getCategory().trim().equals(""))
+                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "ERROR",
+                                       "Category cannot be null or empty");
+               String err = validateCommonWidget(commonWidget);
+               if (err != null)
+                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, err, null);
+               return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success",
+                               searchService.saveWidgetData(commonWidget));
+       }
+
+       /**
+        * Used by the validate function
+        */
+       private final SimpleDateFormat yearMonthDayFormat = new SimpleDateFormat("yyyy-MM-dd");
+
+       /**
+        * Validates the content of a common widget.
+        * 
+        * @param cw
+        * @return null on success; an error message if validation fails.
+        * @throws Exception
+        */
+       private String validateCommonWidget(CommonWidget cw) {
+               if (!isValidResourceType(cw.getCategory()))
+                       return "Invalid category: " + cw.getCategory();
+               if (cw.getTitle() == null || cw.getTitle().trim().length() == 0)
+                       return "Title is missing";
+               if (cw.getHref() == null || cw.getHref().trim().length() == 0)
+                       return "HREF is missing";
+               if (!cw.getHref().toLowerCase().startsWith("http"))
+                       return "HREF does not start with http";
+               if (cw.getSortOrder() == null)
+                       return "Sort order is null";
+               if (WidgetCategory.EVENTS.name().equals(cw.getCategory())) {
+                       if (cw.getEventDate() == null || cw.getEventDate().trim().length() == 0)
+                               return "Date is missing";
+                       try {
+                               yearMonthDayFormat.setLenient(false);
+                               Date date = yearMonthDayFormat.parse(cw.getEventDate());
+                               if (date == null)
+                                       return "Failed to parse date " + cw.getEventDate();
+                       } catch (ParseException ex) {
+                               return ex.toString();
+                       }
+               }
+               return null;
+       }
+
+       /**
+        * Deletes one: event, news or resource
+        * 
+        * @param commonWidget
+        *            read from POST body
+        * @return Rest response wrapped around a String; e.g., "success" or "ERROR"
+        */
+       @RequestMapping(value = "/deleteData", method = RequestMethod.POST, produces = "application/json")
+       public PortalRestResponse<String> deleteWidgetData(@RequestBody CommonWidget commonWidget) {
+               logger.debug(EELFLoggerDelegate.debugLogger, "deleteWidgetData: argument is {}", commonWidget);
+               return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success",
+                               searchService.deleteWidgetData(commonWidget));
+       }
+
+       /**
+        * Searches all portal for the input string.
+        * 
+        * @param request
+        * @param searchString
+        * @return Rest response wrapped around a Map of String to List of Search
+        *         Result Item.
+        */
+       @EPAuditLog
+       @RequestMapping(value = "/search", method = RequestMethod.GET, produces = "application/json")
+       public PortalRestResponse<Map<String, List<SearchResultItem>>> searchPortal(HttpServletRequest request,
+                       @RequestParam String searchString) {
+
+               if (searchString != null)
+                       searchString = searchString.trim();
+               EPUser user = EPUserUtils.getUserSession(request);
+               try {
+                       if (user == null) {
+                               return new PortalRestResponse<>(PortalRestStatusEnum.ERROR,
+                                               "searchPortal: User object is null? - check logs",
+                                               new HashMap<String, List<SearchResultItem>>());
+                       } else if (searchString == null || searchString.length() == 0) {
+                               return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "searchPortal: String string is null",
+                                               new HashMap<String, List<SearchResultItem>>());
+                       } else {
+                               logger.debug(EELFLoggerDelegate.debugLogger, "searchPortal: user {}, search string '{}'",
+                                               user.getLoginId(), searchString);
+                               Map<String, List<SearchResultItem>> results = searchService.searchResults(user.getLoginId(),
+                                               searchString);
+                               /*Audit log the search*/
+                               AuditLog auditLog = new AuditLog();
+                               auditLog.setUserId(user.getId());
+                               auditLog.setActivityCode(EcompAuditLog.CD_ACTIVITY_SEARCH);
+                               auditLog.setComments(searchString);
+                               MDC.put(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC());          
+                               auditService.logActivity(auditLog, null);
+                               MDC.put(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP,EPEELFLoggerAdvice.getCurrentDateTimeUTC());
+                               EcompPortalUtils.calculateDateTimeDifferenceForLog(MDC.get(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP),MDC.get(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP));
+                               logger.info(EELFLoggerDelegate.auditLogger, EPLogUtil.formatAuditLogMessage("DashboardController.PortalRestResponse", 
+                                               EcompAuditLog.CD_ACTIVITY_SEARCH, user.getOrgUserId(), null, searchString));    
+                               MDC.remove(EPCommonSystemProperties.AUDITLOG_BEGIN_TIMESTAMP);
+                               MDC.remove(EPCommonSystemProperties.AUDITLOG_END_TIMESTAMP);
+                               MDC.remove(SystemProperties.MDC_TIMER);
+                               return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);
+                       }
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "searchPortal failed", e);
+                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage() + " - check logs.",
+                                       new HashMap<String, List<SearchResultItem>>());
+               }
+       }
+
+       /**
+        * Gets all active users.
+        * 
+        * TODO: should only the superuser be allowed to use this API?
+        * 
+        * @param request
+        * @return Rest response wrapped around a list of String
+        */
+       @RequestMapping(value = "/activeUsers", method = RequestMethod.GET, produces = "application/json")
+       public List<String> getActiveUsers(HttpServletRequest request) {
+               List<String> activeUsers = null;
+               List<String> onlineUsers = new ArrayList<>();
+               try {
+                       EPUser user = EPUserUtils.getUserSession(request);
+                       String userId = user.getOrgUserId();
+
+                       activeUsers = searchService.getRelatedUsers(userId);
+                       HashSet<String> usersSet = CollaborateList.getInstance().getAllUserName();
+                       for (String users : activeUsers) {
+                               if (usersSet.contains(users)) {
+                                       onlineUsers.add(users);
+                               }
+                       }
+
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "getActiveUsers failed", e);
+               }
+               return onlineUsers;
+       }
+       
+       /**
+        * Gets the refresh interval and duration of a cycle of continuous refreshing for the online users side panel, both in milliseconds.
+        * 
+        * @param request
+        * @return Rest response wrapped around a number that is the number of milliseconds.
+        */
+       @RequestMapping(value = "/onlineUserUpdateRate", method = RequestMethod.GET, produces = "application/json")
+       public PortalRestResponse<Map<String, String>> getOnlineUserUpdateRate(HttpServletRequest request) {
+               try {
+                       String updateRate = SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_RATE);     
+                       String updateDuration = SystemProperties.getProperty(EPCommonSystemProperties.ONLINE_USER_UPDATE_DURATION);                             
+                       Integer rateInMiliSec = Integer.valueOf(updateRate)*1000;
+                       Integer durationInMiliSec = Integer.valueOf(updateDuration)*1000;
+                       Map<String, String> results = new HashMap<String,String>();
+                       results.put("onlineUserUpdateRate", String.valueOf(rateInMiliSec));
+                       results.put("onlineUserUpdateDuration", String.valueOf(durationInMiliSec));                     
+                       return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "getOnlineUserUpdateRate failed", e);
+                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);
+               }               
+       }
+
+       /**
+        * Gets the window width threshold for collapsing right menu from system.properties.
+        * 
+        * @param request
+        * @return Rest response wrapped around a number that is the window width threshold to collapse right menu.
+        */
+       @RequestMapping(value = "/windowWidthThresholdRightMenu", method = RequestMethod.GET, produces = "application/json")
+       public PortalRestResponse<Map<String, String>> getWindowWidthThresholdForRightMenu(HttpServletRequest request) {
+               try {
+                       String windowWidthString = SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_RIGHT_MENU);    
+                       Integer windowWidth = Integer.valueOf(windowWidthString);
+                       Map<String, String> results = new HashMap<String,String>();
+                       results.put("windowWidth", String.valueOf(windowWidth));
+                       return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "getWindowWidthThresholdForRightMenu failed", e);
+                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);
+               }               
+       }
+
+
+       /**
+        * Gets the window width threshold for collapsing left menu from system.properties.
+        * 
+        * @param request
+        * @return Rest response wrapped around a number that is the window width threshold to collapse the left menu.
+        */
+       @RequestMapping(value = "/windowWidthThresholdLeftMenu", method = RequestMethod.GET, produces = "application/json")
+       public PortalRestResponse<Map<String, String>> getWindowWidthThresholdForLeftMenu(HttpServletRequest request) {
+               try {
+                       String windowWidthString = SystemProperties.getProperty(EPCommonSystemProperties.WINDOW_WIDTH_THRESHOLD_LEFT_MENU);     
+                       Integer windowWidth = Integer.valueOf(windowWidthString);
+                       Map<String, String> results = new HashMap<String,String>();
+                       results.put("windowWidth", String.valueOf(windowWidth));
+                       return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", results);
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "getWindowWidthThresholdForLeftMenu failed", e);
+                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.toString(), null);
+               }               
+       }
+       
+       /**
+        * Gets only those users that are 'related' to the currently logged-in user.
+        * 
+        * @param request
+        * @return Rest response wrapped around a List of String
+        */
+       @RequestMapping(value = "/relatedUsers", method = RequestMethod.GET, produces = "application/json")
+       public PortalRestResponse<List<String>> activeUsers(HttpServletRequest request) {
+               EPUser user = EPUserUtils.getUserSession(request);
+               try {
+                       if (user == null) {
+                               return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "User object is null? - check logs",
+                                               new ArrayList<>());
+                       } else {
+                               logger.debug(EELFLoggerDelegate.debugLogger, "activeUsers: searching for user {}", user.getLoginId());
+                               return new PortalRestResponse<>(PortalRestStatusEnum.OK, "success",
+                                               searchService.getRelatedUsers(user.getLoginId()));
+                       }
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "activeUsers failed", e);
+                       return new PortalRestResponse<>(PortalRestStatusEnum.ERROR, e.getMessage() + " - check logs.",
+                                       new ArrayList<>());
+               }
+       }
+
+}