use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.
the class CheckViewTableExistenceAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
if (id == null || (id.intValue() == -1)) {
message = i18n.getString("sql_view_instance_invalid");
return ERROR;
}
SqlView sqlView = sqlViewService.getSqlView(id);
if (sqlView.isQuery()) {
return SUCCESS;
}
String viewTableName = sqlView.getViewName();
if (!sqlViewService.viewTableExists(viewTableName)) {
message = i18n.getString("sql_view_table_is_not_created_yet");
return ERROR;
}
message = viewTableName;
return SUCCESS;
}
use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.
the class ExecuteSqlViewQueryAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() {
if (id == null || (id.intValue() == -1)) {
message = i18n.getString("sql_view_instance_invalid");
return ERROR;
}
SqlView sqlView = sqlViewService.getSqlView(id);
String viewName = sqlView.getViewName();
try {
message = sqlViewService.createViewTable(sqlView);
} catch (IllegalQueryException ex) {
message = ex.getMessage();
return ERROR;
}
if (message != null && !message.isEmpty()) {
message = i18n.getString("failed_to_create_view_table_for") + ": " + sqlView.getName() + "<br/><br/>" + i18n.getString("error_at") + ": " + message;
return ERROR;
}
message = i18n.getString("sql_view_table_name") + " [ " + viewName + " ] " + i18n.getString("is_created");
return SUCCESS;
}
use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.
the class RemoveSqlViewAction method execute.
// -------------------------------------------------------------------------
// Action
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
SqlView sqlView = sqlViewService.getSqlView(id);
sqlViewService.deleteSqlView(sqlView);
return SUCCESS;
}
use of org.hisp.dhis.sqlview.SqlView in project dhis2-core by dhis2.
the class UpdateSqlViewAction method execute.
// -------------------------------------------------------------------------
// Action implementation
// -------------------------------------------------------------------------
@Override
public String execute() throws Exception {
SqlView sqlView = sqlViewService.getSqlView(id);
sqlView.setDescription(description.replaceAll("\\s+", " ").trim());
sqlView.setSqlQuery(sqlquery);
if (cacheStrategy != null) {
sqlView.setCacheStrategy(cacheStrategy != null ? cacheStrategy : SqlView.DEFAULT_CACHE_STRATEGY);
}
if (jsonAttributeValues != null) {
attributeService.updateAttributeValues(sqlView, jsonAttributeValues);
}
sqlViewService.updateSqlView(sqlView);
return SUCCESS;
}
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;
}
Aggregations