Search in sources :

Example 1 with SearchException

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

the class SidifyMainContoller method doSearch.

private void doSearch(String searchCriteria2) {
    stopPlay();
    songs.clear();
    try {
        String criteria = searchCriteria2;
        Integer period = searchPeriod.getSelectionModel().getSelectedItem().getDays();
        if (period > -1 && criteria.length() == 0) {
            criteria = "***";
        } else if (StringUtils.isEmpty(criteria) && period.equals(-1)) {
            GenericMessageDialogController.withErrorProps("Oops", "Please enter valid searchcriterias").showAndWait();
            return;
        }
        List<PlaylistEntry> items = SearchService.getInstance().search2(criteria, criteria, "***", "***", "***", "***", "***", "n", "n", "N", "N", "N", "N", "N", "N", "Y", "N", "N", "Y", period).stream().map(item -> {
            PlaylistEntry entry = new PlaylistEntry(item.getId(), item.getCategory(), null, item.getName());
            entry.setGroup(item.getGroup());
            if (item.getYear() != null) {
                entry.setYear(String.valueOf(item.getYear()));
            }
            return entry;
        }).collect(Collectors.toList());
        Comparator<PlaylistEntry> nameComp = (item1, item2) -> item1.getName().compareToIgnoreCase(item2.getName());
        Collections.sort(items, nameComp);
        for (PlaylistEntry entry : items) {
            songs.add(entry);
        }
        songlist.setItems(songs);
        playListService.addTmpPlaylist(items);
    } catch (SearchException se) {
        GenericMessageDialogController.withErrorProps("Sidify", "Please refine search!").showAndWait();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) EventHandler(javafx.event.EventHandler) Support.isOffline(se.light.assembly64.Support.isOffline) ListCell(javafx.scene.control.ListCell) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) PathService(se.light.assembly64.service.PathService) StringUtils(org.apache.commons.lang3.StringUtils) ContentEntryInfo(se.light.assembly64.model.ContentEntryInfo) CachedImageService(se.light.assembly64.service.CachedImageService) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ContextMenu(javafx.scene.control.ContextMenu) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) ContentEntry(se.light.assembly64.model.ContentEntry) Pane(javafx.scene.layout.Pane) TextField(javafx.scene.control.TextField) PlaylistEntryMenuItem(se.light.assembly64.model.PlaylistEntryMenuItem) MenuItem(javafx.scene.control.MenuItem) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) SidTune(libsidplay.sidtune.SidTune) SidFileInfo(se.light.assembly64.model.SidFileInfo) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) SearchException(se.light.assembly64.model.SearchException) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) List(java.util.List) DataFormat(javafx.scene.input.DataFormat) PlaylistMenuItem(se.light.assembly64.model.PlaylistMenuItem) AnchorPane(javafx.scene.layout.AnchorPane) ObservableList(javafx.collections.ObservableList) ClipboardContent(javafx.scene.input.ClipboardContent) ReturningTask(se.light.assembly64.model.ReturningTask) MouseButton(javafx.scene.input.MouseButton) ListView(javafx.scene.control.ListView) PlaylistEntry(se.light.assembly64.model.PlaylistEntry) MouseEvent(javafx.scene.input.MouseEvent) SearchService(se.light.assembly64.service.SearchService) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FXCollections(javafx.collections.FXCollections) PoisonPill(se.light.assembly64.model.PoisonPill) PlaylistInfo(se.light.assembly64.model.PlaylistInfo) GlobalRepoService(se.light.assembly64.service.GlobalRepoService) TransferMode(javafx.scene.input.TransferMode) ArrayList(java.util.ArrayList) TableColumn(javafx.scene.control.TableColumn) Support.isSearchActive(se.light.assembly64.Support.isSearchActive) Dragboard(javafx.scene.input.Dragboard) Slider(javafx.scene.control.Slider) GuiUtils(se.light.assembly64.util.GuiUtils) Support(se.light.assembly64.Support) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) MetadataService(se.light.assembly64.fx.mdresolve.MetadataService) DownloadArtifactsService(se.light.assembly64.service.DownloadArtifactsService) PlaylistService(se.light.assembly64.service.PlaylistService) BaseGuiController(se.light.assembly64.model.BaseGuiController) Analytics(se.light.assembly64.Analytics) KeyCode(javafx.scene.input.KeyCode) Logger(org.slf4j.Logger) Label(javafx.scene.control.Label) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) TargetAndPath(se.light.assembly64.model.TargetAndPath) TableRow(javafx.scene.control.TableRow) ContentEntryInfoMenuItem(se.light.assembly64.model.ContentEntryInfoMenuItem) Support.resolveFilename(se.light.assembly64.Support.resolveFilename) Support.setSearchActive(se.light.assembly64.Support.setSearchActive) SongNotAvailableException(se.light.assembly64.model.SongNotAvailableException) Support.isPlaylistMine(se.light.assembly64.Support.isPlaylistMine) File(java.io.File) ChoiceBox(javafx.scene.control.ChoiceBox) Menu(javafx.scene.control.Menu) SIDPlayerService(se.light.assembly64.service.SIDPlayerService) TimeUnit(java.util.concurrent.TimeUnit) ActionEvent(javafx.event.ActionEvent) SpecifyFileIdException(se.light.assembly64.model.SpecifyFileIdException) SelectionMode(javafx.scene.control.SelectionMode) Stage(javafx.stage.Stage) ImageView(javafx.scene.image.ImageView) LocalDBService(se.light.assembly64.service.LocalDBService) ObservableValue(javafx.beans.value.ObservableValue) SEARCH_PERIOD(se.light.assembly64.Support.SEARCH_PERIOD) Comparator(java.util.Comparator) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) Image(javafx.scene.image.Image) SearchException(se.light.assembly64.model.SearchException) PlaylistEntry(se.light.assembly64.model.PlaylistEntry)

Example 2 with SearchException

use of se.light.assembly64.model.SearchException 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 3 with SearchException

use of se.light.assembly64.model.SearchException 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)

Aggregations

List (java.util.List)2 Label (javafx.scene.control.Label)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 Random (java.util.Random)1 Set (java.util.Set)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Platform (javafx.application.Platform)1 ChangeListener (javafx.beans.value.ChangeListener)1 ObservableValue (javafx.beans.value.ObservableValue)1 FXCollections (javafx.collections.FXCollections)1