Search in sources :

Example 6 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)

Example 7 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 8 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)

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

Example 10 with SqlView

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

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