Search in sources :

Example 61 with DfIllegalPropertySettingException

use of org.dbflute.exception.DfIllegalPropertySettingException in project dbflute-core by dbflute.

the class DfJsonSchemaLoadingAgent method throwJsonTableReferenceNotFoundException.

protected void throwJsonTableReferenceNotFoundException(String currentTableName, String specifiedTableName) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Not found the table by the reference at the type. (FreeGen)");
    br.addItem("Request Name");
    br.addElement(_requestName);
    br.addItem("JSON File");
    br.addElement(_resource.getResourceFile());
    br.addItem("Current Table");
    br.addElement(currentTableName);
    br.addItem("Specified Table");
    br.addElement(specifiedTableName);
    final String msg = br.buildExceptionMessage();
    throw new DfIllegalPropertySettingException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 62 with DfIllegalPropertySettingException

use of org.dbflute.exception.DfIllegalPropertySettingException in project dbflute-core by dbflute.

the class DfPropTableLoader method throwFreeGenPropExtendsRequestNotFoundException.

protected void throwFreeGenPropExtendsRequestNotFoundException(String requestName, String extendsPropRequest, Map<String, DfFreeGenRequest> requestMap) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Not found the request to be extended for properties.");
    br.addItem("Advice");
    br.addElement("Make sure your request name in freeGenDefinition.dfprop.");
    br.addElement("And also check definition order of requests.");
    br.addElement("Extends requests should be defined before the request.");
    br.addItem("Current Request");
    br.addElement(requestName);
    br.addItem("Extended Request");
    br.addElement(extendsPropRequest);
    br.addItem("Existing Requests");
    br.addElement(requestMap.keySet());
    final String msg = br.buildExceptionMessage();
    throw new DfIllegalPropertySettingException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 63 with DfIllegalPropertySettingException

use of org.dbflute.exception.DfIllegalPropertySettingException in project dbflute-core by dbflute.

the class DfPropTableLoader method throwFreeGenPropExtendsRequestNotPropException.

protected void throwFreeGenPropExtendsRequestNotPropException(String requestName, String extendsPropRequest, DfFreeGenRequest extendsRequest) {
    final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
    br.addNotice("Not PROP request to be extended for properties.");
    br.addItem("Advice");
    br.addElement("Make sure your request name in freeGenDefinition.dfprop.");
    br.addElement("The extends request should be PROP type.");
    br.addItem("Current Request");
    br.addElement(requestName);
    br.addItem("Not PROP Extended Request");
    br.addElement(extendsPropRequest);
    br.addElement(extendsRequest.getResource().getResourceType());
    final String msg = br.buildExceptionMessage();
    throw new DfIllegalPropertySettingException(msg);
}
Also used : ExceptionMessageBuilder(org.dbflute.helper.message.ExceptionMessageBuilder) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException)

Example 64 with DfIllegalPropertySettingException

use of org.dbflute.exception.DfIllegalPropertySettingException in project dbflute-core by dbflute.

the class DfXlsTableLoader method processColumnValue.

protected boolean processColumnValue(final String requestName, final Map<String, String> columnMap, final Row row, final Map<String, Object> beanMap, final String key, final String value, List<DfFreeGenLazyReflector> reflectorList, Map<String, Map<String, String>> mappingMap) {
    if (convertByMethod(requestName, beanMap, key, value, reflectorList)) {
        return false;
    }
    // normal setting (cell number)
    boolean exists = false;
    final Integer cellNumber;
    try {
        cellNumber = Integer.valueOf(value) - 1;
    } catch (NumberFormatException e) {
        String msg = "The property value should be Integer in FreeGen " + requestName + ":";
        msg = msg + " key=" + key + " value=" + value;
        throw new DfIllegalPropertySettingException(msg);
    }
    final Cell cell = row.getCell(cellNumber);
    if (cell == null) {
        return false;
    }
    final RichTextString cellValue = cell.getRichStringCellValue();
    if (cellValue == null) {
        return false;
    }
    exists = true;
    String resultValue = cellValue.getString();
    final Map<String, String> mapping = mappingMap.get(key);
    if (mapping != null) {
        final String mappingValue = mapping.get(resultValue);
        if (mappingValue != null) {
            resultValue = mappingValue;
        }
    }
    beanMap.put(key, resultValue);
    return exists;
}
Also used : RichTextString(org.apache.poi.ss.usermodel.RichTextString) RichTextString(org.apache.poi.ss.usermodel.RichTextString) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException) Cell(org.apache.poi.ss.usermodel.Cell)

Example 65 with DfIllegalPropertySettingException

use of org.dbflute.exception.DfIllegalPropertySettingException in project dbflute-core by dbflute.

the class DfXlsTableLoader method loadTable.

// ===================================================================================
// Load Table
// ==========
// ; resourceMap = map:{
// ; resourceType = XLS
// ; resourceFile = ../../...
// }
// ; outputMap = map:{
// ; templateFile = CsvDto.vm
// ; outputDirectory = ../src/main/java
// ; package = org.dbflute...
// ; className = FooDto
// }
// ; optionMap = map:{
// ; sheetName = [sheet-name]
// ; rowBeginNumber = 3
// ; columnMap = map:{
// ; name = 3
// ; type = 4
// }
// ; mappingMap = map:{
// ; type = map:{
// ; INTEGER = Integer
// ; VARCHAR = String
// }
// }
// }
@Override
public DfFreeGenMetaData loadTable(String requestName, DfFreeGenResource resource, DfFreeGenMapProp mapProp) {
    final Map<String, Object> tableMap = mapProp.getOptionMap();
    final Map<String, Map<String, String>> mappingMap = mapProp.getMappingMap();
    if (tableMap == null || tableMap.isEmpty()) {
        String msg = "The tableMap was not found in the FreeGen property: " + requestName;
        throw new DfRequiredPropertyNotFoundException(msg);
    }
    final String sheetName = (String) tableMap.get("sheetName");
    if (sheetName == null) {
        String msg = "The sheetName was not found in the FreeGen property: " + requestName;
        throw new DfRequiredPropertyNotFoundException(msg);
    }
    final Integer rowBeginNumber;
    {
        final String numStr = (String) tableMap.get("rowBeginNumber");
        if (numStr == null) {
            String msg = "The rowBeginNumber was not found in the FreeGen property: " + requestName;
            throw new DfRequiredPropertyNotFoundException(msg);
        }
        rowBeginNumber = Integer.valueOf(numStr);
    }
    final String resourceFile = resource.getResourceFile();
    @SuppressWarnings("unchecked") final Map<String, String> columnMap = (Map<String, String>) tableMap.get("columnMap");
    final Workbook workbook = DfXlsFactory.instance().createWorkbook(new File(resourceFile));
    final Sheet sheet = workbook.getSheet(sheetName);
    if (sheet == null) {
        String msg = "Not found the sheet name in the file: name=" + sheetName + " xls=" + resourceFile;
        throw new IllegalStateException(msg);
    }
    // rows
    final List<Map<String, Object>> columnList = new ArrayList<Map<String, Object>>();
    for (int i = (rowBeginNumber - 1); i < Integer.MAX_VALUE; i++) {
        final Row row = sheet.getRow(i);
        if (row == null) {
            break;
        }
        final Map<String, Object> beanMap = DfCollectionUtil.newLinkedHashMap();
        final List<DfFreeGenLazyReflector> reflectorList = DfCollectionUtil.newArrayList();
        boolean exists = false;
        for (Entry<String, String> entry : columnMap.entrySet()) {
            final String key = entry.getKey();
            final String value = entry.getValue();
            if (value == null) {
                String msg = "Not found the value of the key in FreeGen " + requestName + ": " + key;
                throw new DfIllegalPropertySettingException(msg);
            }
            if (processColumnValue(requestName, columnMap, row, beanMap, key, value, reflectorList, mappingMap)) {
                exists = true;
            }
        }
        prepareColumnNameConversion(requestName, beanMap, reflectorList);
        if (exists) {
            columnList.add(beanMap);
        } else {
            // means empty row
            break;
        }
        for (DfFreeGenLazyReflector reflector : reflectorList) {
            reflector.reflect();
        }
    }
    // basically unused, also for compatible
    final String tableName = sheetName;
    return DfFreeGenMetaData.asOnlyOne(tableMap, tableName, columnList);
}
Also used : DfRequiredPropertyNotFoundException(org.dbflute.exception.DfRequiredPropertyNotFoundException) DfFreeGenLazyReflector(org.dbflute.logic.manage.freegen.reflector.DfFreeGenLazyReflector) ArrayList(java.util.ArrayList) RichTextString(org.apache.poi.ss.usermodel.RichTextString) DfIllegalPropertySettingException(org.dbflute.exception.DfIllegalPropertySettingException) Workbook(org.apache.poi.ss.usermodel.Workbook) Row(org.apache.poi.ss.usermodel.Row) Map(java.util.Map) File(java.io.File) Sheet(org.apache.poi.ss.usermodel.Sheet)

Aggregations

DfIllegalPropertySettingException (org.dbflute.exception.DfIllegalPropertySettingException)76 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)58 Map (java.util.Map)9 DfClassificationTop (org.dbflute.properties.assistant.classification.DfClassificationTop)9 List (java.util.List)8 DfClassificationElement (org.dbflute.properties.assistant.classification.DfClassificationElement)8 LinkedHashMap (java.util.LinkedHashMap)6 ArrayList (java.util.ArrayList)5 StringKeyMap (org.dbflute.helper.StringKeyMap)4 DfClassificationGroup (org.dbflute.properties.assistant.classification.DfClassificationGroup)4 Collectors (java.util.stream.Collectors)3 ClassificationUndefinedHandlingType (org.dbflute.jdbc.ClassificationUndefinedHandlingType)3 DfRefClsElement (org.dbflute.properties.assistant.classification.DfRefClsElement)3 RichTextString (org.apache.poi.ss.usermodel.RichTextString)2 DfIllegalPropertyTypeException (org.dbflute.exception.DfIllegalPropertyTypeException)2 ScopeInfo (org.dbflute.util.Srl.ScopeInfo)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1