Package org.socialmusicdiscovery.server.api.management.mediaimport

Examples of org.socialmusicdiscovery.server.api.management.mediaimport.MediaImportStatus


    public MediaImportStatus getModuleStatus(String module) {
        synchronized (RUNNING_MODULES) {
            ProcessState state = runningModules.get(module);
            if (state != null) {
                if (state.phase == ProcessState.Phase.EXECUTING) {
                    return new MediaImportStatus(state.module.getId(), state.currentDescription, state.currentNo, state.totalNo, 1L, 1L + postProcessors.size(), MediaImportStatus.Status.Running);
                } else if (state.phase == ProcessState.Phase.POSTPROCESSING) {
                    ProcessState postProcessState = runningModules.get(state.currentPostProcessingModule);
                    if (abortingModules.containsKey(module)) {
                        return new MediaImportStatus(postProcessState.module.getId(), postProcessState.currentDescription, postProcessState.currentNo, postProcessState.totalNo, 1L + state.currentPostProcessingModuleNo, 1L + postProcessors.size(), MediaImportStatus.Status.Aborting);
                    } else {
                        return new MediaImportStatus(postProcessState.module.getId(), postProcessState.currentDescription, postProcessState.currentNo, postProcessState.totalNo, 1L + state.currentPostProcessingModuleNo, 1L + postProcessors.size(), MediaImportStatus.Status.Running);
                    }
                }
            } else {
                if (failedModules.containsKey(module)) {
                    ProcessState failedState = failedModules.get(module);
                    return new MediaImportStatus(failedState.module.getId(), failedState.currentDescription, failedState.currentNo, failedState.totalNo, 1L + failedState.currentPostProcessingModuleNo, 1L + postProcessors.size(), MediaImportStatus.Status.Failed);
                } else if (finishedModules.containsKey(module)) {
                    ProcessState finishedState = finishedModules.get(module);
                    return new MediaImportStatus(finishedState.module.getId(), finishedState.currentDescription, finishedState.currentNo, finishedState.totalNo, 1L + postProcessors.size(), 1L + postProcessors.size(), MediaImportStatus.Status.FinishedOk);
                } else {
                    return new MediaImportStatus(module, "", 0L, 0L, 0L, 1L + postProcessors.size(), MediaImportStatus.Status.FinishedOk);
                }
            }
        }
        return null;
    }
View Full Code Here


        // Set focus to search field
        searchTextInput.requestFocus();

        // Check if an import is in progress and refresh the progress bar if it is
        MediaImportStatus status = Client.create(config).resource(HOSTURL + "/mediaimportmodules/" + selectedImporterButton.getSelectedItem()).accept(MediaType.APPLICATION_JSON).get(MediaImportStatus.class);
        if (status != null) {
            startImportProgressBar();
        }

        // Setup listeners for Import/Abort button
        importButton.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                if (importTask != null) {
                    abortImport(selectedImporterButton.getSelectedItem().toString());
                } else {
                    startImport(selectedImporterButton.getSelectedItem().toString());
                }
            }
        });

        // Setup listeners for close button
        closeButton.getButtonPressListeners().add(new ButtonPressListener() {
             @Override
             public void buttonPressed(Button button) {
                 getWindow().close();
              }
        });

        // When search button is clicked, we want to search for both artists, releases and works
        searchButton.getButtonPressListeners().add(new ButtonPressListener() {
            @Override
            public void buttonPressed(Button button) {
                searchArtists(searchTextInput.getText(), null, null);
                searchReleases(searchTextInput.getText(), null, null);
                searchWorks(searchTextInput.getText(), null, null);
            }
        });

        // When search field is changed, we want to search for both artists, releases and works
        searchTextInput.getTextInputContentListeners().add(new TextInputContentListener.Adapter() {
            @Override
            public void textChanged(TextInput textInput) {
                if (textInput.getText() != null && textInput.getText().length() > 2) {
                    searchArtists(searchTextInput.getText(), null, null);
                    searchReleases(searchTextInput.getText(), null, null);
                    searchWorks(searchTextInput.getText(), null, null);
                }
            }
        });

        // Selection changes in release results should trigger refresh of artists and works
        releaseResultsTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener.Adapter() {
            @Override
            public void selectedRangesChanged(TableView tableView, Sequence<Span> spanSequence) {
                Release release = (Release) tableView.getSelectedRow();
                if(release!=null) {
                    searchTextInput.setText("");
                    searchArtists(null, null, release.getId());
                    searchWorks(null, null, release.getId());
                }
            }
        });

        // Selection changes in artist results should trigger refresh of releases and works
        artistResultsTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener.Adapter() {
            @Override
            public void selectedRangesChanged(TableView tableView, Sequence<Span> spanSequence) {
                Artist artist = (Artist) tableView.getSelectedRow();
                if(artist!=null) {
                    searchTextInput.setText("");
                    searchReleases(null, artist.getId(), null);
                    searchWorks(null, artist.getId(), null);
                }
            }
        });

        // Selection changes in work results should trigger refresh of artists and releases
        workResultsTableView.getTableViewSelectionListeners().add(new TableViewSelectionListener.Adapter() {
            @Override
            public void selectedRangesChanged(TableView tableView, Sequence<Span> spanSequence) {
                Work work = (Work) tableView.getSelectedRow();
                if(work!=null) {
                    searchTextInput.setText("");
                    searchReleases(null, null, work.getId());
                    searchArtists(null, work.getId(), null);
                }
            }
        });

        // Double click handler for releases
        releaseResultsTableView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener.Adapter() {
            @Override
            public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
                try {
                    if (count == 2) {
                        Release release = (Release) releaseResultsTableView.getSelectedRow();
                        BXMLSerializer wtkxSerializer = new BXMLSerializer();
                        EditReleaseWindow window = (EditReleaseWindow) wtkxSerializer.readObject(getClass().getResource("EditReleaseWindow.bxml"),new Resources(resources,EditReleaseWindow.class.getName()));
                        window.open(getDisplay(), getWindow(), release);
                        return true;
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (SerializationException e) {
                    throw new RuntimeException(e);
                }
                return false;
            }
        });
        selectedImporterButton.getListButtonSelectionListeners().add(new ListButtonSelectionListener.Adapter() {
            @Override
            public void selectedIndexChanged(ListButton listButton, int i) {
                MediaImportStatus status = Client.create(config).resource(HOSTURL + "/mediaimportmodules/" + selectedImporterButton.getSelectedItem()).accept(MediaType.APPLICATION_JSON).get(MediaImportStatus.class);
                if (status != null) {
                    startImportProgressBar();
                }
            }
        });
View Full Code Here

                        selectedImporterButton.setEnabled(false);
                        importButton.setButtonData(resources.get("abortButton"));
                        importProgressMeter.setPercentage(0);
                        importProgressMeter.setText("");
                        importProgressMeter.setVisible(true);
                        MediaImportStatus status = Client.create(config).resource(HOSTURL + "/mediaimportmodules/" + selectedImporterButton.getSelectedItem().toString()).accept(MediaType.APPLICATION_JSON).get(MediaImportStatus.class);
                        while (status != null && (status.getStatus()==MediaImportStatus.Status.Running || status.getStatus()==MediaImportStatus.Status.Aborting)) {
                            if (status.getTotalNumber() > 0) {
                                importProgressMeter.setPercentage((double) status.getCurrentNumber() / status.getTotalNumber());
                                importProgressMeter.setText(status.getCurrentNumber() + " of " + status.getTotalNumber());
                            }
                            importProgressDescription.setText(status.getCurrentDescription());
                            if(status.getStatus()==MediaImportStatus.Status.Aborting) {
                                importButton.setButtonData(resources.get("abortingButton"));
                                importButton.setEnabled(false);
                            }
                            try {
                                Thread.sleep(1000);
                            } catch (InterruptedException e) {
                                throw new TaskExecutionException(e);
                            }
                            status = Client.create(config).resource(HOSTURL + "/mediaimportmodules/" + selectedImporterButton.getSelectedItem().toString()).accept(MediaType.APPLICATION_JSON).get(MediaImportStatus.class);
                        }
                        if(status != null && status.getStatus()==MediaImportStatus.Status.Failed) {
                            if (status.getTotalNumber() > 0) {
                                importProgressMeter.setPercentage((double) status.getCurrentNumber() / status.getTotalNumber());
                                importProgressMeter.setText(status.getCurrentNumber() + " of " + status.getTotalNumber());
                            }
                            importProgressDescription.setText("Failed or aborted");
                        }
                    } catch (UniformInterfaceException e) {
                        if (e.getResponse().getStatus() != 204) {
                            throw e;
                        }
                    }
                    return null;
                }
            };
            importTask.execute(new TaskAdapter<Void>(new TaskListener<Void>() {
                @Override
                public void taskExecuted(Task<Void> task) {
                    MediaImportStatus status = Client.create(config).resource(HOSTURL + "/mediaimportmodules/" + selectedImporterButton.getSelectedItem().toString()).accept(MediaType.APPLICATION_JSON).get(MediaImportStatus.class);
                    importProgressMeter.setPercentage(0);
                    if(status!=null && status.getTotalNumber()>0 && status.getStatus()!=MediaImportStatus.Status.FinishedOk) {
                        importProgressMeter.setText(status.getCurrentNumber() + " of " + status.getTotalNumber());
                        importProgressDescription.setText("Failed or aborted");
                    }else {
                        importProgressMeter.setText("");
                        importProgressMeter.setVisible(false);
                        if(status!=null && status.getTotalNumber()>0) {
                            importProgressDescription.setText("Finished");
                        }else {
                            importProgressDescription.setText("");
                        }
                    }
View Full Code Here

TOP

Related Classes of org.socialmusicdiscovery.server.api.management.mediaimport.MediaImportStatus

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.