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