use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.
the class AddSqlViewAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
SqlView sqlView = new SqlView();
sqlView.setName(name);
sqlView.setDescription(description);
sqlView.setSqlQuery(sqlquery);
sqlView.setType(SqlViewType.valueOf(type));
if (cacheStrategy != null) {
sqlView.setCacheStrategy(cacheStrategy != null ? cacheStrategy : SqlView.DEFAULT_CACHE_STRATEGY);
} else {
sqlView.setCacheStrategy(SqlView.DEFAULT_CACHE_STRATEGY);
}
if (jsonAttributeValues != null) {
attributeService.updateAttributeValues(sqlView, jsonAttributeValues);
}
sqlViewService.saveSqlView(sqlView);
return SUCCESS;
}
use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.
the class ValidateAddUpdateSqlViewAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
message = null;
if (name == null || name.trim().isEmpty()) {
message = i18n.getString("name_is_null");
return INPUT;
}
if (mode.equals(ADD) && sqlViewService.getSqlView(name) != null) {
message = i18n.getString("name_in_use");
return INPUT;
}
if (sqlquery == null || sqlquery.trim().isEmpty()) {
message = i18n.getString("sqlquery_is_empty");
return INPUT;
}
try {
// Avoid variable check
SqlView sqlView = new SqlView(name, sqlquery, SqlViewType.VIEW);
sqlViewService.validateSqlView(sqlView, null, null);
} catch (IllegalQueryException ex) {
message = ex.getMessage();
return INPUT;
}
if (!query) {
message = sqlViewService.testSqlGrammar(sqlquery);
}
if (message != null) {
return INPUT;
}
return SUCCESS;
}
use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.
the class DhisConvenienceTest method createSqlView.
/**
* @param uniqueCharacter A unique character to identify the object.
* @param sql A query statement to retreive record/data from database.
* @return a sqlView instance
*/
protected static SqlView createSqlView(char uniqueCharacter, String sql) {
SqlView sqlView = new SqlView();
sqlView.setAutoFields();
sqlView.setName("SqlView" + uniqueCharacter);
sqlView.setDescription("Description" + uniqueCharacter);
sqlView.setSqlQuery(sql);
sqlView.setType(SqlViewType.VIEW);
sqlView.setCacheStrategy(CacheStrategy.RESPECT_SYSTEM_SETTING);
return sqlView;
}
use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.
the class SqlViewController method getViewXls.
@RequestMapping(value = "/{uid}/data.xls", method = RequestMethod.GET)
public void getViewXls(@PathVariable("uid") String uid, @RequestParam(required = false) Set<String> criteria, @RequestParam(required = false) Set<String> var, HttpServletResponse response) throws Exception {
SqlView sqlView = sqlViewService.getSqlViewByUid(uid);
if (sqlView == null) {
throw new WebMessageException(WebMessageUtils.notFound("SQL view does not exist: " + uid));
}
List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
Grid grid = sqlViewService.getSqlViewGrid(sqlView, SqlView.getCriteria(criteria), SqlView.getCriteria(var), filters, fields);
String filename = CodecUtils.filenameEncode(grid.getTitle()) + ".xls";
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_EXCEL, sqlView.getCacheStrategy(), filename, true);
GridUtils.toXls(grid, response.getOutputStream());
}
use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.
the class SqlViewController method getViewHtmlCss.
@RequestMapping(value = "/{uid}/data.html+css", method = RequestMethod.GET)
public void getViewHtmlCss(@PathVariable("uid") String uid, @RequestParam(required = false) Set<String> criteria, @RequestParam(required = false) Set<String> var, HttpServletResponse response) throws Exception {
SqlView sqlView = sqlViewService.getSqlViewByUid(uid);
if (sqlView == null) {
throw new WebMessageException(WebMessageUtils.notFound("SQL view does not exist: " + uid));
}
List<String> filters = Lists.newArrayList(contextService.getParameterValues("filter"));
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
Grid grid = sqlViewService.getSqlViewGrid(sqlView, SqlView.getCriteria(criteria), SqlView.getCriteria(var), filters, fields);
contextUtils.configureResponse(response, ContextUtils.CONTENT_TYPE_HTML, sqlView.getCacheStrategy());
GridUtils.toHtmlCss(grid, response.getWriter());
}
Aggregations