use of org.lastaflute.web.response.HtmlResponse in project fess by codelibs.
the class AdminSearchlistAction method delete.
// -----------------------------------------------------
// Confirm
// -------
@Execute
@Secured({ ROLE })
public HtmlResponse delete(final DeleteForm form) {
validate(form, messages -> {
}, this::asListHtml);
verifyToken(this::asListHtml);
final String docId = form.docId;
try {
final QueryBuilder query = QueryBuilders.termQuery(fessConfig.getIndexFieldDocId(), docId);
searchEngineClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(), query);
saveInfo(messages -> messages.addSuccessDeleteDocFromIndex(GLOBAL));
} catch (final Exception e) {
throwValidationError(messages -> messages.addErrorsFailedToDeleteDocInAdmin(GLOBAL), this::asListHtml);
}
return asListHtml();
}
use of org.lastaflute.web.response.HtmlResponse in project fess by codelibs.
the class AdminPluginAction method install.
@Execute
@Secured({ ROLE })
public HtmlResponse install(final InstallForm form) {
validate(form, messages -> {
}, () -> asHtml(path_AdminPlugin_AdminPluginInstallpluginJsp));
verifyToken(() -> asHtml(path_AdminPlugin_AdminPluginInstallpluginJsp));
try {
if (UPLOAD.equals(form.id)) {
if (form.jarFile == null) {
throwValidationError(messages -> messages.addErrorsPluginFileIsNotFound(GLOBAL, form.id), this::asListHtml);
}
if (!form.jarFile.getFileName().endsWith(".jar")) {
throwValidationError(messages -> messages.addErrorsFileIsNotSupported(GLOBAL, form.jarFile.getFileName()), this::asListHtml);
}
final String filename = form.jarFile.getFileName();
final File tempFile = ComponentUtil.getSystemHelper().createTempFile("tmp-adminplugin-", ".jar");
try (final InputStream is = form.jarFile.getInputStream();
final OutputStream os = new FileOutputStream(tempFile)) {
CopyUtil.copy(is, os);
} catch (final Exception e) {
if (tempFile.exists() && !tempFile.delete()) {
logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
}
logger.debug("Failed to copy {}", filename, e);
throwValidationError(messages -> messages.addErrorsFailedToInstallPlugin(GLOBAL, filename), this::asListHtml);
}
new Thread(() -> {
try {
final PluginHelper pluginHelper = ComponentUtil.getPluginHelper();
final Artifact artifact = pluginHelper.getArtifactFromFileName(ArtifactType.UNKNOWN, filename, tempFile.getAbsolutePath());
pluginHelper.installArtifact(artifact);
} catch (final Exception e) {
logger.warn("Failed to install {}", filename, e);
} finally {
if (tempFile.exists() && !tempFile.delete()) {
logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
}
}
}).start();
saveInfo(messages -> messages.addSuccessInstallPlugin(GLOBAL, form.jarFile.getFileName()));
} else {
final Artifact artifact = getArtifactFromInstallForm(form);
if (artifact == null) {
throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), this::asListHtml);
}
installArtifact(artifact);
saveInfo(messages -> messages.addSuccessInstallPlugin(GLOBAL, artifact.getFileName()));
}
} catch (final ValidationErrorException e) {
throw e;
} catch (final Exception e) {
throwValidationError(messages -> messages.addErrorsFailedToInstallPlugin(GLOBAL, form.id), this::asListHtml);
}
return redirect(getClass());
}
use of org.lastaflute.web.response.HtmlResponse in project fess by codelibs.
the class AdminGeneralAction method sendmail.
@Execute
@Secured({ ROLE })
public HtmlResponse sendmail(final MailForm form) {
validate(form, messages -> {
}, () -> 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.response.HtmlResponse in project fess by codelibs.
the class AdminBackupAction method upload.
@Execute
@Secured({ ROLE })
public HtmlResponse upload(final UploadForm form) {
validate(form, messages -> {
}, this::asListHtml);
verifyToken(this::asListHtml);
final String fileName = form.bulkFile.getFileName();
final File tempFile = ComponentUtil.getSystemHelper().createTempFile("fess_restore_", ".tmp");
try (final InputStream in = form.bulkFile.getInputStream();
final OutputStream out = new FileOutputStream(tempFile)) {
CopyUtil.copy(in, out);
asyncImport(fileName, tempFile);
} catch (final IOException e) {
logger.warn("Failed to create a temp file.", e);
if (tempFile.exists() && !tempFile.delete()) {
logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
}
throwValidationError(messages -> messages.addErrorsFileIsNotSupported(GLOBAL, fileName), this::asListHtml);
}
saveInfo(messages -> messages.addSuccessBulkProcessStarted(GLOBAL));
// no-op
return redirect(getClass());
}
use of org.lastaflute.web.response.HtmlResponse in project fess by codelibs.
the class AdminDesignAction method update.
@Execute
@Secured({ ROLE })
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(form));
verifyToken(() -> asEditHtml(form));
try {
write(jspFile.getAbsolutePath(), form.content.getBytes(Constants.UTF_8));
saveInfo(messages -> messages.addSuccessUpdateDesignJspFile(GLOBAL, jspFile.getAbsolutePath()));
} catch (final Exception e) {
logger.error("Failed to update {}", form.fileName, e);
throwValidationError(messages -> messages.addErrorsFailedToUpdateJspFile(GLOBAL), this::asListHtml);
}
return redirect(getClass());
}
Aggregations