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());
}
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()));
}
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;
}
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;
}
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;
}
Aggregations