Search in sources :

Example 16 with SqlView

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);
    }
}
Also used : SqlView(org.hisp.dhis.sqlview.SqlView) WebMessageException(org.hisp.dhis.dxf2.webmessage.WebMessageException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with SqlView

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

Example 18 with SqlView

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

Aggregations

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