Search in sources :

Example 51 with DfIllegalPropertySettingException

use of org.dbflute.exception.DfIllegalPropertySettingException in project dbflute-core by dbflute.

the class DfClassificationProperties method getClassificationDefinitionMap.

// -----------------------------------------------------
// Native Definition
// -----------------
/**
 * Get the map of classification definition.
 * @return The map of classification definition. (NotNull)
 */
protected Map<String, DfClassificationTop> getClassificationDefinitionMap() {
    if (_classificationTopMap != null) {
        return _classificationTopMap;
    }
    _classificationTopMap = newLinkedHashMap();
    final Map<String, Object> plainDefinitionMap;
    {
        final String mapName = KEY_classificationDefinitionMap;
        final String propKey = "torque." + mapName;
        plainDefinitionMap = resolveSplit(mapName, mapProp(propKey, DEFAULT_EMPTY_MAP));
    }
    final DfClsElementLiteralArranger literalArranger = new DfClsElementLiteralArranger();
    String allInOneSql = null;
    Connection conn = null;
    try {
        for (Entry<String, Object> entry : plainDefinitionMap.entrySet()) {
            final String classificationName = entry.getKey();
            final Object objValue = entry.getValue();
            // handle special elements
            if (classificationName.equalsIgnoreCase("$$SQL$$")) {
                allInOneSql = (String) objValue;
                continue;
            }
            // check duplicate classification
            if (_classificationTopMap.containsKey(classificationName)) {
                String msg = "Duplicate classification: " + classificationName;
                throw new DfIllegalPropertySettingException(msg);
            }
            final DfClassificationTop classificationTop = new DfClassificationTop(classificationName);
            _classificationTopMap.put(classificationName, classificationTop);
            // handle classification elements
            if (!(objValue instanceof List<?>)) {
                throwClassificationMapValueIllegalListTypeException(objValue);
            }
            final List<?> plainList = (List<?>) objValue;
            final List<DfClassificationElement> elementList = new ArrayList<DfClassificationElement>();
            boolean tableClassification = false;
            for (Object element : plainList) {
                if (!(element instanceof Map<?, ?>)) {
                    throwClassificationListElementIllegalMapTypeException(element);
                }
                @SuppressWarnings("unchecked") final Map<String, Object> elementMap = (Map<String, Object>) element;
                // from table
                final String table = (String) elementMap.get(DfClassificationElement.KEY_TABLE);
                if (Srl.is_NotNull_and_NotTrimmedEmpty(table)) {
                    tableClassification = true;
                    if (conn == null) {
                        // on demand
                        conn = createMainSchemaConnection();
                    }
                    arrangeTableClassification(classificationTop, elementMap, table, elementList, conn);
                    continue;
                }
                // from literal
                if (isElementMapClassificationTop(elementMap)) {
                    // top definition
                    arrangeClassificationTopFromLiteral(classificationTop, elementMap);
                } else {
                    literalArranger.arrange(classificationName, elementMap);
                    final DfClassificationElement classificationElement = new DfClassificationElement();
                    classificationElement.setClassificationName(classificationName);
                    classificationElement.acceptBasicItemMap(elementMap);
                    elementList.add(classificationElement);
                }
            }
            // adjust classification top
            classificationTop.addClassificationElementAll(elementList);
            classificationTop.setTableClassification(tableClassification);
            _classificationTopMap.put(classificationName, classificationTop);
        }
        if (allInOneSql != null) {
            if (conn == null) {
                // on demand
                conn = createMainSchemaConnection();
            }
            arrangeAllInOneTableClassification(conn, allInOneSql);
        }
        // *Classification Resource Point!
        reflectClassificationResourceToDefinition();
        filterUseDocumentOnly();
        verifyClassificationConstraintsIfNeeds();
        prepareSuppressedDBAccessClassTableSet();
    } finally {
        new DfClassificationJdbcCloser().closeConnection(conn);
    }
    return _classificationTopMap;
}
Also used : Connection(java.sql.Connection) ArrayList(java.util.ArrayList) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException) DfClassificationJdbcCloser(org.dbflute.properties.assistant.classification.coins.DfClassificationJdbcCloser) DfClsElementLiteralArranger(org.dbflute.properties.assistant.classification.element.proploading.DfClsElementLiteralArranger) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap)

Example 52 with DfIllegalPropertySettingException

use of org.dbflute.exception.DfIllegalPropertySettingException in project dbflute-core by dbflute.

the class DfRefClsRefTypeVerifier method verifyFormalRefType.

// ===================================================================================
// Verify Formal RefType
// =====================
public void verifyFormalRefType(DfClassificationTop classificationTop) {
    if (_refType.isFormalRefType()) {
        return;
    }
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Unknown refType to referred classification in the app classification.");
    br.addItem("Advice");
    br.addElement("refType can be set: 'included', 'exists', 'matches'");
    br.addElement("  included : referred classification codes are included as app classification");
    br.addElement("  exists   : app classification codes should exist in referred classification");
    br.addElement("  matches  : app classification codes matches with referred classification");
    br.addItem("dfprop File");
    br.addElement(_resourceFile);
    br.addItem("AppCls");
    br.addElement(classificationTop.getClassificationName());
    br.addItem("Unknown refType");
    br.addElement(_refType);
    final String msg = br.buildExceptionMessage();
    throw new DfIllegalPropertySettingException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 53 with DfIllegalPropertySettingException

use of org.dbflute.exception.DfIllegalPropertySettingException in project dbflute-core by dbflute.

the class DfRefClsRefTypeVerifier method doVerifyRefMatches.

// -----------------------------------------------------
// Matches
// -------
protected void doVerifyRefMatches(DfClassificationTop classificationTop) {
    final List<DfClassificationElement> appElementList = classificationTop.getClassificationElementList();
    final List<DfClassificationElement> referredElementList = _referredElementList;
    final boolean hasNonExisting = appElementList.stream().anyMatch(appElement -> {
        return notMatchesReferredElement(referredElementList, appElement);
    });
    if (appElementList.size() != referredElementList.size() || hasNonExisting) {
        final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
        br.addNotice("Unmatched the web classification code with the referred classification");
        br.addItem("Advice");
        br.addElement("The codes of the web classification should match");
        br.addElement("with referred classification because of refType='matches'.");
        br.addElement("For example:");
        br.addElement("  (x): web(A), referred(A, C)");
        br.addElement("  (x): web(A, B), referred(A, C)");
        br.addElement("  (o): web(A, B), referred(A, B)");
        br.addElement("  (o): web(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("Code Count");
        br.addElement("app=" + appElementList.size() + " / referred=" + referredElementList.size());
        final String msg = br.buildExceptionMessage();
        throw new DfIllegalPropertySettingException(msg);
    }
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 54 with DfIllegalPropertySettingException

use of org.dbflute.exception.DfIllegalPropertySettingException in project dbflute-core by dbflute.

the class DfClassificationResourceDefinitionReflector method throwClassificationAlreadyExistsInDfPropException.

protected void throwClassificationAlreadyExistsInDfPropException(String classificationName, String settingName) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("The classification already exists in dfprop settings.");
    br.addItem("Advice");
    br.addElement("Check the classification names in '" + settingName + "' settings.");
    br.addElement("The settings may contain classifications existing in dfprop.");
    br.addItem("Classification");
    br.addElement(classificationName);
    final String msg = br.buildExceptionMessage();
    throw new DfIllegalPropertySettingException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 55 with DfIllegalPropertySettingException

use of org.dbflute.exception.DfIllegalPropertySettingException in project dbflute-core by dbflute.

the class DfSplittingDfpropHandler method throwClassificationSplitDefinitionNotFoundException.

protected void throwClassificationSplitDefinitionNotFoundException(String mapName, String keyword) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Not found the split definition of DBFlute property.");
    br.addItem("Advice");
    br.addElement("Make sure the file name of your split dfprop");
    br.addElement("or define at least one definition in the split file.");
    br.addElement("");
    br.addElement("For example:");
    br.addElement("    $$split$$ = map:{");
    br.addElement("        ; land = dummy");
    br.addElement("        ; sea  = dummy");
    br.addElement("    }");
    br.addElement("");
    br.addElement("The following files should exist:");
    br.addElement("    dfprop/" + mapName + "_land.dfprop");
    br.addElement("    dfprop/" + mapName + "_sea.dfprop");
    br.addItem("DBFlute Property");
    br.addElement(mapName);
    br.addItem("Split Keyword");
    br.addElement(keyword);
    final String msg = br.buildExceptionMessage();
    throw new DfIllegalPropertySettingException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Aggregations

DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)76 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)58 Map (java.util.Map)9 DfClassificationTop (org.dbflute.properties.assistant.classification.DfClassificationTop)9 List (java.util.List)8 DfClassificationElement (org.dbflute.properties.assistant.classification.DfClassificationElement)8 LinkedHashMap (java.util.LinkedHashMap)6 ArrayList (java.util.ArrayList)5 StringKeyMap (org.dbflute.helper.StringKeyMap)4 DfClassificationGroup (org.dbflute.properties.assistant.classification.DfClassificationGroup)4 Collectors (java.util.stream.Collectors)3 ClassificationUndefinedHandlingType (org.dbflute.jdbc.ClassificationUndefinedHandlingType)3 DfRefClsElement (org.dbflute.properties.assistant.classification.DfRefClsElement)3 RichTextString (org.apache.poi.ss.usermodel.RichTextString)2 DfIllegalPropertyTypeException (org.dbflute.exception.DfIllegalPropertyTypeException)2 ScopeInfo (org.dbflute.util.Srl.ScopeInfo)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1