Search in sources :

Example 21 with FessSystemException

use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.

the class ApiAdminElevatewordAction method post$upload.

// POST /api/admin/elevateword/upload
@Execute
public JsonResponse<ApiResult> post$upload(final UploadForm body) {
    validateApi(body, messages -> {
    });
    CommonPoolUtil.execute(() -> {
        try (Reader reader = new BufferedReader(new InputStreamReader(body.elevateWordFile.getInputStream(), getCsvEncoding()))) {
            elevateWordService.importCsv(reader);
            suggestHelper.storeAllElevateWords(false);
        } catch (final Exception e) {
            throw new FessSystemException("Failed to import data.", e);
        }
    });
    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 22 with FessSystemException

use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.

the class AdminElevatewordAction method upload.

@Execute
@Secured({ ROLE })
public HtmlResponse upload(final UploadForm form) {
    validate(form, messages -> {
    }, this::asUploadHtml);
    verifyToken(this::asUploadHtml);
    CommonPoolUtil.execute(() -> {
        try (Reader reader = new BufferedReader(new InputStreamReader(form.elevateWordFile.getInputStream(), getCsvEncoding()))) {
            elevateWordService.importCsv(reader);
            suggestHelper.deleteAllElevateWord(false);
            suggestHelper.storeAllElevateWords(false);
        } catch (final Exception e) {
            throw new FessSystemException("Failed to import data.", e);
        }
    });
    saveInfo(messages -> messages.addSuccessUploadElevateWord(GLOBAL));
    return redirect(getClass());
}
Also used : 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) Secured(org.codelibs.fess.annotation.Secured)

Example 23 with FessSystemException

use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.

the class AdminLogAction method getLogFileItems.

public static List<Map<String, Object>> getLogFileItems() {
    final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
    final List<Map<String, Object>> logFileItems = new ArrayList<>();
    final String logFilePath = systemHelper.getLogFilePath();
    if (StringUtil.isNotBlank(logFilePath)) {
        final Path logDirPath = Paths.get(logFilePath);
        try (Stream<Path> stream = Files.list(logDirPath)) {
            stream.filter(entry -> isLogFilename(entry.getFileName().toString())).sorted().forEach(filePath -> {
                final Map<String, Object> map = new HashMap<>();
                final String name = filePath.getFileName().toString();
                map.put("id", Base64.getUrlEncoder().encodeToString(name.getBytes(StandardCharsets.UTF_8)));
                map.put("name", name);
                try {
                    map.put("lastModified", new Date(Files.getLastModifiedTime(filePath).toMillis()));
                } catch (final IOException e) {
                    throw new IORuntimeException(e);
                }
                logFileItems.add(map);
            });
        } catch (final Exception e) {
            throw new FessSystemException("Failed to access log files.", e);
        }
    }
    return logFileItems;
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date) FessSystemException(org.codelibs.fess.exception.FessSystemException) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) IOException(java.io.IOException) FessSystemException(org.codelibs.fess.exception.FessSystemException) SystemHelper(org.codelibs.fess.helper.SystemHelper) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

FessSystemException (org.codelibs.fess.exception.FessSystemException)23 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 IOException (java.io.IOException)6 File (java.io.File)5 ArrayList (java.util.ArrayList)5 Execute (org.lastaflute.web.Execute)5 BufferedReader (java.io.BufferedReader)4 InputStream (java.io.InputStream)4 InputStreamReader (java.io.InputStreamReader)4 Reader (java.io.Reader)4 Map (java.util.Map)4 PostConstruct (javax.annotation.PostConstruct)4 HashMap (java.util.HashMap)3 Secured (org.codelibs.fess.annotation.Secured)3 BufferedInputStream (java.io.BufferedInputStream)2 Path (java.nio.file.Path)2 Date (java.util.Date)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 Consumer (java.util.function.Consumer)2