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