Update license; improve coverage; add docs dir
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / service / DashboardSearchServiceImpl.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright © 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.openecomp.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
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;
52
53 @Component
54 public class DashboardSearchServiceImpl implements DashboardSearchService {
55
56         @Autowired
57         private DataAccessService dataAccessService;
58
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());
71                                 if (thisList == null)
72                                         thisList = new ArrayList<SearchResultItem>();
73                                 thisList.add(thisResult);
74                                 finalJson.put(thisResult.getCategory().toLowerCase(), thisList);
75                         }
76                 }
77                 return finalJson;
78         }
79
80         @Override
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);
86                 return activeUsers;
87         }
88
89         @Override
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);
96         }
97
98         @Override
99         public String saveWidgetDataBulk(CommonWidgetMeta commonMetaWidgetData) {
100                 for (CommonWidget widgetData : commonMetaWidgetData.getItems()) {
101                         widgetData.setCategory(commonMetaWidgetData.getCategory());
102                         dataAccessService.saveDomainObject(widgetData, null);
103                 }
104                 return "success";
105         }
106
107         @Override
108         public String saveWidgetData(CommonWidget commonWidgetData) {
109                 dataAccessService.saveDomainObject(commonWidgetData, null);
110                 return "success";
111         }
112
113         @Override
114         public String deleteWidgetData(CommonWidget eventWidget) {
115                 dataAccessService.deleteDomainObject(eventWidget, null);
116                 return "success";
117         }
118 }