Search in sources :

Example 16 with FessSystemException

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

the class AdminBadwordAction 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.badWordFile.getInputStream(), getCsvEncoding()))) {
            badWordService.importCsv(reader);
            suggestHelper.storeAllBadWords(false);
        } catch (final Exception e) {
            throw new FessSystemException("Failed to import data.", e);
        }
    });
    saveInfo(messages -> messages.addSuccessUploadBadWord(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 17 with FessSystemException

use of org.codelibs.fess.exception.FessSystemException 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 -> {
    });
    CommonPoolUtil.execute(() -> {
        try (Reader reader = new BufferedReader(new InputStreamReader(body.badWordFile.getInputStream(), getCsvEncoding()))) {
            badWordService.importCsv(reader);
            suggestHelper.storeAllBadWords(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 18 with FessSystemException

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

the class ThumbnailManager method init.

@PostConstruct
public void init() {
    if (logger.isDebugEnabled()) {
        logger.debug("Initialize {}", this.getClass().getSimpleName());
    }
    final String thumbnailPath = System.getProperty(Constants.FESS_THUMBNAIL_PATH);
    if (thumbnailPath != null) {
        baseDir = new File(thumbnailPath);
    } else {
        final String varPath = System.getProperty(Constants.FESS_VAR_PATH);
        if (varPath != null) {
            baseDir = new File(varPath, THUMBNAILS_DIR_NAME);
        } else {
            baseDir = ResourceUtil.getThumbnailPath().toFile();
        }
    }
    if (baseDir.mkdirs()) {
        logger.info("Created: {}", baseDir.getAbsolutePath());
    }
    if (!baseDir.isDirectory()) {
        throw new FessSystemException("Not found: " + baseDir.getAbsolutePath());
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Thumbnail Directory: {}", baseDir.getAbsolutePath());
    }
    thumbnailTaskQueue = new LinkedBlockingQueue<>(thumbnailTaskQueueSize);
    generating = !Constants.TRUE.equalsIgnoreCase(System.getProperty("fess.thumbnail.process"));
    thumbnailQueueThread = new Thread((Runnable) () -> {
        final List<Tuple3<String, String, String>> taskList = new ArrayList<>();
        while (generating) {
            try {
                final Tuple3<String, String, String> task = thumbnailTaskQueue.poll(thumbnailTaskQueueTimeout, TimeUnit.MILLISECONDS);
                if (task == null) {
                    if (!taskList.isEmpty()) {
                        storeQueue(taskList);
                    }
                } else if (!taskList.contains(task)) {
                    taskList.add(task);
                    if (taskList.size() > thumbnailTaskBulkSize) {
                        storeQueue(taskList);
                    }
                }
            } catch (final InterruptedException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Interupted task.", e);
                }
            } catch (final Exception e) {
                if (generating) {
                    logger.warn("Failed to generate thumbnail.", e);
                }
            }
        }
        if (!taskList.isEmpty()) {
            storeQueue(taskList);
        }
    }, "ThumbnailGenerator");
    thumbnailQueueThread.start();
}
Also used : Tuple3(org.codelibs.core.misc.Tuple3) ArrayList(java.util.ArrayList) File(java.io.File) FessSystemException(org.codelibs.fess.exception.FessSystemException) JobProcessingException(org.codelibs.fess.exception.JobProcessingException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) FessSystemException(org.codelibs.fess.exception.FessSystemException) PostConstruct(javax.annotation.PostConstruct)

Example 19 with FessSystemException

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

the class PrunedTag method parse.

public static PrunedTag[] parse(final String value) {
    return split(value, ",").get(stream -> stream.filter(StringUtil::isNotBlank).map(v -> {
        final Pattern pattern = Pattern.compile("(\\w+)(\\[[^\\]]+\\])?(\\.[\\w\\-]+)?(#[\\w\\-]+)?");
        final Matcher matcher = pattern.matcher(v.trim());
        if (matcher.matches()) {
            final PrunedTag tag = new PrunedTag(matcher.group(1));
            if (matcher.group(2) != null) {
                final String attrPair = matcher.group(2).substring(1, matcher.group(2).length() - 1);
                final Matcher equalMatcher = Pattern.compile("([\\w\\-]+)=(\\S+)").matcher(attrPair);
                if (equalMatcher.matches()) {
                    tag.setAttr(equalMatcher.group(1), equalMatcher.group(2));
                }
            }
            if (matcher.group(3) != null) {
                tag.setCss(matcher.group(3).substring(1));
            }
            if (matcher.group(4) != null) {
                tag.setId(matcher.group(4).substring(1));
            }
            return tag;
        }
        throw new FessSystemException("Invalid pruned tag: " + v);
    }).toArray(n -> new PrunedTag[n]));
}
Also used : Objects(java.util.Objects) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) Matcher(java.util.regex.Matcher) StreamUtil(org.codelibs.core.stream.StreamUtil) FessSystemException(org.codelibs.fess.exception.FessSystemException) Node(org.w3c.dom.Node) StringUtil(org.codelibs.core.lang.StringUtil) Pattern(java.util.regex.Pattern) StringUtils(org.apache.commons.lang3.StringUtils) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) FessSystemException(org.codelibs.fess.exception.FessSystemException)

Example 20 with FessSystemException

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

the class PluginHelperTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    pluginHelper = new PluginHelper() {

        protected String[] getRepositories() {
            return new String[] { "plugin/repo1/", "plugin/repo2/" };
        }

        protected String getRepositoryContent(String url) {
            if (url.endsWith("/")) {
                url = url + "index.html";
            }
            if (url.contains("plugin/repo1")) {
                try (InputStream is = ResourceUtil.getResourceAsStream(url)) {
                    return new String(InputStreamUtil.getBytes(is), Constants.UTF_8);
                } catch (Exception e) {
                    return "";
                }
            } else if (url.contains("plugin/repo2")) {
                try (InputStream is = ResourceUtil.getResourceAsStream(url)) {
                    return new String(InputStreamUtil.getBytes(is), Constants.UTF_8);
                } catch (Exception e) {
                    return "";
                }
            } else if (url.contains("plugin/repo.yaml")) {
                try (InputStream is = ResourceUtil.getResourceAsStream(url)) {
                    return new String(InputStreamUtil.getBytes(is), Constants.UTF_8);
                } catch (Exception e) {
                    return "";
                }
            }
            throw new FessSystemException("unknown");
        }

        protected boolean isTargetPluginVersion(final String version) {
            return true;
        }
    };
}
Also used : InputStream(java.io.InputStream) FessSystemException(org.codelibs.fess.exception.FessSystemException) FessSystemException(org.codelibs.fess.exception.FessSystemException)

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