Skip to content

Commit 2df5390

Browse files
authored
Spago resteasy (#962)
* delete mapping action spago for migration to resteasy * delete mapping spago action for migration to resteasy * migration qbe services Spago to RESTeasy * migration qbe services Spago to RESTEasy (Corino) * Fix post integration test FE-BE * Delete old Spago services
1 parent 3d38c8d commit 2df5390

9 files changed

Lines changed: 988 additions & 278 deletions

File tree

knowageqbeengine/src/main/java/it/eng/spagobi/engines/qbe/services/core/GetValuesForQbeFilterLookup.java renamed to knowageqbeengine/src/main/java/it/eng/spagobi/engines/qbe/api/QbeFilterLookupResource.java

Lines changed: 111 additions & 119 deletions
Large diffs are not rendered by default.

knowageqbeengine/src/main/java/it/eng/spagobi/engines/qbe/services/dataset/GetSQLQueryAction.java renamed to knowageqbeengine/src/main/java/it/eng/spagobi/engines/qbe/api/QbeGetSQLQueryResource.java

Lines changed: 49 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
/*
2-
* Knowage, Open Source Business Intelligence suite
3-
* Copyright (C) 2016 Engineering Ingegneria Informatica S.p.A.
4-
*
5-
* Knowage is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Affero General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* Knowage is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Affero General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Affero General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
*/
18-
package it.eng.spagobi.engines.qbe.services.dataset;
19-
20-
import java.io.IOException;
1+
package it.eng.spagobi.engines.qbe.api;
2+
213
import java.util.List;
224
import java.util.regex.Matcher;
235
import java.util.regex.Pattern;
246

7+
import javax.ws.rs.FormParam;
8+
import javax.ws.rs.POST;
9+
import javax.ws.rs.Path;
10+
import javax.ws.rs.Produces;
11+
import javax.ws.rs.core.MediaType;
12+
import javax.ws.rs.core.Response;
13+
2514
import org.apache.log4j.Logger;
2615
import org.hibernate.jdbc.util.BasicFormatterImpl;
2716
import org.json.JSONObject;
@@ -32,74 +21,63 @@
3221
import it.eng.qbe.query.ISelectField;
3322
import it.eng.qbe.query.Query;
3423
import it.eng.qbe.statement.IStatement;
35-
import it.eng.spago.base.SourceBean;
3624
import it.eng.spagobi.commons.bo.UserProfile;
3725
import it.eng.spagobi.commons.utilities.StringUtilities;
38-
import it.eng.spagobi.engines.qbe.services.core.AbstractQbeEngineAction;
26+
import it.eng.spagobi.container.ObjectUtils;
3927
import it.eng.spagobi.engines.qbe.services.core.ExecuteQueryAction;
4028
import it.eng.spagobi.utilities.assertion.Assert;
4129
import it.eng.spagobi.utilities.engines.EngineConstants;
42-
import it.eng.spagobi.utilities.engines.SpagoBIEngineServiceException;
4330
import it.eng.spagobi.utilities.engines.SpagoBIEngineServiceExceptionHandler;
44-
import it.eng.spagobi.utilities.service.JSONSuccess;
45-
46-
/**
47-
* The Class GetSQLQueryAction.
48-
*
49-
* @author Davide Zerbetto (davide.zerbetto@eng.it)
50-
*/
51-
public class GetSQLQueryAction extends AbstractQbeEngineAction {
52-
53-
// INPUT PARAMETERS
5431

55-
// OUTPUT PARAMETERS
32+
@Path("/GetSqlQuery")
33+
public class QbeGetSQLQueryResource extends AbstractQbeEngineResource {
5634

57-
// SESSION PARAMETRES
58-
59-
// AVAILABLE PUBLISHERS
60-
61-
/** Logger component. */
62-
private static final Logger LOGGER = Logger.getLogger(GetSQLQueryAction.class);
6335

6436
public static final String ENGINE_NAME = "SpagoBIQbeEngine";
65-
public static final String REPLACE_PARAMETERS_WITH_QUESTION = "replaceParametersWithQuestion";
6637

67-
@Override
68-
public void service(SourceBean request, SourceBean response) {
38+
public static transient Logger logger = Logger.getLogger(QbeGetSQLQueryResource.class);
6939

40+
@POST
41+
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
42+
public Response getSQLQuery(@FormParam("queryId") String queryId
43+
, @FormParam("replaceParametersWithQuestion") Boolean replaceParametersWithQuestion
44+
, @FormParam("promptableFilters") String promptableFilters ) {
45+
7046
Query query = null;
7147
IStatement statement = null;
7248

73-
LOGGER.debug("IN");
49+
logger.debug("IN");
7450

7551
try {
76-
super.service(request, response);
77-
78-
boolean replaceParametersWithQuestion = getAttributeAsBoolean("replaceParametersWithQuestion");
79-
80-
// retrieving query specified by id on request
81-
query = getEngineInstance().getQueryCatalogue().getQuery(getAttributeAsString("queryId"));
52+
query = getEngineInstance().getQueryCatalogue().getQuery(queryId);
8253
if (query == null) {
8354
query = getEngineInstance().getQueryCatalogue().getFirstQuery();
8455

8556
}
8657
Assert.assertNotNull(query, "Query not found!!");
8758

88-
UserProfile userProfile = (UserProfile) getEnv().get(EngineConstants.ENV_USER_PROFILE);
59+
UserProfile userProfile = (UserProfile) getEnv().get(EngineConstants.ENV_USER_PROFILE);
8960
IModelAccessModality accessModality = getEngineInstance().getDataSource().getModelAccessModality();
9061
Query filteredQuery = accessModality.getFilteredStatement(query, this.getEngineInstance().getDataSource(), userProfile.getUserAttributes());
9162

9263
getEngineInstance().setActiveQuery(filteredQuery);
93-
94-
95-
if (replaceParametersWithQuestion) {
96-
// promptable filters values may come with request (read-only
97-
// user modality)
98-
ExecuteQueryAction.updatePromptableFiltersValue(filteredQuery, this, true);
99-
} else {
100-
// promptable filters values may come with request (read-only
101-
// user modality)
102-
ExecuteQueryAction.updatePromptableFiltersValue(filteredQuery, this);
64+
JSONObject promptFileds = null;
65+
66+
if (promptableFilters != null && !promptableFilters.isEmpty()) {
67+
try {
68+
if (replaceParametersWithQuestion) {
69+
// promptable filters values may come with request (read-only
70+
// user modality)
71+
QbeQueryResource.updatePromptableFiltersValue(filteredQuery, true, promptableFilters);
72+
} else {
73+
// promptable filters values may come with request (read-only
74+
// user modality)
75+
QbeQueryResource.updatePromptableFiltersValue(filteredQuery, promptableFilters);
76+
}
77+
} catch (Exception e) {
78+
logger.error("Errore nel parsing dei promptableFilters", e);
79+
promptFileds = new JSONObject();
80+
}
10381
}
10482

10583
statement = getEngineInstance().getStatment();
@@ -112,7 +90,7 @@ public void service(SourceBean request, SourceBean response) {
11290
String sqlQuery = statement.getSqlQueryString();
11391
String sqlQueryFormatted = formatQueryString(sqlQuery);
11492

115-
LOGGER.debug("Executable query (SQL): [" + sqlQuery + "]");
93+
logger.debug("Executable query (SQL): [" + sqlQuery + "]");
11694

11795
toReturn.put("sql", sqlQuery);
11896
toReturn.put("sqlFormatted", sqlQueryFormatted);
@@ -122,28 +100,22 @@ public void service(SourceBean request, SourceBean response) {
122100
String jpaQueryStrFormatted = formatQueryString(addAliasInJqpl(query, jpaQueryStr));
123101
String sqlQueryFormatted = formatQueryString(addAliasInSql(query, sqlQuery));
124102

125-
LOGGER.debug("Executable query (HQL/JPQL): [" + jpaQueryStr + "]");
126-
LOGGER.debug("Executable query (SQL): [" + sqlQuery + "]");
103+
logger.debug("Executable query (HQL/JPQL): [" + jpaQueryStr + "]");
104+
logger.debug("Executable query (SQL): [" + sqlQuery + "]");
127105

128106
toReturn.put("sql", sqlQuery);
129107
toReturn.put("jpqlFormatted", jpaQueryStrFormatted);
130108
toReturn.put("sqlFormatted", sqlQueryFormatted);
131109
}
132110

133-
try {
134-
writeBackToClient(new JSONSuccess(toReturn));
135-
} catch (IOException e) {
136-
String message = "Impossible to write back the responce to the client";
137-
throw new SpagoBIEngineServiceException(getActionName(), message, e);
138-
}
111+
return Response.status(200).entity(toReturn.toString()).build();
139112

140113
} catch (Throwable t) {
141-
throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), getEngineInstance(), t);
114+
throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(this.getClass().getName(), getEngineInstance(), t);
142115
} finally {
143-
LOGGER.debug("OUT");
116+
logger.debug("OUT");
144117
}
145-
146-
}
118+
}
147119

148120
/**
149121
* Get the query string of the passed Query. The returned query is formatted
@@ -157,7 +129,7 @@ public String formatQueryString(String queryString) {
157129
BasicFormatterImpl fromatter;
158130

159131
if (queryString == null || queryString.equals("")) {
160-
LOGGER.error("Impossible to get the query string because the query is null");
132+
logger.error("Impossible to get the query string because the query is null");
161133
return "";
162134
}
163135

@@ -218,4 +190,5 @@ public String addAliasInJqpl(Query query, String queryString) {
218190
return queryString;
219191
}
220192

221-
}
193+
194+
}

knowageqbeengine/src/main/java/it/eng/spagobi/engines/qbe/services/core/datamart/GetTreeAction.java renamed to knowageqbeengine/src/main/java/it/eng/spagobi/engines/qbe/api/QbeGetTreeResource.java

Lines changed: 28 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1-
/*
2-
* Knowage, Open Source Business Intelligence suite
3-
* Copyright (C) 2016 Engineering Ingegneria Informatica S.p.A.
4-
*
5-
* Knowage is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Affero General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* Knowage is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Affero General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Affero General Public License
16-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17-
*/
18-
package it.eng.spagobi.engines.qbe.services.core.datamart;
19-
20-
import java.io.IOException;
1+
package it.eng.spagobi.engines.qbe.api;
2+
213
import java.util.Iterator;
224

5+
import javax.ws.rs.DefaultValue;
6+
import javax.ws.rs.GET;
7+
import javax.ws.rs.Path;
8+
import javax.ws.rs.Produces;
9+
import javax.ws.rs.QueryParam;
10+
import javax.ws.rs.core.MediaType;
11+
import javax.ws.rs.core.Response;
12+
2313
import org.apache.log4j.Logger;
2414
import org.json.JSONArray;
2515
import org.json.JSONObject;
@@ -33,23 +23,14 @@
3323
import it.eng.qbe.model.structure.filter.QbeTreeOrderFieldFilter;
3424
import it.eng.qbe.model.structure.filter.QbeTreeQueryEntityFilter;
3525
import it.eng.qbe.query.Query;
36-
import it.eng.spago.base.SourceBean;
3726
import it.eng.spagobi.commons.bo.UserProfile;
38-
import it.eng.spagobi.engines.qbe.services.core.AbstractQbeEngineAction;
3927
import it.eng.spagobi.engines.qbe.tree.ExtJsQbeTreeBuilder;
4028
import it.eng.spagobi.utilities.assertion.Assert;
4129
import it.eng.spagobi.utilities.engines.EngineConstants;
42-
import it.eng.spagobi.utilities.engines.SpagoBIEngineServiceException;
4330
import it.eng.spagobi.utilities.engines.SpagoBIEngineServiceExceptionHandler;
44-
import it.eng.spagobi.utilities.service.JSONSuccess;
45-
46-
/**
47-
*
48-
* @author Andrea Gioia (andrea.gioia@eng.it)
49-
*/
50-
public class GetTreeAction extends AbstractQbeEngineAction {
5131

52-
private static final long serialVersionUID = 1325035833244562916L;
32+
@Path("/GetTree")
33+
public class QbeGetTreeResource extends AbstractQbeEngineResource {
5334

5435
// INPUT PARAMETERS
5536
public static final String QUERY_ID = "parentQueryId";
@@ -58,13 +39,12 @@ public class GetTreeAction extends AbstractQbeEngineAction {
5839
public static final String ENTITIES = "entities";
5940

6041
/** Logger component. */
61-
public static transient Logger logger = Logger.getLogger(GetTreeAction.class);
62-
63-
@Override
64-
public void service(SourceBean request, SourceBean response) {
42+
public static transient Logger logger = Logger.getLogger(QbeGetTreeResource.class);
6543

44+
@GET
45+
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
46+
public Response getTree(@QueryParam("datamartName") String datamartName, @QueryParam("openDatasetInQbe") @DefaultValue("false")Boolean openDatasetInQbe) {
6647
String queryId = null;
67-
String datamartName = null;
6848
Query query = null;
6949

7050
IQbeTreeEntityFilter entityFilter = null;
@@ -76,17 +56,15 @@ public void service(SourceBean request, SourceBean response) {
7656
JSONArray nodes = null;
7757
logger.debug("IN");
7858

79-
try {
80-
super.service(request, response);
81-
82-
UserProfile userProfile = (UserProfile) getEnv().get(EngineConstants.ENV_USER_PROFILE);
59+
UserProfile userProfile = (UserProfile) getEnv().get(EngineConstants.ENV_USER_PROFILE);
8360

84-
queryId = getAttributeAsString(QUERY_ID);
85-
logger.debug("Parameter [" + QUERY_ID + "] is equals to [" + queryId + "]");
61+
// queryId = getAttributeAsString(QUERY_ID);
62+
// logger.debug("Parameter [" + QUERY_ID + "] is equals to [" + queryId + "]");
8663

87-
Assert.assertNotNull(getEngineInstance(),
88-
"It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
64+
Assert.assertNotNull(getEngineInstance(),
65+
"It's not possible to execute GetTree service before having properly created an instance of EngineInstance class");
8966

67+
try {
9068
logger.debug("Filtering entities list ...");
9169
entityFilter = new QbeTreeAccessModalityEntityFilter();
9270
logger.debug("Apply entity filter [" + entityFilter.getClass().getName() + "]");
@@ -110,21 +88,17 @@ public void service(SourceBean request, SourceBean response) {
11088

11189
qbeBuilder = new ExtJsQbeTreeBuilder(treeFilter);
11290

113-
datamartName = getAttributeAsString(DATAMART_NAME);
114-
115-
boolean openDatasetInQbe = getAttributeAsBoolean("openDatasetInQbe");
116-
11791
if (!openDatasetInQbe && datamartName != null && !datamartName.equals("null")) {
11892
// if(datamartName.equals("null"))
11993
// datamartName="";
120-
nodes = qbeBuilder.getQbeTree(getDataSource(), getLocale(), datamartName, userProfile);
94+
nodes = qbeBuilder.getQbeTree(getEngineInstance().getDataSource(), getLocale(), datamartName, userProfile);
12195

12296
} else {
12397
nodes = new JSONArray();
124-
Iterator<String> it = getDataSource().getModelStructure(userProfile).getModelNames().iterator();
98+
Iterator<String> it = getEngineInstance().getDataSource().getModelStructure(userProfile).getModelNames().iterator();
12599
while (it.hasNext()) {
126100
String modelName = it.next();
127-
JSONArray temp = qbeBuilder.getQbeTree(getDataSource(), getLocale(), modelName, userProfile);
101+
JSONArray temp = qbeBuilder.getQbeTree(getEngineInstance().getDataSource(), getLocale(), modelName, userProfile);
128102
for (int i = 0; i < temp.length(); i++) {
129103
Object object = temp.get(i);
130104
nodes.put(object);
@@ -134,16 +108,11 @@ public void service(SourceBean request, SourceBean response) {
134108
}
135109

136110
node.put(ENTITIES, nodes);
137-
138-
try {
139-
writeBackToClient(new JSONSuccess(node));
140-
} catch (IOException e) {
141-
String message = "Impossible to write back the responce to the client";
142-
throw new SpagoBIEngineServiceException(getActionName(), message, e);
143-
}
111+
// writeBackToClient(new JSONSuccess(node));
112+
return Response.status(200).entity(node.toString()).build();
144113

145114
} catch (Throwable t) {
146-
throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), getEngineInstance(), t);
115+
throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException("GetTree", getEngineInstance(), t);
147116
} finally {
148117
logger.debug("OUT");
149118
}

0 commit comments

Comments
 (0)