use of org.lastaflute.web.Execute in project fess by codelibs.
the class AdminGeneralAction method sendmail.
@Execute
public HtmlResponse sendmail(final MailForm form) {
validate(form, messages -> {
}, () -> {
return asHtml(path_AdminGeneral_AdminGeneralJsp);
});
final String[] toAddresses = form.notificationTo.split(",");
final Map<String, Object> dataMap = new HashMap<>();
dataMap.put("hostname", systemHelper.getHostname());
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final Postbox postbox = ComponentUtil.getComponent(Postbox.class);
try {
TestmailPostcard.droppedInto(postbox, postcard -> {
postcard.setFrom(fessConfig.getMailFromAddress(), fessConfig.getMailFromName());
postcard.addReplyTo(fessConfig.getMailReturnPath());
stream(toAddresses).of(stream -> stream.forEach(address -> {
postcard.addTo(address);
}));
BeanUtil.copyMapToBean(dataMap, postcard);
});
saveInfo(messages -> messages.addSuccessSendTestmail(GLOBAL));
updateProperty(Constants.NOTIFICATION_TO_PROPERTY, form.notificationTo);
systemProperties.store();
} catch (final Exception e) {
logger.warn("Failed to send a test mail.", e);
saveError(messages -> messages.addErrorsFailedToSendTestmail(GLOBAL));
}
return redirectByParam(AdminGeneralAction.class, "notificationTo", form.notificationTo);
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class AdminDesignAction method edit.
// -----------------------------------------------------
// Edit
// ------
@Execute
public HtmlResponse edit(final EditForm form) {
final String jspType = "view";
final File jspFile = getJspFile(form.fileName, jspType);
try {
form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
} catch (final UnsupportedEncodingException e) {
throw new FessSystemException("Invalid encoding", e);
}
saveToken();
return asEditHtml();
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class AdminDesignAction method update.
@Execute
public HtmlResponse update(final EditForm form) {
final String jspType = "view";
final File jspFile = getJspFile(form.fileName, jspType);
if (form.content == null) {
form.content = StringUtil.EMPTY;
}
validate(form, messages -> {
}, () -> asEditHtml());
verifyToken(() -> asEditHtml());
try {
write(jspFile.getAbsolutePath(), form.content.getBytes(Constants.UTF_8));
saveInfo(messages -> messages.addSuccessUpdateDesignJspFile(GLOBAL, systemHelper.getDesignJspFileName(form.fileName)));
} catch (final Exception e) {
logger.error("Failed to update {}", form.fileName, e);
throwValidationError(messages -> messages.addErrorsFailedToUpdateJspFile(GLOBAL), () -> asListHtml());
}
return redirect(getClass());
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class AdminWizardAction method startCrawling.
@Execute
public HtmlResponse startCrawling(final StartCrawlingForm form) {
verifyToken(() -> asIndexHtml());
if (!processHelper.isProcessRunning()) {
final List<ScheduledJob> scheduledJobList = scheduledJobService.getCrawlerJobList();
final JobManager jobManager = ComponentUtil.getJobManager();
for (final ScheduledJob scheduledJob : scheduledJobList) {
jobManager.findJobByUniqueOf(LaJobUnique.of(scheduledJob.getId())).ifPresent(job -> {
job.launchNow();
});
}
saveInfo(messages -> messages.addSuccessStartCrawlProcess(GLOBAL));
} else {
saveError(messages -> messages.addErrorsFailedToStartCrawlProcess(GLOBAL));
}
return redirect(AdminWizardAction.class);
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class ApiAdminAccesstokenAction method post$setting.
// POST /api/admin/accesstoken/setting
@Execute
public JsonResponse<ApiResult> post$setting(final EditBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.EDIT;
final AccessToken accessToken = getAccessToken(body).map(entity -> {
try {
accessTokenService.store(entity);
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToUpdateCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return entity;
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, body.id));
return null;
});
return asJson(new ApiUpdateResponse().id(accessToken.getId()).created(false).status(Status.OK).result());
}
Aggregations