/** * Returns a resolved Promise when every Promise in the list is resolved. * If any Promise is rejected, the resulting Promise will be rejected. */ @SafeVarargs public final <O> Promise<O> all(final Promise<O>... promises) { return Arrays.stream(promises).reduce(resolve(), (p1, p2) -> p1.then(ignore -> p2)); }
/** * Maps the objects to Promises using the provided function then behaves just like {@link org.uberfire.client.promise.Promises#all}. */ public <T, O> Promise<O> all(final List<T> objects, final Function<T, Promise<O>> f) { return objects.stream().map(f).reduce(resolve(), (p1, p2) -> p1.then(ignore -> p2)); }
/** * Maps the objects to Promises using the provided function then behaves just like {@link org.uberfire.client.promise.Promises#all}. */ public <T, O> Promise<O> all(final List<T> objects, final Function<T, Promise<O>> f) { return objects.stream().map(f).reduce(resolve(), (p1, p2) -> p1.then(ignore -> p2)); }
/** * Returns a resolved Promise when every Promise in the list is resolved. * If any Promise is rejected, the resulting Promise will be rejected. */ @SafeVarargs public final <O> Promise<O> all(final Promise<O>... promises) { return Arrays.stream(promises).reduce(resolve(), (p1, p2) -> p1.then(ignore -> p2)); }
void forceSave(final String comment, final Supplier<Promise<Void>> chain) { concurrentPomUpdateInfo = null; conflictingRepositoriesPopup.hide(); saveProjectScreenModel(comment, DeploymentMode.FORCED, chain).then(i -> chain.get()); }
public void addAllProjectsPersistableDataObjects() { promises.promisify(dataModelerService, s -> { return s.findPersistableClasses(pathToPersistenceXml); }).then(classes -> { classes.stream() .filter(clazz -> !getPersistenceUnitModel().getClasses().contains(clazz)) .forEach(this::add); return promises.resolve(); }); }
<T> Promise<Boolean> executeValidation(final Caller<T> caller, final Function<T, Boolean> call, final String errorMessage) { return promises .promisify(caller, call) .then(valid -> valid ? promises.resolve(true) : promises.reject(errorMessage)); }
@Override public void onPathSelection(final String pathToDependency) { promises.promisify(m2RepoService, s -> { return s.loadGAVFromJar(pathToDependency); }).then(gav -> { selectionHandlers.forEach(h -> h.onSelection(gav)); return promises.resolve(); }); view.hide(); }
@Override public Disposable schedule(Runnable action, long delayTime, TimeUnit unit) { action = RxJavaPlugins.onSchedule(action); ScheduledAction scheduledAction = new ScheduledAction(action); if (incremental && (delayTime <= 0 || unit == null)) { Promise.resolve(0).then(o -> { scheduledAction.run(); return null; }); } else { DomGlobal.setTimeout(args -> scheduledAction.run(), (int) unit.toMillis(delayTime)); } return scheduledAction; }
@Override public Disposable schedule(Runnable action, long delayTime, TimeUnit unit) { action = RxJavaPlugins.onSchedule(action); ScheduledAction scheduledAction = new ScheduledAction(action); if (incremental && (delayTime <= 0 || unit == null)) { Promise.resolve(0).then(o -> { scheduledAction.run(); return null; }); } else { DomGlobal.setTimeout(args -> scheduledAction.run(), (int) unit.toMillis(delayTime)); } return scheduledAction; }
public void showSettings() { settingsPresenter.setupUsingCurrentSection().then(i -> { SettingsPresenter.View settingsView = this.settingsPresenter.getView(); this.view.setContent(settingsView.getElement()); return promises.resolve(); }); }
@Test public void testHandlePomConcurrentUpdate() { presenter.model = mock(ProjectScreenModel.class); doReturn(mock(POM.class)).when(presenter.model).getPOM(); presenter.handlePomConcurrentUpdate("Test comment", null, new GAVAlreadyExistsException()).then(i -> { fail("Promise should've not been resolved!"); return promises.resolve(); }); verify(view).hideBusyIndicator(); verify(conflictingRepositoriesPopup).setContent(any(), any(), any()); verify(conflictingRepositoriesPopup).show(); }
@Test public void testSetupSectionsWithEmptyListAfterSetup() { final Section<ProjectScreenModel> section1 = newMockedSection(); final Section<ProjectScreenModel> section2 = newMockedSection(); doReturn(true).when(sectionManager).isEmpty(); doReturn(new ArrayList<>(Arrays.asList(section1, section2))).when(sectionManager).getSections(); presenter.setupSections(mock(ProjectScreenModel.class)).then(i -> { fail("Promise should've not been resolved!"); return promises.resolve(); }); verify(presenter, times(2)).setupSection(any(), any()); }
@Test public void testShowErrorAndRejectWithException() { final RuntimeException testException = new RuntimeException("Test message"); doNothing().when(view).showError(any()); generalSettingsPresenter.showErrorAndReject(testException).then(i -> { Assert.fail("Promise should've not been resolved!"); return promises.resolve(); }).catch_(e -> { verify(view).showError(eq("Test message")); Assert.assertEquals(e, generalSettingsPresenter); return promises.resolve(); }); }
@Override public Promise<Void> setup(final ProjectScreenModel model) { this.model = model; view.init(this); return loadServiceTasks().then(tasks -> promises.create((resolve, reject) -> { serviceTasksItemPresenters.setup(view.getServiceTasksTable(), tasks, (serviceTask, presenter) -> presenter.setup(serviceTask, this)); resolve.onInvoke(promises.resolve()); })); }
@Override public Promise<Void> setup(final ProjectScreenModel model) { this.model = model; view.init(this); return loadServiceTasks().then(tasks -> promises.create((resolve, reject) -> { serviceTasksItemPresenters.setup(view.getServiceTasksTable(), tasks, (serviceTask, presenter) -> presenter.setup(serviceTask, this)); resolve.onInvoke(promises.resolve()); })); }
CommandWithFileNameAndCommitMessage getDuplicateCommand() { return details -> { copyPopUpPresenter.getView().hide(); view.showBusyIndicator(view.getLoadingMessage()); promises.promisify(projectScreenService, s -> { s.copy(workspaceProject, details.getNewFileName()); }).then(i -> { view.hideBusyIndicator(); notificationEvent.fire(new NotificationEvent(view.getItemSuccessfullyDuplicatedMessage(), NotificationEvent.NotificationType.SUCCESS)); return promises.resolve(); }).catch_(this::onError); }; }
@Test public void testAllMappingWithNoRejections() { promises.all(Arrays.asList(1, 2, 3, 4), promises::resolve).then(i -> { assertEquals((Integer) 4, i); return promises.resolve(); }).catch_(e -> { fail("Promise should've not been resolved!"); return promises.resolve(); }); }
@Test public void testAllMappingWithOneRejection() { promises.all(Arrays.asList(1, 2, 3, 4), i -> i == 3 ? promises.reject(i) : promises.resolve(i)).then(i -> { fail("Promise should've not been resolved!"); return promises.resolve(); }).catch_(e -> { assertEquals(3, e); return promises.resolve(); }); }
@Test public void testValidateStringIsNotEmpty() { generalSettingsPresenter.validateStringIsNotEmpty("NotEmptyString", "Message").then(e -> { Assert.assertEquals(e, true); return promises.resolve(); }).catch_(e -> { Assert.fail("Promise should've been resolved!"); return promises.resolve(); }); }