edae78ae3dd51b2b788a95eb1b2469af6ef979e1
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
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.onap.portalsdk.analytics.system.fusion.service;
39
40 import java.util.List;
41 import java.util.Map;
42
43 import org.onap.portalsdk.analytics.system.fusion.domain.CR_Report;
44 import org.onap.portalsdk.core.service.DataAccessService;
45 import org.onap.portalsdk.core.service.support.FusionService;
46 import org.springframework.context.ApplicationContext;
47
48 public class RaptorServiceImpl extends FusionService implements RaptorService {
49
50         private DataAccessService dataAccessService;
51         
52         private int totalSize;
53
54         public DataAccessService getDataAccessService() {
55                 return dataAccessService;
56         }
57
58         public void setDataAccessService(DataAccessService dataAccessService) {
59                 this.dataAccessService = dataAccessService;
60         }
61         
62         private ApplicationContext applicationContext;
63
64     //raptorSearchAllReportsCount
65         
66         public int executeCountQuery(Class entity, String query, Map params, String whereClause) {
67                 List l  = getDataAccessService().executeNamedCountQuery(entity, query, whereClause, params);
68                 //List l  = getDataAccessService().executeNamedQuery(query, params, null);
69                 int searchCount = 0;
70                 if(l != null) {
71                         if (!l.isEmpty()) {
72                                 searchCount = (((Long) l.get(0))).intValue();
73                         }
74                 }
75                 totalSize = searchCount;
76                 return totalSize;
77         }
78         
79         //raptorSearchAllReports
80         public List executeGridQuery(String query, Map params, Integer fromIndex, Integer toIndex) {
81           return getDataAccessService().executeNamedQuery(query, params, fromIndex, toIndex, null);
82         }
83
84         public List executeGridQueryOrderByWithLimit(Class entity, String query, Map params, String _orderBy, boolean asc, Integer fromIndex, Integer toIndex) {
85                 return getDataAccessService().executeNamedQueryWithOrderBy(entity, query, params, _orderBy, asc, fromIndex, toIndex, null);
86         }
87         
88     //with where clause
89         public List executeGridQuery(Class entity, String query, String whereClause, Map params, Integer fromIndex, Integer toIndex) {
90                   return getDataAccessService().executeNamedQuery(entity, query, whereClause, params, fromIndex, toIndex, null);
91         }
92
93         public List executeGridQueryOrderByWithLimit(Class entity, String query, String whereClause, Map params, String _orderBy, boolean asc, Integer fromIndex, Integer toIndex) {
94                         return getDataAccessService().executeNamedQueryWithOrderBy(entity, query, whereClause, params, _orderBy, asc, fromIndex, toIndex, null);
95         }       
96         
97         /*
98         public int getUserReportsCount(Map params) {
99                 List l  = getDataAccessService().executeNamedQuery("raptorSearchUserReportsCount", params, null);
100                 int count = 0;
101                 if(l != null) {
102                         if (!l.isEmpty()) {
103                                 Object[] result = (Object[]) l.get(0);
104                                 count = ((Long)result[0]).intValue();
105                         }
106                 }
107                 totalSize = count;
108                 return totalSize;
109         }
110         
111         public List getUserReports(Map params, Integer fromIndex, Integer toIndex) {
112           return getDataAccessService().executeNamedQuery("raptorSearchUserReports", params, fromIndex, toIndex, null);
113         }
114
115         public int getPublicReportsCount(Map params) {
116                 List l  = getDataAccessService().executeNamedQuery("raptorPublicUserReportsCount", params, null);
117                 int count = 0;
118                 if(l != null) {
119                         if (!l.isEmpty()) {
120                                 Object[] result = (Object[]) l.get(0);
121                                 count = ((Long)result[0]).intValue();
122                         }
123                 }
124                 totalSize = count;
125                 return totalSize;
126         }
127         
128         public List getPublicReports(Map params, Integer fromIndex, Integer toIndex) {
129           return getDataAccessService().executeNamedQuery("raptorPublicUserReports", params, fromIndex, toIndex, null);
130         }
131
132         public int getFavReportsCount(Map params) {
133                 List l  = getDataAccessService().executeNamedQuery("raptorSearchFavReportsCount", params, null);
134                 int count = 0;
135                 if(l != null) {
136                         if (!l.isEmpty()) {
137                                 Object[] result = (Object[]) l.get(0);
138                                 count = ((Long)result[0]).intValue();
139                         }
140                 }
141                 totalSize = count;
142                 return totalSize;
143         }
144         
145         public List getFavReports(Map params, Integer fromIndex, Integer toIndex) {
146           return getDataAccessService().executeNamedQuery("raptorSearchFavReports", params, fromIndex, toIndex, null);
147         }
148         */      
149         public int getTotalSize() {
150                 return totalSize;
151         }
152         
153         public void deleteReport(Long reportId) {
154                 getDataAccessService().deleteDomainObject(getDataAccessService().getDomainObject(CR_Report.class, reportId, null), null);
155         }
156         
157         public List getReportInfo(Map params) {
158                 return getDataAccessService().executeNamedQuery("raptorInfoQuery", params, null);
159         }
160          
161 /*      public List executeGridQueryWithOrderBy(String query, Map params, String _orderBy, boolean asc, Integer fromIndex, Integer toIndex) {
162                 query = String.format(query, _orderBy, asc ? "ASC" : "DESC", fromIndex, toIndex);
163                 DataSource ds = (DataSource)getApplicationContext().getBean(searchBean.getDatasourceName());
164                 NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(ds);
165         }*/
166
167         /**
168          * @return the applicationContext
169          */
170         public ApplicationContext getApplicationContext() {
171                 return applicationContext;
172         }
173
174         /**
175          * @param applicationContext the applicationContext to set
176          */
177         public void setApplicationContext(ApplicationContext applicationContext) {
178                 this.applicationContext = applicationContext;
179         }
180
181 }