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.portal.controller;
 
  22 import javax.servlet.http.HttpServletRequest;
 
  23 import org.openecomp.portalapp.portal.controller.DashboardController.WidgetCategory;
 
  24 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
 
  25 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
 
  26 import org.openecomp.portalapp.portal.service.DashboardSearchService;
 
  27 import org.openecomp.portalapp.portal.transport.CommonWidgetMeta;
 
  28 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
 
  29 import org.springframework.beans.factory.annotation.Autowired;
 
  30 import org.springframework.web.bind.annotation.RequestMapping;
 
  31 import org.springframework.web.bind.annotation.RequestMethod;
 
  32 import org.springframework.web.bind.annotation.RequestParam;
 
  33 import org.springframework.web.bind.annotation.RestController;
 
  36 public class CommonWidgetController implements BasicAuthenticationController{
 
  39         private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CommonWidgetController.class);
 
  41         private DashboardSearchService searchService;
 
  44          * Validates the resource type parameter.
 
  47          * @return True if known in the enum WidgetCategory, else false.
 
  49         private boolean isValidResourceType(String resourceType) {
 
  50                 if (resourceType == null)
 
  52                 for (WidgetCategory wc : WidgetCategory.values())
 
  53                         if (wc.name().equals(resourceType))
 
  59          * Gets all widgets of the specified resource type.
 
  64          * @return Rest response wrapped around a CommonWidgetMeta object.
 
  66         @RequestMapping(value = "/widgetData", method = RequestMethod.GET, produces = "application/json")
 
  67         public PortalRestResponse<CommonWidgetMeta> getWidgetData(HttpServletRequest request,
 
  68                         @RequestParam String resourceType) {
 
  69                 if (!isValidResourceType(resourceType)){
 
  70                         logger.debug(EELFLoggerDelegate.debugLogger, "Unexpected resource type {}", resourceType);
 
  71                         return new PortalRestResponse<CommonWidgetMeta>(PortalRestStatusEnum.ERROR,
 
  72                                         "Unexpected resource type " + resourceType, null);
 
  74                 return new PortalRestResponse<CommonWidgetMeta>(PortalRestStatusEnum.OK, "success",
 
  75                                 searchService.getWidgetData(resourceType));