2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.controller;
40 import java.util.Collections;
41 import java.util.Comparator;
42 import java.util.HashMap;
43 import java.util.List;
45 import javax.servlet.http.HttpServletRequest;
47 import org.json.JSONObject;
48 import org.onap.portalapp.controller.EPRestrictedBaseController;
49 import org.onap.portalapp.portal.ecomp.model.AppCategoryFunctionsItem;
50 import org.onap.portalapp.portal.ecomp.model.AppContactUsItem;
51 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
52 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
53 import org.onap.portalapp.portal.logging.aop.EPAuditLog;
54 import org.onap.portalapp.portal.service.AppContactUsService;
55 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
56 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
57 import org.onap.portalsdk.core.util.SystemProperties;
58 import org.springframework.beans.factory.annotation.Autowired;
59 import org.springframework.context.annotation.EnableAspectJAutoProxy;
60 import org.springframework.web.bind.annotation.PathVariable;
61 import org.springframework.web.bind.annotation.RequestBody;
62 import org.springframework.web.bind.annotation.RequestMapping;
63 import org.springframework.web.bind.annotation.RequestMethod;
64 import org.springframework.web.bind.annotation.RestController;
67 @RequestMapping("/portalApi/contactus")
68 @org.springframework.context.annotation.Configuration
69 @EnableAspectJAutoProxy
71 public class AppContactUsController extends EPRestrictedBaseController {
73 static final String FAILURE = "failure";
75 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppContactUsController.class);
78 private AppContactUsService contactUsService;
81 * Answers a JSON object with three items from the system.properties file:
82 * user self-help ticket URL, email for feedback, and Portal info link.
84 * @param request HttpServletRequest
85 * @return PortalRestResponse
87 @RequestMapping(value = "/feedback", method = RequestMethod.GET, produces = "application/json")
88 public PortalRestResponse<String> getPortalDetails(HttpServletRequest request) {
89 PortalRestResponse<String> portalRestResponse = null;
91 final String ticketUrl = SystemProperties.getProperty(EPCommonSystemProperties.USH_TICKET_URL);
92 final String portalInfoUrl = SystemProperties.getProperty(EPCommonSystemProperties.PORTAL_INFO_URL);
93 final String feedbackEmail = SystemProperties.getProperty(EPCommonSystemProperties.FEEDBACK_EMAIL_ADDRESS);
94 HashMap<String, String> map = new HashMap<String, String>();
95 map.put(EPCommonSystemProperties.USH_TICKET_URL, ticketUrl);
96 map.put(EPCommonSystemProperties.PORTAL_INFO_URL, portalInfoUrl);
97 map.put(EPCommonSystemProperties.FEEDBACK_EMAIL_ADDRESS, feedbackEmail);
98 JSONObject j = new JSONObject(map);
99 String contactUsPortalResponse = j.toString();
100 portalRestResponse = new PortalRestResponse<String>(PortalRestStatusEnum.OK, "success",
101 contactUsPortalResponse);
102 } catch (Exception e) {
103 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, FAILURE, e.getMessage());
105 return portalRestResponse;
109 * Answers the contents of the contact-us table, extended with the
112 * @param request HttpServletRequest
113 * @return PortalRestResponse<List<AppContactUsItem>>
115 @RequestMapping(value = "/list", method = RequestMethod.GET, produces = "application/json")
116 public PortalRestResponse<List<AppContactUsItem>> getAppContactUsList(HttpServletRequest request) {
117 PortalRestResponse<List<AppContactUsItem>> portalRestResponse = null;
119 List<AppContactUsItem> contents = contactUsService.getAppContactUs();
120 portalRestResponse = new PortalRestResponse<List<AppContactUsItem>>(PortalRestStatusEnum.OK, "success",
122 } catch (Exception e) {
123 logger.error(EELFLoggerDelegate.errorLogger, "getAppContactUsList failed", e);
124 portalRestResponse = new PortalRestResponse<List<AppContactUsItem>>(PortalRestStatusEnum.ERROR,
125 e.getMessage(), null);
127 return portalRestResponse;
131 * Answers a list of objects, one per application, extended with available
132 * data on how to contact that app's organization (possibly none).
134 * @param request HttpServletRequest
135 * @return PortalRestResponse<List<AppContactUsItem>>
137 @RequestMapping(value = "/allapps", method = RequestMethod.GET, produces = "application/json")
138 public PortalRestResponse<List<AppContactUsItem>> getAppsAndContacts(HttpServletRequest request) {
139 PortalRestResponse<List<AppContactUsItem>> portalRestResponse = null;
141 List<AppContactUsItem> contents = contactUsService.getAppsAndContacts();
142 portalRestResponse = new PortalRestResponse<List<AppContactUsItem>>(PortalRestStatusEnum.OK, "success",
144 } catch (Exception e) {
145 logger.error(EELFLoggerDelegate.errorLogger, "getAllAppsAndContacts failed", e);
146 portalRestResponse = new PortalRestResponse<List<AppContactUsItem>>(PortalRestStatusEnum.ERROR,
147 e.getMessage(), null);
149 return portalRestResponse;
153 * Sorts by category name.
155 private Comparator<AppCategoryFunctionsItem> appCategoryFunctionsItemComparator = new Comparator<AppCategoryFunctionsItem>() {
157 public int compare(AppCategoryFunctionsItem o1, AppCategoryFunctionsItem o2) {
158 return o1.getCategory().compareTo(o2.getCategory());
163 * Answers a list of objects with category-application-function details. Not
164 * all applications participate in the functional menu.
166 * @param request HttpServletRequest
167 * @return PortalRestResponse<List<AppCategoryFunctionsItem>>
169 @RequestMapping(value = "/functions", method = RequestMethod.GET, produces = "application/json")
170 public PortalRestResponse<List<AppCategoryFunctionsItem>> getAppCategoryFunctions(HttpServletRequest request) {
171 PortalRestResponse<List<AppCategoryFunctionsItem>> portalRestResponse = null;
173 List<AppCategoryFunctionsItem> contents = contactUsService.getAppCategoryFunctions();
174 // logger.debug(EELFLoggerDelegate.debugLogger,
175 // "getAppCategoryFunctions: result list size is " +
177 Collections.sort(contents, appCategoryFunctionsItemComparator);
178 portalRestResponse = new PortalRestResponse<List<AppCategoryFunctionsItem>>(PortalRestStatusEnum.OK,
179 "success", contents);
180 } catch (Exception e) {
181 logger.error(EELFLoggerDelegate.errorLogger, "getAppCategoryFunctions failed", e);
182 // TODO build JSON error
183 portalRestResponse = new PortalRestResponse<List<AppCategoryFunctionsItem>>(PortalRestStatusEnum.ERROR,
184 e.getMessage(), null);
186 return portalRestResponse;
190 * Accepts a new application's contact us details.
192 * @param contactUs AppContactUsItem
193 * @return PortalRestResponse<String>
195 @RequestMapping(value = "/save", method = RequestMethod.POST, produces = "application/json")
196 public PortalRestResponse<String> save(@RequestBody AppContactUsItem contactUs) {
198 if (contactUs == null || contactUs.getAppName() == null)
199 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, FAILURE,
200 "AppName cannot be null or empty");
202 String saveAppContactUs = FAILURE;
204 saveAppContactUs = contactUsService.saveAppContactUs(contactUs);
205 } catch (Exception e) {
206 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, saveAppContactUs, e.getMessage());
208 return new PortalRestResponse<String>(PortalRestStatusEnum.OK, saveAppContactUs, "");
211 @RequestMapping(value = "/saveAll", method = RequestMethod.POST, produces = "application/json")
212 public PortalRestResponse<String> save(@RequestBody List<AppContactUsItem> contactUsList) {
214 String saveAppContactUs = FAILURE;
216 saveAppContactUs = contactUsService.saveAppContactUs(contactUsList);
217 } catch (Exception e) {
218 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, saveAppContactUs, e.getMessage());
220 return new PortalRestResponse<String>(PortalRestStatusEnum.OK, saveAppContactUs, "");
224 * Deletes the specified application's contact-us details entry from the
228 * @return PortalRestResponse<String>
230 @RequestMapping(value = "/delete/{appid}", method = RequestMethod.POST, produces = "application/json")
231 public PortalRestResponse<String> delete(@PathVariable("appid") Long id) {
233 String saveAppContactUs = FAILURE;
235 saveAppContactUs = contactUsService.deleteContactUs(id);
236 } catch (Exception e) {
237 return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, saveAppContactUs, e.getMessage());
239 return new PortalRestResponse<String>(PortalRestStatusEnum.OK, saveAppContactUs, "");