-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-package org.openecomp.portalapp.portal.service;\r
-\r
-import java.util.Collections;\r
-import java.util.Comparator;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.transaction.annotation.Transactional;\r
-\r
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
-import org.openecomp.portalsdk.core.service.DataAccessService;\r
-import org.openecomp.portalapp.portal.domain.AppContactUs;\r
-import org.openecomp.portalapp.portal.domain.EPApp;\r
-import org.openecomp.portalapp.portal.ecomp.model.AppCategoryFunctionsItem;\r
-import org.openecomp.portalapp.portal.ecomp.model.AppContactUsItem;\r
-\r
-/**\r
- * Provides database access for the contact-us page controllers.\r
- */\r
-@Transactional\r
-@org.springframework.context.annotation.Configuration\r
-public class AppContactUsServiceImpl implements AppContactUsService {\r
-\r
- private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AppContactUsServiceImpl.class);\r
-\r
- @Autowired\r
- private DataAccessService dataAccessService;\r
-\r
- public DataAccessService getDataAccessService() {\r
- return dataAccessService;\r
- }\r
-\r
- public void setDataAccessService(DataAccessService dataAccessService) {\r
- this.dataAccessService = dataAccessService;\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see org.openecomp.portalapp.portal.service.AppContactUsService#\r
- * getAppContactUs()\r
- */\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public List<AppContactUsItem> getAppContactUs() throws Exception {\r
- List<AppContactUsItem> contactUsItemList = (List<AppContactUsItem>) getDataAccessService()\r
- .executeNamedQuery("getAppContactUsItems", null, null);\r
- Collections.sort(contactUsItemList, new AppContactUsItemCompare());\r
- return contactUsItemList;\r
- }\r
-\r
- /*\r
- * (non-Javadoc)\r
- * \r
- * @see org.openecomp.portalapp.portal.service.AppContactUsService#\r
- * getAllAppsAndContacts()\r
- */\r
- @SuppressWarnings("unchecked")\r
- @Override\r
- public List<AppContactUsItem> getAppsAndContacts() throws Exception {\r
- List<AppContactUsItem> contactUsItemList = (List<AppContactUsItem>) getDataAccessService()\r
- .executeNamedQuery("getAppsAndContacts", null, null);\r
- Collections.sort(contactUsItemList, new AppContactUsItemCompare());\r
- return contactUsItemList;\r
- }\r
-\r
- /**\r
- * Assists in sorting app-contact-us items by application name.\r
- */\r
- class AppContactUsItemCompare implements Comparator<AppContactUsItem> {\r
- @Override\r
- public int compare(AppContactUsItem o1, AppContactUsItem o2) {\r
- return o1.getAppName().compareTo(o2.getAppName());\r
- }\r
- }\r
-\r
- /**\r
- * Gets a table of category and function details for apps that participate\r
- * in the functional menu.\r
- */\r
- @Override\r
- public List<AppCategoryFunctionsItem> getAppCategoryFunctions() throws Exception {\r
- @SuppressWarnings("unchecked")\r
- // This named query requires no parameters.\r
- List<AppCategoryFunctionsItem> list = (List<AppCategoryFunctionsItem>) dataAccessService\r
- .executeNamedQuery("getAppCategoryFunctions", null, null);\r
- logger.debug(EELFLoggerDelegate.debugLogger, "getAppCategoryFunctions: result list size is " + list.size());\r
- return list;\r
- }\r
-\r
- /**\r
- * Saves the list of contact-us objects to the database.\r
- */\r
- @Override\r
- @Transactional(rollbackFor = Exception.class)\r
- public String saveAppContactUs(List<AppContactUsItem> contactUsModelList) throws Exception {\r
- try {\r
- for (AppContactUsItem contactUs : contactUsModelList) {\r
- String status = saveAppContactUs(contactUs);\r
- if (!status.equals("success"))\r
- throw new Exception("saveAppContaatUsFailed: service returned " + status);\r
- }\r
- return "success";\r
-\r
- } catch (Exception e) {\r
- logger.error(EELFLoggerDelegate.errorLogger, "", e);\r
- throw new Exception(e);\r
- }\r
-\r
- }\r
-\r
- /**\r
- * Saves a single contact-us object to the database, either creating a new\r
- * row or updating if the argument has the ID of an existing row.\r
- */\r
- @Override\r
- @Transactional(rollbackFor = Exception.class)\r
- public String saveAppContactUs(AppContactUsItem contactUsModel) throws Exception {\r
- try {\r
- HashMap<String, Object> map = new HashMap<String, Object>();\r
- AppContactUs contactUs = null;\r
- try {\r
- contactUs = (AppContactUs) getDataAccessService().getDomainObject(AppContactUs.class,\r
- contactUsModel.getAppId(), map);\r
- } catch (Exception e) {\r
- logger.debug(EELFLoggerDelegate.debugLogger, "saveAppContactUs: not found for App {}, adding new entry",\r
- contactUsModel.getAppName());\r
- contactUs = new AppContactUs();\r
- }\r
-\r
- // Populate the AppContactUs model for the database.\r
- EPApp app = (EPApp) getDataAccessService().getDomainObject(EPApp.class, contactUsModel.getAppId(), map);\r
- if (app == null || app.getId() == null)\r
- throw new Exception("saveAppContactus: App not found for Id " + contactUsModel.getAppId());\r
- contactUs.setApp(app);\r
- contactUs.setDescription(contactUsModel.getDescription());\r
- contactUs.setContactName(contactUsModel.getContactName());\r
- contactUs.setContactEmail(contactUsModel.getContactEmail());\r
- contactUs.setActiveYN(contactUsModel.getActiveYN());\r
- contactUs.setUrl(contactUsModel.getUrl());\r
- getDataAccessService().saveDomainObject(contactUs, map);\r
- return "success";\r
- } catch (Exception e) {\r
- logger.error(EELFLoggerDelegate.errorLogger, "saveAppContactUs failed", e);\r
- throw e;\r
- // return "failure";\r
- }\r
- }\r
-\r
- /**\r
- * Deletes the row from the app contact us table with the specified ID.\r
- */\r
- @Override\r
- public String deleteContactUs(Long id) throws Exception {\r
- try {\r
- HashMap<String, Object> map = new HashMap<String, Object>();\r
- AppContactUs contactUs = (AppContactUs) getDataAccessService().getDomainObject(AppContactUs.class, id, map);\r
- if (contactUs.getApp() == null)\r
- throw new Exception("Delete unsuccessful for Id " + id);\r
- getDataAccessService().deleteDomainObject(contactUs, map);\r
- return "success";\r
- } catch (Exception e) {\r
-\r
- logger.info(EELFLoggerDelegate.errorLogger, "", e);\r
- throw e;\r
- }\r
- }\r
-\r
-}\r
+/*-
+ * ================================================================================
+ * 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<AppContactUsItem> getAppContactUs() throws Exception {
+ List<AppContactUsItem> contactUsItemList = (List<AppContactUsItem>) 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<AppContactUsItem> getAppsAndContacts() throws Exception {
+ List<AppContactUsItem> contactUsItemList = (List<AppContactUsItem>) 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<AppContactUsItem> {
+ @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<AppCategoryFunctionsItem> getAppCategoryFunctions() throws Exception {
+ @SuppressWarnings("unchecked")
+ // This named query requires no parameters.
+ List<AppCategoryFunctionsItem> list = (List<AppCategoryFunctionsItem>) 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<AppContactUsItem> 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<String, Object> map = new HashMap<String, Object>();
+ 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<String, Object> map = new HashMap<String, Object>();
+ 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;
+ }
+ }
+
+}