Search in sources :

Example 26 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo 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)

Example 27 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project lastaflute by lastaflute.

the class HookedXADataSource method resolveClassesUrl.

protected String resolveClassesUrl(String url) {
    // for e.g. H2 local file
    final String beginMark = CLASSES_BEGIN_MARK;
    final String endMark = CLASSES_END_MARK;
    final ScopeInfo classesScope = Srl.extractScopeFirst(url, beginMark, endMark);
    if (classesScope == null) {
        return url;
    }
    final String className = classesScope.getContent().trim();
    final String front = Srl.substringFirstFront(url, beginMark);
    final String rear = Srl.substringFirstRear(url, endMark);
    final Class<?> lardmarkType = LdiClassUtil.forName(className);
    final File buildDir = DfResourceUtil.getBuildDir(lardmarkType);
    try {
        final String canonicalPath = buildDir.getCanonicalPath();
        return front + canonicalPath.replace('\\', '/') + rear;
    } catch (IOException e) {
        throw new IllegalStateException("Failed to get canonical path: " + buildDir, e);
    }
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo) IOException(java.io.IOException) File(java.io.File)

Example 28 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfSql2EntityMarkAnalyzer method getTitle.

// ===================================================================================
// Title/Description
// =================
public String getTitle(String sql) {
    // should be first not to conflict
    final String oldStyleTitle = findOldStyleTitle(sql);
    if (oldStyleTitle != null) {
        return oldStyleTitle;
    }
    if (sql.startsWith("/*") && sql.contains("*/")) {
        // new style
        final ScopeInfo commentScope = Srl.extractScopeFirst(sql, "/*", "*/");
        final String comment = commentScope.getContent();
        final ScopeInfo titleScope = Srl.extractScopeFirst(comment, "[", "]");
        if (titleScope != null) {
            final String title = titleScope.getContent().trim();
            if (!title.isEmpty()) {
                return title;
            }
        }
    }
    return null;
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Example 29 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfIncludeQueryProperties method extractColumnDrivenInterfaceMap.

protected Map<String, Map<String, List<String>>> extractColumnDrivenInterfaceMap(Map<String, Object> targetMap) {
    // ; $MEMBER = map:{
    // ; BIRTHDATE(Date) = list:{ !GreaterThan ; !LessThan }
    // ; MEMBER_NAME(String) = list:{}
    // }
    final Map<String, Map<String, List<String>>> interfaceMap = newLinkedHashMap();
    for (Entry<String, Object> propEntry : targetMap.entrySet()) {
        final String propType = propEntry.getKey();
        final Object value = propEntry.getValue();
        if (!(value instanceof Map)) {
            String msg = "The key '" + KEY_conditionBeanMap + "' should have map value:";
            msg = msg + " key=" + propType + " value=" + value + " targetMap=" + targetMap;
            throw new DfIllegalPropertyTypeException(msg);
        }
        if (!propType.startsWith("$")) {
            continue;
        }
        final String tableName = Srl.substringFirstRear(propType, "$");
        @SuppressWarnings("unchecked") final Map<String, List<String>> columnCKeyMap = (Map<String, List<String>>) value;
        Set<Entry<String, List<String>>> entrySet = columnCKeyMap.entrySet();
        for (Entry<String, List<String>> entry : entrySet) {
            final String columnExp = entry.getKey();
            final List<String> ckeyList = entry.getValue();
            if (!ckeyList.isEmpty()) {
                columnCKeyMap.put(columnExp, ckeyList);
            } else {
                final ScopeInfo scopeFirst = Srl.extractScopeFirst(columnExp, "(", ")");
                if (scopeFirst == null) {
                    String msg = "The column expression should be e.g. Member(Date) but: " + columnExp;
                    throw new DfIllegalPropertySettingException(msg);
                }
                final String currentPropType = scopeFirst.getContent().trim();
                final Set<String> ckeySet = _ckeySetMap.get(currentPropType);
                if (ckeySet == null) {
                    String msg = "Unknown condition-key: " + currentPropType + ", expected=" + _ckeySetMap.keySet();
                    throw new DfIllegalPropertySettingException(msg);
                }
                final List<String> allCKeyList = new ArrayList<String>();
                for (String ckey : ckeySet) {
                    allCKeyList.add("!" + ckey);
                }
                columnCKeyMap.put(columnExp, allCKeyList);
            }
        }
        interfaceMap.put(tableName, columnCKeyMap);
    }
    return interfaceMap;
}
Also used : ArrayList(java.util.ArrayList) ScopeInfo(org.dbflute.util.Srl.ScopeInfo) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException) DfIllegalPropertyTypeException(org.dbflute.exception.DfIllegalPropertyTypeException) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap)

Example 30 with ScopeInfo

use of org.dbflute.util.Srl.ScopeInfo in project dbflute-core by dbflute.

the class DfClassificationResourceFileAnalyzer method extractRelatedColumnNameFronTitleLine.

protected AnalyzedTitleLine extractRelatedColumnNameFronTitleLine(String line) {
    if (!isTitleLine(line)) {
        String msg = "The line should be title line: line=" + line;
        throw new IllegalArgumentException(msg);
    }
    final String connectBeginMark = "[";
    final String connectEndMark = "]:";
    final String wildCard = "*";
    final String prefixMark = DfNameHintUtil.PREFIX_MARK;
    final String suffixMark = DfNameHintUtil.SUFFIX_MARK;
    if (!Srl.containsAll(line, connectBeginMark, connectEndMark)) {
        return null;
    }
    line = line.trim();
    line = removeRearXmlEndIfNeeds(line);
    final AnalyzedTitleLine titleLine = new AnalyzedTitleLine();
    final ScopeInfo scopeFirst = Srl.extractScopeFirst(line, connectBeginMark, connectEndMark);
    if (scopeFirst == null) {
        // basically no way
        return null;
    }
    titleLine.setTitle(scopeFirst.getContent().trim());
    final String relatedColumnName;
    final String option;
    {
        String pureValue = Srl.substringFirstRear(line, connectEndMark).trim();
        if (pureValue.startsWith(wildCard)) {
            // *_FLG
            pureValue = suffixMark + pureValue.substring(wildCard.length());
        } else if (pureValue.endsWith(wildCard)) {
            // LD_*
            pureValue = pureValue.substring(0, pureValue.lastIndexOf(wildCard));
            pureValue = prefixMark + pureValue;
        }
        if (pureValue.contains("|")) {
            relatedColumnName = Srl.substringFirstFront(pureValue, "|").trim();
            option = Srl.substringFirstRear(pureValue, "|").trim();
        } else {
            relatedColumnName = pureValue;
            option = null;
        }
    }
    titleLine.setRelatedColumnName(relatedColumnName);
    if (Srl.is_NotNull_and_NotTrimmedEmpty(option)) {
        final String codeTypeNumber = DfClassificationTop.CODE_TYPE_NUMBER;
        if (Srl.containsIgnoreCase(option, codeTypeNumber)) {
            titleLine.setCodeType(codeTypeNumber);
        }
        titleLine.setCheckImplicitSet(Srl.containsIgnoreCase(option, "check"));
    }
    return titleLine;
}
Also used : ScopeInfo(org.dbflute.util.Srl.ScopeInfo)

Aggregations

ScopeInfo (org.dbflute.util.Srl.ScopeInfo)42 File (java.io.File)7 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 FileTextIO (org.dbflute.helper.filesystem.FileTextIO)6 FileInputStream (java.io.FileInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4 LinkedHashSet (java.util.LinkedHashSet)4 IOException (java.io.IOException)3 Arrays (java.util.Arrays)3 Set (java.util.Set)3 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)3 DateTimeFormatter (java.time.format.DateTimeFormatter)2 TemporalAccessor (java.time.temporal.TemporalAccessor)2 DfBuildProperties (org.dbflute.DfBuildProperties)2 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)2 StringKeyMap (org.dbflute.helper.StringKeyMap)2 FileHierarchyTracer (org.dbflute.helper.filesystem.FileHierarchyTracer)2