Search in sources :

Example 1 with DfClassificationProperties

use of org.dbflute.properties.DfClassificationProperties 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 DfClassificationProperties

use of org.dbflute.properties.DfClassificationProperties in project dbflute-core by dbflute.

the class DfClassificationPropertiesTest method test_getAllClassificationName_ByPinpoint.

public void test_getAllClassificationName_ByPinpoint() {
    // ## Arrange ##
    final Map<String, Map<String, String>> deploymentMap = new LinkedHashMap<String, Map<String, String>>();
    {
        final Map<String, String> columnClassificationMap = new LinkedHashMap<String, String>();
        columnClassificationMap.put("ABC", "abc");
        columnClassificationMap.put("DELETE_FLG", "Flg");
        columnClassificationMap.put("DEF", "def");
        deploymentMap.put(ALL_MARK, columnClassificationMap);
    }
    final DfClassificationProperties prop = createClassificationProperties(deploymentMap);
    // ## Act & Assert ##
    assertEquals("Flg", prop.getAllClassificationName("DELETE_FLG"));
    assertEquals("Flg", prop.getAllClassificationName("delete_flg"));
    assertNull(prop.getAllClassificationName("VALID_FLG"));
    assertNull(prop.getAllClassificationName("valid_flg"));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) DfClassificationProperties(org.dbflute.properties.DfClassificationProperties) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with DfClassificationProperties

use of org.dbflute.properties.DfClassificationProperties in project dbflute-core by dbflute.

the class DfClassificationPropertiesTest method test_isElementMapClassificationMeta.

public void test_isElementMapClassificationMeta() {
    // ## Arrange ##
    final Map<String, Map<String, String>> deploymentMap = new LinkedHashMap<String, Map<String, String>>();
    final DfClassificationProperties prop = createClassificationProperties(deploymentMap);
    final Map<String, String> elementMap = new HashMap<String, String>();
    // ## Act & Assert ##
    assertFalse(prop.isElementMapClassificationTop(elementMap));
    elementMap.put(DfClassificationTop.KEY_CODE_TYPE, "foo");
    assertFalse(prop.isElementMapClassificationTop(elementMap));
    elementMap.put(DfClassificationTop.KEY_TOP_COMMENT, "bar");
    assertTrue(prop.isElementMapClassificationTop(elementMap));
    elementMap.put(DfClassificationTop.KEY_CODE_TYPE, null);
    assertTrue(prop.isElementMapClassificationTop(elementMap));
    elementMap.put(DfClassificationTop.KEY_TOP_COMMENT, null);
    assertFalse(prop.isElementMapClassificationTop(elementMap));
    elementMap.put(DfClassificationElement.KEY_CODE, "foo");
    assertFalse(prop.isElementMapClassificationTop(elementMap));
    elementMap.put(DfClassificationTop.KEY_TOP_COMMENT, "foo");
    assertTrue(prop.isElementMapClassificationTop(elementMap));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) DfClassificationProperties(org.dbflute.properties.DfClassificationProperties) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with DfClassificationProperties

use of org.dbflute.properties.DfClassificationProperties in project dbflute-core by dbflute.

the class DfClassificationPropertiesTest method test_isAllClassificationColumn_ByPinpoint.

public void test_isAllClassificationColumn_ByPinpoint() {
    // ## Arrange ##
    final Map<String, Map<String, String>> deploymentMap = new LinkedHashMap<String, Map<String, String>>();
    {
        final Map<String, String> columnClassificationMap = new LinkedHashMap<String, String>();
        columnClassificationMap.put("ABC", "abc");
        columnClassificationMap.put("DELETE_FLG", "Flg");
        columnClassificationMap.put("DEF", "def");
        deploymentMap.put(ALL_MARK, columnClassificationMap);
    }
    final DfClassificationProperties prop = createClassificationProperties(deploymentMap);
    // ## Act & Assert ##
    assertTrue(prop.isAllClassificationColumn("DELETE_FLG"));
    assertTrue(prop.isAllClassificationColumn("delete_flg"));
    assertFalse(prop.isAllClassificationColumn("VALID_FLG"));
    assertFalse(prop.isAllClassificationColumn("valid_flg"));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) DfClassificationProperties(org.dbflute.properties.DfClassificationProperties) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with DfClassificationProperties

use of org.dbflute.properties.DfClassificationProperties in project dbflute-core by dbflute.

the class DfClassificationPropertiesTest method test_hasClassification_SameCase.

public void test_hasClassification_SameCase() throws Exception {
    // ## Arrange ##
    final Map<String, Map<String, String>> deploymentMap = new LinkedHashMap<String, Map<String, String>>();
    {
        final Map<String, String> columnClassificationMap = new LinkedHashMap<String, String>();
        columnClassificationMap.put("MEMBER_STATUS_CODE", "MemberStatus");
        deploymentMap.put("MEMBER_STATUS", columnClassificationMap);
    }
    final DfClassificationProperties prop = createClassificationProperties(deploymentMap);
    // ## Act ##
    final boolean actual = prop.hasClassification("MEMBER_STATUS", "MEMBER_STATUS_CODE");
    // ## Assert ##
    Assert.assertTrue(actual);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap) DfClassificationProperties(org.dbflute.properties.DfClassificationProperties) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

DfClassificationProperties (org.dbflute.properties.DfClassificationProperties)15 Map (java.util.Map)9 HashMap (java.util.HashMap)7 LinkedHashMap (java.util.LinkedHashMap)7 DfClassificationTop (org.dbflute.properties.assistant.classification.DfClassificationTop)5 ArrayList (java.util.ArrayList)4 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 List (java.util.List)2 ClassificationUndefinedHandlingType (org.dbflute.jdbc.ClassificationUndefinedHandlingType)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)1 MapListFile (org.dbflute.helper.mapstring.MapListFile)1 DfClassificationElement (org.dbflute.properties.assistant.classification.DfClassificationElement)1 DfClassificationLiteralArranger (org.dbflute.properties.assistant.classification.DfClassificationLiteralArranger)1 DfRefClsElement (org.dbflute.properties.assistant.classification.DfRefClsElement)1 DfClsElementLiteralArranger (org.dbflute.properties.assistant.classification.element.proploading.DfClsElementLiteralArranger)1 DfRefClsElement (org.dbflute.properties.assistant.classification.refcls.DfRefClsElement)1