Search in sources :

Example 1 with ShortcutReader

use of org.phoenicis.library.ShortcutReader in project POL-POM-5 by PlayOnLinux.

the class GenericContainersManager method deleteContainer.

/**
 * {@inheritDoc}
 */
@Override
public void deleteContainer(ContainerDTO container, Consumer<ContainerDTO> onSuccess, Consumer<Exception> onError) {
    try {
        final File containerFile = new File(container.getPath());
        FileUtils.deleteDirectory(containerFile);
    } catch (IOException e) {
        LOGGER.error("Cannot delete container (" + container.getPath() + ")! Exception: " + e.toString());
        onError.accept(e);
    }
    // TODO: better way to get engine ID
    final String engineId = container.getEngine().toLowerCase();
    final List<ShortcutCategoryDTO> categories = this.libraryManager.fetchShortcuts();
    // remove the shortcuts leading to the container
    categories.stream().flatMap(shortcutCategory -> shortcutCategory.getShortcuts().stream()).forEach(shortcut -> {
        final InteractiveScriptSession interactiveScriptSession = this.scriptInterpreter.createInteractiveSession();
        interactiveScriptSession.eval("include(\"engines." + engineId + ".shortcuts.reader\");", result -> {
            final org.graalvm.polyglot.Value shortcutReaderClass = (org.graalvm.polyglot.Value) result;
            final ShortcutReader shortcutReader = shortcutReaderClass.newInstance().as(ShortcutReader.class);
            shortcutReader.of(shortcut);
            final String containerName = shortcutReader.getContainer();
            if (containerName.equals(container.getName())) {
                this.shortcutManager.deleteShortcut(shortcut);
            }
        }, onError);
    });
    onSuccess.accept(container);
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) ContainerCategoryDTO(org.phoenicis.containers.dto.ContainerCategoryDTO) LoggerFactory(org.slf4j.LoggerFactory) ShortcutReader(org.phoenicis.library.ShortcutReader) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) Map(java.util.Map) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ContainerDTO(org.phoenicis.containers.dto.ContainerDTO) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession) Consumer(java.util.function.Consumer) List(java.util.List) ShortcutManager(org.phoenicis.library.ShortcutManager) ConfigFile(org.phoenicis.tools.config.ConfigFile) Safe(org.phoenicis.configuration.security.Safe) CompatibleConfigFileFormatFactory(org.phoenicis.tools.config.CompatibleConfigFileFormatFactory) CollectionUtils(org.springframework.util.CollectionUtils) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) LibraryManager(org.phoenicis.library.LibraryManager) Collections(java.util.Collections) IOException(java.io.IOException) ShortcutReader(org.phoenicis.library.ShortcutReader) Value(org.springframework.beans.factory.annotation.Value) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) InteractiveScriptSession(org.phoenicis.scripts.session.InteractiveScriptSession) File(java.io.File) ConfigFile(org.phoenicis.tools.config.ConfigFile)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 FileUtils (org.apache.commons.io.FileUtils)1 Safe (org.phoenicis.configuration.security.Safe)1 ContainerCategoryDTO (org.phoenicis.containers.dto.ContainerCategoryDTO)1 ContainerDTO (org.phoenicis.containers.dto.ContainerDTO)1 WinePrefixContainerDTO (org.phoenicis.containers.dto.WinePrefixContainerDTO)1 LibraryManager (org.phoenicis.library.LibraryManager)1 ShortcutManager (org.phoenicis.library.ShortcutManager)1 ShortcutReader (org.phoenicis.library.ShortcutReader)1 ShortcutCategoryDTO (org.phoenicis.library.dto.ShortcutCategoryDTO)1 ShortcutDTO (org.phoenicis.library.dto.ShortcutDTO)1