Search in sources :

Example 1 with Promise

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();
    }));
}
Also used : HasBusyIndicator(org.uberfire.ext.widgets.common.client.common.HasBusyIndicator) SectionManager(org.kie.workbench.common.screens.library.client.settings.util.sections.SectionManager) Promises(org.uberfire.client.promise.Promises) SpaceSettings(org.kie.workbench.common.screens.library.client.screens.organizationalunit.settings.annotation.SpaceSettings) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) Promise(elemental2.promise.Promise) Supplier(java.util.function.Supplier) SettingsSectionChange(org.kie.workbench.common.screens.library.client.settings.SettingsSectionChange) ArrayList(java.util.ArrayList) SettingsSectionChangeType(org.kie.workbench.common.screens.library.client.settings.SettingsSectionChangeType) Inject(javax.inject.Inject) ERROR(org.uberfire.workbench.events.NotificationEvent.NotificationType.ERROR) HTMLElement(elemental2.dom.HTMLElement) Observes(javax.enterprise.event.Observes) SettingsSections(org.kie.workbench.common.screens.library.client.settings.sections.SettingsSections) OrganizationalUnitController(org.guvnor.structure.client.security.OrganizationalUnitController) Event(javax.enterprise.event.Event) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) LibraryConstants(org.kie.workbench.common.screens.library.client.resources.i18n.LibraryConstants) BusyIndicatorView(org.uberfire.ext.widgets.common.client.common.BusyIndicatorView) TranslationService(org.jboss.errai.ui.client.local.spi.TranslationService) WARNING(org.uberfire.workbench.events.NotificationEvent.NotificationType.WARNING) WorkspaceProjectContext(org.guvnor.common.services.project.client.context.WorkspaceProjectContext) SpaceScreenModel(org.kie.workbench.common.screens.library.api.settings.SpaceScreenModel) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Dependent(javax.enterprise.context.Dependent) SUCCESS(org.uberfire.workbench.events.NotificationEvent.NotificationType.SUCCESS) PostConstruct(javax.annotation.PostConstruct) Section(org.kie.workbench.common.screens.library.client.settings.util.sections.Section) UberElement(org.uberfire.client.mvp.UberElement) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) SpaceScreenModel(org.kie.workbench.common.screens.library.api.settings.SpaceScreenModel)

Example 2 with Promise

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();
    });
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Mock(org.mockito.Mock) Promises(org.uberfire.client.promise.Promises) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunWith(org.junit.runner.RunWith) Promise(elemental2.promise.Promise) Captor(org.mockito.Captor) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) PMML(org.kie.workbench.common.dmn.api.editors.included.DMNImportTypes.PMML) ArgumentCaptor(org.mockito.ArgumentCaptor) Map(java.util.Map) Assert.fail(org.junit.Assert.fail) SyncPromises(org.uberfire.promise.SyncPromises) Mockito.doReturn(org.mockito.Mockito.doReturn) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) Before(org.junit.Before) PMMLIncludedModel(org.kie.workbench.common.dmn.api.editors.included.PMMLIncludedModel) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) List(java.util.List) Mockito.never(org.mockito.Mockito.never) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) IncludedModel(org.kie.workbench.common.dmn.api.editors.included.IncludedModel) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) ArrayList(java.util.ArrayList) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) Map(java.util.Map) Test(org.junit.Test)

Example 3 with Promise

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;
}
Also used : Function(java.util.function.Function) Promise(elemental2.promise.Promise) Caller(org.jboss.errai.common.client.api.Caller)

Example 4 with Promise

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();
}
Also used : ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) SettingsPage(org.drools.workbench.screens.testscenario.client.page.settings.SettingsPage) WorkbenchPartTitleDecoration(org.uberfire.client.annotations.WorkbenchPartTitleDecoration) TestScenarioResult(org.drools.workbench.screens.testscenario.model.TestScenarioResult) AuditPage(org.drools.workbench.screens.testscenario.client.page.audit.AuditPage) TestScenarioModelContent(org.drools.workbench.screens.testscenario.model.TestScenarioModelContent) Promise(elemental2.promise.Promise) Metadata(org.guvnor.common.services.shared.metadata.model.Metadata) Supplier(java.util.function.Supplier) TestScenarioConstants(org.drools.workbench.screens.testscenario.client.resources.i18n.TestScenarioConstants) Inject(javax.inject.Inject) AsyncPackageDataModelOracleFactory(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracleFactory) TestScenarioResourceType(org.drools.workbench.screens.testscenario.client.type.TestScenarioResourceType) WorkbenchPartTitle(org.uberfire.client.annotations.WorkbenchPartTitle) IsWidget(com.google.gwt.user.client.ui.IsWidget) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) HasBusyIndicatorDefaultErrorCallback(org.uberfire.ext.widgets.common.client.callbacks.HasBusyIndicatorDefaultErrorCallback) OnStartup(org.uberfire.lifecycle.OnStartup) Scenario(org.drools.workbench.models.testscenarios.shared.Scenario) Event(javax.enterprise.event.Event) OnShowTestPanelEvent(org.kie.workbench.common.workbench.client.test.OnShowTestPanelEvent) ScenarioUtils(org.drools.workbench.screens.testscenario.client.utils.ScenarioUtils) TestReportingDocksHandler(org.kie.workbench.common.workbench.client.test.TestReportingDocksHandler) Menus(org.uberfire.workbench.model.menu.Menus) OnMayClose(org.uberfire.lifecycle.OnMayClose) ScenarioTestEditorService(org.drools.workbench.screens.testscenario.service.ScenarioTestEditorService) RemoteCallback(org.jboss.errai.common.client.api.RemoteCallback) AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) SupportsSaveAndRename(org.uberfire.ext.editor.commons.service.support.SupportsSaveAndRename) PlaceRequest(org.uberfire.mvp.PlaceRequest) WorkbenchMenu(org.uberfire.client.annotations.WorkbenchMenu) Consumer(java.util.function.Consumer) KieEditor(org.kie.workbench.common.widgets.metadata.client.KieEditor) ImportsWidgetPresenter(org.kie.workbench.common.widgets.configresource.client.widget.bound.ImportsWidgetPresenter) ObservablePath(org.uberfire.backend.vfs.ObservablePath) User(org.jboss.errai.security.shared.api.identity.User) Caller(org.jboss.errai.common.client.api.Caller) OnHideTestPanelEvent(org.kie.workbench.common.workbench.client.test.OnHideTestPanelEvent) Optional(java.util.Optional) WorkbenchPartView(org.uberfire.client.annotations.WorkbenchPartView) OnClose(org.uberfire.lifecycle.OnClose) ExecutionTrace(org.drools.workbench.models.testscenarios.shared.ExecutionTrace) WorkbenchEditor(org.uberfire.client.annotations.WorkbenchEditor) TestRunnerReportingPanel(org.kie.workbench.common.workbench.client.test.TestRunnerReportingPanel) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject)

Example 5 with Promise

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();
    });
}
Also used : ConcurrentChangePopup.newConcurrentUpdate(org.uberfire.ext.widgets.common.client.common.ConcurrentChangePopup.newConcurrentUpdate) HasBusyIndicator(org.uberfire.ext.widgets.common.client.common.HasBusyIndicator) Promises(org.uberfire.client.promise.Promises) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) ListPresenter(org.kie.workbench.common.screens.library.client.settings.util.ListPresenter) HashMap(java.util.HashMap) SavePopUpPresenter(org.uberfire.ext.editor.commons.client.file.popups.SavePopUpPresenter) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) Promise(elemental2.promise.Promise) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) UberElementalListItem(org.kie.workbench.common.screens.library.client.settings.util.UberElementalListItem) IsElement(org.jboss.errai.ui.client.local.api.elemental2.IsElement) ERROR(org.uberfire.workbench.events.NotificationEvent.NotificationType.ERROR) HTMLElement(elemental2.dom.HTMLElement) Map(java.util.Map) Observes(javax.enterprise.event.Observes) ProjectScreenService(org.kie.workbench.common.screens.projecteditor.service.ProjectScreenService) Customizable(org.uberfire.annotations.Customizable) DefaultErrorCallback(org.uberfire.ext.widgets.common.client.callbacks.DefaultErrorCallback) Event(javax.enterprise.event.Event) ListItemPresenter(org.kie.workbench.common.screens.library.client.settings.util.ListItemPresenter) DomGlobal(elemental2.dom.DomGlobal) ProjectScreenModel(org.kie.workbench.common.screens.projecteditor.model.ProjectScreenModel) WARNING(org.uberfire.workbench.events.NotificationEvent.NotificationType.WARNING) WorkspaceProjectContext(org.guvnor.common.services.project.client.context.WorkspaceProjectContext) List(java.util.List) DeploymentMode(org.guvnor.common.services.project.service.DeploymentMode) Message(org.jboss.errai.bus.client.api.messaging.Message) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) GAVAlreadyExistsException(org.guvnor.common.services.project.service.GAVAlreadyExistsException) OnOpen(org.uberfire.lifecycle.OnOpen) Dependent(javax.enterprise.context.Dependent) ConflictingRepositoriesPopup(org.guvnor.common.services.project.client.repositories.ConflictingRepositoriesPopup) ObservablePath(org.uberfire.backend.vfs.ObservablePath) SUCCESS(org.uberfire.workbench.events.NotificationEvent.NotificationType.SUCCESS) Caller(org.jboss.errai.common.client.api.Caller) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) UberElemental(org.uberfire.client.mvp.UberElemental) NotificationEvent(org.uberfire.workbench.events.NotificationEvent)

Aggregations

Promise (elemental2.promise.Promise)15 Inject (javax.inject.Inject)12 List (java.util.List)10 Caller (org.jboss.errai.common.client.api.Caller)10 Supplier (java.util.function.Supplier)9 ArrayList (java.util.ArrayList)8 Event (javax.enterprise.event.Event)8 ObservablePath (org.uberfire.backend.vfs.ObservablePath)8 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)8 IsWidget (com.google.gwt.user.client.ui.IsWidget)7 PostConstruct (javax.annotation.PostConstruct)7 Observes (javax.enterprise.event.Observes)7 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)7 RemoteCallback (org.jboss.errai.common.client.api.RemoteCallback)7 Promises (org.uberfire.client.promise.Promises)7 Consumer (java.util.function.Consumer)6 Dependent (javax.enterprise.context.Dependent)6 KieEditor (org.kie.workbench.common.widgets.metadata.client.KieEditor)6 ParameterizedCommand (org.uberfire.mvp.ParameterizedCommand)6 PlaceRequest (org.uberfire.mvp.PlaceRequest)6