Search in sources :

Example 6 with VoidResult

use of org.activityinfo.shared.command.result.VoidResult in project activityinfo by bedatadriven.

the class DeleteSiteAttachmentHandler method execute.

@Override
public void execute(DeleteSiteAttachment command, ExecutionContext context, AsyncCallback<VoidResult> callback) {
    attachmentService.delete(command.getBlobId());
    SqlUpdate.delete(Tables.SITE_ATTACHMENT).where("blobid", command.getBlobId()).execute(context.getTransaction());
    callback.onSuccess(new VoidResult());
}
Also used : VoidResult(org.activityinfo.shared.command.result.VoidResult)

Example 7 with VoidResult

use of org.activityinfo.shared.command.result.VoidResult in project activityinfo by bedatadriven.

the class UpdateMonthlyReportsHandler method execute.

@Override
public CommandResult execute(UpdateMonthlyReports cmd, User user) throws CommandException {
    Site site = em.find(Site.class, cmd.getSiteId());
    if (site == null) {
        throw new CommandException(cmd, "site " + cmd.getSiteId() + " not found for user " + user.getEmail());
    }
    Map<Month, ReportingPeriod> periods = Maps.newHashMap();
    Map<String, Object> siteHistoryChangeMap = createChangeMap();
    for (ReportingPeriod period : site.getReportingPeriods()) {
        periods.put(HandlerUtil.monthFromRange(period.getDate1(), period.getDate2()), period);
    }
    for (UpdateMonthlyReports.Change change : cmd.getChanges()) {
        ReportingPeriod period = periods.get(change.getMonth());
        if (period == null) {
            period = new ReportingPeriod(site);
            period.setId(keyGenerator.generateInt());
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.YEAR, change.getMonth().getYear());
            calendar.set(Calendar.MONTH, change.getMonth().getMonth() - 1);
            calendar.set(Calendar.DATE, 1);
            period.setDate1(calendar.getTime());
            calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
            period.setDate2(calendar.getTime());
            em.persist(period);
            periods.put(change.getMonth(), period);
        }
        updateIndicatorValue(em, period, change.getIndicatorId(), change.getValue(), false);
        siteHistoryChangeMap.put(IndicatorDTO.getPropertyName(change.getIndicatorId(), change.getMonth()), change.getValue());
    }
    siteHistoryProcessor.persistHistory(site, user, ChangeType.UPDATE, siteHistoryChangeMap);
    return new VoidResult();
}
Also used : Site(org.activityinfo.server.database.hibernate.entity.Site) Month(org.activityinfo.shared.command.Month) ReportingPeriod(org.activityinfo.server.database.hibernate.entity.ReportingPeriod) UpdateMonthlyReports(org.activityinfo.shared.command.UpdateMonthlyReports) VoidResult(org.activityinfo.shared.command.result.VoidResult) Calendar(java.util.Calendar) CommandException(org.activityinfo.shared.exception.CommandException)

Example 8 with VoidResult

use of org.activityinfo.shared.command.result.VoidResult in project activityinfo by bedatadriven.

the class RequestChangeHandler method execute.

@Override
public CommandResult execute(RequestChange cmd, User user) throws CommandException {
    ChangeRequestBuilder request = new ChangeRequestBuilder().setChangeType(ChangeType.valueOf(cmd.getChangeType())).setEntityId(cmd.getEntityId()).setEntityType(cmd.getEntityType()).setUser(user);
    if (cmd.getPropertyMap() != null) {
        request.setProperties(cmd.getPropertyMap().getTransientMap());
    }
    changeHandler.execute(request);
    return new VoidResult();
}
Also used : VoidResult(org.activityinfo.shared.command.result.VoidResult) ChangeRequestBuilder(org.activityinfo.server.entity.change.ChangeRequestBuilder)

Example 9 with VoidResult

use of org.activityinfo.shared.command.result.VoidResult in project activityinfo by bedatadriven.

the class UpdateUserProfileHandler method execute.

@Override
public void execute(final UpdateUserProfile command, ExecutionContext context, final AsyncCallback<VoidResult> callback) {
    UserProfileDTO model = command.getModel();
    SqlUpdate.update("userlogin").where("userId", model.getUserId()).value("name", model.getName()).value("organization", model.getOrganization()).value("jobtitle", model.getJobtitle()).value("emailNotification", model.isEmailNotification()).execute(context.getTransaction());
    callback.onSuccess(new VoidResult());
}
Also used : VoidResult(org.activityinfo.shared.command.result.VoidResult) UserProfileDTO(org.activityinfo.shared.dto.UserProfileDTO)

Example 10 with VoidResult

use of org.activityinfo.shared.command.result.VoidResult in project activityinfo by bedatadriven.

the class DesignTest method testSaveOnNavigateAway.

@Test
public void testSaveOnNavigateAway() {
    // Dummy Data
    SchemaDTO schema = DTOs.pear();
    // Collaborator
    MockEventBus eventBus = new MockEventBus();
    // Collaborator
    DispatcherStub service = new DispatcherStub();
    service.setResult(GetSchema.class, schema);
    service.setResult(UpdateEntity.class, new VoidResult());
    // Collaborator
    DesignPresenter.View view = createNiceMock(DesignPresenter.View.class);
    replay(view);
    // Collaborator
    UIConstants constants = createNiceMock(UIConstants.class);
    replay(constants);
    DesignPresenter designer = new DesignPresenter(eventBus, service, new StateManagerStub(), view, constants);
    designer.go(schema.getDatabaseById(1));
    // Verify that following a change to the record, a save call
    // triggers an update command
    ActivityDTO activity = (ActivityDTO) ((TreeStore) designer.getStore()).getRootItems().get(0);
    Record record = designer.getStore().getRecord(activity);
    record.set("name", "New Name");
    designer.requestToNavigateAway(new DataEntryPlace(), new NavigationCallback() {

        @Override
        public void onDecided(boolean allowed) {
        }
    });
    UpdateEntity cmd = service.getLastExecuted(UpdateEntity.class);
    Assert.assertTrue(cmd.getChanges().containsKey("name"));
    Assert.assertEquals("New Name", cmd.getChanges().get("name"));
}
Also used : VoidResult(org.activityinfo.shared.command.result.VoidResult) UpdateEntity(org.activityinfo.shared.command.UpdateEntity) DispatcherStub(org.activityinfo.client.dispatch.DispatcherStub) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) TreeStore(com.extjs.gxt.ui.client.store.TreeStore) DataEntryPlace(org.activityinfo.client.page.entry.place.DataEntryPlace) MockEventBus(org.activityinfo.client.MockEventBus) NavigationCallback(org.activityinfo.client.page.NavigationCallback) Record(com.extjs.gxt.ui.client.store.Record) UIConstants(org.activityinfo.client.i18n.UIConstants) StateManagerStub(org.activityinfo.client.mock.StateManagerStub) Test(org.junit.Test)

Aggregations

VoidResult (org.activityinfo.shared.command.result.VoidResult)26 Record (com.extjs.gxt.ui.client.store.Record)4 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)4 MockEventBus (org.activityinfo.client.MockEventBus)4 DispatcherStub (org.activityinfo.client.dispatch.DispatcherStub)4 MaskingAsyncMonitor (org.activityinfo.client.dispatch.monitor.MaskingAsyncMonitor)4 UIConstants (org.activityinfo.client.i18n.UIConstants)4 StateManagerStub (org.activityinfo.client.mock.StateManagerStub)4 UpdateEntity (org.activityinfo.shared.command.UpdateEntity)4 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)4 Test (org.junit.Test)4 FormDialogCallback (org.activityinfo.client.page.common.dialog.FormDialogCallback)3 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)2 FormDialogImpl (org.activityinfo.client.page.common.dialog.FormDialogImpl)2 Delete (org.activityinfo.shared.command.Delete)2 UpdateMonthlyReports (org.activityinfo.shared.command.UpdateMonthlyReports)2 UpdateReportSubscription (org.activityinfo.shared.command.UpdateReportSubscription)2 UpdateUserPermissions (org.activityinfo.shared.command.UpdateUserPermissions)2 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)2 CommandException (org.activityinfo.shared.exception.CommandException)2