Search in sources :

Example 1 with DfClassificationLiteralArranger

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

the class DfWebClsTableLoader method loadTable.

// ===================================================================================
// Load Table
// ==========
// ; resourceMap = map:{
// ; baseDir = ../src/main
// ; resourceType = WEB_CLS
// ; resourceFile = ../../../dockside_webcls.properties
// }
// ; outputMap = map:{
// ; templateFile = LaAppCDef.vm
// ; outputDirectory = $$baseDir$$/java
// ; package = org.dbflute...
// ; className = unused
// }
// ; optionMap = map:{
// }
@Override
public DfFreeGenMetaData loadTable(String requestName, DfFreeGenResource resource, DfFreeGenMapProp mapProp) {
    // _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
    // very similar to AppCls but no recycle because of silent maintenance
    // _/_/_/_/_/_/_/_/_/_/
    final String resourceFile = resource.getResourceFile();
    final Map<String, Object> webclsMap;
    try {
        webclsMap = new MapListFile().readMap(new FileInputStream(resourceFile));
    } catch (FileNotFoundException e) {
        throw new DfIllegalPropertySettingException("Not found the dfprop file: " + resourceFile, e);
    } catch (IOException e) {
        throw new DfIllegalPropertySettingException("Cannot read the the dfprop file: " + resourceFile, e);
    }
    // lazy load because it might be unused
    Map<String, DfClassificationTop> dbClsMap = null;
    boolean hasRefCls = false;
    final DfClassificationProperties clsProp = getClassificationProperties();
    final DfClassificationLiteralArranger literalArranger = new DfClassificationLiteralArranger();
    final List<DfClassificationTop> topList = new ArrayList<DfClassificationTop>();
    for (Entry<String, Object> entry : webclsMap.entrySet()) {
        final String classificationName = entry.getKey();
        final DfClassificationTop classificationTop = new DfClassificationTop();
        topList.add(classificationTop);
        classificationTop.setClassificationName(classificationName);
        DfRefClsElement refClsElement = null;
        @SuppressWarnings("unchecked") final List<Map<String, Object>> elementMapList = (List<Map<String, Object>>) entry.getValue();
        for (Map<String, Object> elementMap : elementMapList) {
            if (isElementMapClassificationTop(elementMap)) {
                classificationTop.acceptClassificationTopBasicItemMap(elementMap);
                // pickup from DfClassificationProperties@processClassificationTopFromLiteralIfNeeds()
                classificationTop.putGroupingAll(clsProp.getElementMapGroupingMap(elementMap));
                classificationTop.putDeprecatedAll(clsProp.getElementMapDeprecatedMap(elementMap));
            } else {
                if (isElementMapRefCls(elementMap)) {
                    assertRefClsOnlyOne(classificationName, refClsElement, elementMap, resource);
                    if (dbClsMap == null) {
                        dbClsMap = getClassificationProperties().getClassificationTopMap();
                    }
                    refClsElement = createRefClsElement(classificationName, elementMap, dbClsMap, resource);
                    handleRefCls(classificationTop, refClsElement);
                } else {
                    literalArranger.arrange(classificationName, elementMap);
                    final DfClassificationElement element = new DfClassificationElement();
                    element.setClassificationName(classificationName);
                    element.acceptBasicItemMap(elementMap);
                    classificationTop.addClassificationElement(element);
                }
            }
        }
        if (refClsElement != null) {
            refClsElement.checkRelationshipByRefTypeIfNeeds(classificationTop);
            hasRefCls = true;
        }
    }
    final Map<String, Object> optionMap = mapProp.getOptionMap();
    final String clsTheme = "webcls";
    optionMap.put("clsTheme", clsTheme);
    optionMap.put("classificationTopList", topList);
    optionMap.put("classificationNameList", topList.stream().map(top -> {
        return top.getClassificationName();
    }).collect(Collectors.toList()));
    optionMap.put("hasRefCls", hasRefCls);
    optionMap.put("allcommonPackage", getBasicProperties().getBaseCommonPackage());
    return DfFreeGenMetaData.asOnlyOne(optionMap, clsTheme, Collections.emptyList());
}
Also used : MapListFile(org.dbflute.helper.mapstring.MapListFile) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException) DfRefClsElement(org.dbflute.properties.assistant.classification.DfRefClsElement) FileInputStream(java.io.FileInputStream) DfClassificationLiteralArranger(org.dbflute.properties.assistant.classification.DfClassificationLiteralArranger) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) DfClassificationProperties(org.dbflute.properties.DfClassificationProperties)

Example 2 with DfClassificationLiteralArranger

use of org.dbflute.properties.assistant.classification.DfClassificationLiteralArranger 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 DfClassificationLiteralArranger literalArranger = new DfClassificationLiteralArranger();
    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();
            classificationTop.setClassificationName(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();
                    }
                    processTableClassification(classificationTop, elementMap, table, elementList, conn);
                    continue;
                }
                // from literal
                if (isElementMapClassificationTop(elementMap)) {
                    // top definition
                    processClassificationTopFromLiteralIfNeeds(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();
            }
            processAllInOneTableClassification(conn, allInOneSql);
        }
        // *Classification Resource Point!
        reflectClassificationResourceToDefinition();
        filterUseDocumentOnly();
        checkClassificationConstraintsIfNeeds();
        prepareSuppressedDBAccessClassTableSet();
    } finally {
        new DfClassificationSqlResourceCloser().closeConnection(conn);
    }
    return _classificationTopMap;
}
Also used : DfClassificationSqlResourceCloser(org.dbflute.properties.assistant.classification.DfClassificationSqlResourceCloser) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException) DfClassificationLiteralArranger(org.dbflute.properties.assistant.classification.DfClassificationLiteralArranger) 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 3 with DfClassificationLiteralArranger

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

the class DfAppClsTableLoader method loadTable.

// ===================================================================================
// Load Table
// ==========
// ; resourceMap = map:{
// ; baseDir = ../src/main
// ; resourceType = APP_CLS
// ; resourceFile = ../../../dockside_appcls.properties
// }
// ; outputMap = map:{
// ; templateFile = LaAppCDef.vm
// ; outputDirectory = $$baseDir$$/java
// ; package = org.dbflute...
// ; className = unused
// }
// ; optionMap = map:{
// }
@Override
public DfFreeGenMetaData loadTable(String requestName, DfFreeGenResource resource, DfFreeGenMapProp mapProp) {
    final String resourceFile = resource.getResourceFile();
    final Map<String, Object> appClsMap;
    try {
        appClsMap = new MapListFile().readMap(new FileInputStream(resourceFile));
    } catch (FileNotFoundException e) {
        throw new DfIllegalPropertySettingException("Not found the dfprop file: " + resourceFile, e);
    } catch (IOException e) {
        throw new DfIllegalPropertySettingException("Cannot read the the dfprop file: " + resourceFile, e);
    }
    // lazy load because it might be unused
    Map<String, DfClassificationTop> dbClsMap = null;
    boolean hasRefCls = false;
    final DfClassificationProperties clsProp = getClassificationProperties();
    final DfClassificationLiteralArranger literalArranger = new DfClassificationLiteralArranger();
    final List<DfClassificationTop> topList = new ArrayList<DfClassificationTop>();
    for (Entry<String, Object> entry : appClsMap.entrySet()) {
        final String classificationName = entry.getKey();
        final DfClassificationTop classificationTop = new DfClassificationTop();
        topList.add(classificationTop);
        classificationTop.setClassificationName(classificationName);
        DfRefClsElement refClsElement = null;
        @SuppressWarnings("unchecked") final List<Map<String, Object>> elementMapList = (List<Map<String, Object>>) entry.getValue();
        for (Map<String, Object> elementMap : elementMapList) {
            if (isElementMapClassificationTop(elementMap)) {
                classificationTop.acceptClassificationTopBasicItemMap(elementMap);
                // pickup from DfClassificationProperties@processClassificationTopFromLiteralIfNeeds()
                classificationTop.putGroupingAll(clsProp.getElementMapGroupingMap(elementMap));
                classificationTop.putDeprecatedAll(clsProp.getElementMapDeprecatedMap(elementMap));
            } else {
                if (isElementMapRefCls(elementMap)) {
                    assertRefClsOnlyOne(classificationName, refClsElement, elementMap, resource);
                    if (dbClsMap == null) {
                        dbClsMap = clsProp.getClassificationTopMap();
                    }
                    refClsElement = createRefClsElement(classificationName, elementMap, dbClsMap, resource);
                    handleRefCls(classificationTop, refClsElement);
                } else {
                    literalArranger.arrange(classificationName, elementMap);
                    final DfClassificationElement element = new DfClassificationElement();
                    element.setClassificationName(classificationName);
                    element.acceptBasicItemMap(elementMap);
                    classificationTop.addClassificationElement(element);
                }
            }
        }
        if (refClsElement != null) {
            refClsElement.checkRelationshipByRefTypeIfNeeds(classificationTop);
            hasRefCls = true;
        }
    }
    final Map<String, Object> optionMap = mapProp.getOptionMap();
    final String clsTheme = (String) optionMap.getOrDefault("clsTheme", "appcls");
    optionMap.put("clsTheme", clsTheme);
    optionMap.put("classificationTopList", topList);
    optionMap.put("classificationNameList", topList.stream().map(top -> {
        return top.getClassificationName();
    }).collect(Collectors.toList()));
    optionMap.put("hasRefCls", hasRefCls);
    optionMap.put("allcommonPackage", getBasicProperties().getBaseCommonPackage());
    // #for_now can be flexible? (table name is unused?)
    return DfFreeGenMetaData.asOnlyOne(optionMap, clsTheme, Collections.emptyList());
}
Also used : MapListFile(org.dbflute.helper.mapstring.MapListFile) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException) DfRefClsElement(org.dbflute.properties.assistant.classification.DfRefClsElement) FileInputStream(java.io.FileInputStream) DfClassificationLiteralArranger(org.dbflute.properties.assistant.classification.DfClassificationLiteralArranger) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) DfClassificationProperties(org.dbflute.properties.DfClassificationProperties)

Aggregations

ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)3 DfClassificationElement (org.dbflute.properties.assistant.classification.DfClassificationElement)3 DfClassificationLiteralArranger (org.dbflute.properties.assistant.classification.DfClassificationLiteralArranger)3 DfClassificationTop (org.dbflute.properties.assistant.classification.DfClassificationTop)3 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 MapListFile (org.dbflute.helper.mapstring.MapListFile)2 DfClassificationProperties (org.dbflute.properties.DfClassificationProperties)2 DfRefClsElement (org.dbflute.properties.assistant.classification.DfRefClsElement)2 Connection (java.sql.Connection)1 LinkedHashMap (java.util.LinkedHashMap)1 StringKeyMap (org.dbflute.helper.StringKeyMap)1 DfClassificationSqlResourceCloser (org.dbflute.properties.assistant.classification.DfClassificationSqlResourceCloser)1