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.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.stereotype.Component;
30 import org.openecomp.portalsdk.core.service.DataAccessService;
31 import org.openecomp.portalapp.portal.transport.CommonWidget;
32 import org.openecomp.portalapp.portal.transport.CommonWidgetMeta;
33 import org.openecomp.portalapp.portal.ecomp.model.SearchResultItem;
36 public class DashboardSearchServiceImpl implements DashboardSearchService {
39 private DataAccessService dataAccessService;
41 public Map<String, List<SearchResultItem>> searchResults(String userId, String searchString) {
42 Map<String, String> params = new HashMap<>();
43 params.put("userId", userId);
44 params.put("searchQuery", searchString);
45 // Named query is stored in a *.hbm.xml file, mapped to SearchResultItem
46 @SuppressWarnings("unchecked")
47 List<SearchResultItem> list = dataAccessService.executeNamedQuery("searchPortal", params, null);
48 Map<String, List<SearchResultItem>> finalJson = null;
49 if (list.size() > 0) {
50 finalJson = new HashMap<String, List<SearchResultItem>>();
51 for (SearchResultItem thisResult : list) {
52 List<SearchResultItem> thisList = finalJson.get(thisResult.getCategory().toLowerCase());
54 thisList = new ArrayList<SearchResultItem>();
55 thisList.add(thisResult);
56 finalJson.put(thisResult.getCategory().toLowerCase(), thisList);
63 public List<String> getRelatedUsers(String userId) {
64 Map<String, String> params = new HashMap<>();
65 params.put("userId", userId);
66 @SuppressWarnings("unchecked")
67 List<String> activeUsers = dataAccessService.executeNamedQuery("relatedUsers", params, null);
72 public CommonWidgetMeta getWidgetData(String resourceType) {
73 Map<String, String> params = new HashMap<>();
74 params.put("cat", resourceType);
75 @SuppressWarnings("unchecked")
76 List<CommonWidget> widgetItems = (List<CommonWidget>) dataAccessService.executeNamedQuery("getCommonWidgetItem", params, null);
77 return new CommonWidgetMeta(resourceType, widgetItems);
81 public String saveWidgetDataBulk(CommonWidgetMeta commonMetaWidgetData) {
82 for (CommonWidget widgetData : commonMetaWidgetData.getItems()) {
83 widgetData.setCategory(commonMetaWidgetData.getCategory());
84 dataAccessService.saveDomainObject(widgetData, null);
90 public String saveWidgetData(CommonWidget commonWidgetData) {
91 dataAccessService.saveDomainObject(commonWidgetData, null);
96 public String deleteWidgetData(CommonWidget eventWidget) {
97 dataAccessService.deleteDomainObject(eventWidget, null);