1427a2eae7589932731192c5a720f06c77974605
[portal/sdk.git] /
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20 package org.openecomp.portalsdk.analytics.system.fusion.service;
21
22 import java.io.BufferedInputStream;
23 import java.io.BufferedOutputStream;
24 import java.io.FileOutputStream;
25 import java.io.IOException;
26 import java.io.InputStream;
27 import java.io.OutputStream;
28 import java.math.BigDecimal;
29 import java.util.Date;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Set;
34
35 import javax.sql.DataSource;
36
37 import org.hibernate.Query;
38 import org.hibernate.Session;
39 import org.openecomp.portalsdk.analytics.system.fusion.domain.CR_Report;
40 import org.openecomp.portalsdk.core.domain.Role;
41 import org.openecomp.portalsdk.core.service.DataAccessService;
42 import org.openecomp.portalsdk.core.service.support.FusionService;
43 import org.openecomp.portalsdk.core.util.SystemProperties;
44 import org.openecomp.portalsdk.core.web.support.UserUtils;
45 import org.springframework.context.ApplicationContext;
46 import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
47 import org.springframework.orm.hibernate3.SessionFactoryUtils;
48 import org.springframework.web.multipart.MultipartFile;
49
50 public class RaptorServiceImpl extends FusionService implements RaptorService {
51
52         private DataAccessService dataAccessService;
53         
54         private int totalSize;
55
56         public DataAccessService getDataAccessService() {
57                 return dataAccessService;
58         }
59
60         public void setDataAccessService(DataAccessService dataAccessService) {
61                 this.dataAccessService = dataAccessService;
62         }
63         
64         private ApplicationContext applicationContext;
65
66     //raptorSearchAllReportsCount
67         
68         public int executeCountQuery(Class entity, String query, Map params, String whereClause) {
69                 List l  = getDataAccessService().executeNamedCountQuery(entity, query, whereClause, params);
70                 //List l  = getDataAccessService().executeNamedQuery(query, params, null);
71                 int searchCount = 0;
72                 if(l != null) {
73                         if (!l.isEmpty()) {
74                                 searchCount = (((Long) l.get(0))).intValue();
75                         }
76                 }
77                 totalSize = searchCount;
78                 return totalSize;
79         }
80         
81         //raptorSearchAllReports
82         public List executeGridQuery(String query, Map params, Integer fromIndex, Integer toIndex) {
83           return getDataAccessService().executeNamedQuery(query, params, fromIndex, toIndex, null);
84         }
85
86         public List executeGridQueryOrderByWithLimit(Class entity, String query, Map params, String _orderBy, boolean asc, Integer fromIndex, Integer toIndex) {
87                 return getDataAccessService().executeNamedQueryWithOrderBy(entity, query, params, _orderBy, asc, fromIndex, toIndex, null);
88         }
89         
90     //with where clause
91         public List executeGridQuery(Class entity, String query, String whereClause, Map params, Integer fromIndex, Integer toIndex) {
92                   return getDataAccessService().executeNamedQuery(entity, query, whereClause, params, fromIndex, toIndex, null);
93         }
94
95         public List executeGridQueryOrderByWithLimit(Class entity, String query, String whereClause, Map params, String _orderBy, boolean asc, Integer fromIndex, Integer toIndex) {
96                         return getDataAccessService().executeNamedQueryWithOrderBy(entity, query, whereClause, params, _orderBy, asc, fromIndex, toIndex, null);
97         }       
98         
99         /*
100         public int getUserReportsCount(Map params) {
101                 List l  = getDataAccessService().executeNamedQuery("raptorSearchUserReportsCount", params, null);
102                 int count = 0;
103                 if(l != null) {
104                         if (!l.isEmpty()) {
105                                 Object[] result = (Object[]) l.get(0);
106                                 count = ((Long)result[0]).intValue();
107                         }
108                 }
109                 totalSize = count;
110                 return totalSize;
111         }
112         
113         public List getUserReports(Map params, Integer fromIndex, Integer toIndex) {
114           return getDataAccessService().executeNamedQuery("raptorSearchUserReports", params, fromIndex, toIndex, null);
115         }
116
117         public int getPublicReportsCount(Map params) {
118                 List l  = getDataAccessService().executeNamedQuery("raptorPublicUserReportsCount", params, null);
119                 int count = 0;
120                 if(l != null) {
121                         if (!l.isEmpty()) {
122                                 Object[] result = (Object[]) l.get(0);
123                                 count = ((Long)result[0]).intValue();
124                         }
125                 }
126                 totalSize = count;
127                 return totalSize;
128         }
129         
130         public List getPublicReports(Map params, Integer fromIndex, Integer toIndex) {
131           return getDataAccessService().executeNamedQuery("raptorPublicUserReports", params, fromIndex, toIndex, null);
132         }
133
134         public int getFavReportsCount(Map params) {
135                 List l  = getDataAccessService().executeNamedQuery("raptorSearchFavReportsCount", params, null);
136                 int count = 0;
137                 if(l != null) {
138                         if (!l.isEmpty()) {
139                                 Object[] result = (Object[]) l.get(0);
140                                 count = ((Long)result[0]).intValue();
141                         }
142                 }
143                 totalSize = count;
144                 return totalSize;
145         }
146         
147         public List getFavReports(Map params, Integer fromIndex, Integer toIndex) {
148           return getDataAccessService().executeNamedQuery("raptorSearchFavReports", params, fromIndex, toIndex, null);
149         }
150         */      
151         public int getTotalSize() {
152                 return totalSize;
153         }
154         
155         public void deleteReport(Long reportId) {
156                 getDataAccessService().deleteDomainObject(getDataAccessService().getDomainObject(CR_Report.class, reportId, null), null);
157         }
158         
159         public List getReportInfo(Map params) {
160                 return getDataAccessService().executeNamedQuery("raptorInfoQuery", params, null);
161         }
162          
163 /*      public List executeGridQueryWithOrderBy(String query, Map params, String _orderBy, boolean asc, Integer fromIndex, Integer toIndex) {
164                 query = String.format(query, _orderBy, asc ? "ASC" : "DESC", fromIndex, toIndex);
165                 DataSource ds = (DataSource)getApplicationContext().getBean(searchBean.getDatasourceName());
166                 NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(ds);
167         }*/
168
169         /**
170          * @return the applicationContext
171          */
172         public ApplicationContext getApplicationContext() {
173                 return applicationContext;
174         }
175
176         /**
177          * @param applicationContext the applicationContext to set
178          */
179         public void setApplicationContext(ApplicationContext applicationContext) {
180                 this.applicationContext = applicationContext;
181         }
182
183 }