improve validation
BadWord, CrawlingInfo, DataConfig, Kuromoji
This commit is contained in:
parent
c869401a0e
commit
b4e5669df5
5 changed files with 205 additions and 150 deletions
|
@ -46,10 +46,8 @@ import org.dbflute.optional.OptionalThing;
|
|||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.callback.ActionRuntime;
|
||||
import org.lastaflute.web.response.HtmlResponse;
|
||||
import org.lastaflute.web.response.next.HtmlNext;
|
||||
import org.lastaflute.web.response.render.RenderData;
|
||||
import org.lastaflute.web.util.LaResponseUtil;
|
||||
import org.lastaflute.web.validation.VaErrorHook;
|
||||
|
||||
/**
|
||||
* @author Keiichi Watanabe
|
||||
|
@ -83,10 +81,8 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
// Search Execute
|
||||
// ==============
|
||||
@Execute
|
||||
public HtmlResponse index(final SearchForm form) {
|
||||
return asHtml(path_AdminBadword_AdminBadwordJsp).renderWith(data -> {
|
||||
searchPaging(data, form);
|
||||
});
|
||||
public HtmlResponse index() {
|
||||
return asListHtml();
|
||||
}
|
||||
|
||||
@Execute
|
||||
|
@ -131,9 +127,9 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
// Entry Page
|
||||
// ----------
|
||||
@Execute
|
||||
//(token = TxToken.SAVE)
|
||||
public HtmlResponse createnew() {
|
||||
return asHtml(path_AdminBadword_AdminBadwordEditJsp).useForm(CreateForm.class, op -> {
|
||||
saveToken();
|
||||
return asEditHtml().useForm(CreateForm.class, op -> {
|
||||
op.setup(form -> {
|
||||
form.initialize();
|
||||
form.crudMode = CrudMode.CREATE;
|
||||
|
@ -142,27 +138,24 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
}
|
||||
|
||||
@Execute
|
||||
//(token = TxToken.SAVE)
|
||||
|
||||
public HtmlResponse edit(final EditForm form) {
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
HtmlNext next;
|
||||
switch (form.crudMode) {
|
||||
case CrudMode.EDIT: // back
|
||||
form.crudMode = CrudMode.DETAILS;
|
||||
next = path_AdminBadword_AdminBadwordDetailsJsp;
|
||||
break;
|
||||
default:
|
||||
form.crudMode = CrudMode.EDIT;
|
||||
next = path_AdminBadword_AdminBadwordEditJsp;
|
||||
break;
|
||||
}
|
||||
validate(form, messages -> {}, () -> asListHtml());
|
||||
final String id = form.id;
|
||||
suggestBadWordService.getSuggestBadWord(id).ifPresent(entity -> {
|
||||
copyBeanToBean(entity, form, op -> {});
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asListHtml());
|
||||
});
|
||||
return asHtml(next);
|
||||
saveToken();
|
||||
if (form.crudMode.intValue() == CrudMode.EDIT) {
|
||||
// back
|
||||
form.crudMode = CrudMode.DETAILS;
|
||||
return asDetailsHtml();
|
||||
} else {
|
||||
form.crudMode = CrudMode.EDIT;
|
||||
return asEditHtml();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
@ -171,7 +164,8 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
@Execute
|
||||
public HtmlResponse details(final int crudMode, final String id) {
|
||||
verifyCrudMode(crudMode, CrudMode.DETAILS);
|
||||
return asHtml(path_AdminBadword_AdminBadwordDetailsJsp).useForm(EditForm.class, op -> {
|
||||
saveToken();
|
||||
return asDetailsHtml().useForm(EditForm.class, op -> {
|
||||
op.setup(form -> {
|
||||
suggestBadWordService.getSuggestBadWord(id).ifPresent(entity -> {
|
||||
copyBeanToBean(entity, form, copyOp -> {
|
||||
|
@ -179,7 +173,7 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
});
|
||||
form.crudMode = crudMode;
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asListHtml());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -189,14 +183,14 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
// Download
|
||||
// -------
|
||||
@Execute
|
||||
//(token = TxToken.SAVE)
|
||||
public HtmlResponse downloadpage(final SearchForm form) {
|
||||
return asHtml(path_AdminBadword_AdminBadwordDownloadJsp);
|
||||
saveToken();
|
||||
return asDownloadHtml();
|
||||
}
|
||||
|
||||
@Execute
|
||||
//(token = TxToken.VALIDATE)
|
||||
public HtmlResponse download(final SearchForm form) {
|
||||
verifyTokenKeep(() -> asDownloadHtml());
|
||||
final HttpServletResponse response = LaResponseUtil.getResponse();
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + "badword.csv" + "\"");
|
||||
|
@ -207,16 +201,16 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return asHtml(path_AdminBadword_AdminBadwordDownloadJsp);
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
// Upload
|
||||
// -------
|
||||
@Execute
|
||||
//(token = TxToken.SAVE)
|
||||
public HtmlResponse uploadpage(final UploadForm form) {
|
||||
return asHtml(path_AdminBadword_AdminBadwordUploadJsp);
|
||||
saveToken();
|
||||
return asUploadHtml();
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
@ -225,13 +219,14 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
@Execute
|
||||
public HtmlResponse create(final CreateForm form) {
|
||||
verifyCrudMode(form.crudMode, CrudMode.CREATE);
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
verifyToken(() -> asEditHtml());
|
||||
validate(form, messages -> {}, () -> asEditHtml());
|
||||
getSuggestBadWord(form).ifPresent(entity -> {
|
||||
suggestBadWordService.store(entity);
|
||||
suggestHelper.addBadWord(entity.getSuggestWord());
|
||||
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL), () -> asEditHtml());
|
||||
});
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
@ -239,13 +234,14 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
@Execute
|
||||
public HtmlResponse update(final EditForm form) {
|
||||
verifyCrudMode(form.crudMode, CrudMode.EDIT);
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
verifyToken(() -> asEditHtml());
|
||||
validate(form, messages -> {}, () -> asEditHtml());
|
||||
getSuggestBadWord(form).ifPresent(entity -> {
|
||||
suggestBadWordService.store(entity);
|
||||
suggestHelper.storeAllBadWords();
|
||||
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), () -> asEditHtml());
|
||||
});
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
@ -253,21 +249,22 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
@Execute
|
||||
public HtmlResponse delete(final EditForm form) {
|
||||
verifyCrudMode(form.crudMode, CrudMode.DETAILS);
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
verifyToken(() -> asDetailsHtml());
|
||||
validate(form, messages -> {}, () -> asDetailsHtml());
|
||||
final String id = form.id;
|
||||
suggestBadWordService.getSuggestBadWord(id).ifPresent(entity -> {
|
||||
suggestBadWordService.delete(entity);
|
||||
suggestHelper.deleteBadWord(entity.getSuggestWord());
|
||||
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asDetailsHtml());
|
||||
});
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
||||
@Execute
|
||||
//(token = TxToken.VALIDATE)
|
||||
public HtmlResponse upload(final UploadForm form) {
|
||||
verifyToken(() -> asUploadHtml());
|
||||
BufferedInputStream is = null;
|
||||
File tempFile = null;
|
||||
FileOutputStream fos = null;
|
||||
|
@ -319,6 +316,7 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
}
|
||||
}
|
||||
saveInfo(messages -> messages.addSuccessUploadSuggestBadWord(GLOBAL));
|
||||
saveToken();
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
||||
|
@ -365,13 +363,38 @@ public class AdminBadwordAction extends FessAdminAction {
|
|||
if (crudMode != expectedMode) {
|
||||
throwValidationError(messages -> {
|
||||
messages.addErrorsCrudInvalidMode(GLOBAL, String.valueOf(expectedMode), String.valueOf(crudMode));
|
||||
}, toEditHtml());
|
||||
}, () -> asListHtml());
|
||||
}
|
||||
}
|
||||
|
||||
protected VaErrorHook toEditHtml() {
|
||||
return () -> {
|
||||
return asHtml(path_AdminBadword_AdminBadwordEditJsp);
|
||||
};
|
||||
// ===================================================================================
|
||||
// JSP
|
||||
// =========
|
||||
private HtmlResponse asListHtml() {
|
||||
return asHtml(path_AdminBadword_AdminBadwordJsp).renderWith(data -> {
|
||||
data.register("suggestBadWordItems", suggestBadWordService.getSuggestBadWordList(suggestBadWordPager));
|
||||
}).useForm(SearchForm.class, setup -> {
|
||||
setup.setup(form -> {
|
||||
copyBeanToBean(suggestBadWordPager, form, op -> op.include("id"));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private HtmlResponse asEditHtml() {
|
||||
return asHtml(path_AdminBadword_AdminBadwordEditJsp);
|
||||
}
|
||||
|
||||
private HtmlResponse asDetailsHtml() {
|
||||
return asHtml(path_AdminBadword_AdminBadwordDetailsJsp);
|
||||
}
|
||||
|
||||
private HtmlResponse asUploadHtml() {
|
||||
return asHtml(path_AdminBadword_AdminBadwordUploadJsp);
|
||||
}
|
||||
|
||||
private HtmlResponse asDownloadHtml() {
|
||||
return asHtml(path_AdminBadword_AdminBadwordDownloadJsp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.lastaflute.web.Execute;
|
|||
import org.lastaflute.web.callback.ActionRuntime;
|
||||
import org.lastaflute.web.response.HtmlResponse;
|
||||
import org.lastaflute.web.response.render.RenderData;
|
||||
import org.lastaflute.web.validation.VaErrorHook;
|
||||
|
||||
/**
|
||||
* @author shinsuke
|
||||
|
@ -62,17 +61,15 @@ public class AdminCrawlinginfoAction extends FessAdminAction {
|
|||
// ==============
|
||||
@Execute
|
||||
public HtmlResponse deleteall(final EditForm form) {
|
||||
validate(form, messages -> {}, toIndexHtml());
|
||||
validate(form, messages -> {}, () -> asListHtml());
|
||||
crawlingSessionService.deleteOldSessions(jobHelper.getRunningSessionIdSet());
|
||||
saveInfo(messages -> messages.addSuccessCrawlingSessionDeleteAll(GLOBAL));
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
||||
@Execute
|
||||
public HtmlResponse index(final SearchForm form) {
|
||||
return asHtml(path_AdminCrawlinginfo_AdminCrawlinginfoJsp).renderWith(data -> {
|
||||
searchPaging(data, form);
|
||||
});
|
||||
public HtmlResponse index() {
|
||||
return asListHtml();
|
||||
}
|
||||
|
||||
@Execute
|
||||
|
@ -123,6 +120,7 @@ public class AdminCrawlinginfoAction extends FessAdminAction {
|
|||
@Execute
|
||||
public HtmlResponse details(final int crudMode, final String id) {
|
||||
verifyCrudMode(crudMode, CrudMode.DETAILS);
|
||||
saveToken();
|
||||
return asHtml(path_AdminCrawlinginfo_AdminCrawlinginfoDetailsJsp).useForm(EditForm.class, op -> {
|
||||
op.setup(form -> {
|
||||
crawlingSessionService.getCrawlingSession(id).ifPresent(entity -> {
|
||||
|
@ -131,7 +129,7 @@ public class AdminCrawlinginfoAction extends FessAdminAction {
|
|||
});
|
||||
form.crudMode = crudMode;
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toIndexHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asListHtml());
|
||||
});
|
||||
});
|
||||
}).renderWith(data -> {
|
||||
|
@ -145,7 +143,8 @@ public class AdminCrawlinginfoAction extends FessAdminAction {
|
|||
@Execute
|
||||
public HtmlResponse delete(final EditForm form) {
|
||||
verifyCrudMode(form.crudMode, CrudMode.DETAILS);
|
||||
validate(form, messages -> {}, toIndexHtml());
|
||||
verifyToken(() -> asDetailsHtml());
|
||||
validate(form, messages -> {}, () -> asDetailsHtml());
|
||||
final String id = form.id;
|
||||
crawlingSessionService.getCrawlingSession(id).alwaysPresent(entity -> {
|
||||
crawlingSessionService.delete(entity);
|
||||
|
@ -165,13 +164,25 @@ public class AdminCrawlinginfoAction extends FessAdminAction {
|
|||
if (crudMode != expectedMode) {
|
||||
throwValidationError(messages -> {
|
||||
messages.addErrorsCrudInvalidMode(GLOBAL, String.valueOf(expectedMode), String.valueOf(crudMode));
|
||||
}, toIndexHtml());
|
||||
}, () -> asListHtml());
|
||||
}
|
||||
}
|
||||
|
||||
// ===================================================================================
|
||||
// JSP
|
||||
// =========
|
||||
|
||||
private HtmlResponse asListHtml() {
|
||||
return asHtml(path_AdminCrawlinginfo_AdminCrawlinginfoJsp).renderWith(data -> {
|
||||
data.register("crawlingSessionItems", crawlingSessionService.getCrawlingSessionList(crawlingSessionPager)); // page navi
|
||||
}).useForm(SearchForm.class, setup -> {
|
||||
setup.setup(form -> {
|
||||
copyBeanToBean(crawlingSessionPager, form, op -> op.include("id"));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
protected VaErrorHook toIndexHtml() {
|
||||
return () -> {
|
||||
return asHtml(path_AdminCrawlinginfo_AdminCrawlinginfoJsp);
|
||||
};
|
||||
private HtmlResponse asDetailsHtml() {
|
||||
return asHtml(path_AdminCrawlinginfo_AdminCrawlinginfoDetailsJsp);
|
||||
}
|
||||
}
|
|
@ -39,10 +39,8 @@ import org.dbflute.optional.OptionalThing;
|
|||
import org.lastaflute.web.Execute;
|
||||
import org.lastaflute.web.callback.ActionRuntime;
|
||||
import org.lastaflute.web.response.HtmlResponse;
|
||||
import org.lastaflute.web.response.next.HtmlNext;
|
||||
import org.lastaflute.web.response.render.RenderData;
|
||||
import org.lastaflute.web.util.LaRequestUtil;
|
||||
import org.lastaflute.web.validation.VaErrorHook;
|
||||
|
||||
/**
|
||||
* @author codelibs
|
||||
|
@ -79,10 +77,8 @@ public class AdminDataconfigAction extends FessAdminAction {
|
|||
// Search Execute
|
||||
// ==============
|
||||
@Execute
|
||||
public HtmlResponse index(final SearchForm form) {
|
||||
return asHtml(path_AdminDataconfig_AdminDataconfigJsp).renderWith(data -> {
|
||||
searchPaging(data, form);
|
||||
});
|
||||
public HtmlResponse index() {
|
||||
return asListHtml();
|
||||
}
|
||||
|
||||
@Execute
|
||||
|
@ -127,9 +123,9 @@ public class AdminDataconfigAction extends FessAdminAction {
|
|||
// Entry Page
|
||||
// ----------
|
||||
@Execute
|
||||
//(token = TxToken.SAVE)
|
||||
public HtmlResponse createnew() {
|
||||
return asHtml(path_AdminDataconfig_AdminDataconfigEditJsp).useForm(CreateForm.class, op -> {
|
||||
saveToken();
|
||||
return asEditHtml().useForm(CreateForm.class, op -> {
|
||||
op.setup(form -> {
|
||||
form.initialize();
|
||||
form.crudMode = CrudMode.CREATE;
|
||||
|
@ -143,36 +139,30 @@ public class AdminDataconfigAction extends FessAdminAction {
|
|||
@Execute
|
||||
//(token = TxToken.SAVE)
|
||||
public HtmlResponse edit(final EditForm form) {
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
HtmlNext next;
|
||||
switch (form.crudMode) {
|
||||
case CrudMode.EDIT: // back
|
||||
form.crudMode = CrudMode.DETAILS;
|
||||
next = path_AdminDataconfig_AdminDataconfigDetailsJsp;
|
||||
break;
|
||||
default:
|
||||
form.crudMode = CrudMode.EDIT;
|
||||
next = path_AdminDataconfig_AdminDataconfigEditJsp;
|
||||
break;
|
||||
}
|
||||
form.crudMode = CrudMode.EDIT;
|
||||
validate(form, messages -> {}, () -> asListHtml());
|
||||
final String id = form.id;
|
||||
dataConfigService.getDataConfig(id).ifPresent(entity -> {
|
||||
copyBeanToBean(entity, form, op -> {});
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
||||
});
|
||||
return asHtml(next).renderWith(data -> {
|
||||
registerRolesAndLabels(data);
|
||||
registerHandlerNames(data);
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asListHtml());
|
||||
});
|
||||
if (form.crudMode.intValue() == CrudMode.EDIT) {
|
||||
// back
|
||||
form.crudMode = CrudMode.DETAILS;
|
||||
return asDetailsHtml();
|
||||
} else {
|
||||
form.crudMode = CrudMode.EDIT;
|
||||
return asEditHtml();
|
||||
}
|
||||
}
|
||||
|
||||
@Execute
|
||||
public HtmlResponse createnewjob(final EditForm form) {
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
verifyToken(() -> asDetailsHtml());
|
||||
validate(form, messages -> {}, () -> asDetailsHtml());
|
||||
final ScheduledJob scheduledJob = new ScheduledJob();
|
||||
scheduledJob.setCrawler(true);
|
||||
saveToken();
|
||||
return asHtml(path_AdminScheduler_AdminSchedulerEditJsp).useForm(
|
||||
org.codelibs.fess.app.web.admin.scheduler.CreateForm.class,
|
||||
op -> {
|
||||
|
@ -198,7 +188,8 @@ public class AdminDataconfigAction extends FessAdminAction {
|
|||
@Execute
|
||||
public HtmlResponse details(final int crudMode, final String id) {
|
||||
verifyCrudMode(crudMode, CrudMode.DETAILS);
|
||||
return asHtml(path_AdminDataconfig_AdminDataconfigDetailsJsp).useForm(EditForm.class, op -> {
|
||||
saveToken();
|
||||
return asDetailsHtml().useForm(EditForm.class, op -> {
|
||||
op.setup(form -> {
|
||||
dataConfigService.getDataConfig(id).ifPresent(entity -> {
|
||||
copyBeanToBean(entity, form, copyOp -> {
|
||||
|
@ -206,7 +197,7 @@ public class AdminDataconfigAction extends FessAdminAction {
|
|||
});
|
||||
form.crudMode = crudMode;
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asListHtml());
|
||||
});
|
||||
});
|
||||
}).renderWith(data -> {
|
||||
|
@ -221,12 +212,13 @@ public class AdminDataconfigAction extends FessAdminAction {
|
|||
@Execute
|
||||
public HtmlResponse create(final CreateForm form) {
|
||||
verifyCrudMode(form.crudMode, CrudMode.CREATE);
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
verifyToken(() -> asEditHtml());
|
||||
validate(form, messages -> {}, () -> asEditHtml());
|
||||
getDataConfig(form).ifPresent(entity -> {
|
||||
dataConfigService.store(entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL), () -> asEditHtml());
|
||||
});
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
@ -234,12 +226,13 @@ public class AdminDataconfigAction extends FessAdminAction {
|
|||
@Execute
|
||||
public HtmlResponse update(final EditForm form) {
|
||||
verifyCrudMode(form.crudMode, CrudMode.EDIT);
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
verifyToken(() -> asEditHtml());
|
||||
validate(form, messages -> {}, () -> asEditHtml());
|
||||
getDataConfig(form).ifPresent(entity -> {
|
||||
dataConfigService.store(entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), () -> asEditHtml());
|
||||
});
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
@ -247,13 +240,14 @@ public class AdminDataconfigAction extends FessAdminAction {
|
|||
@Execute
|
||||
public HtmlResponse delete(final EditForm form) {
|
||||
verifyCrudMode(form.crudMode, CrudMode.DETAILS);
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
verifyToken(() -> asDetailsHtml());
|
||||
validate(form, messages -> {}, () -> asDetailsHtml());
|
||||
final String id = form.id;
|
||||
dataConfigService.getDataConfig(id).ifPresent(entity -> {
|
||||
dataConfigService.delete(entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, id), () -> asDetailsHtml());
|
||||
});
|
||||
return redirect(getClass());
|
||||
}
|
||||
|
@ -318,16 +312,30 @@ public class AdminDataconfigAction extends FessAdminAction {
|
|||
if (crudMode != expectedMode) {
|
||||
throwValidationError(messages -> {
|
||||
messages.addErrorsCrudInvalidMode(GLOBAL, String.valueOf(expectedMode), String.valueOf(crudMode));
|
||||
}, toEditHtml());
|
||||
}, () -> asListHtml());
|
||||
}
|
||||
}
|
||||
|
||||
protected VaErrorHook toEditHtml() {
|
||||
return () -> {
|
||||
return asHtml(path_AdminDataconfig_AdminDataconfigEditJsp).renderWith(data -> {
|
||||
registerRolesAndLabels(data);
|
||||
registerHandlerNames(data);
|
||||
// ===================================================================================
|
||||
// JSP
|
||||
// =========
|
||||
|
||||
private HtmlResponse asListHtml() {
|
||||
return asHtml(path_AdminDataconfig_AdminDataconfigJsp).renderWith(data -> {
|
||||
data.register("dataConfigItems", dataConfigService.getDataConfigList(dataConfigPager));
|
||||
}).useForm(SearchForm.class, setup -> {
|
||||
setup.setup(form -> {
|
||||
copyBeanToBean(dataConfigPager, form, op -> op.include("id"));
|
||||
});
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private HtmlResponse asEditHtml() {
|
||||
return asHtml(path_AdminDataconfig_AdminDataconfigEditJsp);
|
||||
}
|
||||
|
||||
private HtmlResponse asDetailsHtml() {
|
||||
return asHtml(path_AdminDataconfig_AdminDataconfigDetailsJsp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class AdminDictAction extends FessAdminAction {
|
|||
// Search Execute
|
||||
// ==============
|
||||
@Execute
|
||||
public HtmlResponse index(final ListForm form) {
|
||||
public HtmlResponse index() {
|
||||
return asHtml(path_AdminDict_AdminDictJsp).renderWith(data -> {
|
||||
final DictionaryFile<? extends DictionaryItem>[] dictFiles = dictionaryManager.getDictionaryFiles();
|
||||
data.register("dictFiles", dictFiles);
|
||||
|
|
|
@ -38,9 +38,7 @@ import org.lastaflute.web.Execute;
|
|||
import org.lastaflute.web.callback.ActionRuntime;
|
||||
import org.lastaflute.web.response.ActionResponse;
|
||||
import org.lastaflute.web.response.HtmlResponse;
|
||||
import org.lastaflute.web.response.next.HtmlNext;
|
||||
import org.lastaflute.web.response.render.RenderData;
|
||||
import org.lastaflute.web.validation.VaErrorHook;
|
||||
|
||||
/**
|
||||
* @author shinsuke
|
||||
|
@ -74,7 +72,7 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
// ==============
|
||||
@Execute
|
||||
public HtmlResponse index(final SearchForm form) {
|
||||
validate(form, messages -> {}, toIndexHtml());
|
||||
validate(form, messages -> {}, () -> asDictIndexHtml());
|
||||
return asHtml(path_AdminDictKuromoji_AdminDictKuromojiJsp).renderWith(data -> {
|
||||
searchPaging(data, form);
|
||||
});
|
||||
|
@ -82,7 +80,7 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
|
||||
@Execute
|
||||
public HtmlResponse list(final OptionalThing<Integer> pageNumber, final SearchForm form) {
|
||||
validate(form, messages -> {}, toIndexHtml());
|
||||
validate(form, messages -> {}, () -> asDictIndexHtml());
|
||||
pageNumber.ifPresent(num -> {
|
||||
kuromojiPager.setCurrentPageNumber(pageNumber.get());
|
||||
}).orElse(() -> {
|
||||
|
@ -95,7 +93,7 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
|
||||
@Execute
|
||||
public HtmlResponse search(final SearchForm form) {
|
||||
validate(form, messages -> {}, toIndexHtml());
|
||||
validate(form, messages -> {}, () -> asDictIndexHtml());
|
||||
copyBeanToBean(form, kuromojiPager, op -> op.exclude(Constants.PAGER_CONVERSION_RULE));
|
||||
return asHtml(path_AdminDictKuromoji_AdminDictKuromojiJsp).renderWith(data -> {
|
||||
searchPaging(data, form);
|
||||
|
@ -104,7 +102,7 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
|
||||
@Execute
|
||||
public HtmlResponse reset(final SearchForm form) {
|
||||
validate(form, messages -> {}, toIndexHtml());
|
||||
validate(form, messages -> {}, () -> asDictIndexHtml());
|
||||
kuromojiPager.clear();
|
||||
return asHtml(path_AdminDictKuromoji_AdminDictKuromojiJsp).renderWith(data -> {
|
||||
searchPaging(data, form);
|
||||
|
@ -128,8 +126,8 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
// Entry Page
|
||||
// ----------
|
||||
@Execute
|
||||
//(token = TxToken.SAVE)
|
||||
public HtmlResponse createnew(final String dictId) {
|
||||
saveToken();
|
||||
return asHtml(path_AdminDictKuromoji_AdminDictKuromojiEditJsp).useForm(CreateForm.class, op -> {
|
||||
op.setup(form -> {
|
||||
form.initialize();
|
||||
|
@ -140,26 +138,22 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
}
|
||||
|
||||
@Execute
|
||||
//(token = TxToken.SAVE)
|
||||
public HtmlResponse edit(final EditForm form) {
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
HtmlNext next;
|
||||
switch (form.crudMode) {
|
||||
case CrudMode.EDIT: // back
|
||||
form.crudMode = CrudMode.DETAILS;
|
||||
next = path_AdminDictKuromoji_AdminDictKuromojiDetailsJsp;
|
||||
break;
|
||||
default:
|
||||
form.crudMode = CrudMode.EDIT;
|
||||
next = path_AdminDictKuromoji_AdminDictKuromojiEditJsp;
|
||||
break;
|
||||
}
|
||||
kuromojiService.getKuromojiItem(form.dictId, form.id).ifPresent(entity -> {
|
||||
validate(form, messages -> {}, () -> asListHtml(form.dictId));
|
||||
kuromojiService.getKuromojiItem(form.dictId, form.id).ifPresent(entity -> {
|
||||
copyBeanToBean(entity, form, op -> {});
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.getDisplayId()), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.getDisplayId()), () -> asListHtml(form.dictId));
|
||||
});
|
||||
return asHtml(next);
|
||||
saveToken();
|
||||
if (form.crudMode.intValue() == CrudMode.EDIT) {
|
||||
// back
|
||||
form.crudMode = CrudMode.DETAILS;
|
||||
return asDetailsHtml();
|
||||
} else {
|
||||
form.crudMode = CrudMode.EDIT;
|
||||
return asEditHtml();
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------
|
||||
|
@ -167,8 +161,9 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
// -------
|
||||
@Execute
|
||||
public HtmlResponse details(final String dictId, final int crudMode, final long id) {
|
||||
verifyCrudMode(crudMode, CrudMode.DETAILS);
|
||||
return asHtml(path_AdminDictKuromoji_AdminDictKuromojiDetailsJsp).useForm(EditForm.class, op -> {
|
||||
verifyCrudMode(crudMode, CrudMode.DETAILS, dictId);
|
||||
saveToken();
|
||||
return asDetailsHtml().useForm(EditForm.class, op -> {
|
||||
op.setup(form -> {
|
||||
kuromojiService.getKuromojiItem(dictId, id).ifPresent(entity -> {
|
||||
copyBeanToBean(entity, form, copyOp -> {
|
||||
|
@ -176,7 +171,7 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
});
|
||||
form.crudMode = crudMode;
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, dictId + ":" + id), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, dictId + ":" + id), () -> asListHtml(dictId));
|
||||
});
|
||||
form.dictId = dictId;
|
||||
});
|
||||
|
@ -187,8 +182,8 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
// Download
|
||||
// -------
|
||||
@Execute
|
||||
//(token = TxToken.VALIDATE)
|
||||
public HtmlResponse downloadpage(final String dictId) {
|
||||
saveToken();
|
||||
return asHtml(path_AdminDictKuromoji_AdminDictKuromojiDownloadJsp).useForm(DownloadForm.class, op -> {
|
||||
op.setup(form -> {
|
||||
form.dictId = dictId;
|
||||
|
@ -197,14 +192,14 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
kuromojiService.getKuromojiFile(dictId).ifPresent(file -> {
|
||||
data.register("path", file.getPath());
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsFailedToDownloadKuromojiFile(GLOBAL), toIndexHtml());
|
||||
throwValidationError(messages -> messages.addErrorsFailedToDownloadKuromojiFile(GLOBAL), () -> asDictIndexHtml());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Execute
|
||||
//(token = TxToken.VALIDATE)
|
||||
public ActionResponse download(final DownloadForm form) {
|
||||
verifyTokenKeep(() -> downloadpage(form.dictId));
|
||||
validate(form, messages -> {}, () -> downloadpage(form.dictId));
|
||||
return kuromojiService.getKuromojiFile(form.dictId).map(file -> {
|
||||
return asStream(new File(file.getPath()).getName()).stream(out -> {
|
||||
|
@ -222,8 +217,8 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
// Upload
|
||||
// -------
|
||||
@Execute
|
||||
//(token = TxToken.VALIDATE)
|
||||
public HtmlResponse uploadpage(final String dictId) {
|
||||
saveToken();
|
||||
return asHtml(path_AdminDictKuromoji_AdminDictKuromojiUploadJsp).useForm(UploadForm.class, op -> {
|
||||
op.setup(form -> {
|
||||
form.dictId = dictId;
|
||||
|
@ -232,14 +227,14 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
kuromojiService.getKuromojiFile(dictId).ifPresent(file -> {
|
||||
data.register("path", file.getPath());
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsFailedToDownloadKuromojiFile(GLOBAL), toIndexHtml());
|
||||
throwValidationError(messages -> messages.addErrorsFailedToDownloadKuromojiFile(GLOBAL), () -> asDictIndexHtml());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@Execute
|
||||
//(token = TxToken.VALIDATE)
|
||||
public HtmlResponse upload(final UploadForm form) {
|
||||
verifyToken(() -> uploadpage(form.dictId));
|
||||
validate(form, messages -> {}, () -> uploadpage(form.dictId));
|
||||
return kuromojiService.getKuromojiFile(form.dictId).map(file -> {
|
||||
try (InputStream inputStream = form.kuromojiFile.getInputStream()) {
|
||||
|
@ -263,39 +258,42 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
// -------------
|
||||
@Execute
|
||||
public HtmlResponse create(final CreateForm form) {
|
||||
verifyCrudMode(form.crudMode, CrudMode.CREATE);
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
verifyCrudMode(form.crudMode, CrudMode.CREATE, form.dictId);
|
||||
verifyToken(() -> asEditHtml());
|
||||
validate(form, messages -> {}, () -> asEditHtml());
|
||||
createKuromojiItem(form).ifPresent(entity -> {
|
||||
kuromojiService.store(form.dictId, entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL), () -> asEditHtml());
|
||||
});
|
||||
return redirectWith(getClass(), moreUrl("list/1").params("dictId", form.dictId));
|
||||
}
|
||||
|
||||
@Execute
|
||||
public HtmlResponse update(final EditForm form) {
|
||||
verifyCrudMode(form.crudMode, CrudMode.EDIT);
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
verifyCrudMode(form.crudMode, CrudMode.EDIT, form.dictId);
|
||||
verifyToken(() -> asEditHtml());
|
||||
validate(form, messages -> {}, () -> asEditHtml());
|
||||
createKuromojiItem(form).ifPresent(entity -> {
|
||||
kuromojiService.store(form.dictId, entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudUpdateCrudTable(GLOBAL));
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.getDisplayId()), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.getDisplayId()), () -> asEditHtml());
|
||||
});
|
||||
return redirectWith(getClass(), moreUrl("list/1").params("dictId", form.dictId));
|
||||
}
|
||||
|
||||
@Execute
|
||||
public HtmlResponse delete(final EditForm form) {
|
||||
verifyCrudMode(form.crudMode, CrudMode.DETAILS);
|
||||
validate(form, messages -> {}, toEditHtml());
|
||||
verifyCrudMode(form.crudMode, CrudMode.DETAILS, form.dictId);
|
||||
verifyToken(() -> asDetailsHtml());
|
||||
validate(form, messages -> {}, () -> asDetailsHtml());
|
||||
kuromojiService.getKuromojiItem(form.dictId, form.id).ifPresent(entity -> {
|
||||
kuromojiService.delete(form.dictId, entity);
|
||||
saveInfo(messages -> messages.addSuccessCrudDeleteCrudTable(GLOBAL));
|
||||
}).orElse(() -> {
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.getDisplayId()), toEditHtml());
|
||||
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.getDisplayId()), () -> asDetailsHtml());
|
||||
});
|
||||
return redirectWith(getClass(), moreUrl("list/1").params("dictId", form.dictId));
|
||||
}
|
||||
|
@ -336,23 +334,38 @@ public class AdminDictKuromojiAction extends FessAdminAction {
|
|||
// ===================================================================================
|
||||
// Small Helper
|
||||
// ============
|
||||
protected void verifyCrudMode(final int crudMode, final int expectedMode) {
|
||||
protected void verifyCrudMode(final int crudMode, final int expectedMode, final String dictId) {
|
||||
if (crudMode != expectedMode) {
|
||||
throwValidationError(messages -> {
|
||||
messages.addErrorsCrudInvalidMode(GLOBAL, String.valueOf(expectedMode), String.valueOf(crudMode));
|
||||
}, toEditHtml());
|
||||
}, () -> asListHtml(dictId));
|
||||
}
|
||||
}
|
||||
|
||||
protected VaErrorHook toIndexHtml() {
|
||||
return () -> {
|
||||
return redirect(AdminDictAction.class);
|
||||
};
|
||||
// ===================================================================================
|
||||
// JSP
|
||||
// =========
|
||||
|
||||
protected HtmlResponse asDictIndexHtml() {
|
||||
return redirect(AdminDictAction.class);
|
||||
}
|
||||
|
||||
private HtmlResponse asListHtml(final String dictId) {
|
||||
return asHtml(path_AdminDictKuromoji_AdminDictKuromojiJsp).renderWith(data -> {
|
||||
data.register("kuromojiItemItems", kuromojiService.getKuromojiList(dictId, kuromojiPager));
|
||||
}).useForm(SearchForm.class, setup -> {
|
||||
setup.setup(form -> {
|
||||
copyBeanToBean(kuromojiPager, form, op -> op.include("id"));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private HtmlResponse asEditHtml() {
|
||||
return asHtml(path_AdminDictKuromoji_AdminDictKuromojiEditJsp);
|
||||
}
|
||||
|
||||
protected VaErrorHook toEditHtml() {
|
||||
return () -> {
|
||||
return asHtml(path_AdminDictKuromoji_AdminDictKuromojiEditJsp);
|
||||
};
|
||||
private HtmlResponse asDetailsHtml() {
|
||||
return asHtml(path_AdminDictKuromoji_AdminDictKuromojiDetailsJsp);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue