Search in sources :

Example 1 with ShortcutCategoryDTO

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

the class WinePrefixContainerController method deletePrefix.

public void deletePrefix(WinePrefixContainerDTO winePrefix, Consumer<Exception> errorCallback) {
    try {
        fileUtilities.remove(new File(winePrefix.getPath()));
    } catch (IOException e) {
        LOGGER.error("Cannot delete Wine prefix (" + winePrefix.getPath() + ")! Exception: " + e.toString());
        errorCallback.accept(e);
    }
    List<ShortcutCategoryDTO> categories = libraryManager.fetchShortcuts();
    categories.stream().flatMap(shortcutCategoryDTO -> shortcutCategoryDTO.getShortcuts().stream()).forEach(shortcutDTO -> {
        final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
        interactiveScriptSession.eval("include([\"Functions\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
            final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
            shortcutReader.callMember("of", shortcutDTO);
            final String container = (String) shortcutReader.callMember("container");
            if (container.equals(winePrefix.getName())) {
                shortcutManager.deleteShortcut(shortcutDTO);
            }
        }, errorCallback), errorCallback);
    });
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) RegistryWriter(org.phoenicis.win32.registry.RegistryWriter) Logger(org.slf4j.Logger) FileUtilities(org.phoenicis.tools.files.FileUtilities) LoggerFactory(org.slf4j.LoggerFactory) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) HashMap(java.util.HashMap) File(java.io.File) Consumer(java.util.function.Consumer) TerminalOpener(org.phoenicis.tools.system.terminal.TerminalOpener) List(java.util.List) RegistryParameter(org.phoenicis.containers.wine.parameters.RegistryParameter) ShortcutManager(org.phoenicis.library.ShortcutManager) Map(java.util.Map) WinePrefixContainerDTO(org.phoenicis.containers.dto.WinePrefixContainerDTO) OperatingSystemFetcher(org.phoenicis.tools.system.OperatingSystemFetcher) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) LibraryManager(org.phoenicis.library.LibraryManager) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) IOException(java.io.IOException) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) File(java.io.File)

Example 2 with ShortcutCategoryDTO

use of org.phoenicis.library.dto.ShortcutCategoryDTO in project POL-POM-5 by PhoenicisOrg.

the class GenericContainersManager method deleteContainer.

/**
 * {@inheritDoc}
 * @param container
 * @param errorCallback
 */
@Override
public void deleteContainer(ContainerDTO container, Consumer<Exception> errorCallback) {
    try {
        this.fileUtilities.remove(new File(container.getPath()));
    } catch (IOException e) {
        LOGGER.error("Cannot delete container (" + container.getPath() + ")! Exception: " + e.toString());
        errorCallback.accept(e);
    }
    List<ShortcutCategoryDTO> categories = this.libraryManager.fetchShortcuts();
    categories.stream().flatMap(shortcutCategoryDTO -> shortcutCategoryDTO.getShortcuts().stream()).forEach(shortcutDTO -> {
        final InteractiveScriptSession interactiveScriptSession = this.scriptInterpreter.createInteractiveSession();
        interactiveScriptSession.eval("include([\"Engines\", \"" + container.getEngine() + "\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
            final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
            shortcutReader.callMember("of", shortcutDTO);
            final String containerName = (String) shortcutReader.callMember("container");
            if (containerName.equals(container.getName())) {
                this.shortcutManager.deleteShortcut(shortcutDTO);
            }
        }, errorCallback), errorCallback);
    });
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) WinePrefixContainerInputConfiguration(org.phoenicis.containers.wine.configurations.WinePrefixContainerInputConfiguration) ContainerCategoryDTO(org.phoenicis.containers.dto.ContainerCategoryDTO) LoggerFactory(org.slf4j.LoggerFactory) 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) WinePrefixContainerDisplayConfiguration(org.phoenicis.containers.wine.configurations.WinePrefixContainerDisplayConfiguration) Logger(org.slf4j.Logger) FileUtilities(org.phoenicis.tools.files.FileUtilities) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) 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) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) LibraryManager(org.phoenicis.library.LibraryManager) Collections(java.util.Collections) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) IOException(java.io.IOException) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) File(java.io.File) ConfigFile(org.phoenicis.tools.config.ConfigFile)

Example 3 with ShortcutCategoryDTO

use of org.phoenicis.library.dto.ShortcutCategoryDTO in project POL-POM-5 by PhoenicisOrg.

the class LibraryManager method fetchShortcuts.

public List<ShortcutCategoryDTO> fetchShortcuts() {
    final File shortcutDirectoryFile = new File(this.shortcutDirectory);
    if (!shortcutDirectoryFile.exists()) {
        shortcutDirectoryFile.mkdirs();
        return Collections.emptyList();
    }
    final File[] directoryContent = shortcutDirectoryFile.listFiles();
    if (directoryContent == null) {
        return Collections.emptyList();
    }
    HashMap<String, List<ShortcutDTO>> categoryMap = new HashMap<>();
    for (File file : directoryContent) {
        if ("shortcut".equals(FilenameUtils.getExtension(file.getName()))) {
            ShortcutDTO shortcut = fetchShortcutDTO(shortcutDirectoryFile, file);
            String categoryId = shortcut.getInfo().getCategory();
            if (!categoryMap.containsKey(categoryId)) {
                categoryMap.put(categoryId, new ArrayList<>());
            }
            categoryMap.get(categoryId).add(shortcut);
        }
    }
    List<ShortcutCategoryDTO> shortcuts = new ArrayList<>();
    for (Map.Entry<String, List<ShortcutDTO>> entry : categoryMap.entrySet()) {
        entry.getValue().sort(ShortcutDTO.nameComparator());
        ShortcutCategoryDTO category = new ShortcutCategoryDTO.Builder().withId(entry.getKey()).withName(entry.getKey()).withShortcuts(entry.getValue()).build();
        shortcuts.add(tr(category));
    }
    return shortcuts;
}
Also used : ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) File(java.io.File)

Example 4 with ShortcutCategoryDTO

use of org.phoenicis.library.dto.ShortcutCategoryDTO in project phoenicis by PhoenicisOrg.

the class GenericContainersManager method deleteContainer.

/**
 * {@inheritDoc}
 * @param container
 * @param errorCallback
 */
@Override
public void deleteContainer(ContainerDTO container, Consumer<Exception> errorCallback) {
    try {
        this.fileUtilities.remove(new File(container.getPath()));
    } catch (IOException e) {
        LOGGER.error("Cannot delete container (" + container.getPath() + ")! Exception: " + e.toString());
        errorCallback.accept(e);
    }
    List<ShortcutCategoryDTO> categories = this.libraryManager.fetchShortcuts();
    categories.stream().flatMap(shortcutCategoryDTO -> shortcutCategoryDTO.getShortcuts().stream()).forEach(shortcutDTO -> {
        final InteractiveScriptSession interactiveScriptSession = this.scriptInterpreter.createInteractiveSession();
        interactiveScriptSession.eval("include([\"Engines\", \"" + container.getEngine() + "\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
            final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
            shortcutReader.callMember("of", shortcutDTO);
            final String containerName = (String) shortcutReader.callMember("container");
            if (containerName.equals(container.getName())) {
                this.shortcutManager.deleteShortcut(shortcutDTO);
            }
        }, errorCallback), errorCallback);
    });
}
Also used : ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) WinePrefixContainerInputConfiguration(org.phoenicis.containers.wine.configurations.WinePrefixContainerInputConfiguration) ContainerCategoryDTO(org.phoenicis.containers.dto.ContainerCategoryDTO) LoggerFactory(org.slf4j.LoggerFactory) 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) WinePrefixContainerDisplayConfiguration(org.phoenicis.containers.wine.configurations.WinePrefixContainerDisplayConfiguration) Logger(org.slf4j.Logger) FileUtilities(org.phoenicis.tools.files.FileUtilities) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) 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) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) LibraryManager(org.phoenicis.library.LibraryManager) Collections(java.util.Collections) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) IOException(java.io.IOException) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) File(java.io.File) ConfigFile(org.phoenicis.tools.config.ConfigFile)

Example 5 with ShortcutCategoryDTO

use of org.phoenicis.library.dto.ShortcutCategoryDTO in project phoenicis by PhoenicisOrg.

the class LibraryManager method fetchShortcuts.

public List<ShortcutCategoryDTO> fetchShortcuts() {
    final File shortcutDirectoryFile = new File(this.shortcutDirectory);
    if (!shortcutDirectoryFile.exists()) {
        shortcutDirectoryFile.mkdirs();
        return Collections.emptyList();
    }
    final File[] directoryContent = shortcutDirectoryFile.listFiles();
    if (directoryContent == null) {
        return Collections.emptyList();
    }
    HashMap<String, List<ShortcutDTO>> categoryMap = new HashMap<>();
    for (File file : directoryContent) {
        if ("shortcut".equals(FilenameUtils.getExtension(file.getName()))) {
            ShortcutDTO shortcut = fetchShortcutDTO(shortcutDirectoryFile, file);
            String categoryId = shortcut.getInfo().getCategory();
            if (!categoryMap.containsKey(categoryId)) {
                categoryMap.put(categoryId, new ArrayList<>());
            }
            categoryMap.get(categoryId).add(shortcut);
        }
    }
    List<ShortcutCategoryDTO> shortcuts = new ArrayList<>();
    for (Map.Entry<String, List<ShortcutDTO>> entry : categoryMap.entrySet()) {
        entry.getValue().sort(ShortcutDTO.nameComparator());
        ShortcutCategoryDTO category = new ShortcutCategoryDTO.Builder().withId(entry.getKey()).withName(entry.getKey()).withShortcuts(entry.getValue()).build();
        shortcuts.add(tr(category));
    }
    return shortcuts;
}
Also used : ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) File(java.io.File)

Aggregations

ShortcutCategoryDTO (org.phoenicis.library.dto.ShortcutCategoryDTO)11 File (java.io.File)8 ShortcutDTO (org.phoenicis.library.dto.ShortcutDTO)7 IOException (java.io.IOException)5 List (java.util.List)5 LibraryManager (org.phoenicis.library.LibraryManager)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Map (java.util.Map)4 Consumer (java.util.function.Consumer)4 WinePrefixContainerDTO (org.phoenicis.containers.dto.WinePrefixContainerDTO)4 ShortcutManager (org.phoenicis.library.ShortcutManager)4 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Collectors (java.util.stream.Collectors)3 ScriptObjectMirror (jdk.nashorn.api.scripting.ScriptObjectMirror)3 Safe (org.phoenicis.configuration.security.Safe)3