Search in sources :

Example 21 with AsyncCallback

use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.

the class SiteDialogLauncher method editSite.

public void editSite(final SiteDTO site, final SiteDialogCallback callback) {
    dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

        @Override
        public void onFailure(Throwable caught) {
            showError(caught);
        }

        @Override
        public void onSuccess(SchemaDTO schema) {
            final ActivityDTO activity = schema.getActivityById(site.getActivityId());
            if (!activity.getClassicView()) {
                promptUseNewEntry(activity);
                return;
            }
            // check whether the site has been locked
            // (this only applies to Once-reported activities because
            // otherwise the date criteria applies to the monthly report)
            LockedPeriodSet locks = new LockedPeriodSet(schema);
            if (activity.getReportingFrequency() == ActivityFormDTO.REPORT_ONCE) {
                if (locks.isLocked(site)) {
                    MessageBox.alert(I18N.CONSTANTS.lockedSiteTitle(), I18N.CONSTANTS.siteIsLocked(), null);
                    return;
                }
            }
            dispatcher.execute(new GetActivityForm(activity.getId())).then(new AsyncCallback<ActivityFormDTO>() {

                @Override
                public void onFailure(Throwable caught) {
                    showError(caught);
                }

                @Override
                public void onSuccess(ActivityFormDTO activity) {
                    SiteDialog dialog = new SiteDialog(dispatcher, locks, activity);
                    dialog.showExisting(site, callback);
                }
            });
        }
    });
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm)

Example 22 with AsyncCallback

use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.

the class SiteDialogLauncher method addSite.

public void addSite(final Filter filter, final SiteDialogCallback callback) {
    if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Activity)) {
        final int activityId = filter.getRestrictedCategory(DimensionType.Activity);
        dispatcher.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

            @Override
            public void onFailure(Throwable caught) {
                showError(caught);
            }

            @Override
            public void onSuccess(SchemaDTO schema) {
                ActivityDTO activity = schema.getActivityById(activityId);
                if (!activity.getClassicView()) {
                    promptUseNewEntry(activity);
                    return;
                }
                Log.trace("adding site for activity " + activity + ", locationType = " + activity.getLocationType());
                if (activity.getDatabase().getPartners().isEmpty()) {
                    // Since we are creating a partner by default for every database,
                    // this shouldn't happen beyond the development environment
                    MessageBox.alert(I18N.CONSTANTS.error(), I18N.CONSTANTS.noPartners(), null);
                    return;
                }
                LockedPeriodSet locks = new LockedPeriodSet(activity.getDatabase());
                dispatcher.execute(new GetActivityForm(activityId)).then(new AsyncCallback<ActivityFormDTO>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        showError(caught);
                    }

                    @Override
                    public void onSuccess(ActivityFormDTO activityForm) {
                        if (activityForm.getLocationType().isAdminLevel()) {
                            addNewSiteWithBoundLocation(locks, activityForm, callback);
                        } else if (activityForm.getLocationType().isNationwide()) {
                            addNewSiteWithNoLocation(locks, activityForm, callback);
                        } else {
                            chooseLocationThenAddSite(locks, activityForm, callback);
                        }
                    }
                });
            }
        });
    }
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm)

Example 23 with AsyncCallback

use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method mergedCommandsShouldEachReceiveACallback.

@Test
public void mergedCommandsShouldEachReceiveACallback() {
    expectRemoteCall(new GetSchema());
    andCallbackWihSuccess(new SchemaDTO());
    replay(service);
    AsyncCallback callback1 = makeCallbackThatExpectsNonNullSuccess();
    AsyncCallback callback2 = makeCallbackThatExpectsNonNullSuccess();
    // simulate successive dispatches of the same command from different
    // components of the application
    dispatcher.execute(new GetSchema(), callback1);
    dispatcher.execute(new GetSchema(), callback2);
    processPendingCommands();
    // verify that only one command was sent
    verify(callback1);
    verify(callback2);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Test(org.junit.Test)

Example 24 with AsyncCallback

use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method commandsUnsuccessfullyExecutedThroughProxiesShouldBeSentToServer.

@Test
public void commandsUnsuccessfullyExecutedThroughProxiesShouldBeSentToServer() {
    GetSchema command = new GetSchema();
    expect(proxy.maybeExecute(eq(command))).andReturn(CacheResult.couldNotExecute());
    replay(proxy);
    expectRemoteCall(command);
    andCallbackWihSuccess(new SchemaDTO());
    replay(service);
    AsyncCallback callback = makeCallbackThatExpectsNonNullSuccess();
    proxyManager.registerProxy(GetSchema.class, proxy);
    dispatcher.execute(new GetSchema(), callback);
    processPendingCommands();
    verify(proxy, service, callback);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Test(org.junit.Test)

Example 25 with AsyncCallback

use of com.google.gwt.user.client.rpc.AsyncCallback in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method commandsSuccessfullyExecutedThroughProxiesShouldNotBeSentToServer.

@Test
public void commandsSuccessfullyExecutedThroughProxiesShouldNotBeSentToServer() {
    GetSchema command = new GetSchema();
    expect(proxy.maybeExecute(eq(command))).andReturn(new CacheResult(new SchemaDTO()));
    replay(proxy);
    // no calls should be made to the remote service
    replay(service);
    AsyncCallback callback = makeCallbackThatExpectsNonNullSuccess();
    proxyManager.registerProxy(GetSchema.class, proxy);
    dispatcher.execute(new GetSchema(), callback);
    processPendingCommands();
    verify(proxy, service, callback);
}
Also used : AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) CacheResult(org.activityinfo.ui.client.dispatch.remote.cache.CacheResult) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Test(org.junit.Test)

Aggregations

AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)64 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)8 Test (org.junit.Test)7 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)6 FormDialogCallback (org.activityinfo.ui.client.page.common.dialog.FormDialogCallback)6 CallbackGroup (com.google.gerrit.client.rpc.CallbackGroup)5 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)4 FormDialogTether (org.activityinfo.ui.client.page.common.dialog.FormDialogTether)4 ChangeInfo (com.google.gerrit.client.info.ChangeInfo)3 Date (java.util.Date)3 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)3 VoidResult (org.activityinfo.legacy.shared.command.result.VoidResult)3 MaskingAsyncMonitor (org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor)3 FormDialogImpl (org.activityinfo.ui.client.page.common.dialog.FormDialogImpl)3 Operation (org.eclipse.che.api.promises.client.Operation)3 OperationException (org.eclipse.che.api.promises.client.OperationException)3 PromiseError (org.eclipse.che.api.promises.client.PromiseError)3 Path (org.eclipse.che.ide.resource.Path)3 EditInfo (com.google.gerrit.client.info.ChangeInfo.EditInfo)2 RevisionInfo (com.google.gerrit.client.info.ChangeInfo.RevisionInfo)2