use of org.lastaflute.web.Execute in project fess by codelibs.
the class ThumbnailAction method index.
// ===================================================================================
// Hook
// ======
// ===================================================================================
// Search Execute
// ==============
@Execute
public ActionResponse index(final ThumbnailForm form) {
validate(form, messages -> {
}, () -> asHtml(virtualHost(path_Error_ErrorJsp)));
if (isLoginRequired()) {
return redirectToLogin();
}
final Map<String, Object> doc = searchService.getDocumentByDocId(form.docId, queryHelper.getResponseFields(), getUserBean()).orElse(null);
final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldUrl(), String.class);
if (StringUtil.isBlank(form.queryId) || StringUtil.isBlank(url) || !thumbnailSupport) {
// 404
throw responseManager.new404("Thumbnail for " + form.docId + " is not found.");
}
final File thumbnailFile = thumbnailManager.getThumbnailFile(form.queryId, form.docId);
if (thumbnailFile == null) {
// 404
thumbnailManager.offer(doc);
throw responseManager.new404("Thumbnail for " + form.docId + " is under generating.");
}
return asStream(form.docId).contentType(getImageMimeType(thumbnailFile)).stream(out -> {
try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(thumbnailFile))) {
out.write(in);
}
});
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class ApiAdminWebconfigAction method put$setting.
// PUT /api/admin/webconfig/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.CREATE;
final WebConfig webConfig = getWebConfig(body).map(entity -> {
try {
webConfigService.store(entity);
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return entity;
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
return null;
});
return asJson(new ApiUpdateResponse().id(webConfig.getId()).created(true).status(Status.OK).result());
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class CacheAction method index.
// ===================================================================================
// Attribute
//
// ===================================================================================
// Hook
// ======
// ===================================================================================
// Search Execute
// ==============
@Execute
public ActionResponse index(final CacheForm form) {
validate(form, messages -> {
}, () -> asHtml(virtualHost(path_Error_ErrorJsp)));
if (isLoginRequired()) {
return redirectToLogin();
}
Map<String, Object> doc = null;
try {
doc = searchService.getDocumentByDocId(form.docId, queryHelper.getCacheResponseFields(), 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 content = viewHelper.createCacheContent(doc, form.hq);
if (content == null) {
saveError(messages -> messages.addErrorsDocidNotFound(GLOBAL, form.docId));
return redirect(ErrorAction.class);
}
final StreamResponse response = asStream(DocumentUtil.getValue(doc, fessConfig.getIndexFieldDocId(), String.class)).contentType("text/html; charset=UTF-8").data(content.getBytes(Constants.CHARSET_UTF_8));
// TODO will be fixed in lastaflute
response.headerContentDispositionInline();
return response;
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class ApiAdminPathmapAction method put$setting.
// PUT /api/admin/pathmap/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
validateApi(body, messages -> {
});
body.crudMode = CrudMode.CREATE;
final PathMapping entity = getPathMapping(body).orElseGet(() -> {
throwValidationErrorApi(messages -> {
messages.addErrorsCrudFailedToCreateInstance(GLOBAL);
});
return null;
});
try {
pathMappingService.store(entity);
saveInfo(messages -> messages.addSuccessCrudCreateCrudTable(GLOBAL));
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return asJson(new ApiResult.ApiUpdateResponse().id(entity.getId()).created(true).status(ApiResult.Status.OK).result());
}
use of org.lastaflute.web.Execute in project fess by codelibs.
the class ApiAdminReqheaderAction method put$setting.
// PUT /api/admin/reqheader/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
validateApi(body, messages -> {
});
if (!isValidWebConfigId(body.webConfigId)) {
return asJson(new ApiErrorResponse().message("invalid webConfigId").status(Status.BAD_REQUEST).result());
}
body.crudMode = CrudMode.CREATE;
final RequestHeader reqHeader = getRequestHeader(body).map(entity -> {
try {
reqHeaderService.store(entity);
} catch (final Exception e) {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateCrudTable(GLOBAL, buildThrowableMessage(e)));
}
return entity;
}).orElseGet(() -> {
throwValidationErrorApi(messages -> messages.addErrorsCrudFailedToCreateInstance(GLOBAL));
return null;
});
return asJson(new ApiUpdateResponse().id(reqHeader.getId()).created(true).status(Status.OK).result());
}
Aggregations