use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class DocumentGeneratorImpl method getTable.
public TablePresentation getTable(Query query, Map<String, String> parameters, int sortColumn, boolean sortDesc) {
List<TableOperationPresentation> operations = collectOperations(query);
final boolean selectable = !operations.isEmpty() && query.getType() == QueryType.D1;
int limit = userAwareMeta.getQuerySettings(query).getMaxRecordsPerPage();
if (limit == 0) {
// todo delete defaultPageLimit, use getQuerySettings(query).getMaxRecordsPerPage()
limit = Integer.parseInt(getLayoutObject(query).getOrDefault("defaultPageLimit", coreUtils.getSystemSetting("be5_defaultPageLimit", "10")).toString());
}
TableModel table = TableModel.from(query, parameters, selectable, injector).sortOrder(sortColumn, sortDesc).limit(limit).build();
return getTable(query, parameters, table);
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class Project method translateSQL.
/**
* Try to translate the SQL query to the current DBMS using com.developmentontheedge.sql
* @param sql
* @return
*/
public String translateSQL(String sql) {
if (beSQL > 0) {
if (--beSQL == 0)
reconfigureFreemarker();
}
if (sqlParser == null) {
throw new IllegalStateException("translateSQL was called without enterSQL");
}
sqlParser.parse(sql);
List<String> messages = sqlParser.getMessages();
if (!messages.isEmpty()) {
throw new IllegalArgumentException(("SQL cannot be parsed:\nQuery:" + sql + "\nErrors: " + String.join("\n", messages)).replace("\r", "").replace("\n", System.lineSeparator()));
}
AstStart ast = sqlParser.getStartNode();
if (databaseSystem != Rdbms.BESQL) {
new MacroExpander().expandMacros(ast);
Dbms dbms = databaseSystem == null ? Dbms.POSTGRESQL : Dbms.valueOf(databaseSystem.name());
DbmsTransformer dbmsTransformer = new Context(dbms).getDbmsTransformer();
dbmsTransformer.setParserContext(sqlParser.getContext());
dbmsTransformer.transformAst(ast);
}
return ast.format();
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class Project method mergeTemplate.
public ParseResult mergeTemplate(TemplateElement element) {
boolean besql = element instanceof Query && ((Query) element).getEntity().isBesql() && ((Query) element).isSqlQuery();
try {
sqlMacros.clear();
if (" ".equals(element.getTemplateCode()))
return new ParseResult(" ");
final DataElementPath path = element.getCompletePath();
final String merged = FreemarkerUtils.mergeTemplateByPath(path.toString(), getContext(element), getConfiguration());
if (besql)
enterSQL();
return new ParseResult(besql ? translateSQL(merged) : merged);
} catch (ProjectElementException e) {
return new ParseResult(e);
} catch (Throwable e) {
return new ParseResult(new ProjectElementException(getCompletePath(), "source", e));
} finally {
beSQL = 0;
sqlMacros.clear();
}
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class ProjectGenerator method createLoginAndLogoutOperations.
private void createLoginAndLogoutOperations(final Project project) {
final Entity logoutEntity = new Entity("_logout_", project.getApplication(), EntityType.TABLE);
logoutEntity.setDisplayName("Logout");
logoutEntity.setOrder("99");
logoutEntity.setPrimaryKey("dummy");
logoutEntity.getIcon().setSource(Icon.SOURCE_BE);
logoutEntity.getIcon().setName("logout.gif");
final Query logout = new Query("Logout", logoutEntity);
logout.setType(QueryType.STATIC);
logout.getRoles().add('@' + SpecialRoleGroup.ALL_ROLES_EXCEPT_GUEST_GROUP);
logout.setQuery("logout");
DataElementUtils.saveQuiet(logout);
EntitiesFactory.addToModule(logoutEntity, project.getApplication());
Module beModule = project.getModule(SYSTEM_MODULE);
Entity usersEntity = new Entity("users", beModule, EntityType.TABLE);
usersEntity.setOrder("90");
usersEntity.getIcon().setSource("be:people.gif");
DataElementUtils.saveQuiet(usersEntity);
Query loginQuery = new Query("Login", usersEntity);
loginQuery.setType(QueryType.STATIC);
loginQuery.setQuery("login");
loginQuery.getRoles().add("Guest");
DataElementUtils.saveQuiet(loginQuery);
// Query forgotPassword = new Query("Forgot Password?", usersEntity);
// forgotPassword.getRoles().add( "Guest" );
// forgotPassword.setParametrizingOperationName( "Send password" );
// DataElementUtils.saveQuiet( forgotPassword );
// Operation sendPassword = Operation.createOperation( "Send password", Operation.OPERATION_TYPE_JAVA, usersEntity );
// sendPassword.setCode( SendPassword.class.getName() );
// DataElementUtils.saveQuiet( sendPassword );
}
use of com.developmentontheedge.be5.metadata.model.Query in project be5 by DevelopmentOnTheEdge.
the class ActionHelperTest method legacyUrlTest2.
@Test
public void legacyUrlTest2() throws Exception {
Query query = getQuery(QueryType.STATIC, "mspReceiverCategories.redir");
assertEquals("table/mspReceiverCategories", ActionUtils.toAction(query).arg);
}
Aggregations