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);
});
}
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);
});
}
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;
}
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);
});
}
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;
}
Aggregations