use of elemental2.promise.Promise in project kie-wb-common by kiegroup.
the class SettingsScreenPresenter method setupUsingCurrentSection.
public Promise<Void> setupUsingCurrentSection() {
this.view.init(this);
showBusyIndicator(ts.getTranslation(LibraryConstants.Loading));
view.enableActions(canUpdate());
return setupSections(new SpaceScreenModel()).then(o -> {
hideBusyIndicator();
if (sectionManager.manages(sectionManager.getCurrentSection())) {
return sectionManager.goToCurrentSection();
} else {
return sectionManager.goToFirstAvailable();
}
}).catch_(o -> promises.catchOrExecute(o, e -> {
hideBusyIndicator();
return promises.reject(e);
}, i -> {
notificationEvent.fire(new NotificationEvent(ts.getTranslation(LibraryConstants.SettingsLoadError), ERROR));
hideBusyIndicator();
return promises.resolve();
}));
}
use of elemental2.promise.Promise in project kie-wb-common by kiegroup.
the class DMNMarshallerImportsClientHelperTest method getPMMLDocumentsAsync.
@Test
public void getPMMLDocumentsAsync() {
final PMMLDocumentMetadata pmmlDocumentMetadata = new PMMLDocumentMetadata(PMML_PATH, PMML_FILE, PMML.getDefaultNamespace(), Collections.emptyList());
when(dmnImportsContentService.getModelsPMMLFilesURIs()).thenReturn(promises.resolve(new String[] { PMML_PATH }));
when(dmnImportsContentService.loadFile(PMML_PATH)).thenReturn(promises.resolve(PMML_CONTENT));
doReturn(promises.resolve(pmmlDocumentMetadata)).when(dmnImportsContentService).getPMMLDocumentMetadata(PMML_PATH);
final List<JSITImport> imports = new ArrayList<>();
final JSITImport jsImportMock = mock(JSITImport.class);
when(jsImportMock.getLocationURI()).thenReturn(PMML_FILE);
imports.add(jsImportMock);
final Promise<Map<JSITImport, PMMLDocumentMetadata>> returnPromise = importsHelper.getPMMLDocumentsAsync(metadataMock, imports);
returnPromise.then(def -> {
assertEquals(1, def.size());
assertEquals(PMML_PATH, def.get(jsImportMock).getPath());
assertEquals(PMML_FILE, def.get(jsImportMock).getName());
assertEquals(PMML.getDefaultNamespace(), def.get(jsImportMock).getImportType());
assertEquals(0, def.get(jsImportMock).getModels().size());
return promises.resolve();
}).catch_(i -> {
fail("Promise should've been resolved!");
return promises.resolve();
});
}
use of elemental2.promise.Promise in project kie-wb-common by kiegroup.
the class PromisesMock method promisify.
@SuppressWarnings("unchecked")
public static Promises promisify(final Promises promises) {
doAnswer(invocationOnMock -> {
final Caller caller = (Caller) invocationOnMock.getArguments()[0];
final Function call = (Function) invocationOnMock.getArguments()[1];
final Promise<Object>[] promise = new Promise[1];
final Object service = caller.call(response -> promise[0] = PromiseMock.success(response));
call.apply(service);
return promise[0];
}).when(promises).promisify(any(Caller.class), any(Function.class));
return promises;
}
use of elemental2.promise.Promise in project drools-wb by kiegroup.
the class ScenarioEditorPresenter method makeMenuBar.
@Override
protected Promise<Void> makeMenuBar() {
if (workbenchContext.getActiveWorkspaceProject().isPresent()) {
final WorkspaceProject activeProject = workbenchContext.getActiveWorkspaceProject().get();
return projectController.canUpdateProject(activeProject).then(canUpdateProject -> {
if (canUpdateProject) {
final ParameterizedCommand<Boolean> onSave = withComments -> {
saveWithComments = withComments;
saveAction();
};
fileMenuBuilder.addSave(versionRecordManager.newSaveMenuItem(onSave)).addCopy(versionRecordManager.getCurrentPath(), assetUpdateValidator).addRename(getSaveAndRename()).addDelete(versionRecordManager.getPathToLatest(), assetUpdateValidator);
}
addDownloadMenuItem(fileMenuBuilder);
fileMenuBuilder.addNewTopLevelMenu(view.getRunScenarioMenuItem()).addNewTopLevelMenu(versionRecordManager.buildMenu()).addNewTopLevelMenu(alertsButtonMenuItemBuilder.build());
return promises.resolve();
});
}
return promises.resolve();
}
use of elemental2.promise.Promise in project kie-wb-common by kiegroup.
the class SettingsPresenter method setupSection.
Promise<Object> setupSection(final ProjectScreenModel model, final Section section) {
return promises.resolve().then(ignore -> section.setup(model)).catch_(e -> {
sections.remove(section);
notificationEvent.fire(new NotificationEvent(getSectionSetupErrorMessage(section), WARNING));
return promises.reject(e);
}).then(i -> {
section.getMenuItem().setup(section, this);
resetDirtyIndicator(section);
return promises.resolve();
}).catch_(e -> {
DomGlobal.console.info(e);
return promises.resolve();
});
}
Aggregations