Search in sources :

Example 1 with PluginHelper

use of org.codelibs.fess.helper.PluginHelper in project fess by codelibs.

the class AdminPluginAction method install.

@Execute
@Secured({ ROLE })
public HtmlResponse install(final InstallForm form) {
    validate(form, messages -> {
    }, () -> asHtml(path_AdminPlugin_AdminPluginInstallpluginJsp));
    verifyToken(() -> asHtml(path_AdminPlugin_AdminPluginInstallpluginJsp));
    try {
        if (UPLOAD.equals(form.id)) {
            if (form.jarFile == null) {
                throwValidationError(messages -> messages.addErrorsPluginFileIsNotFound(GLOBAL, form.id), this::asListHtml);
            }
            if (!form.jarFile.getFileName().endsWith(".jar")) {
                throwValidationError(messages -> messages.addErrorsFileIsNotSupported(GLOBAL, form.jarFile.getFileName()), this::asListHtml);
            }
            final String filename = form.jarFile.getFileName();
            final File tempFile = ComponentUtil.getSystemHelper().createTempFile("tmp-adminplugin-", ".jar");
            try (final InputStream is = form.jarFile.getInputStream();
                final OutputStream os = new FileOutputStream(tempFile)) {
                CopyUtil.copy(is, os);
            } catch (final Exception e) {
                if (tempFile.exists() && !tempFile.delete()) {
                    logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
                }
                logger.debug("Failed to copy {}", filename, e);
                throwValidationError(messages -> messages.addErrorsFailedToInstallPlugin(GLOBAL, filename), this::asListHtml);
            }
            new Thread(() -> {
                try {
                    final PluginHelper pluginHelper = ComponentUtil.getPluginHelper();
                    final Artifact artifact = pluginHelper.getArtifactFromFileName(ArtifactType.UNKNOWN, filename, tempFile.getAbsolutePath());
                    pluginHelper.installArtifact(artifact);
                } catch (final Exception e) {
                    logger.warn("Failed to install {}", filename, e);
                } finally {
                    if (tempFile.exists() && !tempFile.delete()) {
                        logger.warn("Failed to delete {}.", tempFile.getAbsolutePath());
                    }
                }
            }).start();
            saveInfo(messages -> messages.addSuccessInstallPlugin(GLOBAL, form.jarFile.getFileName()));
        } else {
            final Artifact artifact = getArtifactFromInstallForm(form);
            if (artifact == null) {
                throwValidationError(messages -> messages.addErrorsCrudCouldNotFindCrudTable(GLOBAL, form.id), this::asListHtml);
            }
            installArtifact(artifact);
            saveInfo(messages -> messages.addSuccessInstallPlugin(GLOBAL, artifact.getFileName()));
        }
    } catch (final ValidationErrorException e) {
        throw e;
    } catch (final Exception e) {
        throwValidationError(messages -> messages.addErrorsFailedToInstallPlugin(GLOBAL, form.id), this::asListHtml);
    }
    return redirect(getClass());
}
Also used : OutputStream(java.io.OutputStream) Arrays(java.util.Arrays) Secured(org.codelibs.fess.annotation.Secured) Artifact(org.codelibs.fess.helper.PluginHelper.Artifact) PluginHelper(org.codelibs.fess.helper.PluginHelper) FileOutputStream(java.io.FileOutputStream) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) File(java.io.File) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ArtifactType(org.codelibs.fess.helper.PluginHelper.ArtifactType) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) Map(java.util.Map) ValidationErrorException(org.lastaflute.web.validation.exception.ValidationErrorException) Execute(org.lastaflute.web.Execute) CopyUtil(org.codelibs.core.io.CopyUtil) HtmlResponse(org.lastaflute.web.response.HtmlResponse) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) PluginHelper(org.codelibs.fess.helper.PluginHelper) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ValidationErrorException(org.lastaflute.web.validation.exception.ValidationErrorException) File(java.io.File) ValidationErrorException(org.lastaflute.web.validation.exception.ValidationErrorException) Artifact(org.codelibs.fess.helper.PluginHelper.Artifact) Execute(org.lastaflute.web.Execute) Secured(org.codelibs.fess.annotation.Secured)

Example 2 with PluginHelper

use of org.codelibs.fess.helper.PluginHelper in project fess by codelibs.

the class AdminPluginAction method getAllInstalledArtifacts.

public static List<Map<String, String>> getAllInstalledArtifacts() {
    final PluginHelper pluginHelper = ComponentUtil.getPluginHelper();
    final List<Map<String, String>> result = new ArrayList<>();
    for (final PluginHelper.ArtifactType artifactType : PluginHelper.ArtifactType.values()) {
        result.addAll(Arrays.stream(pluginHelper.getInstalledArtifacts(artifactType)).map(AdminPluginAction::beanToMap).collect(Collectors.toList()));
    }
    return result;
}
Also used : PluginHelper(org.codelibs.fess.helper.PluginHelper) ArtifactType(org.codelibs.fess.helper.PluginHelper.ArtifactType) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with PluginHelper

use of org.codelibs.fess.helper.PluginHelper in project fess by codelibs.

the class AdminPluginAction method getAllAvailableArtifacts.

public static List<Map<String, String>> getAllAvailableArtifacts() {
    final PluginHelper pluginHelper = ComponentUtil.getPluginHelper();
    final List<Map<String, String>> result = new ArrayList<>();
    for (final PluginHelper.ArtifactType artifactType : PluginHelper.ArtifactType.values()) {
        result.addAll(Arrays.stream(pluginHelper.getAvailableArtifacts(artifactType)).map(AdminPluginAction::beanToMap).collect(Collectors.toList()));
    }
    return result;
}
Also used : PluginHelper(org.codelibs.fess.helper.PluginHelper) ArtifactType(org.codelibs.fess.helper.PluginHelper.ArtifactType) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 PluginHelper (org.codelibs.fess.helper.PluginHelper)3 ArtifactType (org.codelibs.fess.helper.PluginHelper.ArtifactType)3 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 CopyUtil (org.codelibs.core.io.CopyUtil)1 Secured (org.codelibs.fess.annotation.Secured)1 FessAdminAction (org.codelibs.fess.app.web.base.FessAdminAction)1 Artifact (org.codelibs.fess.helper.PluginHelper.Artifact)1 ComponentUtil (org.codelibs.fess.util.ComponentUtil)1 RenderDataUtil (org.codelibs.fess.util.RenderDataUtil)1