Search in sources :

Example 46 with Query

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);
}
Also used : TableOperationPresentation(com.developmentontheedge.be5.model.TableOperationPresentation) TableModel(com.developmentontheedge.be5.query.impl.model.TableModel)

Example 47 with Query

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();
}
Also used : LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) Context(com.developmentontheedge.sql.format.Context) AstStart(com.developmentontheedge.sql.model.AstStart) MacroExpander(com.developmentontheedge.sql.format.MacroExpander) Dbms(com.developmentontheedge.sql.format.Dbms) DbmsTransformer(com.developmentontheedge.sql.format.DbmsTransformer)

Example 48 with Query

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();
    }
}
Also used : ProjectElementException(com.developmentontheedge.be5.metadata.exception.ProjectElementException) DataElementPath(com.developmentontheedge.be5.metadata.model.base.DataElementPath)

Example 49 with Query

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 );
}
Also used : Entity(com.developmentontheedge.be5.metadata.model.Entity) Query(com.developmentontheedge.be5.metadata.model.Query) Module(com.developmentontheedge.be5.metadata.model.Module)

Example 50 with Query

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);
}
Also used : Query(com.developmentontheedge.be5.metadata.model.Query) Test(org.junit.Test) Be5ProjectTest(com.developmentontheedge.be5.test.Be5ProjectTest)

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