Search in sources :

Example 1 with SqlView

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;
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView)

Example 2 with SqlView

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;
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView) IllegalQueryException(org.hisp.dhis.common.IllegalQueryException)

Example 3 with SqlView

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;
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView)

Example 4 with SqlView

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;
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView)

Example 5 with SqlView

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;
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView)

Aggregations

SqlView (org.hisp.dhis.sqlview.SqlView)21 Grid (org.hisp.dhis.common.Grid)7 GetMapping (org.springframework.web.bind.annotation.GetMapping)7 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)3 ArrayList (java.util.ArrayList)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)1