Search in sources :

Example 11 with ShortcutCategoryDTO

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

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()).withIcon(// choose one category icon
        entry.getValue().get(0).getCategoryIcon()).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