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.service;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.List;
27 import org.openecomp.portalapp.portal.ecomp.model.SearchResultItem;
28 import org.openecomp.portalapp.portal.transport.CommonWidget;
29 import org.openecomp.portalapp.portal.transport.CommonWidgetMeta;
30 import org.openecomp.portalapp.portal.utils.EcompPortalUtils;
31 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.openecomp.portalsdk.core.service.DataAccessService;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
35 import org.springframework.transaction.annotation.Transactional;
39 public class DashboardSearchServiceImpl implements DashboardSearchService{
41 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(DashboardSearchServiceImpl.class);
44 private DataAccessService dataAccessService;
46 @SuppressWarnings("unchecked")
47 public Map<String, List<SearchResultItem>> searchResults(String orgUserId, String searchString){
49 Map<String, String> params = new HashMap<>();
50 params.put("userId", orgUserId);
51 params.put("searchQuery", searchString);
52 // Named query is stored in a *.hbm.xml file, mapped to SearchResultItem
53 @SuppressWarnings("unchecked")
54 List<SearchResultItem> list = dataAccessService.executeNamedQuery("searchPortal", params, null);
55 Map<String, List<SearchResultItem>> finalJson = null;
56 if (list.size() > 0) {
57 finalJson = new HashMap<String, List<SearchResultItem>>();
58 for (SearchResultItem thisResult : list) {
59 List<SearchResultItem> thisList = finalJson.get(thisResult.getCategory().toLowerCase());
61 thisList = new ArrayList<SearchResultItem>();
62 thisList.add(thisResult);
63 finalJson.put(thisResult.getCategory().toLowerCase(), thisList);
70 @SuppressWarnings("unchecked")
72 public List<String> getRelatedUsers(String orgUserId) {
74 Map<String, String> params = new HashMap<>();
76 params.put("org_user_id", orgUserId);
78 List<String> activeUsers = null;
81 activeUsers = dataAccessService.executeNamedQuery("relatedUsers", params, null);
84 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
90 @SuppressWarnings("unchecked")
92 public List<Object[]> getRelatedUserVOs(String orgUserId) {
94 Map<String, String> params = new HashMap<>();
96 params.put("org_user_id", orgUserId);
98 List<Object[]> activeUsers = null;
101 activeUsers = dataAccessService.executeNamedQuery("relatedUserVOs", params, null);
104 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
111 @SuppressWarnings("unchecked")
113 public CommonWidgetMeta getWidgetData(String resourceType) {
115 List<CommonWidget> widgetItems = null;
117 Map<String, String> params = new HashMap<>();
118 params.put("cat", resourceType);
119 widgetItems = (List<CommonWidget>)dataAccessService.executeNamedQuery("getCommonWidgetItem", params, null);
121 /*widgetItems2 = new ArrayList<CommonWidget2>();
123 for(int i = 0; i < widgetItems.size(); i++){
124 CommonWidget2 item = (CommonWidget2)widgetItems.get(i);
125 widgetItems2.add(new CommonWidget2(item.getCategory(), item.getHref(), item.getTitle(), item.getSortOrder()));
129 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
131 return new CommonWidgetMeta(resourceType, widgetItems);
135 public String saveWidgetDataBulk(CommonWidgetMeta commonMetaWidgetData) {
138 for(CommonWidget widgetData : commonMetaWidgetData.getItems()){
139 widgetData.setCategory(commonMetaWidgetData.getCategory());
140 dataAccessService.saveDomainObject(widgetData, null);
146 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
147 return e.getMessage();
152 public String saveWidgetData(CommonWidget commonWidgetData) {
156 dataAccessService.saveDomainObject(commonWidgetData, null);
160 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
161 return e.getMessage();
166 public String deleteWidgetData(CommonWidget eventWidget) {
168 dataAccessService.deleteDomainObject(eventWidget, null);
172 logger.error(EELFLoggerDelegate.errorLogger, EcompPortalUtils.getStackTrace(e));
173 return e.getMessage();
178 public EventWidgetMeta getEventWidgetData() {
179 List<EventWidget> widgetItems = null;
181 Map<String, String> params = new HashMap<>();
182 widgetItems = (List<EventWidget>)dataAccessService.executeNamedQuery("getEventWidgetData", params, null);
184 widgetItems2 = new ArrayList<CommonWidget2>();
186 for(int i = 0; i < widgetItems.size(); i++){
187 CommonWidget2 item = (CommonWidget2)widgetItems.get(i);
188 widgetItems2.add(new CommonWidget2(item.getCategory(), item.getHref(), item.getTitle(), item.getSortOrder()));
194 return new EventWidgetMeta("EVENTS", widgetItems);
198 public String saveEventWidgetDataBulk(EventWidgetMeta eventsWidgetData) {
200 for(EventWidget widgetData : eventsWidgetData.getItems()){
201 widgetData.setCategory(eventsWidgetData.getCategory());
202 dataAccessService.saveDomainObject(widgetData, null);
209 return e.getMessage();
214 public String saveEventWidgetData(EventWidget eventWidget) {
216 dataAccessService.saveDomainObject(eventWidget, null);
221 return e.getMessage();
226 public String deleteEventWidgetData(EventWidget eventWidget) {
228 dataAccessService.deleteDomainObject(eventWidget, null);
233 return e.getMessage();