Search in sources :

Example 11 with DfClassificationTop

use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.

the class DfClassificationProperties method reflectClassificationResourceToDefinition.

// -----------------------------------------------------
// Reflect to Definition
// ---------------------
protected void reflectClassificationResourceToDefinition() {
    // called by definition initialization
    final List<DfClassificationTop> resourceList = getClassificationResourceList();
    final DfClassificationResourceDefinitionReflector reflector = new DfClassificationResourceDefinitionReflector(resourceList);
    reflector.reflectClassificationResourceToDefinition(_classificationTopMap);
}
Also used : DfClassificationResourceDefinitionReflector(org.dbflute.properties.assistant.classification.resource.DfClassificationResourceDefinitionReflector) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop)

Example 12 with DfClassificationTop

use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.

the class DfRefClsRefTypeVerifier method doVerifyRefExists.

// -----------------------------------------------------
// Exists
// ------
protected void doVerifyRefExists(DfClassificationTop classificationTop) {
    final List<DfClassificationElement> appElementList = classificationTop.getClassificationElementList();
    final List<DfClassificationElement> referredElementList = _referredElementList;
    final List<DfClassificationElement> nonExistingList = appElementList.stream().filter(appElement -> {
        return notMatchesReferredElement(referredElementList, appElement);
    }).collect(Collectors.toList());
    if (!nonExistingList.isEmpty()) {
        final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
        br.addNotice("Not found the app classification code in the referred classification");
        br.addItem("Advice");
        br.addElement("The codes of the app classification should be included");
        br.addElement("in the referred classification because of refType='exists'.");
        br.addElement("For example:");
        br.addElement("  (x): app(A), referred(B, C)");
        br.addElement("  (x): app(A, B), referred(A, C)");
        br.addElement("  (x): app(A, B, C), referred(A, B)");
        br.addElement("  (o): app(A), referred(A, B)");
        br.addElement("  (o): app(A, B), referred(A, B, C)");
        br.addElement("  (o): app(A, B, C), referred(A, B, C)");
        br.addItem("dfprop File");
        br.addElement(_resourceFile);
        br.addItem("AppCls");
        br.addElement(classificationTop.getClassificationName() + ": " + buildClsCodesExp(appElementList));
        br.addItem("ReferredCls");
        br.addElement(buildReferredExp() + ": " + buildClsCodesExp(referredElementList));
        br.addItem("Ref Type");
        br.addElement(_refType);
        br.addItem("Non-Existing Code");
        br.addElement(nonExistingList.stream().map(element -> {
            return element.getCode();
        }).collect(Collectors.joining(", ")));
        final String msg = br.buildExceptionMessage();
        throw new DfIllegalPropertySettingException(msg);
    }
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException) List(java.util.List) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) Collectors(java.util.stream.Collectors) Srl(org.dbflute.util.Srl) DfClassificationGroup(org.dbflute.properties.assistant.classification.DfClassificationGroup) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 13 with DfClassificationTop

use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.

the class DfClassificationResourceFileAnalyzer method analyze.

// ===================================================================================
// Analyze
// =======
public List<DfClassificationTop> analyze(final String dirName, final String resourceName, final String extension) {
    final File dir = new File(dirName);
    if (!dir.exists()) {
        return new ArrayList<DfClassificationTop>();
    }
    if (!dir.isDirectory()) {
        return new ArrayList<DfClassificationTop>();
    }
    final File[] listFiles = dir.listFiles(new FileFilter() {

        public boolean accept(File currentFile) {
            if (currentFile.isDirectory()) {
                return false;
            }
            final String currentFileName = currentFile.getName();
            if (!currentFileName.startsWith(resourceName)) {
                return false;
            }
            if (!currentFileName.endsWith(extension)) {
                return false;
            }
            return true;
        }
    });
    final List<DfClassificationTop> topList = new ArrayList<DfClassificationTop>();
    for (File file : listFiles) {
        final List<String> lineList;
        try {
            String encoding = extractEncoding(file);
            if (encoding == null) {
                encoding = DEFAULT_ENCODING;
            }
            _log.info("...Analyzing classification in resource file: encoding=" + encoding);
            lineList = createLineList(file, encoding);
        } catch (RuntimeException ignored) {
            String msg = "Failed to analyze classification in resource file: ";
            msg = msg + " " + dirName + "/" + resourceName + "." + extension;
            _log.info(msg, ignored);
            continue;
        }
        final List<DfClassificationTop> classificationTopList = analyze(lineList);
        if (!classificationTopList.isEmpty()) {
            for (DfClassificationTop top : classificationTopList) {
                _log.info("    " + top.getClassificationName() + ", " + top.getTopCommentDisp() + ", " + top.isCheckClassificationCode() + ", " + top.getUndefinedHandlingType() + ", " + top.isCheckImplicitSet() + ", " + top.isCheckSelectedClassification() + ", " + top.isForceClassificationSetting());
            }
        } else {
            _log.info(" -> no classification in resource file");
        }
        topList.addAll(classificationTopList);
    }
    return topList;
}
Also used : ArrayList(java.util.ArrayList) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) FileFilter(java.io.FileFilter) File(java.io.File)

Example 14 with DfClassificationTop

use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.

the class DfClassificationResourceFileAnalyzer method analyze.

protected List<DfClassificationTop> analyze(final List<String> lineList) {
    final List<DfClassificationTop> classificationList = new ArrayList<DfClassificationTop>();
    AnalyzedTitleLine titleLine = null;
    boolean inGroup = false;
    final int size = lineList.size();
    int index = -1;
    for (String line : lineList) {
        ++index;
        if (inGroup) {
            if (isTopLine(line)) {
                final DfClassificationTop classificationTop = extractClassificationTop(titleLine, line);
                classificationList.add(classificationTop);
                if (titleLine != null) {
                    classificationTop.setRelatedColumnName(titleLine.getRelatedColumnName());
                    final String codeType = titleLine.getCodeType();
                    if (codeType != null) {
                        classificationTop.setCodeType(codeType);
                    }
                    classificationTop.setCheckImplicitSet(titleLine.isCheckImplicitSet());
                }
                continue;
            } else if (isElementLine(line)) {
                final DfClassificationElement classificationElement = extractClassificationElement(line);
                final DfClassificationTop classificationTop = classificationList.get(classificationList.size() - 1);
                classificationTop.addClassificationElement(classificationElement);
                continue;
            } else {
                inGroup = false;
                continue;
            }
        }
        if (!isTitleLine(line)) {
            continue;
        }
        final int nextIndex = index + 1;
        if (nextIndex >= size) {
            break;
        }
        final String nextLine = lineList.get(nextIndex);
        if (!isTopLine(nextLine)) {
            continue;
        }
        final int nextNextIndex = nextIndex + 1;
        if (nextNextIndex >= size) {
            break;
        }
        final String nextNextLine = lineList.get(nextNextIndex);
        if (!isElementLine(nextNextLine)) {
            continue;
        }
        titleLine = extractRelatedColumnNameFronTitleLine(line);
        inGroup = true;
    }
    return classificationList;
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) ArrayList(java.util.ArrayList)

Example 15 with DfClassificationTop

use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.

the class DfClassificationResourceFileAnalyzer method extractClassificationTop.

protected DfClassificationTop extractClassificationTop(AnalyzedTitleLine titleLine, String line) {
    if (!isTopLine(line)) {
        String msg = "The line should be top line: line=" + line;
        throw new IllegalArgumentException(msg);
    }
    line = line.trim();
    line = removeRearXmlEndIfNeeds(line);
    line = line.substring(line.indexOf("$ ") + "$ ".length());
    final String classificationName;
    final String topDesc;
    if (line.contains(",")) {
        classificationName = line.substring(0, line.indexOf(",")).trim();
        topDesc = line.substring(line.indexOf(",") + ",".length()).trim();
    } else {
        classificationName = line.trim();
        topDesc = null;
    }
    final DfClassificationTop classificationTop = new DfClassificationTop(classificationName);
    final String title = titleLine != null ? titleLine.getTitle() : null;
    final String topComment;
    if (topDesc != null) {
        if (Srl.is_NotNull_and_NotTrimmedEmpty(title) && !topDesc.startsWith(title)) {
            topComment = title + ": " + topDesc;
        } else {
            // title is not found or topComment starts with same word as title
            topComment = topDesc;
        }
    } else {
        topComment = title;
    }
    if (Srl.is_NotNull_and_NotTrimmedEmpty(topComment)) {
        classificationTop.setTopComment(topComment);
    }
    setupClassificationTopOption(classificationTop);
    return classificationTop;
}
Also used : DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop)

Aggregations

DfClassificationTop (org.dbflute.properties.assistant.classification.DfClassificationTop)38 DfClassificationElement (org.dbflute.properties.assistant.classification.DfClassificationElement)11 ArrayList (java.util.ArrayList)10 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)10 List (java.util.List)6 Map (java.util.Map)6 DfClassificationProperties (org.dbflute.properties.DfClassificationProperties)5 DfClassificationGroup (org.dbflute.properties.assistant.classification.DfClassificationGroup)5 LinkedHashMap (java.util.LinkedHashMap)4 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)4 DfRefClsElement (org.dbflute.properties.assistant.classification.refcls.DfRefClsElement)4 DfRefClsElement (org.dbflute.properties.assistant.classification.DfRefClsElement)3 DfRefClsReferredCDef (org.dbflute.properties.assistant.classification.refcls.DfRefClsReferredCDef)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Collectors (java.util.stream.Collectors)2 DfFixedConditionInvalidClassificationEmbeddedCommentException (org.dbflute.exception.DfFixedConditionInvalidClassificationEmbeddedCommentException)2 StringKeyMap (org.dbflute.helper.StringKeyMap)2 ClassificationUndefinedHandlingType (org.dbflute.jdbc.ClassificationUndefinedHandlingType)2 DfClsElementLiteralArranger (org.dbflute.properties.assistant.classification.element.proploading.DfClsElementLiteralArranger)2