2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
20 package org.openecomp.portalsdk.analytics.system.fusion.service;
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;
35 import javax.sql.DataSource;
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;
50 public class RaptorServiceImpl extends FusionService implements RaptorService {
52 private DataAccessService dataAccessService;
54 private int totalSize;
56 public DataAccessService getDataAccessService() {
57 return dataAccessService;
60 public void setDataAccessService(DataAccessService dataAccessService) {
61 this.dataAccessService = dataAccessService;
64 private ApplicationContext applicationContext;
66 //raptorSearchAllReportsCount
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);
74 searchCount = (((Long) l.get(0))).intValue();
77 totalSize = searchCount;
81 //raptorSearchAllReports
82 public List executeGridQuery(String query, Map params, Integer fromIndex, Integer toIndex) {
83 return getDataAccessService().executeNamedQuery(query, params, fromIndex, toIndex, null);
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);
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);
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);
100 public int getUserReportsCount(Map params) {
101 List l = getDataAccessService().executeNamedQuery("raptorSearchUserReportsCount", params, null);
105 Object[] result = (Object[]) l.get(0);
106 count = ((Long)result[0]).intValue();
113 public List getUserReports(Map params, Integer fromIndex, Integer toIndex) {
114 return getDataAccessService().executeNamedQuery("raptorSearchUserReports", params, fromIndex, toIndex, null);
117 public int getPublicReportsCount(Map params) {
118 List l = getDataAccessService().executeNamedQuery("raptorPublicUserReportsCount", params, null);
122 Object[] result = (Object[]) l.get(0);
123 count = ((Long)result[0]).intValue();
130 public List getPublicReports(Map params, Integer fromIndex, Integer toIndex) {
131 return getDataAccessService().executeNamedQuery("raptorPublicUserReports", params, fromIndex, toIndex, null);
134 public int getFavReportsCount(Map params) {
135 List l = getDataAccessService().executeNamedQuery("raptorSearchFavReportsCount", params, null);
139 Object[] result = (Object[]) l.get(0);
140 count = ((Long)result[0]).intValue();
147 public List getFavReports(Map params, Integer fromIndex, Integer toIndex) {
148 return getDataAccessService().executeNamedQuery("raptorSearchFavReports", params, fromIndex, toIndex, null);
151 public int getTotalSize() {
155 public void deleteReport(Long reportId) {
156 getDataAccessService().deleteDomainObject(getDataAccessService().getDomainObject(CR_Report.class, reportId, null), null);
159 public List getReportInfo(Map params) {
160 return getDataAccessService().executeNamedQuery("raptorInfoQuery", params, null);
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);
170 * @return the applicationContext
172 public ApplicationContext getApplicationContext() {
173 return applicationContext;
177 * @param applicationContext the applicationContext to set
179 public void setApplicationContext(ApplicationContext applicationContext) {
180 this.applicationContext = applicationContext;