2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.service;
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.List;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.stereotype.Component;
47 import org.onap.portalapp.portal.ecomp.model.SearchResultItem;
48 import org.onap.portalapp.portal.transport.CommonWidget;
49 import org.onap.portalapp.portal.transport.CommonWidgetMeta;
50 import org.onap.portalsdk.core.service.DataAccessService;
53 public class DashboardSearchServiceImpl implements DashboardSearchService {
56 private DataAccessService dataAccessService;
58 public Map<String, List<SearchResultItem>> searchResults(String userId, String searchString) {
59 Map<String, String> params = new HashMap<>();
60 params.put("userId", userId);
61 params.put("searchQuery", searchString);
62 // Named query is stored in a *.hbm.xml file, mapped to SearchResultItem
63 @SuppressWarnings("unchecked")
64 List<SearchResultItem> list = dataAccessService.executeNamedQuery("searchPortal", params, null);
65 Map<String, List<SearchResultItem>> finalJson = null;
66 if (list.size() > 0) {
67 finalJson = new HashMap<String, List<SearchResultItem>>();
68 for (SearchResultItem thisResult : list) {
69 List<SearchResultItem> thisList = finalJson.get(thisResult.getCategory().toLowerCase());
71 thisList = new ArrayList<SearchResultItem>();
72 thisList.add(thisResult);
73 finalJson.put(thisResult.getCategory().toLowerCase(), thisList);
80 public List<String> getRelatedUsers(String userId) {
81 Map<String, String> params = new HashMap<>();
82 params.put("userId", userId);
83 @SuppressWarnings("unchecked")
84 List<String> activeUsers = dataAccessService.executeNamedQuery("relatedUsers", params, null);
89 public CommonWidgetMeta getWidgetData(String resourceType) {
90 Map<String, String> params = new HashMap<>();
91 params.put("cat", resourceType);
92 @SuppressWarnings("unchecked")
93 List<CommonWidget> widgetItems = (List<CommonWidget>) dataAccessService.executeNamedQuery("getCommonWidgetItem", params, null);
94 return new CommonWidgetMeta(resourceType, widgetItems);
98 public String saveWidgetDataBulk(CommonWidgetMeta commonMetaWidgetData) {
99 for (CommonWidget widgetData : commonMetaWidgetData.getItems()) {
100 widgetData.setCategory(commonMetaWidgetData.getCategory());
101 dataAccessService.saveDomainObject(widgetData, null);
107 public String saveWidgetData(CommonWidget commonWidgetData) {
108 dataAccessService.saveDomainObject(commonWidgetData, null);
113 public String deleteWidgetData(CommonWidget eventWidget) {
114 dataAccessService.deleteDomainObject(eventWidget, null);