use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfClassificationProperties method reflectClassificationResourceToDefinition.
// -----------------------------------------------------
// Reflect to Definition
// ---------------------
protected void reflectClassificationResourceToDefinition() {
// called by definition initialization
final List<DfClassificationTop> resourceList = getClassificationResourceList();
final DfClassificationResourceDefinitionReflector reflector = new DfClassificationResourceDefinitionReflector(resourceList);
reflector.reflectClassificationResourceToDefinition(_classificationTopMap);
}
use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfRefClsRefTypeVerifier method doVerifyRefExists.
// -----------------------------------------------------
// Exists
// ------
protected void doVerifyRefExists(DfClassificationTop classificationTop) {
final List<DfClassificationElement> appElementList = classificationTop.getClassificationElementList();
final List<DfClassificationElement> referredElementList = _referredElementList;
final List<DfClassificationElement> nonExistingList = appElementList.stream().filter(appElement -> {
return notMatchesReferredElement(referredElementList, appElement);
}).collect(Collectors.toList());
if (!nonExistingList.isEmpty()) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("Not found the app classification code in the referred classification");
br.addItem("Advice");
br.addElement("The codes of the app classification should be included");
br.addElement("in the referred classification because of refType='exists'.");
br.addElement("For example:");
br.addElement(" (x): app(A), referred(B, C)");
br.addElement(" (x): app(A, B), referred(A, C)");
br.addElement(" (x): app(A, B, C), referred(A, B)");
br.addElement(" (o): app(A), referred(A, B)");
br.addElement(" (o): app(A, B), referred(A, B, C)");
br.addElement(" (o): app(A, B, C), referred(A, B, C)");
br.addItem("dfprop File");
br.addElement(_resourceFile);
br.addItem("AppCls");
br.addElement(classificationTop.getClassificationName() + ": " + buildClsCodesExp(appElementList));
br.addItem("ReferredCls");
br.addElement(buildReferredExp() + ": " + buildClsCodesExp(referredElementList));
br.addItem("Ref Type");
br.addElement(_refType);
br.addItem("Non-Existing Code");
br.addElement(nonExistingList.stream().map(element -> {
return element.getCode();
}).collect(Collectors.joining(", ")));
final String msg = br.buildExceptionMessage();
throw new DfIllegalPropertySettingException(msg);
}
}
use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfClassificationResourceFileAnalyzer method analyze.
// ===================================================================================
// Analyze
// =======
public List<DfClassificationTop> analyze(final String dirName, final String resourceName, final String extension) {
final File dir = new File(dirName);
if (!dir.exists()) {
return new ArrayList<DfClassificationTop>();
}
if (!dir.isDirectory()) {
return new ArrayList<DfClassificationTop>();
}
final File[] listFiles = dir.listFiles(new FileFilter() {
public boolean accept(File currentFile) {
if (currentFile.isDirectory()) {
return false;
}
final String currentFileName = currentFile.getName();
if (!currentFileName.startsWith(resourceName)) {
return false;
}
if (!currentFileName.endsWith(extension)) {
return false;
}
return true;
}
});
final List<DfClassificationTop> topList = new ArrayList<DfClassificationTop>();
for (File file : listFiles) {
final List<String> lineList;
try {
String encoding = extractEncoding(file);
if (encoding == null) {
encoding = DEFAULT_ENCODING;
}
_log.info("...Analyzing classification in resource file: encoding=" + encoding);
lineList = createLineList(file, encoding);
} catch (RuntimeException ignored) {
String msg = "Failed to analyze classification in resource file: ";
msg = msg + " " + dirName + "/" + resourceName + "." + extension;
_log.info(msg, ignored);
continue;
}
final List<DfClassificationTop> classificationTopList = analyze(lineList);
if (!classificationTopList.isEmpty()) {
for (DfClassificationTop top : classificationTopList) {
_log.info(" " + top.getClassificationName() + ", " + top.getTopCommentDisp() + ", " + top.isCheckClassificationCode() + ", " + top.getUndefinedHandlingType() + ", " + top.isCheckImplicitSet() + ", " + top.isCheckSelectedClassification() + ", " + top.isForceClassificationSetting());
}
} else {
_log.info(" -> no classification in resource file");
}
topList.addAll(classificationTopList);
}
return topList;
}
use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfClassificationResourceFileAnalyzer method analyze.
protected List<DfClassificationTop> analyze(final List<String> lineList) {
final List<DfClassificationTop> classificationList = new ArrayList<DfClassificationTop>();
AnalyzedTitleLine titleLine = null;
boolean inGroup = false;
final int size = lineList.size();
int index = -1;
for (String line : lineList) {
++index;
if (inGroup) {
if (isTopLine(line)) {
final DfClassificationTop classificationTop = extractClassificationTop(titleLine, line);
classificationList.add(classificationTop);
if (titleLine != null) {
classificationTop.setRelatedColumnName(titleLine.getRelatedColumnName());
final String codeType = titleLine.getCodeType();
if (codeType != null) {
classificationTop.setCodeType(codeType);
}
classificationTop.setCheckImplicitSet(titleLine.isCheckImplicitSet());
}
continue;
} else if (isElementLine(line)) {
final DfClassificationElement classificationElement = extractClassificationElement(line);
final DfClassificationTop classificationTop = classificationList.get(classificationList.size() - 1);
classificationTop.addClassificationElement(classificationElement);
continue;
} else {
inGroup = false;
continue;
}
}
if (!isTitleLine(line)) {
continue;
}
final int nextIndex = index + 1;
if (nextIndex >= size) {
break;
}
final String nextLine = lineList.get(nextIndex);
if (!isTopLine(nextLine)) {
continue;
}
final int nextNextIndex = nextIndex + 1;
if (nextNextIndex >= size) {
break;
}
final String nextNextLine = lineList.get(nextNextIndex);
if (!isElementLine(nextNextLine)) {
continue;
}
titleLine = extractRelatedColumnNameFronTitleLine(line);
inGroup = true;
}
return classificationList;
}
use of org.dbflute.properties.assistant.classification.DfClassificationTop in project dbflute-core by dbflute.
the class DfClassificationResourceFileAnalyzer method extractClassificationTop.
protected DfClassificationTop extractClassificationTop(AnalyzedTitleLine titleLine, String line) {
if (!isTopLine(line)) {
String msg = "The line should be top line: line=" + line;
throw new IllegalArgumentException(msg);
}
line = line.trim();
line = removeRearXmlEndIfNeeds(line);
line = line.substring(line.indexOf("$ ") + "$ ".length());
final String classificationName;
final String topDesc;
if (line.contains(",")) {
classificationName = line.substring(0, line.indexOf(",")).trim();
topDesc = line.substring(line.indexOf(",") + ",".length()).trim();
} else {
classificationName = line.trim();
topDesc = null;
}
final DfClassificationTop classificationTop = new DfClassificationTop(classificationName);
final String title = titleLine != null ? titleLine.getTitle() : null;
final String topComment;
if (topDesc != null) {
if (Srl.is_NotNull_and_NotTrimmedEmpty(title) && !topDesc.startsWith(title)) {
topComment = title + ": " + topDesc;
} else {
// title is not found or topComment starts with same word as title
topComment = topDesc;
}
} else {
topComment = title;
}
if (Srl.is_NotNull_and_NotTrimmedEmpty(topComment)) {
classificationTop.setTopComment(topComment);
}
setupClassificationTopOption(classificationTop);
return classificationTop;
}
Aggregations