Security/ Package Name changes
[portal.git] / ecomp-portal-BE-common / src / main / java / org / onap / portalapp / portal / service / DashboardSearchServiceImpl.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.portal.service;
39
40 import java.util.ArrayList;
41 import java.util.HashMap;
42 import java.util.List;
43 import java.util.Map;
44
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;
51
52 @Component
53 public class DashboardSearchServiceImpl implements DashboardSearchService {
54
55         @Autowired
56         private DataAccessService dataAccessService;
57
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());
70                                 if (thisList == null)
71                                         thisList = new ArrayList<SearchResultItem>();
72                                 thisList.add(thisResult);
73                                 finalJson.put(thisResult.getCategory().toLowerCase(), thisList);
74                         }
75                 }
76                 return finalJson;
77         }
78
79         @Override
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);
85                 return activeUsers;
86         }
87
88         @Override
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);
95         }
96
97         @Override
98         public String saveWidgetDataBulk(CommonWidgetMeta commonMetaWidgetData) {
99                 for (CommonWidget widgetData : commonMetaWidgetData.getItems()) {
100                         widgetData.setCategory(commonMetaWidgetData.getCategory());
101                         dataAccessService.saveDomainObject(widgetData, null);
102                 }
103                 return "success";
104         }
105
106         @Override
107         public String saveWidgetData(CommonWidget commonWidgetData) {
108                 dataAccessService.saveDomainObject(commonWidgetData, null);
109                 return "success";
110         }
111
112         @Override
113         public String deleteWidgetData(CommonWidget eventWidget) {
114                 dataAccessService.deleteDomainObject(eventWidget, null);
115                 return "success";
116         }
117 }