Search in sources :

Example 6 with MapListString

use of org.dbflute.helper.mapstring.MapListString in project dbflute-core by dbflute.

the class DfClsElementLiteralArranger method doArrange.

protected void doArrange(String classificationName, Map<String, Object> elementMap, boolean suppressDefault) {
    final String codeKey = DfClassificationElement.KEY_CODE;
    final String code = (String) elementMap.get(codeKey);
    if (code == null) {
        // required check
        throwClassificationLiteralCodeNotFoundException(classificationName, elementMap);
    }
    // _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
    // #for_now jflute default is set at element accepting process so maybe unneeded here (2021/07/11)
    // _/_/_/_/_/_/_/_/_/_/
    final String nameKey = DfClassificationElement.KEY_NAME;
    final String name = (String) elementMap.get(nameKey);
    if (name == null && !suppressDefault) {
        // use code
        elementMap.put(nameKey, code);
    }
    final String aliasKey = DfClassificationElement.KEY_ALIAS;
    final String alias = (String) elementMap.get(aliasKey);
    if (alias == null && !suppressDefault) {
        // use name or code
        elementMap.put(aliasKey, name != null ? name : code);
    }
    final String subItemMapKey = DfClassificationElement.KEY_SUB_ITEM_MAP;
    @SuppressWarnings("unchecked") final Map<String, Object> subItemMap = (Map<String, Object>) elementMap.get(subItemMapKey);
    if (subItemMap != null) {
        final MapListString mapListString = new MapListString();
        for (Entry<String, Object> entry : subItemMap.entrySet()) {
            String key = entry.getKey();
            final Object value = entry.getValue();
            if (value != null && value instanceof List<?>) {
                // nested List is treated as string
                final List<?> listValue = (List<?>) value;
                final String listString = mapListString.buildListString(listValue);
                subItemMap.put(key, filterLineStringOnMapListString(listString));
            } else if (value != null && value instanceof Map<?, ?>) {
                // nested Map is treated as string
                @SuppressWarnings("unchecked") final Map<String, ?> mapValue = (Map<String, ?>) value;
                final String mapString = mapListString.buildMapString(mapValue);
                subItemMap.put(key, filterLineStringOnMapListString(mapString));
            } else if (value != null && value instanceof String) {
                subItemMap.put(key, filterLineStringOnMapListString((String) value));
            }
        }
    }
}
Also used : MapListString(org.dbflute.helper.mapstring.MapListString) List(java.util.List) MapListString(org.dbflute.helper.mapstring.MapListString) Map(java.util.Map)

Aggregations

MapListString (org.dbflute.helper.mapstring.MapListString)6 List (java.util.List)2 Map (java.util.Map)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 LinkedHashMap (java.util.LinkedHashMap)1 Table (org.apache.torque.engine.database.model.Table)1