Search in sources :

Example 6 with SearchResultItem

use of se.light.assembly64.model.SearchResultItem in project assembly64fx by freabemania.

the class InstallationService method downloadLatestFromDatabase.

public void downloadLatestFromDatabase() {
    if (controller != null) {
        controller.getStage().show();
        return;
    }
    long nofDays = 0;
    File latestDateFile = new File(Support.removeEndingSlash(userService.getPrimaryInstallation().getPath()) + "/.db/latest");
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
    try {
        if (!latestDateFile.exists()) {
            nofDays = LocalDBService.getInstance().getMagAgeIndexAsLong();
            FileUtils.writeStringToFile(latestDateFile, formatter.format(LocalDate.now()));
        } else {
            nofDays = ChronoUnit.DAYS.between(LocalDate.parse(FileUtils.readFileToString(latestDateFile).substring(0, 8), formatter), LocalDate.now());
            // just to be safe
            nofDays++;
        }
    } catch (Exception e) {
        nofDays = MAX_CONTENT_AGE_DAYS;
        LOGGER.error("Error creating file", e);
    }
    String location = Support.removeEndingSlash(userService.getPrimaryInstallation().getPath()) + "/Misc/Latest-from-db";
    try {
        LOGGER.info("Fetching latest " + (int) nofDays + " days");
        List<SearchResultItem> items = SearchService.getInstance().search2("***", "***", "***", "***", "***", "***", "***", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "n", (int) nofDays);
        CancelableTask cancelTask = CancelableTask.of();
        controller = GuiUtils.showDialogOwnerNoWait("progressBarDbUpdate.fxml", "Progress", true, NullWindowOwner.of(), new Object[] { items.size(), cancelTask, location, "Latest content from database installed to " + location });
        ReturningTask<Void> task = () -> {
            for (SearchResultItem it : items) {
                if (cancelTask.isCancelled()) {
                    break;
                }
                List<ContentEntry> searchItems = SearchService.getInstance().getSearchItems(it.getId(), it.getCategory()).getContentEntry();
                try {
                    for (ContentEntry entry : searchItems) {
                        if (cancelTask.isCancelled()) {
                            break;
                        }
                        try {
                            DownloadArtifactsService.getInstance().downloadItem(it.getId(), it.getCategory(), entry.getId(), it.getName(), entry.getName(), it.getCategoryShortName(), FILE_ACTION.DOWNLOAD, location);
                        } catch (Exception e) {
                            LOGGER.error("Error during contentdownload {}", entry.getId());
                        }
                    }
                } catch (Exception e) {
                    LOGGER.error("Error during download {}", it.getId(), e);
                }
                controller.setProgressLabel("Installing " + it.getName());
                controller.increaseProgress();
            }
            controller.progressDone();
            Platform.runLater(() -> {
                controller.getStage().show();
                controller = null;
            });
            return null;
        };
        ExecutorUtil.executeAsyncWithRetry(task);
    } catch (Exception e) {
        LOGGER.error("Error during search of new items", e);
    }
}
Also used : SearchResultItem(se.light.assembly64.model.SearchResultItem) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) IOException(java.io.IOException) ContentEntry(se.light.assembly64.model.ContentEntry) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) DateTimeFormatter(java.time.format.DateTimeFormatter) CancelableTask(se.light.assembly64.model.CancelableTask)

Example 7 with SearchResultItem

use of se.light.assembly64.model.SearchResultItem in project assembly64fx by freabemania.

the class SearchService method search2.

public List<SearchResultItem> search2(String name, String group, String year, String handle, String event, String rating, String category, String searchFromStart, String d64, String t64, String d71, String d81, String prg, String tap, String crt, String sid, String bin, String g64, String orSearch, int days) throws SearchException {
    Response response = null;
    try {
        boolean anyCat = d64.equals("Y") || t64.equals("Y") || d71.equals("Y") || d81.equals("Y") || prg.equals("Y") || tap.equals("Y") || crt.equals("Y") || sid.equals("Y") || bin.equals("Y") || g64.equals("Y");
        boolean anyField = !name.equals("***") || !group.equals("***") || !handle.equals("***") || !event.equals("***");
        if (!(days > -1 || anyField) && anyCat) {
            GenericMessageDialogController.withErrorProps("Oops", "Please enter valid searchcriterias").showAndWait();
            return Collections.<SearchResultItem>emptyList();
        }
        response = getClient().target(getBackendServer()).path("/leet/search/get/" + urlEncode(name) + "/" + urlEncode(group) + "/" + urlEncode(year) + "/" + urlEncode(handle) + "/" + urlEncode(event) + "/" + urlEncode(rating) + "/" + urlEncode(category) + "/" + searchFromStart + "/" + d64 + "/" + t64 + "/" + d71 + "/" + d81 + "/" + prg + "/" + tap + "/" + crt + "/" + sid + "/" + bin + "/" + g64 + "/" + orSearch + "/" + Integer.toString(days)).request().header("Content-Type", "application/json").header("email", getSessionInfo().getEmail()).header("token", getSessionInfo().getToken()).get();
        if (response.getStatus() == 200) {
            return response.readEntity(new GenericType<List<SearchResultItem>>() {
            });
        } else if (response.getStatus() == 425) {
            throw SearchException.ofRefineSearch();
        } else if (response.getStatus() == 424) {
            throw SearchException.ofSearchesExceeded();
        } else {
            throw new RuntimeException("Unknown");
        }
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) SearchResultItem(se.light.assembly64.model.SearchResultItem) List(java.util.List)

Example 8 with SearchResultItem

use of se.light.assembly64.model.SearchResultItem in project assembly64fx by freabemania.

the class SearchController method performSearch.

private void performSearch() {
    data.clear();
    String name = nameInput.getText().length() == 0 ? "***" : nameInput.getText();
    String group = groupInput.getText().length() == 0 ? "***" : groupInput.getText();
    String year = yearInput.getSelectionModel().getSelectedItem().equals(ALL) ? "***" : yearInput.getSelectionModel().getSelectedItem();
    String handle = handleInput.getText().length() == 0 ? "***" : handleInput.getText();
    String event = eventInput.getText().length() == 0 ? "***" : eventInput.getText();
    String rating = ratingInput.getSelectionModel().getSelectedItem().equals(ALL) ? "***" : ratingInput.getSelectionModel().getSelectedItem();
    String categoryVal = categoryInput.getSelectionModel().getSelectedItem();
    String category = categoryVal.equals(ALL) ? "***" : String.valueOf(mappingService.getCategoryMappingByDescr(categoryVal).getId());
    String searchD64 = d64.isSelected() ? "Y" : "N";
    String searchT64 = t64.isSelected() ? "Y" : "N";
    String searchD81 = d81.isSelected() ? "Y" : "N";
    String searchD71 = d71.isSelected() ? "Y" : "N";
    String searchPrg = prg.isSelected() ? "Y" : "N";
    String searchTap = tap.isSelected() ? "Y" : "N";
    String searchCrt = crt.isSelected() ? "Y" : "N";
    String searchSid = sid.isSelected() ? "Y" : "N";
    String searchBin = bin.isSelected() ? "Y" : "N";
    String searchG64 = g64.isSelected() ? "Y" : "N";
    int period = searchPeriod.getSelectionModel().getSelectedItem().getDays();
    String fromStart = searchFromStartOfString.isSelected() ? "y" : "n";
    try {
        if (period > 60) {
            if (name.equals("***") && group.equals("***") && handle.equals("***") && event.equals("***")) {
                return;
            }
        }
        List<SearchResultItem> searchResult = SearchService.getInstance().search2(name, group, year, handle, event, rating, category, fromStart, searchD64, searchT64, searchD71, searchD81, searchPrg, searchTap, searchCrt, searchSid, searchBin, searchG64, "n", period);
        if (searchResult.size() == 0) {
            table.setPlaceholder(new Label("No content found for the given searchcriteria"));
        } else {
            table.setPlaceholder(new Label(""));
        }
        for (SearchResultItem entry : searchResult) {
            // entry.setMappingHelper(mappingService);
            data.add(entry);
        }
        table.setItems(data);
        GuiUtils.selectFirstInList(table);
        Analytics.sendEvent("search", "performsearch");
    } catch (SearchException se) {
        if (se.isRefineSearch()) {
            Analytics.sendEvent("search", "refine");
            GenericMessageDialogController.withInfoProps("Ooops...", "Search returned too many results").showAndWait();
        } else if (se.isSearchesExceeded()) {
            Analytics.sendEvent("search", "exceed");
            GenericMessageDialogController.withInfoProps("Max searches reached for", "the free version of Assembly64").showAndWait();
        }
    }
}
Also used : SearchResultItem(se.light.assembly64.model.SearchResultItem) Label(javafx.scene.control.Label) SearchException(se.light.assembly64.model.SearchException)

Example 9 with SearchResultItem

use of se.light.assembly64.model.SearchResultItem in project assembly64fx by freabemania.

the class SearchController method downloadFiles.

private void downloadFiles(List<SearchResultItem> selectedItems, String downloadPath) {
    if (selectedItems.size() > MAX_DOWNLOADSPAN) {
        GenericMessageDialogController.withErrorProps("Ooops...", "Please narrow downloadspan").showAndWait();
        return;
    }
    CancelableTask cancelTask = CancelableTask.of();
    ProgressDBController controller = GuiUtils.showDialogOwnerNoWait("progressBarDbUpdate.fxml", "Progress", true, getStage(), new Object[] { selectedItems.size(), cancelTask, downloadPath, "Files were installed to " + downloadPath });
    ReturningTask<Void> task = () -> {
        int failureCtr = 0;
        for (SearchResultItem item : selectedItems) {
            if (cancelTask.isCancelled()) {
                break;
            }
            controller.setProgressLabel("Installing " + item.getName());
            controller.increaseProgress();
            boolean res = downloadEntryAndSubItems(item, downloadPath);
            if (!res) {
                failureCtr++;
            }
        }
        if (failureCtr == 0) {
            controller.progressDone();
        } else {
            controller.progressDone(failureCtr + " of " + selectedItems.size() + " could not be installed to " + downloadPath);
        }
        return null;
    };
    ExecutorUtil.executeAsyncWithRetry(task, 3);
}
Also used : SearchResultItem(se.light.assembly64.model.SearchResultItem) CancelableTask(se.light.assembly64.model.CancelableTask)

Example 10 with SearchResultItem

use of se.light.assembly64.model.SearchResultItem in project assembly64fx by freabemania.

the class ShowInstalledContentController method init.

public void init(String base) {
    File releaseLog = new File(base + "/releaselog.json");
    releaseList.setPlaceholder(new Label("No content"));
    name.setCellValueFactory(new PropertyValueFactory<ReleaseInfo, String>("name"));
    group.setCellValueFactory(new PropertyValueFactory<ReleaseInfo, String>("group"));
    year.setCellValueFactory(new PropertyValueFactory<ReleaseInfo, String>("year"));
    newReleases = Support.readList(ReleaseInfo.class, releaseLog);
    releaseList.setItems(items);
    releaseList.getSelectionModel().select(0);
    releaseList.getFocusModel().focus(0);
    releaseList.setOnMousePressed(event -> {
        ReleaseInfo selectedItem = releaseList.getSelectionModel().getSelectedItem();
        String path = base + "/" + selectedItem.getPath();
        if (event.getButton() == MouseButton.SECONDARY || event.isControlDown()) {
            final ContextMenu contextMenu = new ContextMenu();
            MenuItem infoItem = new MenuItem("Open folder");
            infoItem.setOnAction((ActionEvent event2) -> {
                PlatformInfoService.getInstance().openFolder(path);
            });
            contextMenu.getItems().add(infoItem);
            releaseList.setContextMenu(contextMenu);
        } else if (event.getClickCount() == 2) {
            File target = new File(path);
            SearchResultItem searchResult = ReleaseInfo.toSearchResult(selectedItem);
            if (target.exists()) {
                List<ContentEntry> cEntries = FileUtils.listFiles(new File(base + "/" + selectedItem.getPath()), null, true).stream().map(item -> new ContentEntry(item.getPath(), item.getName())).collect(Collectors.toList());
                ContentEntryInfo searchItems = new ContentEntryInfo(cEntries, false);
                GuiUtils.showDialogBare("searchViewFiles.fxml", "Files and info for '" + selectedItem.getName() + "'", searchResult, searchItems, false);
            } else {
                GenericMessageDialogController.withErrorProps("Oopss...", "Was not able to find the directory").showAndWait();
            }
        }
    });
    populateList();
}
Also used : ActionEvent(javafx.event.ActionEvent) ContentEntry(se.light.assembly64.model.ContentEntry) Label(javafx.scene.control.Label) SearchResultItem(se.light.assembly64.model.SearchResultItem) ReleaseInfo(se.light.assembly64.model.ReleaseInfo) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) List(java.util.List) ObservableList(javafx.collections.ObservableList) File(java.io.File) ContentEntryInfo(se.light.assembly64.model.ContentEntryInfo)

Aggregations

SearchResultItem (se.light.assembly64.model.SearchResultItem)8 ContentEntry (se.light.assembly64.model.ContentEntry)4 File (java.io.File)3 List (java.util.List)3 Label (javafx.scene.control.Label)3 SearchException (se.light.assembly64.model.SearchException)3 ArrayList (java.util.ArrayList)2 ActionEvent (javafx.event.ActionEvent)2 ContextMenu (javafx.scene.control.ContextMenu)2 MenuItem (javafx.scene.control.MenuItem)2 MouseEvent (javafx.scene.input.MouseEvent)2 CancelableTask (se.light.assembly64.model.CancelableTask)2 ContentEntryInfo (se.light.assembly64.model.ContentEntryInfo)2 IOException (java.io.IOException)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ObservableValue (javafx.beans.value.ObservableValue)1 ObservableList (javafx.collections.ObservableList)1 Image (javafx.scene.image.Image)1 DirectoryChooser (javafx.stage.DirectoryChooser)1 Response (javax.ws.rs.core.Response)1