use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.
the class SqlViewController method executeView.
// -------------------------------------------------------------------------
// Post
// -------------------------------------------------------------------------
@RequestMapping(value = "/{uid}/execute", method = RequestMethod.POST)
public void executeView(@PathVariable("uid") String uid, @RequestParam(required = false) Set<String> var, HttpServletResponse response, HttpServletRequest request) throws WebMessageException {
SqlView sqlView = sqlViewService.getSqlViewByUid(uid);
if (sqlView == null) {
throw new WebMessageException(WebMessageUtils.notFound("SQL view not found"));
}
if (sqlView.isQuery()) {
throw new WebMessageException(WebMessageUtils.conflict("SQL view is a query, no view to create"));
}
String result = sqlViewService.createViewTable(sqlView);
if (result != null) {
throw new WebMessageException(WebMessageUtils.conflict(result));
} else {
response.addHeader("Location", SqlViewSchemaDescriptor.API_ENDPOINT + "/" + sqlView.getUid());
webMessageService.send(WebMessageUtils.created("SQL view created"), response, request);
}
}
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;
}
Aggregations