Search in sources :

Example 1 with CSV_EXTENTION

use of org.codelibs.fess.app.web.admin.backup.AdminBackupAction.CSV_EXTENTION 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)

Aggregations

CsvConfig (com.orangesignal.csv.CsvConfig)1 CsvWriter (com.orangesignal.csv.CsvWriter)1 BufferedWriter (java.io.BufferedWriter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 StreamUtil.stream (org.codelibs.core.stream.StreamUtil.stream)1 Curl (org.codelibs.elasticsearch.runner.net.Curl)1 CurlResponse (org.codelibs.elasticsearch.runner.net.CurlResponse)1 CSV_EXTENTION (org.codelibs.fess.app.web.admin.backup.AdminBackupAction.CSV_EXTENTION)1 AdminBackupAction.getBackupItems (org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getBackupItems)1 AdminBackupAction.getClickLogCsvWriteCall (org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getClickLogCsvWriteCall)1 AdminBackupAction.getFavoriteLogCsvWriteCall (org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getFavoriteLogCsvWriteCall)1 AdminBackupAction.getSearchFieldLogCsvWriteCall (org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getSearchFieldLogCsvWriteCall)1 AdminBackupAction.getSearchLogCsvWriteCall (org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getSearchLogCsvWriteCall)1 AdminBackupAction.getUserInfoCsvWriteCall (org.codelibs.fess.app.web.admin.backup.AdminBackupAction.getUserInfoCsvWriteCall)1