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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations