Search in sources :

Example 6 with DfClassificationTop

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

use of org.dbflute.properties.assistant.classification.DfClassificationTop 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)

Example 8 with DfClassificationTop

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

the class DfWebClsTableLoader method findDBCls.

protected DfClassificationTop findDBCls(String classificationName, String refClsName, Map<String, DfClassificationTop> dbClsMap, DfFreeGenResource resource) {
    final DfClassificationTop refTop = dbClsMap.get(refClsName);
    if (refTop == null) {
        final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
        br.addNotice("Not found the DB classification for web classification.");
        br.addItem("Advice");
        br.addElement("Make sure your DB classification name.");
        br.addItem("WebCls");
        br.addElement(classificationName);
        br.addItem("NotFound DBCls");
        br.addElement(refClsName);
        br.addItem("Existing DBCls");
        br.addElement(dbClsMap.keySet());
        br.addItem("dfprop File");
        br.addElement(resource.getResourceFile());
        final String msg = br.buildExceptionMessage();
        throw new DfIllegalPropertySettingException(msg);
    }
    return refTop;
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 9 with DfClassificationTop

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

the class DfFixedConditionDynamicAnalyzer method extractEmbeddedCommentClassification.

// ===================================================================================
// EmbeddedComment Classification
// ==============================
protected String extractEmbeddedCommentClassification(String peace, String parameterType) {
    // parameterType is e.g. MemberStatus.Formalized
    if (!parameterType.contains(".")) {
        String msg = "The classification expression should be 'classificationName.elementName':";
        msg = msg + " expression=" + parameterType + " embeddedComment=" + peace;
        throw new DfFixedConditionInvalidClassificationEmbeddedCommentException(msg);
    }
    // e.g. MemberStatus
    final String classificationName = parameterType.substring(0, parameterType.indexOf("."));
    // e.g. Formalized
    final String elementName = parameterType.substring(parameterType.indexOf(".") + ".".length());
    final Map<String, DfClassificationTop> topMap = getClassificationProperties().getClassificationTopMap();
    final DfClassificationTop classificationTop = topMap.get(classificationName);
    if (classificationTop == null) {
        throwFixedConditionEmbeddedCommentClassificationNotFoundException(classificationName);
    }
    String code = doExtractEmbeddedCommentClassificationNormalCode(classificationTop, elementName);
    if (code != null) {
        return code;
    }
    // may be group here
    code = doExtractEmbeddedCommentClassificationGroupCode(classificationTop, elementName);
    if (code != null) {
        return code;
    }
    throwFixedConditionEmbeddedCommentClassificationElementNotFoundException(classificationTop, elementName);
    // unreachable
    return null;
}
Also used : DfFixedConditionInvalidClassificationEmbeddedCommentException(org.dbflute.exception.DfFixedConditionInvalidClassificationEmbeddedCommentException) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop)

Example 10 with DfClassificationTop

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

the class DfClassificationProperties method reflectClassificationResourceToDeployment.

// -----------------------------------------------------
// Reflect to Deployment
// ---------------------
protected void reflectClassificationResourceToDeployment() {
    // called by deployment initialization
    final List<DfClassificationTop> resourceList = getClassificationResourceList();
    final DfClassificationResourceDeploymentReflector reflector = new DfClassificationResourceDeploymentReflector(resourceList, () -> setupAllColumnClassificationEmptyMapIfNeeds());
    reflector.reflectClassificationResourceToDeployment(() -> getAllColumnClassificationMap());
}
Also used : DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) DfClassificationResourceDeploymentReflector(org.dbflute.properties.assistant.classification.resource.DfClassificationResourceDeploymentReflector)

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