@Test public void testDoSaveDiskResourceQueryTemplate_Case2() { DataSearchPresenterImpl spy = spy(dsPresenter); SaveDiskResourceQueryClickedEvent mockEvent = mock(SaveDiskResourceQueryClickedEvent.class); DiskResourceQueryTemplate mockTemplate = mock(DiskResourceQueryTemplate.class); when(mockEvent.getQueryTemplate()).thenReturn(mockTemplate); when(mockTemplate.getName()).thenReturn(""); when(mockEvent.getQueryTemplate()).thenReturn(mockTemplate); spy.onSaveDiskResourceQueryClicked(mockEvent); verify(spy).onSaveDiskResourceQueryClicked(eq(mockEvent)); verifyZeroInteractions(searchService); verifyNoMoreInteractions(spy); }
@Override public void onSaveDiskResourceQueryClicked(final SaveDiskResourceQueryClickedEvent event) { final DiskResourceQueryTemplate queryTemplate = event.getQueryTemplate(); if (Strings.isNullOrEmpty(queryTemplate.getName())) { LOG.fine("TODO: User tried to save query with no name, cannot save. Ripple error back to view"); return; } else { final Set<String> uniqueNames = getUniqueNames(getQueryTemplates()); if (uniqueNames.size() == getQueryTemplates().size()) { if (uniqueNames.contains(queryTemplate.getName())) { for (DiskResourceQueryTemplate hasId : ImmutableList.copyOf(getQueryTemplates())) { String inListName = hasId.getName(); if (queryTemplate.getName().equalsIgnoreCase(inListName)) { getQueryTemplates().remove(hasId); break; } } } } } final ImmutableList<DiskResourceQueryTemplate> toBeSaved = ImmutableList.copyOf(Iterables.concat(queryTemplates, Collections.singletonList(queryTemplate))); searchService.saveQueryTemplates(toBeSaved, new AsyncCallback<List<DiskResourceQueryTemplate>>() { @Override public void onFailure(Throwable caught) { announcer.schedule(new ErrorAnnouncementConfig("Unable to save filter.")); } @Override public void onSuccess(List<DiskResourceQueryTemplate> savedTemplates) { queryTemplates.clear(); if (toBeSaved.size() != savedTemplates.size()) { LOG.warning("Saved templates returned from search service facade is a different size than what we submitted."); } queryTemplates.addAll(savedTemplates); List<DiskResourceQueryTemplate> queriesToRemove = Lists.newArrayList(); for (DiskResourceQueryTemplate qt : cleanCopyQueryTemplates) { if (qt.getName().equals(event.getOriginalName())) { queriesToRemove.add(qt); } } setCleanCopyQueryTemplates(searchService.createFrozenList(toBeSaved)); List<DiskResourceQueryTemplate> toUpdate = Lists.newArrayList(); if (templateHasChanged(queryTemplate, cleanCopyQueryTemplates)) { queryTemplate.setDirty(true); for (DiskResourceQueryTemplate qt : getQueryTemplates()) { if (qt.getName().equalsIgnoreCase(queryTemplate.getName())) { toUpdate.add(queryTemplate); } else { toUpdate.add(qt); } } getQueryTemplates().clear(); getQueryTemplates().addAll(toUpdate); } else { toUpdate = Lists.newArrayList(getQueryTemplates()); } fireEvent(new UpdateSavedSearchesEvent(toUpdate, queriesToRemove)); } }); }
DataSearchPresenterImpl implements SearchView.Presenter { @Override public void onSaveDiskResourceQueryClicked(final SaveDiskResourceQueryClickedEvent event) { final DiskResourceQueryTemplate queryTemplate = event.getQueryTemplate(); if (Strings.isNullOrEmpty(queryTemplate.getName())) { LOG.fine("TODO: User tried to save query with no name, cannot save. Ripple error back to view"); return; } else { final Set<String> uniqueNames = getUniqueNames(getQueryTemplates()); if (uniqueNames.size() == getQueryTemplates().size()) { if (uniqueNames.contains(queryTemplate.getName())) { for (DiskResourceQueryTemplate hasId : ImmutableList.copyOf(getQueryTemplates())) { String inListName = hasId.getName(); if (queryTemplate.getName().equalsIgnoreCase(inListName)) { getQueryTemplates().remove(hasId); break; } } } } } final ImmutableList<DiskResourceQueryTemplate> toBeSaved = ImmutableList.copyOf(Iterables.concat(queryTemplates, Collections.singletonList(queryTemplate))); searchService.saveQueryTemplates(toBeSaved, new AsyncCallback<List<DiskResourceQueryTemplate>>() { @Override public void onFailure(Throwable caught) { announcer.schedule(new ErrorAnnouncementConfig("Unable to save filter.")); } @Override public void onSuccess(List<DiskResourceQueryTemplate> savedTemplates) { queryTemplates.clear(); if (toBeSaved.size() != savedTemplates.size()) { LOG.warning("Saved templates returned from search service facade is a different size than what we submitted."); } queryTemplates.addAll(savedTemplates); List<DiskResourceQueryTemplate> queriesToRemove = Lists.newArrayList(); for (DiskResourceQueryTemplate qt : cleanCopyQueryTemplates) { if (qt.getName().equals(event.getOriginalName())) { queriesToRemove.add(qt); } } setCleanCopyQueryTemplates(searchService.createFrozenList(toBeSaved)); List<DiskResourceQueryTemplate> toUpdate = Lists.newArrayList(); if (templateHasChanged(queryTemplate, cleanCopyQueryTemplates)) { queryTemplate.setDirty(true); for (DiskResourceQueryTemplate qt : getQueryTemplates()) { if (qt.getName().equalsIgnoreCase(queryTemplate.getName())) { toUpdate.add(queryTemplate); } else { toUpdate.add(qt); } } getQueryTemplates().clear(); getQueryTemplates().addAll(toUpdate); } else { toUpdate = Lists.newArrayList(getQueryTemplates()); } fireEvent(new UpdateSavedSearchesEvent(toUpdate, queriesToRemove)); } }); } }
DataSearchPresenterImpl implements SearchView.Presenter { @Override public void onSaveDiskResourceQueryClicked(final SaveDiskResourceQueryClickedEvent event) { final DiskResourceQueryTemplate queryTemplate = event.getQueryTemplate(); if (Strings.isNullOrEmpty(queryTemplate.getName())) { LOG.fine("TODO: User tried to save query with no name, cannot save. Ripple error back to view"); return; } else { final Set<String> uniqueNames = getUniqueNames(getQueryTemplates()); if (uniqueNames.size() == getQueryTemplates().size()) { if (uniqueNames.contains(queryTemplate.getName())) { for (DiskResourceQueryTemplate hasId : ImmutableList.copyOf(getQueryTemplates())) { String inListName = hasId.getName(); if (queryTemplate.getName().equalsIgnoreCase(inListName)) { getQueryTemplates().remove(hasId); break; } } } } } final ImmutableList<DiskResourceQueryTemplate> toBeSaved = ImmutableList.copyOf(Iterables.concat(queryTemplates, Collections.singletonList(queryTemplate))); searchService.saveQueryTemplates(toBeSaved, new AsyncCallback<List<DiskResourceQueryTemplate>>() { @Override public void onFailure(Throwable caught) { announcer.schedule(new ErrorAnnouncementConfig("Unable to save filter.")); } @Override public void onSuccess(List<DiskResourceQueryTemplate> savedTemplates) { queryTemplates.clear(); if (toBeSaved.size() != savedTemplates.size()) { LOG.warning("Saved templates returned from search service facade is a different size than what we submitted."); } queryTemplates.addAll(savedTemplates); List<DiskResourceQueryTemplate> queriesToRemove = Lists.newArrayList(); for (DiskResourceQueryTemplate qt : cleanCopyQueryTemplates) { if (qt.getName().equals(event.getOriginalName())) { queriesToRemove.add(qt); } } setCleanCopyQueryTemplates(searchService.createFrozenList(toBeSaved)); List<DiskResourceQueryTemplate> toUpdate = Lists.newArrayList(); if (templateHasChanged(queryTemplate, cleanCopyQueryTemplates)) { queryTemplate.setDirty(true); for (DiskResourceQueryTemplate qt : getQueryTemplates()) { if (qt.getName().equalsIgnoreCase(queryTemplate.getName())) { toUpdate.add(queryTemplate); } else { toUpdate.add(qt); } } getQueryTemplates().clear(); getQueryTemplates().addAll(toUpdate); } else { toUpdate = Lists.newArrayList(getQueryTemplates()); } fireEvent(new UpdateSavedSearchesEvent(toUpdate, queriesToRemove)); } }); } @Inject  DataSearchPresenterImpl(final SearchServiceFacade searchService,
                            final IplantAnnouncer announcer); }
DataSearchPresenterImpl implements SearchView.Presenter { @Override public void onSaveDiskResourceQueryClicked(final SaveDiskResourceQueryClickedEvent event) { final DiskResourceQueryTemplate queryTemplate = event.getQueryTemplate(); if (Strings.isNullOrEmpty(queryTemplate.getName())) { LOG.fine("TODO: User tried to save query with no name, cannot save. Ripple error back to view"); return; } else { final Set<String> uniqueNames = getUniqueNames(getQueryTemplates()); if (uniqueNames.size() == getQueryTemplates().size()) { if (uniqueNames.contains(queryTemplate.getName())) { for (DiskResourceQueryTemplate hasId : ImmutableList.copyOf(getQueryTemplates())) { String inListName = hasId.getName(); if (queryTemplate.getName().equalsIgnoreCase(inListName)) { getQueryTemplates().remove(hasId); break; } } } } } final ImmutableList<DiskResourceQueryTemplate> toBeSaved = ImmutableList.copyOf(Iterables.concat(queryTemplates, Collections.singletonList(queryTemplate))); searchService.saveQueryTemplates(toBeSaved, new AsyncCallback<List<DiskResourceQueryTemplate>>() { @Override public void onFailure(Throwable caught) { announcer.schedule(new ErrorAnnouncementConfig("Unable to save filter.")); } @Override public void onSuccess(List<DiskResourceQueryTemplate> savedTemplates) { queryTemplates.clear(); if (toBeSaved.size() != savedTemplates.size()) { LOG.warning("Saved templates returned from search service facade is a different size than what we submitted."); } queryTemplates.addAll(savedTemplates); List<DiskResourceQueryTemplate> queriesToRemove = Lists.newArrayList(); for (DiskResourceQueryTemplate qt : cleanCopyQueryTemplates) { if (qt.getName().equals(event.getOriginalName())) { queriesToRemove.add(qt); } } setCleanCopyQueryTemplates(searchService.createFrozenList(toBeSaved)); List<DiskResourceQueryTemplate> toUpdate = Lists.newArrayList(); if (templateHasChanged(queryTemplate, cleanCopyQueryTemplates)) { queryTemplate.setDirty(true); for (DiskResourceQueryTemplate qt : getQueryTemplates()) { if (qt.getName().equalsIgnoreCase(queryTemplate.getName())) { toUpdate.add(queryTemplate); } else { toUpdate.add(qt); } } getQueryTemplates().clear(); getQueryTemplates().addAll(toUpdate); } else { toUpdate = Lists.newArrayList(getQueryTemplates()); } fireEvent(new UpdateSavedSearchesEvent(toUpdate, queriesToRemove)); } }); } @Inject  DataSearchPresenterImpl(final SearchServiceFacade searchService,
                            final IplantAnnouncer announcer); @Override HandlerRegistration addSavedSearchDeletedEventHandler(SavedSearchDeletedEvent.SavedSearchDeletedEventHandler handler); @Override HandlerRegistration addUpdateSavedSearchesEventHandler(UpdateSavedSearchesEvent.UpdateSavedSearchesHandler handler); @Override void onDeleteSavedSearchClicked(DeleteSavedSearchClickedEvent event); @Override void onSaveDiskResourceQueryClicked(final SaveDiskResourceQueryClickedEvent event); @Override void onSavedSearchedRetrieved(SavedSearchesRetrievedEvent event); }
DataSearchPresenterImpl implements SearchView.Presenter { @Override public void onSaveDiskResourceQueryClicked(final SaveDiskResourceQueryClickedEvent event) { final DiskResourceQueryTemplate queryTemplate = event.getQueryTemplate(); if (Strings.isNullOrEmpty(queryTemplate.getName())) { LOG.fine("TODO: User tried to save query with no name, cannot save. Ripple error back to view"); return; } else { final Set<String> uniqueNames = getUniqueNames(getQueryTemplates()); if (uniqueNames.size() == getQueryTemplates().size()) { if (uniqueNames.contains(queryTemplate.getName())) { for (DiskResourceQueryTemplate hasId : ImmutableList.copyOf(getQueryTemplates())) { String inListName = hasId.getName(); if (queryTemplate.getName().equalsIgnoreCase(inListName)) { getQueryTemplates().remove(hasId); break; } } } } } final ImmutableList<DiskResourceQueryTemplate> toBeSaved = ImmutableList.copyOf(Iterables.concat(queryTemplates, Collections.singletonList(queryTemplate))); searchService.saveQueryTemplates(toBeSaved, new AsyncCallback<List<DiskResourceQueryTemplate>>() { @Override public void onFailure(Throwable caught) { announcer.schedule(new ErrorAnnouncementConfig("Unable to save filter.")); } @Override public void onSuccess(List<DiskResourceQueryTemplate> savedTemplates) { queryTemplates.clear(); if (toBeSaved.size() != savedTemplates.size()) { LOG.warning("Saved templates returned from search service facade is a different size than what we submitted."); } queryTemplates.addAll(savedTemplates); List<DiskResourceQueryTemplate> queriesToRemove = Lists.newArrayList(); for (DiskResourceQueryTemplate qt : cleanCopyQueryTemplates) { if (qt.getName().equals(event.getOriginalName())) { queriesToRemove.add(qt); } } setCleanCopyQueryTemplates(searchService.createFrozenList(toBeSaved)); List<DiskResourceQueryTemplate> toUpdate = Lists.newArrayList(); if (templateHasChanged(queryTemplate, cleanCopyQueryTemplates)) { queryTemplate.setDirty(true); for (DiskResourceQueryTemplate qt : getQueryTemplates()) { if (qt.getName().equalsIgnoreCase(queryTemplate.getName())) { toUpdate.add(queryTemplate); } else { toUpdate.add(qt); } } getQueryTemplates().clear(); getQueryTemplates().addAll(toUpdate); } else { toUpdate = Lists.newArrayList(getQueryTemplates()); } fireEvent(new UpdateSavedSearchesEvent(toUpdate, queriesToRemove)); } }); } @Inject  DataSearchPresenterImpl(final SearchServiceFacade searchService,
                            final IplantAnnouncer announcer); @Override HandlerRegistration addSavedSearchDeletedEventHandler(SavedSearchDeletedEvent.SavedSearchDeletedEventHandler handler); @Override HandlerRegistration addUpdateSavedSearchesEventHandler(UpdateSavedSearchesEvent.UpdateSavedSearchesHandler handler); @Override void onDeleteSavedSearchClicked(DeleteSavedSearchClickedEvent event); @Override void onSaveDiskResourceQueryClicked(final SaveDiskResourceQueryClickedEvent event); @Override void onSavedSearchedRetrieved(SavedSearchesRetrievedEvent event);  }