Search in sources :

Example 1 with Be5QueryExecutor

use of com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor in project be5 by DevelopmentOnTheEdge.

the class QueryBuilder method select.

private void select(String sql, Request req, Injector injector) {
    DocumentGenerator documentGenerator = injector.get(DocumentGenerator.class);
    String userQBuilderQueryName = UserInfoHolder.getUserName() + "Query";
    Map<String, String> parametersMap = req.getValuesFromJsonAsStrings(RestApiConstants.VALUES);
    Entity entity = new Entity(entityName, injector.getProject().getApplication(), EntityType.TABLE);
    DataElementUtils.save(entity);
    Query query = new Query(userQBuilderQueryName, entity);
    query.setType(QueryType.D1_UNKNOWN);
    if (sql != null) {
        query.setQuery(sql);
    }
    DataElementUtils.save(query);
    try {
        resourceDataList.add(new ResourceData("finalSql", FrontendConstants.STATIC_ACTION, new StaticPagePresentation("Final sql", new Be5QueryExecutor(query, parametersMap, injector).getFinalSql()), null));
    } catch (Be5Exception e) {
        errorModelList.add(new ErrorModel(e));
    }
    try {
        JsonApiModel document = documentGenerator.getDocument(query, parametersMap);
        // todo refactor documentGenerator
        document.getData().setId("result");
        resourceDataList.add(document.getData());
        resourceDataList.addAll(Arrays.asList(document.getIncluded()));
    } catch (Be5Exception e) {
        errorModelList.add(new ErrorModel(e));
    }
    entity.getOrigin().remove(entityName);
}
Also used : Be5Exception(com.developmentontheedge.be5.api.exceptions.Be5Exception) Entity(com.developmentontheedge.be5.metadata.model.Entity) ResourceData(com.developmentontheedge.be5.model.jsonapi.ResourceData) StaticPagePresentation(com.developmentontheedge.be5.model.StaticPagePresentation) Query(com.developmentontheedge.be5.metadata.model.Query) SqlQuery(com.developmentontheedge.sql.model.SqlQuery) DocumentGenerator(com.developmentontheedge.be5.query.DocumentGenerator) ErrorModel(com.developmentontheedge.be5.model.jsonapi.ErrorModel) Be5QueryExecutor(com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor) JsonApiModel(com.developmentontheedge.be5.model.jsonapi.JsonApiModel)

Example 2 with Be5QueryExecutor

use of com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor in project be5 by DevelopmentOnTheEdge.

the class OperationHelper method getTagsFromCustomSelectionViewExecute.

// 
// public Map<String, String> getTagsMapFromQuery( Map<String, String> parameters, String query, Object... params )
// {
// //return getTagsListFromQuery( Collections.emptyMap(), query, params );
// List<String[]> tags = db.selectList("SELECT " + valueColumnName + ", " + textColumnName + " FROM " + tableName,
// rs -> new String[]{rs.getString(valueColumnName), rs.getString(textColumnName)}
// );
// String[][] stockArr = new String[tags.size()][2];
// return tags.toArray(stockArr);
// }
private String[][] getTagsFromCustomSelectionViewExecute(Query query, Map<String, ?> parameters) {
    String entityName = query.getEntity().getName();
    // todo refactoring Be5QueryExecutor,
    Map<String, String> stringStringMap = new HashMap<>();
    // parameters.forEach((key, value) -> stringStringMap.put(key, value.toString()));
    for (Map.Entry<String, ?> entry : parameters.entrySet()) {
        if (entry.getValue() != null)
            stringStringMap.put(entry.getKey(), entry.getValue().toString());
    }
    TableModel table = TableModel.from(query, stringStringMap, false, injector).limit(Integer.MAX_VALUE).build();
    String[][] stockArr = new String[table.getRows().size()][2];
    int i = 0;
    for (TableModel.RowModel row : table.getRows()) {
        String first = row.getCells().size() >= 1 ? row.getCells().get(0).content.toString() : "";
        String second = row.getCells().size() >= 2 ? row.getCells().get(1).content.toString() : "";
        stockArr[i++] = new String[] { first, userAwareMeta.getColumnTitle(entityName, second) };
    }
    return stockArr;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TableModel(com.developmentontheedge.be5.query.impl.model.TableModel)

Aggregations

Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)1 Entity (com.developmentontheedge.be5.metadata.model.Entity)1 Query (com.developmentontheedge.be5.metadata.model.Query)1 StaticPagePresentation (com.developmentontheedge.be5.model.StaticPagePresentation)1 ErrorModel (com.developmentontheedge.be5.model.jsonapi.ErrorModel)1 JsonApiModel (com.developmentontheedge.be5.model.jsonapi.JsonApiModel)1 ResourceData (com.developmentontheedge.be5.model.jsonapi.ResourceData)1 DocumentGenerator (com.developmentontheedge.be5.query.DocumentGenerator)1 Be5QueryExecutor (com.developmentontheedge.be5.query.impl.model.Be5QueryExecutor)1 TableModel (com.developmentontheedge.be5.query.impl.model.TableModel)1 SqlQuery (com.developmentontheedge.sql.model.SqlQuery)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1