Search in sources :

Example 1 with DfSPolicyIfClause

use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause in project dbflute-core by dbflute.

the class DfSPolicyLogicalSecretaryTest method createMockStatement.

protected DfSPolicyStatement createMockStatement() {
    List<DfSPolicyIfPart> ifPartList = newArrayList(new DfSPolicyIfPart("columnName", "$$ALL$$", false));
    DfSPolicyIfClause ifClause = new DfSPolicyIfClause(ifPartList, false);
    DfSPolicyThenClause thenClause = new DfSPolicyThenClause("bad", false, DfCollectionUtil.emptyList(), false, null);
    return new DfSPolicyStatement("if columnName is $$ALL$$ then bad", ifClause, thenClause);
}
Also used : DfSPolicyIfPart(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart) DfSPolicyStatement(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement) DfSPolicyThenClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause) DfSPolicyIfClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause)

Example 2 with DfSPolicyIfClause

use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause in project dbflute-core by dbflute.

the class DfSPolicyLogicalSecretary method parseStatement.

// ===================================================================================
// Statement
// =========
public DfSPolicyStatement parseStatement(String statement) {
    if (!statement.startsWith("if ")) {
        String msg = "The element of statementList should start with 'if' for SchemaPolicyCheck: " + statement;
        throw new IllegalStateException(msg);
    }
    final ScopeInfo ifScope = Srl.extractScopeFirst(statement, "if ", " then ");
    if (ifScope == null) {
        final String additional = "The statement should start with 'if' and contain 'then'.";
        throwSchemaPolicyCheckIllegalIfThenStatementException(statement, additional);
    }
    final DfSPolicyIfClause ifClause = analyzeIfClause(statement, ifScope);
    final DfSPolicyThenClause thenClause = analyzeThenClause(statement, ifScope);
    return new DfSPolicyStatement(statement, ifClause, thenClause);
}
Also used : DfSPolicyStatement(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement) DfSPolicyThenClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) DfSPolicyIfClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause)

Example 3 with DfSPolicyIfClause

use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause in project dbflute-core by dbflute.

the class DfSPolicyLogicalSecretary method analyzeIfClause.

// -----------------------------------------------------
// If Clause
// ---------
protected DfSPolicyIfClause analyzeIfClause(String statement, ScopeInfo ifScope) {
    final String ifWhole = ifScope.getContent().trim();
    if (!ifWhole.contains(EQUALS_DELIMITER)) {
        final String additional = "The if-clause should contain 'is': " + ifWhole;
        throwSchemaPolicyCheckIllegalIfThenStatementException(statement, additional);
    }
    // e.g. if tableName is sea and alias is land and piari and tableName is bonvo then ...
    boolean connectedByOr = false;
    List<String> ifPartStrList = splitClauseByConnector(ifWhole, " and ");
    if (ifPartStrList.size() == 1) {
        ifPartStrList = splitClauseByConnector(ifWhole, " or ");
        if (ifPartStrList.size() >= 2) {
            connectedByOr = true;
        }
    }
    final List<DfSPolicyIfPart> ifPartList = new ArrayList<DfSPolicyIfPart>();
    for (String ifPartStr : ifPartStrList) {
        final String ifItem = Srl.substringFirstFront(ifPartStr, EQUALS_DELIMITER).trim();
        final String ifValueCandidate = Srl.substringFirstRear(ifPartStr, EQUALS_DELIMITER).trim();
        final boolean notIfValue = ifValueCandidate.startsWith(NOT_PREFIX);
        final String ifValue = notIfValue ? Srl.substringFirstRear(ifValueCandidate, NOT_PREFIX).trim() : ifValueCandidate;
        final DfSPolicyIfPart part = new DfSPolicyIfPart(ifItem, ifValue, notIfValue);
        ifPartList.add(part);
    }
    return new DfSPolicyIfClause(Collections.unmodifiableList(ifPartList), connectedByOr);
}
Also used : DfSPolicyIfPart(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart) ArrayList(java.util.ArrayList) DfSPolicyIfClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause)

Example 4 with DfSPolicyIfClause

use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause in project dbflute-core by dbflute.

the class DfSPolicyMiscSecretary method analyzeIfClause.

// -----------------------------------------------------
// If Clause
// ---------
protected DfSPolicyIfClause analyzeIfClause(String statement, ScopeInfo ifScope) {
    final String ifWhole = ifScope.getContent().trim();
    if (!ifWhole.contains(EQUALS_DELIMITER)) {
        final String additional = "The if-clause should contain 'is': " + ifWhole;
        throwSchemaPolicyCheckIllegalIfThenStatementException(statement, additional);
    }
    // e.g. if tableName is sea and alias is land and piari and tableName is bonvo then ...
    boolean connectedByOr = false;
    List<String> ifPartStrList = splitClauseByConnector(ifWhole, " and ");
    if (ifPartStrList.size() == 1) {
        ifPartStrList = splitClauseByConnector(ifWhole, " or ");
        if (ifPartStrList.size() >= 2) {
            connectedByOr = true;
        }
    }
    final List<DfSPolicyIfPart> ifPartList = new ArrayList<DfSPolicyIfPart>();
    for (String ifPartStr : ifPartStrList) {
        final String ifItem = Srl.substringFirstFront(ifPartStr, EQUALS_DELIMITER).trim();
        final String ifValueCandidate = Srl.substringFirstRear(ifPartStr, EQUALS_DELIMITER).trim();
        final boolean notIfValue = ifValueCandidate.startsWith(NOT_PREFIX);
        final String ifValue = notIfValue ? Srl.substringFirstRear(ifValueCandidate, NOT_PREFIX).trim() : ifValueCandidate;
        final DfSPolicyIfPart part = new DfSPolicyIfPart(ifItem, ifValue, notIfValue);
        ifPartList.add(part);
    }
    return new DfSPolicyIfClause(Collections.unmodifiableList(ifPartList), connectedByOr);
}
Also used : DfSPolicyIfPart(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart) ArrayList(java.util.ArrayList) DfSPolicyIfClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause)

Example 5 with DfSPolicyIfClause

use of org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause in project dbflute-core by dbflute.

the class DfSPolicyMiscSecretary method parseStatement.

// ===================================================================================
// Statement
// =========
public DfSPolicyStatement parseStatement(String statement) {
    if (!statement.startsWith("if ")) {
        String msg = "The element of statementList should start with 'if' for SchemaPolicyCheck: " + statement;
        throw new IllegalStateException(msg);
    }
    final ScopeInfo ifScope = Srl.extractScopeFirst(statement, "if ", " then ");
    if (ifScope == null) {
        final String additional = "The statement should start with 'if' and contain 'then'.";
        throwSchemaPolicyCheckIllegalIfThenStatementException(statement, additional);
    }
    final DfSPolicyIfClause ifClause = analyzeIfClause(statement, ifScope);
    final DfSPolicyThenClause thenClause = analyzeThenClause(statement, ifScope);
    return new DfSPolicyStatement(statement, ifClause, thenClause);
}
Also used : DfSPolicyStatement(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement) DfSPolicyThenClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) DfSPolicyIfClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause)

Aggregations

DfSPolicyIfClause (org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfClause)5 DfSPolicyStatement (org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement)3 DfSPolicyIfPart (org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart)3 DfSPolicyThenClause (org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause)3 ArrayList (java.util.ArrayList)2 ScopeInfo (org.dbflute.util.Srl.ScopeInfo)2