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 java.util.Collections;
23 import java.util.Comparator;
24 import java.util.HashMap;
25 import java.util.List;
27 import javax.servlet.http.HttpServletRequest;
29 import org.json.JSONObject;
30 import org.openecomp.portalapp.controller.EPRestrictedBaseController;
31 import org.openecomp.portalapp.portal.ecomp.model.AppCategoryFunctionsItem;
32 import org.openecomp.portalapp.portal.ecomp.model.AppContactUsItem;
33 import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
34 import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
35 import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
36 import org.openecomp.portalapp.portal.service.AppContactUsService;
37 import org.openecomp.portalapp.portal.utils.EPCommonSystemProperties;
38 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
39 import org.openecomp.portalsdk.core.util.SystemProperties;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.context.annotation.EnableAspectJAutoProxy;
42 import org.springframework.web.bind.annotation.PathVariable;
43 import org.springframework.web.bind.annotation.RequestBody;
44 import org.springframework.web.bind.annotation.RequestMapping;
45 import org.springframework.web.bind.annotation.RequestMethod;
46 import org.springframework.web.bind.annotation.RestController;
49 @RequestMapping("/portalApi/contactus")
50 @org.springframework.context.annotation.Configuration
51 @EnableAspectJAutoProxy
53 public class AppContactUsController extends EPRestrictedBaseController {
55 static final String FAILURE = "failure";
57 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppContactUsController.class);
60 private AppContactUsService contactUsService;
63 * Answers a JSON object with three items from the system.properties file:
64 * user self-help ticket URL, email for feedback, and Portal info link.
69 @RequestMapping(value = "/feedback", method = RequestMethod.GET, produces = "application/json")
70 public PortalRestResponse<String> getPortalDetails(HttpServletRequest request) {
71 PortalRestResponse<String> portalRestResponse = null;
73 final String ticketUrl = SystemProperties.getProperty(EPCommonSystemProperties.USH_TICKET_URL);
74 final String portalInfoUrl = SystemProperties.getProperty(EPCommonSystemProperties.PORTAL_INFO_URL);
75 final String feedbackEmail = SystemProperties.getProperty(EPCommonSystemProperties.FEEDBACK_EMAIL_ADDRESS);
76 HashMap<String, String> map = new HashMap<String, String>();
77 map.put(EPCommonSystemProperties.USH_TICKET_URL, ticketUrl);
78 map.put(EPCommonSystemProperties.PORTAL_INFO_URL, portalInfoUrl);
79 map.put(EPCommonSystemProperties.FEEDBACK_EMAIL_ADDRESS, feedbackEmail);
80 JSONObject j = new JSONObject(map);
81 String contactUsPortalResponse = j.toString();
82 portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success",
83 contactUsPortalResponse);
84 } catch (Exception e) {
85 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, FAILURE, e.getMessage());
87 return portalRestResponse;
91 * Answers the contents of the contact-us table, extended with the
97 @RequestMapping(value = "/list", method = RequestMethod.GET, produces = "application/json")
98 public PortalRestResponse<List<AppContactUsItem>> getAppContactUsList(HttpServletRequest request) {
99 PortalRestResponse<List<AppContactUsItem>> portalRestResponse = null;
101 List<AppContactUsItem> contents = contactUsService.getAppContactUs();
102 portalRestResponse = new PortalRestResponse<List<AppContactUsItem>>(PortalRestStatusEnum.OK, "success",
104 } catch (Exception e) {
105 logger.error(EELFLoggerDelegate.errorLogger, "getAppContactUsList failed", e);
106 portalRestResponse = new PortalRestResponse<List<AppContactUsItem>>(PortalRestStatusEnum.ERROR,
107 e.getMessage(), null);
109 return portalRestResponse;
113 * Answers a list of objects, one per application, extended with available
114 * data on how to contact that app's organization (possibly none).
119 @RequestMapping(value = "/allapps", method = RequestMethod.GET, produces = "application/json")
120 public PortalRestResponse<List<AppContactUsItem>> getAppsAndContacts(HttpServletRequest request) {
121 PortalRestResponse<List<AppContactUsItem>> portalRestResponse = null;
123 List<AppContactUsItem> contents = contactUsService.getAppsAndContacts();
124 portalRestResponse = new PortalRestResponse<List<AppContactUsItem>>(PortalRestStatusEnum.OK, "success",
126 } catch (Exception e) {
127 logger.error(EELFLoggerDelegate.errorLogger, "getAllAppsAndContacts failed", e);
128 portalRestResponse = new PortalRestResponse<List<AppContactUsItem>>(PortalRestStatusEnum.ERROR,
129 e.getMessage(), null);
131 return portalRestResponse;
135 * Sorts by category name.
137 private Comparator<AppCategoryFunctionsItem> appCategoryFunctionsItemComparator = new Comparator<AppCategoryFunctionsItem>() {
139 public int compare(AppCategoryFunctionsItem o1, AppCategoryFunctionsItem o2) {
140 return o1.getCategory().compareTo(o2.getCategory());
145 * Answers a list of objects with category-application-function details. Not
146 * all applications participate in the functional menu.
151 @RequestMapping(value = "/functions", method = RequestMethod.GET, produces = "application/json")
152 public PortalRestResponse<List<AppCategoryFunctionsItem>> getAppCategoryFunctions(HttpServletRequest request) {
153 PortalRestResponse<List<AppCategoryFunctionsItem>> portalRestResponse = null;
155 List<AppCategoryFunctionsItem> contents = contactUsService.getAppCategoryFunctions();
156 // logger.debug(EELFLoggerDelegate.debugLogger,
157 // "getAppCategoryFunctions: result list size is " +
159 Collections.sort(contents, appCategoryFunctionsItemComparator);
160 portalRestResponse = new PortalRestResponse<List<AppCategoryFunctionsItem>>(PortalRestStatusEnum.OK,
161 "success", contents);
162 } catch (Exception e) {
163 logger.error(EELFLoggerDelegate.errorLogger, "getAppCategoryFunctions failed", e);
164 // TODO build JSON error
165 portalRestResponse = new PortalRestResponse<List<AppCategoryFunctionsItem>>(PortalRestStatusEnum.ERROR,
166 e.getMessage(), null);
168 return portalRestResponse;
172 * Accepts a new application's contact us details.
177 @RequestMapping(value = "/save", method = RequestMethod.POST, produces = "application/json")
178 public PortalRestResponse<String> save(@RequestBody AppContactUsItem contactUs) {
180 if (contactUs == null || contactUs.getAppName() == null)
181 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, FAILURE,
182 "AppName cannot be null or empty");
184 String saveAppContactUs = FAILURE;
186 saveAppContactUs = contactUsService.saveAppContactUs(contactUs);
187 } catch (Exception e) {
188 return new PortalRestResponse<String>(PortalRestStatusEnum.OK, saveAppContactUs, e.getMessage());
190 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, saveAppContactUs, "");
193 @RequestMapping(value = "/saveAll", method = RequestMethod.POST, produces = "application/json")
194 public PortalRestResponse<String> save(@RequestBody List<AppContactUsItem> contactUsList) {
196 String saveAppContactUs = FAILURE;
198 saveAppContactUs = contactUsService.saveAppContactUs(contactUsList);
199 } catch (Exception e) {
200 return new PortalRestResponse<String>(PortalRestStatusEnum.OK, saveAppContactUs, e.getMessage());
202 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, saveAppContactUs, "");
206 * Deletes the specified application's contact-us details entry from the
212 @RequestMapping(value = "/delete/{appid}", method = RequestMethod.POST, produces = "application/json")
213 public PortalRestResponse<String> delete(@PathVariable("appid") Long id) {
215 String saveAppContactUs = FAILURE;
217 saveAppContactUs = contactUsService.deleteContactUs(id);
218 } catch (Exception e) {
219 return new PortalRestResponse<String>(PortalRestStatusEnum.OK, saveAppContactUs, e.getMessage());
221 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, saveAppContactUs, "");