2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 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============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.openecomp.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;
48 import org.openecomp.portalsdk.core.service.DataAccessService;
49 import org.openecomp.portalapp.portal.transport.CommonWidget;
50 import org.openecomp.portalapp.portal.transport.CommonWidgetMeta;
51 import org.openecomp.portalapp.portal.ecomp.model.SearchResultItem;
54 public class DashboardSearchServiceImpl implements DashboardSearchService {
57 private DataAccessService dataAccessService;
59 public Map<String, List<SearchResultItem>> searchResults(String userId, String searchString) {
60 Map<String, String> params = new HashMap<>();
61 params.put("userId", userId);
62 params.put("searchQuery", searchString);
63 // Named query is stored in a *.hbm.xml file, mapped to SearchResultItem
64 @SuppressWarnings("unchecked")
65 List<SearchResultItem> list = dataAccessService.executeNamedQuery("searchPortal", params, null);
66 Map<String, List<SearchResultItem>> finalJson = null;
67 if (list.size() > 0) {
68 finalJson = new HashMap<String, List<SearchResultItem>>();
69 for (SearchResultItem thisResult : list) {
70 List<SearchResultItem> thisList = finalJson.get(thisResult.getCategory().toLowerCase());
72 thisList = new ArrayList<SearchResultItem>();
73 thisList.add(thisResult);
74 finalJson.put(thisResult.getCategory().toLowerCase(), thisList);
81 public List<String> getRelatedUsers(String userId) {
82 Map<String, String> params = new HashMap<>();
83 params.put("userId", userId);
84 @SuppressWarnings("unchecked")
85 List<String> activeUsers = dataAccessService.executeNamedQuery("relatedUsers", params, null);
90 public CommonWidgetMeta getWidgetData(String resourceType) {
91 Map<String, String> params = new HashMap<>();
92 params.put("cat", resourceType);
93 @SuppressWarnings("unchecked")
94 List<CommonWidget> widgetItems = (List<CommonWidget>) dataAccessService.executeNamedQuery("getCommonWidgetItem", params, null);
95 return new CommonWidgetMeta(resourceType, widgetItems);
99 public String saveWidgetDataBulk(CommonWidgetMeta commonMetaWidgetData) {
100 for (CommonWidget widgetData : commonMetaWidgetData.getItems()) {
101 widgetData.setCategory(commonMetaWidgetData.getCategory());
102 dataAccessService.saveDomainObject(widgetData, null);
108 public String saveWidgetData(CommonWidget commonWidgetData) {
109 dataAccessService.saveDomainObject(commonWidgetData, null);
114 public String deleteWidgetData(CommonWidget eventWidget) {
115 dataAccessService.deleteDomainObject(eventWidget, null);