Search in sources :

Example 81 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminKeymatchAction method settings.

// ===================================================================================
//                                                                      Search Execute
//                                                                      ==============
// GET /api/admin/keymatch/settings
// POST /api/admin/keymatch/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final KeyMatchPager pager = copyBeanToNewBean(body, KeyMatchPager.class);
    final List<KeyMatch> list = keyMatchService.getKeyMatchList(pager);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
Also used : ApiResult(org.codelibs.fess.app.web.api.ApiResult) KeyMatch(org.codelibs.fess.es.config.exentity.KeyMatch) AdminKeymatchAction.getKeyMatch(org.codelibs.fess.app.web.admin.keymatch.AdminKeymatchAction.getKeyMatch) KeyMatchPager(org.codelibs.fess.app.pager.KeyMatchPager) Execute(org.lastaflute.web.Execute)

Example 82 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminBackupAction method get$file.

// GET /api/admin/backup/file/{id}
@Execute
public StreamResponse get$file(final String id) {
    FessConfig fessConfig = ComponentUtil.getFessConfig();
    if (stream(fessConfig.getIndexBackupAllTargets()).get(stream -> stream.anyMatch(s -> s.equals(id)))) {
        if (id.equals("system.properties")) {
            return asStream(id).contentTypeOctetStream().stream(out -> {
                try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
                    ComponentUtil.getSystemProperties().store(baos, id);
                    try (final InputStream in = new ByteArrayInputStream(baos.toByteArray())) {
                        out.write(in);
                    }
                }
            });
        } else if (id.endsWith(CSV_EXTENTION)) {
            final String name = id.substring(0, id.length() - CSV_EXTENTION.length());
            if ("search_log".equals(name)) {
                return writeCsvResponse(id, getSearchLogCsvWriteCall());
            } else if ("search_field_log".equals(name)) {
                return writeCsvResponse(id, getSearchFieldLogCsvWriteCall());
            } else if ("user_info".equals(name)) {
                return writeCsvResponse(id, getUserInfoCsvWriteCall());
            } else if ("click_log".equals(name)) {
                return writeCsvResponse(id, getClickLogCsvWriteCall());
            } else if ("favorite_log".equals(name)) {
                return writeCsvResponse(id, getFavoriteLogCsvWriteCall());
            }
        } else {
            final String index;
            final String filename;
            if (id.endsWith(".bulk")) {
                index = id.substring(0, id.length() - 5);
                filename = id;
            } else {
                index = id;
                filename = id + ".bulk";
            }
            return asStream(filename).contentTypeOctetStream().stream(out -> {
                try (CurlResponse response = Curl.get(ResourceUtil.getElasticsearchHttpUrl() + "/" + index + "/_data").header("Content-Type", "application/json").param("format", "json").execute()) {
                    out.write(response.getContentAsStream());
                }
            });
        }
    }
    throwValidationErrorApi(messages -> messages.addErrorsCouldNotFindBackupIndex(GLOBAL));
    // no-op
    return StreamResponse.asEmptyBody();
}
Also used : AdminBackupAction.getClickLogCsvWriteCall(org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getClickLogCsvWriteCall) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ApiBackupFilesResponse(org.codelibs.fess.app.web.api.ApiResult.ApiBackupFilesResponse) ApiResult(org.codelibs.fess.app.web.api.ApiResult) Curl(org.codelibs.elasticsearch.runner.net.Curl) ResourceUtil(org.codelibs.fess.util.ResourceUtil) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamResponse(org.lastaflute.web.response.StreamResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) OutputStreamWriter(java.io.OutputStreamWriter) CurlResponse(org.codelibs.elasticsearch.runner.net.CurlResponse) AdminBackupAction.getSearchLogCsvWriteCall(org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getSearchLogCsvWriteCall) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) BufferedWriter(java.io.BufferedWriter) AdminBackupAction.getBackupItems(org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getBackupItems) CsvWriter(com.orangesignal.csv.CsvWriter) JsonResponse(org.lastaflute.web.response.JsonResponse) Consumer(java.util.function.Consumer) CsvConfig(com.orangesignal.csv.CsvConfig) AdminBackupAction.getFavoriteLogCsvWriteCall(org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getFavoriteLogCsvWriteCall) List(java.util.List) CSV_EXTENTION(org.codelibs.fess.app.web.admin.backup.AdminBackupAction.CSV_EXTENTION) ComponentUtil(org.codelibs.fess.util.ComponentUtil) AdminBackupAction.getUserInfoCsvWriteCall(org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getUserInfoCsvWriteCall) Execute(org.lastaflute.web.Execute) AdminBackupAction.getSearchFieldLogCsvWriteCall(org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getSearchFieldLogCsvWriteCall) InputStream(java.io.InputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CurlResponse(org.codelibs.elasticsearch.runner.net.CurlResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) Execute(org.lastaflute.web.Execute)

Example 83 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminBadwordAction method post$upload.

// POST /api/admin/badword/upload
@Execute
public JsonResponse<ApiResult> post$upload(final UploadForm body) {
    validateApi(body, messages -> {
    });
    new Thread(() -> {
        try (Reader reader = new BufferedReader(new InputStreamReader(body.badWordFile.getInputStream(), getCsvEncoding()))) {
            badWordService.importCsv(reader);
            suggestHelper.storeAllBadWords();
        } catch (final Exception e) {
            throw new FessSystemException("Failed to import data.", e);
        }
    }).start();
    return asJson(new ApiResult.ApiResponse().status(ApiResult.Status.OK).result());
}
Also used : ApiResult(org.codelibs.fess.app.web.api.ApiResult) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) FessSystemException(org.codelibs.fess.exception.FessSystemException) FessSystemException(org.codelibs.fess.exception.FessSystemException) Execute(org.lastaflute.web.Execute)

Example 84 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminDuplicatehostAction method settings.

// ===================================================================================
//                                                                      Search Execute
//                                                                      ==============
// GET /api/admin/duplicatehost/settings
// POST /api/admin/duplicatehost/settings
@Execute
public JsonResponse<ApiResult> settings(final SearchBody body) {
    validateApi(body, messages -> {
    });
    final DuplicateHostPager pager = copyBeanToNewBean(body, DuplicateHostPager.class);
    final List<DuplicateHost> list = duplicateHostService.getDuplicateHostList(pager);
    return asJson(new ApiResult.ApiConfigsResponse<EditBody>().settings(list.stream().map(entity -> createEditBody(entity)).collect(Collectors.toList())).total(pager.getAllRecordCount()).status(ApiResult.Status.OK).result());
}
Also used : ApiResult(org.codelibs.fess.app.web.api.ApiResult) DuplicateHostPager(org.codelibs.fess.app.pager.DuplicateHostPager) AdminDuplicatehostAction.getDuplicateHost(org.codelibs.fess.app.web.admin.duplicatehost.AdminDuplicatehostAction.getDuplicateHost) DuplicateHost(org.codelibs.fess.es.config.exentity.DuplicateHost) Execute(org.lastaflute.web.Execute)

Example 85 with Execute

use of org.lastaflute.web.Execute in project fess by codelibs.

the class ApiAdminDuplicatehostAction method put$setting.

// PUT /api/admin/duplicatehost/setting
@Execute
public JsonResponse<ApiResult> put$setting(final CreateBody body) {
    validateApi(body, messages -> {
    });
    body.crudMode = CrudMode.CREATE;
    final DuplicateHost duplicateHost = getDuplicateHost(body).map(entity -> {
        try {
            duplicateHostService.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(duplicateHost.getId()).created(true).status(Status.OK).result());
}
Also used : DuplicateHostPager(org.codelibs.fess.app.pager.DuplicateHostPager) FessApiAdminAction(org.codelibs.fess.app.web.api.admin.FessApiAdminAction) Resource(javax.annotation.Resource) ApiConfigResponse(org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse) JsonResponse(org.lastaflute.web.response.JsonResponse) Collectors(java.util.stream.Collectors) ApiResult(org.codelibs.fess.app.web.api.ApiResult) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) Status(org.codelibs.fess.app.web.api.ApiResult.Status) List(java.util.List) CrudMode(org.codelibs.fess.app.web.CrudMode) DuplicateHostService(org.codelibs.fess.app.service.DuplicateHostService) Execute(org.lastaflute.web.Execute) ApiResponse(org.codelibs.fess.app.web.api.ApiResult.ApiResponse) AdminDuplicatehostAction.getDuplicateHost(org.codelibs.fess.app.web.admin.duplicatehost.AdminDuplicatehostAction.getDuplicateHost) DuplicateHost(org.codelibs.fess.es.config.exentity.DuplicateHost) ApiUpdateResponse(org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse) AdminDuplicatehostAction.getDuplicateHost(org.codelibs.fess.app.web.admin.duplicatehost.AdminDuplicatehostAction.getDuplicateHost) DuplicateHost(org.codelibs.fess.es.config.exentity.DuplicateHost) Execute(org.lastaflute.web.Execute)

Aggregations

Execute (org.lastaflute.web.Execute)125 ApiResult (org.codelibs.fess.app.web.api.ApiResult)94 Resource (javax.annotation.Resource)83 CrudMode (org.codelibs.fess.app.web.CrudMode)77 FessApiAdminAction (org.codelibs.fess.app.web.api.admin.FessApiAdminAction)71 JsonResponse (org.lastaflute.web.response.JsonResponse)71 Collectors (java.util.stream.Collectors)70 List (java.util.List)51 InputStream (java.io.InputStream)39 File (java.io.File)35 StreamResponse (org.lastaflute.web.response.StreamResponse)34 ApiResponse (org.codelibs.fess.app.web.api.ApiResult.ApiResponse)32 Status (org.codelibs.fess.app.web.api.ApiResult.Status)31 Constants (org.codelibs.fess.Constants)26 ApiUpdateResponse (org.codelibs.fess.app.web.api.ApiResult.ApiUpdateResponse)26 StringUtil (org.codelibs.core.lang.StringUtil)24 ComponentUtil (org.codelibs.fess.util.ComponentUtil)23 ApiConfigResponse (org.codelibs.fess.app.web.api.ApiResult.ApiConfigResponse)22 HtmlResponse (org.lastaflute.web.response.HtmlResponse)20 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)14