use of org.lastaflute.web.response.ActionResponse in project fess by codelibs.
the class AdminDictProtwordsAction method download.
@Execute
public ActionResponse download(final DownloadForm form) {
validate(form, messages -> {
}, () -> downloadpage(form.dictId));
verifyTokenKeep(() -> downloadpage(form.dictId));
return protwordsService.getProtwordsFile(form.dictId).map(file -> {
return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
try (InputStream inputStream = file.getInputStream()) {
out.write(inputStream);
}
});
}).orElseGet(() -> {
throwValidationError(messages -> messages.addErrorsFailedToDownloadProtwordsFile(GLOBAL), () -> downloadpage(form.dictId));
return null;
});
}
use of org.lastaflute.web.response.ActionResponse in project fess by codelibs.
the class AdminDictSeunjeonAction method download.
@Execute
public ActionResponse download(final DownloadForm form) {
validate(form, messages -> {
}, () -> downloadpage(form.dictId));
verifyTokenKeep(() -> downloadpage(form.dictId));
return seunjeonService.getSeunjeonFile(form.dictId).map(file -> {
return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
try (InputStream inputStream = file.getInputStream()) {
out.write(inputStream);
}
});
}).orElseGet(() -> {
throwValidationError(messages -> messages.addErrorsFailedToDownloadSynonymFile(GLOBAL), () -> downloadpage(form.dictId));
return null;
});
}
use of org.lastaflute.web.response.ActionResponse in project fess by codelibs.
the class AdminDictSynonymAction method download.
@Execute
public ActionResponse download(final DownloadForm form) {
validate(form, messages -> {
}, () -> downloadpage(form.dictId));
verifyTokenKeep(() -> downloadpage(form.dictId));
return synonymService.getSynonymFile(form.dictId).map(file -> {
return asStream(new File(file.getPath()).getName()).contentTypeOctetStream().stream(out -> {
try (InputStream inputStream = file.getInputStream()) {
out.write(inputStream);
}
});
}).orElseGet(() -> {
throwValidationError(messages -> messages.addErrorsFailedToDownloadSynonymFile(GLOBAL), () -> downloadpage(form.dictId));
return null;
});
}
use of org.lastaflute.web.response.ActionResponse in project fess by codelibs.
the class GoAction method index.
// ===================================================================================
// Attribute
//
// ===================================================================================
// Hook
// ======
// ===================================================================================
// Search Execute
// ==============
@Execute
public ActionResponse index(final GoForm form) throws IOException {
validate(form, messages -> {
}, () -> asHtml(virtualHost(path_Error_ErrorJsp)));
if (isLoginRequired()) {
return redirectToLogin();
}
Map<String, Object> doc = null;
try {
doc = searchService.getDocumentByDocId(form.docId, new String[] { fessConfig.getIndexFieldUrl(), fessConfig.getIndexFieldConfigId() }, getUserBean()).orElse(null);
} catch (final Exception e) {
logger.warn("Failed to request: " + form.docId, e);
}
if (doc == null) {
saveError(messages -> messages.addErrorsDocidNotFound(GLOBAL, form.docId));
return redirect(ErrorAction.class);
}
final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
if (url == null) {
saveError(messages -> messages.addErrorsDocumentNotFound(GLOBAL, form.docId));
return redirect(ErrorAction.class);
}
if (fessConfig.isSearchLog()) {
final String userSessionId = userInfoHelper.getUserCode();
if (userSessionId != null) {
final SearchLogHelper searchLogHelper = ComponentUtil.getSearchLogHelper();
final ClickLog clickLog = new ClickLog();
clickLog.setUrl(url);
clickLog.setRequestedAt(systemHelper.getCurrentTimeAsLocalDateTime());
clickLog.setQueryRequestedAt(DfTypeUtil.toLocalDateTime(Long.parseLong(form.rt)));
clickLog.setUserSessionId(userSessionId);
clickLog.setDocId(form.docId);
clickLog.setQueryId(form.queryId);
if (form.order != null) {
clickLog.setOrder(form.order);
}
searchLogHelper.addClickLog(clickLog);
}
}
String hash;
if (StringUtil.isNotBlank(form.hash)) {
final String value = URLUtil.decode(form.hash, Constants.UTF_8);
final StringBuilder buf = new StringBuilder(value.length() + 100);
for (final char c : value.toCharArray()) {
if (CharUtil.isUrlChar(c) || c == ' ') {
buf.append(c);
} else {
try {
buf.append(URLEncoder.encode(String.valueOf(c), Constants.UTF_8));
} catch (final UnsupportedEncodingException e) {
// NOP
}
}
}
hash = buf.toString();
} else {
hash = StringUtil.EMPTY;
}
final String targetUrl = pathMappingHelper.replaceUrl(url);
if (isFileSystemPath(targetUrl)) {
if (fessConfig.isSearchFileProxyEnabled()) {
final ViewHelper viewHelper = ComponentUtil.getViewHelper();
try {
final StreamResponse response = viewHelper.asContentResponse(doc);
if (response.getHttpStatus().orElse(200) == 404) {
logger.debug("Not found: " + targetUrl);
saveError(messages -> messages.addErrorsNotFoundOnFileSystem(GLOBAL, targetUrl));
return redirect(ErrorAction.class);
}
return response;
} catch (final Exception e) {
logger.warn("Failed to load: " + doc, e);
saveError(messages -> messages.addErrorsNotLoadFromServer(GLOBAL, targetUrl));
return redirect(ErrorAction.class);
}
} else {
return redirect(targetUrl + hash);
}
} else {
return redirect(targetUrl + hash);
}
}
use of org.lastaflute.web.response.ActionResponse in project fess by codelibs.
the class SsoAction method index.
// ===================================================================================
// Login Execute
// ==============
@Execute
public ActionResponse index() {
final SsoManager ssoManager = ComponentUtil.getSsoManager();
final LoginCredential loginCredential = ssoManager.getLoginCredential();
if (loginCredential == null) {
if (logger.isDebugEnabled()) {
logger.debug("No user in SSO request.");
}
if (ssoManager.available()) {
saveError(messages -> messages.addErrorsSsoLoginError(GLOBAL));
}
return redirect(LoginAction.class);
} else if (loginCredential instanceof ActionResponseCredential) {
return ((ActionResponseCredential) loginCredential).execute();
}
try {
return fessLoginAssist.loginRedirect(loginCredential, op -> {
}, () -> {
activityHelper.login(getUserBean());
userInfoHelper.deleteUserCodeFromCookie(request);
return getHtmlResponse();
});
} catch (final LoginFailureException lfe) {
if (logger.isDebugEnabled()) {
logger.debug("SSO login failure.", lfe);
}
if (ssoManager.available()) {
saveError(messages -> messages.addErrorsSsoLoginError(GLOBAL));
}
return redirect(LoginAction.class);
}
}
Aggregations