X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ecomp-portal-BE-common%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fportalapp%2Fportal%2Fservice%2FAppContactUsServiceImpl.java;h=2f9870758da7cf5156bf6b4e8895fe80e205ece6;hb=51d83152697da4f2ef2242471ee43f36e6b64300;hp=41c5d9fddb592408420eb3fc73448f033da47911;hpb=b54df0ddd0c6a0372327c5aa3668e5a6458fcd64;p=portal.git diff --git a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/AppContactUsServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/AppContactUsServiceImpl.java index 41c5d9fd..2f987075 100644 --- a/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/AppContactUsServiceImpl.java +++ b/ecomp-portal-BE-common/src/main/java/org/openecomp/portalapp/portal/service/AppContactUsServiceImpl.java @@ -1,189 +1,207 @@ -/*- - * ================================================================================ - * ECOMP Portal - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ================================================================================ - */ -package org.openecomp.portalapp.portal.service; - -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; - -import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; -import org.openecomp.portalsdk.core.service.DataAccessService; -import org.openecomp.portalapp.portal.domain.AppContactUs; -import org.openecomp.portalapp.portal.domain.EPApp; -import org.openecomp.portalapp.portal.ecomp.model.AppCategoryFunctionsItem; -import org.openecomp.portalapp.portal.ecomp.model.AppContactUsItem; - -/** - * Provides database access for the contact-us page controllers. - */ -@Transactional -@org.springframework.context.annotation.Configuration -public class AppContactUsServiceImpl implements AppContactUsService { - - private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppContactUsServiceImpl.class); - - @Autowired - private DataAccessService dataAccessService; - - public DataAccessService getDataAccessService() { - return dataAccessService; - } - - public void setDataAccessService(DataAccessService dataAccessService) { - this.dataAccessService = dataAccessService; - } - - /* - * (non-Javadoc) - * - * @see org.openecomp.portalapp.portal.service.AppContactUsService# - * getAppContactUs() - */ - @SuppressWarnings("unchecked") - @Override - public List getAppContactUs() throws Exception { - List contactUsItemList = (List) getDataAccessService() - .executeNamedQuery("getAppContactUsItems", null, null); - Collections.sort(contactUsItemList, new AppContactUsItemCompare()); - return contactUsItemList; - } - - /* - * (non-Javadoc) - * - * @see org.openecomp.portalapp.portal.service.AppContactUsService# - * getAllAppsAndContacts() - */ - @SuppressWarnings("unchecked") - @Override - public List getAppsAndContacts() throws Exception { - List contactUsItemList = (List) getDataAccessService() - .executeNamedQuery("getAppsAndContacts", null, null); - Collections.sort(contactUsItemList, new AppContactUsItemCompare()); - return contactUsItemList; - } - - /** - * Assists in sorting app-contact-us items by application name. - */ - class AppContactUsItemCompare implements Comparator { - @Override - public int compare(AppContactUsItem o1, AppContactUsItem o2) { - return o1.getAppName().compareTo(o2.getAppName()); - } - } - - /** - * Gets a table of category and function details for apps that participate - * in the functional menu. - */ - @Override - public List getAppCategoryFunctions() throws Exception { - @SuppressWarnings("unchecked") - // This named query requires no parameters. - List list = (List) dataAccessService - .executeNamedQuery("getAppCategoryFunctions", null, null); - logger.debug(EELFLoggerDelegate.debugLogger, "getAppCategoryFunctions: result list size is " + list.size()); - return list; - } - - /** - * Saves the list of contact-us objects to the database. - */ - @Override - @Transactional(rollbackFor = Exception.class) - public String saveAppContactUs(List contactUsModelList) throws Exception { - try { - for (AppContactUsItem contactUs : contactUsModelList) { - String status = saveAppContactUs(contactUs); - if (!status.equals("success")) - throw new Exception("saveAppContaatUsFailed: service returned " + status); - } - return "success"; - - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, "", e); - throw new Exception(e); - } - - } - - /** - * Saves a single contact-us object to the database, either creating a new - * row or updating if the argument has the ID of an existing row. - */ - @Override - @Transactional(rollbackFor = Exception.class) - public String saveAppContactUs(AppContactUsItem contactUsModel) throws Exception { - try { - HashMap map = new HashMap(); - AppContactUs contactUs = null; - try { - contactUs = (AppContactUs) getDataAccessService().getDomainObject(AppContactUs.class, - contactUsModel.getAppId(), map); - } catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger, "saveAppContactUs: not found for App {}, adding new entry", - contactUsModel.getAppName()); - contactUs = new AppContactUs(); - } - - // Populate the AppContactUs model for the database. - EPApp app = (EPApp) getDataAccessService().getDomainObject(EPApp.class, contactUsModel.getAppId(), map); - if (app == null || app.getId() == null) - throw new Exception("saveAppContactus: App not found for Id " + contactUsModel.getAppId()); - contactUs.setApp(app); - contactUs.setDescription(contactUsModel.getDescription()); - contactUs.setContactName(contactUsModel.getContactName()); - contactUs.setContactEmail(contactUsModel.getContactEmail()); - contactUs.setActiveYN(contactUsModel.getActiveYN()); - contactUs.setUrl(contactUsModel.getUrl()); - getDataAccessService().saveDomainObject(contactUs, map); - return "success"; - } catch (Exception e) { - logger.error(EELFLoggerDelegate.errorLogger, "saveAppContactUs failed", e); - throw e; - // return "failure"; - } - } - - /** - * Deletes the row from the app contact us table with the specified ID. - */ - @Override - public String deleteContactUs(Long id) throws Exception { - try { - HashMap map = new HashMap(); - AppContactUs contactUs = (AppContactUs) getDataAccessService().getDomainObject(AppContactUs.class, id, map); - if (contactUs.getApp() == null) - throw new Exception("Delete unsuccessful for Id " + id); - getDataAccessService().deleteDomainObject(contactUs, map); - return "success"; - } catch (Exception e) { - - logger.info(EELFLoggerDelegate.errorLogger, "", e); - throw e; - } - } - -} +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the “License”); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the “License”); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.openecomp.portalapp.portal.service; + +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; + +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.openecomp.portalsdk.core.service.DataAccessService; +import org.openecomp.portalapp.portal.domain.AppContactUs; +import org.openecomp.portalapp.portal.domain.EPApp; +import org.openecomp.portalapp.portal.ecomp.model.AppCategoryFunctionsItem; +import org.openecomp.portalapp.portal.ecomp.model.AppContactUsItem; + +/** + * Provides database access for the contact-us page controllers. + */ +@Transactional +@org.springframework.context.annotation.Configuration +public class AppContactUsServiceImpl implements AppContactUsService { + + private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppContactUsServiceImpl.class); + + @Autowired + private DataAccessService dataAccessService; + + public DataAccessService getDataAccessService() { + return dataAccessService; + } + + public void setDataAccessService(DataAccessService dataAccessService) { + this.dataAccessService = dataAccessService; + } + + /* + * (non-Javadoc) + * + * @see org.openecomp.portalapp.portal.service.AppContactUsService# + * getAppContactUs() + */ + @SuppressWarnings("unchecked") + @Override + public List getAppContactUs() throws Exception { + List contactUsItemList = (List) getDataAccessService() + .executeNamedQuery("getAppContactUsItems", null, null); + Collections.sort(contactUsItemList, new AppContactUsItemCompare()); + return contactUsItemList; + } + + /* + * (non-Javadoc) + * + * @see org.openecomp.portalapp.portal.service.AppContactUsService# + * getAllAppsAndContacts() + */ + @SuppressWarnings("unchecked") + @Override + public List getAppsAndContacts() throws Exception { + List contactUsItemList = (List) getDataAccessService() + .executeNamedQuery("getAppsAndContacts", null, null); + Collections.sort(contactUsItemList, new AppContactUsItemCompare()); + return contactUsItemList; + } + + /** + * Assists in sorting app-contact-us items by application name. + */ + class AppContactUsItemCompare implements Comparator { + @Override + public int compare(AppContactUsItem o1, AppContactUsItem o2) { + return o1.getAppName().compareTo(o2.getAppName()); + } + } + + /** + * Gets a table of category and function details for apps that participate + * in the functional menu. + */ + @Override + public List getAppCategoryFunctions() throws Exception { + @SuppressWarnings("unchecked") + // This named query requires no parameters. + List list = (List) dataAccessService + .executeNamedQuery("getAppCategoryFunctions", null, null); + logger.debug(EELFLoggerDelegate.debugLogger, "getAppCategoryFunctions: result list size is " + list.size()); + return list; + } + + /** + * Saves the list of contact-us objects to the database. + */ + @Override + @Transactional(rollbackFor = Exception.class) + public String saveAppContactUs(List contactUsModelList) throws Exception { + try { + for (AppContactUsItem contactUs : contactUsModelList) { + String status = saveAppContactUs(contactUs); + if (!status.equals("success")) + throw new Exception("saveAppContaatUsFailed: service returned " + status); + } + return "success"; + + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "", e); + throw new Exception(e); + } + + } + + /** + * Saves a single contact-us object to the database, either creating a new + * row or updating if the argument has the ID of an existing row. + */ + @Override + @Transactional(rollbackFor = Exception.class) + public String saveAppContactUs(AppContactUsItem contactUsModel) throws Exception { + try { + HashMap map = new HashMap(); + AppContactUs contactUs = null; + try { + contactUs = (AppContactUs) getDataAccessService().getDomainObject(AppContactUs.class, + contactUsModel.getAppId(), map); + } catch (Exception e) { + logger.debug(EELFLoggerDelegate.debugLogger, "saveAppContactUs: not found for App {}, adding new entry", + contactUsModel.getAppName()); + contactUs = new AppContactUs(); + } + + // Populate the AppContactUs model for the database. + EPApp app = (EPApp) getDataAccessService().getDomainObject(EPApp.class, contactUsModel.getAppId(), map); + if (app == null || app.getId() == null) + throw new Exception("saveAppContactus: App not found for Id " + contactUsModel.getAppId()); + contactUs.setApp(app); + contactUs.setDescription(contactUsModel.getDescription()); + contactUs.setContactName(contactUsModel.getContactName()); + contactUs.setContactEmail(contactUsModel.getContactEmail()); + contactUs.setActiveYN(contactUsModel.getActiveYN()); + contactUs.setUrl(contactUsModel.getUrl()); + getDataAccessService().saveDomainObject(contactUs, map); + return "success"; + } catch (Exception e) { + logger.error(EELFLoggerDelegate.errorLogger, "saveAppContactUs failed", e); + throw e; + // return "failure"; + } + } + + /** + * Deletes the row from the app contact us table with the specified ID. + */ + @Override + public String deleteContactUs(Long id) throws Exception { + try { + HashMap map = new HashMap(); + AppContactUs contactUs = (AppContactUs) getDataAccessService().getDomainObject(AppContactUs.class, id, map); + if (contactUs.getApp() == null) + throw new Exception("Delete unsuccessful for Id " + id); + getDataAccessService().deleteDomainObject(contactUs, map); + return "success"; + } catch (Exception e) { + + logger.info(EELFLoggerDelegate.errorLogger, "", e); + throw e; + } + } + +}