2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
20 package org.openecomp.portalapp.portal.service;
\r
22 import java.util.ArrayList;
\r
23 import java.util.HashMap;
\r
24 import java.util.List;
\r
25 import java.util.Map;
\r
27 import org.springframework.beans.factory.annotation.Autowired;
\r
28 import org.springframework.stereotype.Component;
\r
30 import org.openecomp.portalsdk.core.service.DataAccessService;
\r
31 import org.openecomp.portalapp.portal.transport.CommonWidget;
\r
32 import org.openecomp.portalapp.portal.transport.CommonWidgetMeta;
\r
33 import org.openecomp.portalapp.portal.ecomp.model.SearchResultItem;
\r
36 public class DashboardSearchServiceImpl implements DashboardSearchService {
\r
39 private DataAccessService dataAccessService;
\r
41 public Map<String, List<SearchResultItem>> searchResults(String userId, String searchString) {
\r
42 Map<String, String> params = new HashMap<>();
\r
43 params.put("userId", userId);
\r
44 params.put("searchQuery", searchString);
\r
45 // Named query is stored in a *.hbm.xml file, mapped to SearchResultItem
\r
46 @SuppressWarnings("unchecked")
\r
47 List<SearchResultItem> list = dataAccessService.executeNamedQuery("searchPortal", params, null);
\r
48 Map<String, List<SearchResultItem>> finalJson = null;
\r
49 if (list.size() > 0) {
\r
50 finalJson = new HashMap<String, List<SearchResultItem>>();
\r
51 for (SearchResultItem thisResult : list) {
\r
52 List<SearchResultItem> thisList = finalJson.get(thisResult.getCategory().toLowerCase());
\r
53 if (thisList == null)
\r
54 thisList = new ArrayList<SearchResultItem>();
\r
55 thisList.add(thisResult);
\r
56 finalJson.put(thisResult.getCategory().toLowerCase(), thisList);
\r
63 public List<String> getRelatedUsers(String userId) {
\r
64 Map<String, String> params = new HashMap<>();
\r
65 params.put("userId", userId);
\r
66 @SuppressWarnings("unchecked")
\r
67 List<String> activeUsers = dataAccessService.executeNamedQuery("relatedUsers", params, null);
\r
72 public CommonWidgetMeta getWidgetData(String resourceType) {
\r
73 Map<String, String> params = new HashMap<>();
\r
74 params.put("cat", resourceType);
\r
75 @SuppressWarnings("unchecked")
\r
76 List<CommonWidget> widgetItems = (List<CommonWidget>) dataAccessService.executeNamedQuery("getCommonWidgetItem", params, null);
\r
77 return new CommonWidgetMeta(resourceType, widgetItems);
\r
81 public String saveWidgetDataBulk(CommonWidgetMeta commonMetaWidgetData) {
\r
82 for (CommonWidget widgetData : commonMetaWidgetData.getItems()) {
\r
83 widgetData.setCategory(commonMetaWidgetData.getCategory());
\r
84 dataAccessService.saveDomainObject(widgetData, null);
\r
90 public String saveWidgetData(CommonWidget commonWidgetData) {
\r
91 dataAccessService.saveDomainObject(commonWidgetData, null);
\r
96 public String deleteWidgetData(CommonWidget eventWidget) {
\r
97 dataAccessService.deleteDomainObject(eventWidget, null);
\r