2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 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============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.portalapp.portal.service;
40 import java.util.Collections;
41 import java.util.Comparator;
42 import java.util.HashMap;
43 import java.util.List;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.transaction.annotation.Transactional;
48 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
49 import org.openecomp.portalsdk.core.service.DataAccessService;
50 import org.openecomp.portalapp.portal.domain.AppContactUs;
51 import org.openecomp.portalapp.portal.domain.EPApp;
52 import org.openecomp.portalapp.portal.ecomp.model.AppCategoryFunctionsItem;
53 import org.openecomp.portalapp.portal.ecomp.model.AppContactUsItem;
56 * Provides database access for the contact-us page controllers.
59 @org.springframework.context.annotation.Configuration
60 public class AppContactUsServiceImpl implements AppContactUsService {
62 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppContactUsServiceImpl.class);
65 private DataAccessService dataAccessService;
67 public DataAccessService getDataAccessService() {
68 return dataAccessService;
71 public void setDataAccessService(DataAccessService dataAccessService) {
72 this.dataAccessService = dataAccessService;
78 * @see org.openecomp.portalapp.portal.service.AppContactUsService#
81 @SuppressWarnings("unchecked")
83 public List<AppContactUsItem> getAppContactUs() throws Exception {
84 List<AppContactUsItem> contactUsItemList = (List<AppContactUsItem>) getDataAccessService()
85 .executeNamedQuery("getAppContactUsItems", null, null);
86 Collections.sort(contactUsItemList, new AppContactUsItemCompare());
87 return contactUsItemList;
93 * @see org.openecomp.portalapp.portal.service.AppContactUsService#
94 * getAllAppsAndContacts()
96 @SuppressWarnings("unchecked")
98 public List<AppContactUsItem> getAppsAndContacts() throws Exception {
99 List<AppContactUsItem> contactUsItemList = (List<AppContactUsItem>) getDataAccessService()
100 .executeNamedQuery("getAppsAndContacts", null, null);
101 Collections.sort(contactUsItemList, new AppContactUsItemCompare());
102 return contactUsItemList;
106 * Assists in sorting app-contact-us items by application name.
108 class AppContactUsItemCompare implements Comparator<AppContactUsItem> {
110 public int compare(AppContactUsItem o1, AppContactUsItem o2) {
111 return o1.getAppName().compareTo(o2.getAppName());
116 * Gets a table of category and function details for apps that participate
117 * in the functional menu.
120 public List<AppCategoryFunctionsItem> getAppCategoryFunctions() throws Exception {
121 @SuppressWarnings("unchecked")
122 // This named query requires no parameters.
123 List<AppCategoryFunctionsItem> list = (List<AppCategoryFunctionsItem>) dataAccessService
124 .executeNamedQuery("getAppCategoryFunctions", null, null);
125 logger.debug(EELFLoggerDelegate.debugLogger, "getAppCategoryFunctions: result list size is " + list.size());
130 * Saves the list of contact-us objects to the database.
133 @Transactional(rollbackFor = Exception.class)
134 public String saveAppContactUs(List<AppContactUsItem> contactUsModelList) throws Exception {
136 for (AppContactUsItem contactUs : contactUsModelList) {
137 String status = saveAppContactUs(contactUs);
138 if (!status.equals("success"))
139 throw new Exception("saveAppContaatUsFailed: service returned " + status);
143 } catch (Exception e) {
144 logger.error(EELFLoggerDelegate.errorLogger, "", e);
145 throw new Exception(e);
151 * Saves a single contact-us object to the database, either creating a new
152 * row or updating if the argument has the ID of an existing row.
155 @Transactional(rollbackFor = Exception.class)
156 public String saveAppContactUs(AppContactUsItem contactUsModel) throws Exception {
158 HashMap<String, Object> map = new HashMap<String, Object>();
159 AppContactUs contactUs = null;
161 contactUs = (AppContactUs) getDataAccessService().getDomainObject(AppContactUs.class,
162 contactUsModel.getAppId(), map);
163 } catch (Exception e) {
164 logger.debug(EELFLoggerDelegate.debugLogger, "saveAppContactUs: not found for App {}, adding new entry",
165 contactUsModel.getAppName());
166 contactUs = new AppContactUs();
169 // Populate the AppContactUs model for the database.
170 EPApp app = (EPApp) getDataAccessService().getDomainObject(EPApp.class, contactUsModel.getAppId(), map);
171 if (app == null || app.getId() == null)
172 throw new Exception("saveAppContactus: App not found for Id " + contactUsModel.getAppId());
173 contactUs.setApp(app);
174 contactUs.setDescription(contactUsModel.getDescription());
175 contactUs.setContactName(contactUsModel.getContactName());
176 contactUs.setContactEmail(contactUsModel.getContactEmail());
177 contactUs.setActiveYN(contactUsModel.getActiveYN());
178 contactUs.setUrl(contactUsModel.getUrl());
179 getDataAccessService().saveDomainObject(contactUs, map);
181 } catch (Exception e) {
182 logger.error(EELFLoggerDelegate.errorLogger, "saveAppContactUs failed", e);
189 * Deletes the row from the app contact us table with the specified ID.
192 public String deleteContactUs(Long id) throws Exception {
194 HashMap<String, Object> map = new HashMap<String, Object>();
195 AppContactUs contactUs = (AppContactUs) getDataAccessService().getDomainObject(AppContactUs.class, id, map);
196 if (contactUs.getApp() == null)
197 throw new Exception("Delete unsuccessful for Id " + id);
198 getDataAccessService().deleteDomainObject(contactUs, map);
200 } catch (Exception e) {
202 logger.info(EELFLoggerDelegate.errorLogger, "", e);