Search in sources :

Example 1 with DfClassificationElement

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

the class ForeignKey method doExtractFixedConditionEmbeddedCommentClassificationGroupCode.

protected String doExtractFixedConditionEmbeddedCommentClassificationGroupCode(DfClassificationTop classificationTop, String elementName) {
    String code = null;
    final List<DfClassificationGroup> groupList = classificationTop.getGroupList();
    for (DfClassificationGroup group : groupList) {
        final String groupName = group.getGroupName();
        if (elementName.equals(groupName)) {
            final List<DfClassificationElement> groupElementList = group.getElementList();
            StringBuilder sb = new StringBuilder();
            for (DfClassificationElement groupelement : groupElementList) {
                if (sb.length() > 0) {
                    sb.append(", ");
                }
                sb.append(quoteClassifiationElementIfNeeds(classificationTop, groupelement.getCode()));
            }
            sb.insert(0, "(").append(")");
            code = sb.toString();
            break;
        }
    }
    return code;
}
Also used : DfClassificationGroup(org.dbflute.properties.assistant.classification.DfClassificationGroup) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfColumnListToStringBuilder(org.dbflute.logic.generate.column.DfColumnListToStringBuilder)

Example 2 with DfClassificationElement

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

the class DfClassificationProperties method getClassificationElementCodeList.

public List<String> getClassificationElementCodeList(String classificationName) {
    final List<DfClassificationElement> elementList = getClassificationElementList(classificationName);
    final List<String> codeList = DfCollectionUtil.newArrayList();
    for (DfClassificationElement element : elementList) {
        codeList.add(element.getCode());
    }
    return codeList;
}
Also used : DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement)

Example 3 with DfClassificationElement

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

the class DfAppClsTableLoader method handleRefCls.

protected void handleRefCls(DfClassificationTop classificationTop, DfRefClsElement refClsElement) {
    refClsElement.checkFormalRefType(classificationTop);
    classificationTop.addRefClsElement(refClsElement);
    if (refClsElement.isRefTypeIncluded()) {
        final DfClassificationTop dbClsTop = refClsElement.getDBClsTop();
        final String groupName = refClsElement.getGroupName();
        if (groupName != null) {
            final DfClassificationGroup group = dbClsTop.getGroupList().stream().filter(gr -> {
                return gr.getGroupName().equals(groupName);
            }).findFirst().orElseThrow(() -> {
                String msg = "Not found the group name: " + refClsElement.getClassificationName() + "." + groupName;
                return new DfIllegalPropertySettingException(msg);
            });
            classificationTop.addClassificationElementAll(group.getElementList());
        } else {
            final List<DfClassificationElement> dbElementList = dbClsTop.getClassificationElementList();
            classificationTop.addClassificationElementAll(dbElementList);
            classificationTop.acceptGroupList(dbClsTop.getGroupList());
        }
    }
}
Also used : DfClassificationGroup(org.dbflute.properties.assistant.classification.DfClassificationGroup) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 4 with DfClassificationElement

use of org.dbflute.properties.assistant.classification.DfClassificationElement 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 5 with DfClassificationElement

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

the class DfWebClsTableLoader method handleRefCls.

protected void handleRefCls(DfClassificationTop classificationTop, DfRefClsElement refClsElement) {
    refClsElement.checkFormalRefType(classificationTop);
    classificationTop.addRefClsElement(refClsElement);
    if (refClsElement.isRefTypeIncluded()) {
        final DfClassificationTop dbClsTop = refClsElement.getDBClsTop();
        final String groupName = refClsElement.getGroupName();
        if (groupName != null) {
            final DfClassificationGroup group = dbClsTop.getGroupList().stream().filter(gr -> {
                return gr.getGroupName().equals(groupName);
            }).findFirst().orElseThrow(() -> {
                String msg = "Not found the group name: " + refClsElement.getClassificationName() + "." + groupName;
                return new DfIllegalPropertySettingException(msg);
            });
            classificationTop.addClassificationElementAll(group.getElementList());
        } else {
            final List<DfClassificationElement> dbElementList = dbClsTop.getClassificationElementList();
            classificationTop.addClassificationElementAll(dbElementList);
            classificationTop.acceptGroupList(dbClsTop.getGroupList());
        }
    }
}
Also used : DfClassificationGroup(org.dbflute.properties.assistant.classification.DfClassificationGroup) DfClassificationElement(org.dbflute.properties.assistant.classification.DfClassificationElement) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Aggregations

DfClassificationElement (org.dbflute.properties.assistant.classification.DfClassificationElement)30 DfClassificationTop (org.dbflute.properties.assistant.classification.DfClassificationTop)10 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)8 ArrayList (java.util.ArrayList)6 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)6 LinkedHashMap (java.util.LinkedHashMap)5 List (java.util.List)5 DfClassificationGroup (org.dbflute.properties.assistant.classification.DfClassificationGroup)5 Map (java.util.Map)4 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Statement (java.sql.Statement)2 DfFixedConditionInvalidClassificationEmbeddedCommentException (org.dbflute.exception.DfFixedConditionInvalidClassificationEmbeddedCommentException)2 SQLFailureException (org.dbflute.exception.SQLFailureException)2 StringKeyMap (org.dbflute.helper.StringKeyMap)2 DfClassificationJdbcCloser (org.dbflute.properties.assistant.classification.coins.DfClassificationJdbcCloser)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1