Search in sources :

Example 36 with Query

use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.

the class EntityLocalizationsTest method testLocalizations.

@Test
public void testLocalizations() {
    Project proj = new Project("test");
    proj.getApplication().getLocalizations().addLocalization("de", "entity", Arrays.asList("@AllQueries", "topic"), "Hello", "Guten Tag");
    Entity entity = new Entity("entity", proj.getApplication(), EntityType.TABLE);
    DataElementUtils.save(entity);
    DataElementUtils.save(new Query("testQuery", entity));
    DataElementUtils.save(new Query("testQuery2", entity));
    EntityLocalizations el = proj.getApplication().getLocalizations().get("de").get("entity");
    Set<LocalizationRow> expected = StreamEx.of("testQuery", "testQuery2", "topic").map(topic -> new EntityLocalizations.LocalizationRow(topic, "Hello", "Guten Tag")).toSet();
    assertEquals(expected, el.getRawRows());
    assertEquals(expected, el.getRows());
    el.remove("Hello", Collections.singleton("topic"));
    expected = StreamEx.of("testQuery", "testQuery2").map(topic -> new EntityLocalizations.LocalizationRow(topic, "Hello", "Guten Tag")).toSet();
    assertEquals(expected, el.getRawRows());
    assertEquals(expected, el.getRows());
}
Also used : Arrays(java.util.Arrays) LocalizationRow(com.developmentontheedge.be5.metadata.model.EntityLocalizations.LocalizationRow) StreamEx(one.util.streamex.StreamEx) Set(java.util.Set) Test(org.junit.Test) Assert(org.junit.Assert) Collections(java.util.Collections) LocalizationRow(com.developmentontheedge.be5.metadata.model.EntityLocalizations.LocalizationRow) LocalizationRow(com.developmentontheedge.be5.metadata.model.EntityLocalizations.LocalizationRow) Test(org.junit.Test)

Example 37 with Query

use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.

the class AppValidate method checkQuery.

private void checkQuery() throws MojoFailureException {
    if (queryPath == null)
        return;
    int pos = queryPath.indexOf('.');
    if (pos <= 0) {
        throw new MojoFailureException("Invalid query path supplied: " + queryPath);
    }
    String entityName = queryPath.substring(0, pos);
    String queryName = queryPath.substring(pos + 1);
    Entity entity = be5Project.getEntity(entityName);
    if (entity == null) {
        throw new MojoFailureException("Invalid entity: " + entityName);
    }
    Query query = entity.getQueries().get(queryName);
    if (query == null) {
        try {
            queryName = new String(queryName.getBytes("CP866"), "CP1251");
            query = entity.getQueries().get(queryName);
        } catch (UnsupportedEncodingException e) {
            throw new MojoFailureException("Can not load query, path=" + queryPath, e);
        }
    }
    if (query == null) {
        throw new MojoFailureException("Invalid query: " + queryName);
    }
    getLog().info("Query: " + query.getQueryCompiled().getResult().replaceAll("\n", System.lineSeparator()));
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) MojoFailureException(org.apache.maven.plugin.MojoFailureException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 38 with Query

use of com.developmentontheedge.be5.metadata.model.Query 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)

Example 39 with Query

use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.

the class MetaImpl method createQueryFromSql.

@Override
public Query createQueryFromSql(String sql) {
    Entity e = new Entity("be5DynamicQueries", getProject().getApplication(), EntityType.TABLE);
    e.setBesql(true);
    DataElementUtils.save(e);
    Query query = new Query("query", e);
    DataElementUtils.save(query);
    query.setQuery(sql);
    return query;
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query)

Example 40 with Query

use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.

the class MetaImpl method getQueryIgnoringRoles.

@Override
public Query getQueryIgnoringRoles(String entityName, String queryName) {
    Entity entity = getEntity(entityName);
    if (entity == null) {
        throw Be5Exception.unknownEntity(entityName);
    }
    Query query = entity.getQueries().get(queryName);
    if (query == null) {
        throw Be5ErrorCode.UNKNOWN_QUERY.exception(entityName, queryName);
    }
    return query;
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query)

Aggregations

Query (com.developmentontheedge.be5.metadata.model.Query)29 Entity (com.developmentontheedge.be5.metadata.model.Entity)16 ArrayList (java.util.ArrayList)15 Test (org.junit.Test)15 Project (com.developmentontheedge.be5.metadata.model.Project)12 Module (com.developmentontheedge.be5.metadata.model.Module)8 Path (java.nio.file.Path)8 Operation (com.developmentontheedge.be5.metadata.model.Operation)6 HashMap (java.util.HashMap)6 Be5Exception (com.developmentontheedge.be5.api.exceptions.Be5Exception)4 ProjectElementException (com.developmentontheedge.be5.metadata.exception.ProjectElementException)4 Be5ProjectTest (com.developmentontheedge.be5.test.Be5ProjectTest)4 Map (java.util.Map)4 UserAwareMeta (com.developmentontheedge.be5.api.helpers.UserAwareMeta)3 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)3 DataElementPath (com.developmentontheedge.be5.metadata.model.base.DataElementPath)3 LoadContext (com.developmentontheedge.be5.metadata.serialization.LoadContext)3 LinkedHashMap (java.util.LinkedHashMap)3 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)2 Action (com.developmentontheedge.be5.model.Action)2