Search in sources :

Example 6 with VoidResult

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

the class ReportGridPanel method onDashboardClicked.

private void onDashboardClicked(final ReportMetadataDTO model) {
    model.setDashboard(!model.isDashboard());
    store.update(model);
    UpdateReportSubscription update = new UpdateReportSubscription();
    update.setReportId(model.getId());
    update.setPinnedToDashboard(model.isDashboard());
    dispatcher.execute(update, new AsyncCallback<VoidResult>() {

        @Override
        public void onFailure(Throwable caught) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onSuccess(VoidResult result) {
            Info.displayText(I18N.CONSTANTS.saved(), model.isDashboard() ? I18N.MESSAGES.addedToDashboard(model.getTitle()) : I18N.MESSAGES.removedFromDashboard(model.getTitle()));
        }
    });
}
Also used : UpdateReportSubscription(org.activityinfo.legacy.shared.command.UpdateReportSubscription) VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult)

Example 7 with VoidResult

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

the class EmailDialog method onButtonPressed.

@Override
protected void onButtonPressed(Button button) {
    if (button.getItemId().equals(OK)) {
        final UpdateReportSubscription update = new UpdateReportSubscription();
        update.setReportId(reportMetadata.getId());
        if (weekly.getValue()) {
            update.setEmailDelivery(EmailDelivery.WEEKLY);
            update.setEmailDay(dayOfWeek.getMappedValue());
        } else if (monthly.getValue()) {
            update.setEmailDelivery(EmailDelivery.MONTHLY);
            update.setEmailDay(dayOfMonth.getMappedValue());
        } else {
            update.setEmailDelivery(EmailDelivery.NONE);
        }
        dispatcher.execute(update, new MaskingAsyncMonitor(this, I18N.CONSTANTS.saving()), new AsyncCallback<VoidResult>() {

            @Override
            public void onFailure(Throwable caught) {
            }

            @Override
            public void onSuccess(VoidResult result) {
                hide();
                reportMetadata.setEmailDelivery(update.getEmailDelivery());
                reportMetadata.setDay(update.getEmailDay());
                callback.onUpdated();
            }
        });
    } else if (button.getItemId().equals(CANCEL)) {
        hide();
    }
}
Also used : UpdateReportSubscription(org.activityinfo.legacy.shared.command.UpdateReportSubscription) VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) MaskingAsyncMonitor(org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor)

Example 8 with VoidResult

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

the class CreateSiteAttachmentHandler method execute.

@Override
public void execute(CreateSiteAttachment command, ExecutionContext context, AsyncCallback<VoidResult> callback) {
    SqlInsert.insertInto("siteattachment").value("siteid", command.getSiteId()).value("blobid", command.getBlobId()).value("filename", command.getFileName()).value("uploadedby", context.getUser().getUserId()).value("blobsize", command.getBlobSize()).value("contenttype", command.getContentType()).execute(context.getTransaction());
    callback.onSuccess(new VoidResult());
}
Also used : VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult)

Example 9 with VoidResult

use of org.activityinfo.legacy.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.legacy.shared.command.result.VoidResult) ChangeRequestBuilder(org.activityinfo.server.entity.change.ChangeRequestBuilder)

Example 10 with VoidResult

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

the class UpdateMonthlyReportsHandler method execute.

@Override
public CommandResult execute(UpdateMonthlyReports cmd, User user) throws CommandException {
    // Phantom Row issue occurs when attempting to update Monthly ReportingPeriods concurrently.
    // To prevent this, we introduce a locking mechanism to prevent simultaneous insertions into table which result
    // in duplicate reporting periods on the given site.
    // Once we have acquired a lock, we can then safely execute the command
    acquireLock(cmd.getSiteId());
    try {
        Site site = em.find(Site.class, cmd.getSiteId());
        if (site == null) {
            throw new CommandException(cmd, "site " + cmd.getSiteId() + " not found for user " + user.getEmail());
        }
        if (!permissionOracle.isEditAllowed(site, user)) {
            throw new IllegalAccessCommandException("Not authorized to modify sites");
        }
        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()) {
            if (!periods.containsKey(change.getMonth())) {
                ReportingPeriod 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);
            }
        }
        for (UpdateMonthlyReports.Change change : cmd.getChanges()) {
            updateIndicatorValue(em, periods.get(change.getMonth()), change.getIndicatorId(), change.getValue(), false);
            siteHistoryChangeMap.put(getPropertyName(change.getIndicatorId(), change.getMonth()), change.getValue());
        }
        // update the timestamp on the site entity so changes get picked up
        // by the synchro mechanism
        site.setVersion(site.getActivity().incrementSiteVersion());
        siteHistoryProcessor.persistHistory(site, user, ChangeType.UPDATE, siteHistoryChangeMap);
    } finally {
        releaseLock(cmd.getSiteId());
    }
    return new VoidResult();
}
Also used : UpdateMonthlyReports(org.activityinfo.legacy.shared.command.UpdateMonthlyReports) VoidResult(org.activityinfo.legacy.shared.command.result.VoidResult) Calendar(java.util.Calendar) IllegalAccessCommandException(org.activityinfo.legacy.shared.exception.IllegalAccessCommandException) CommandException(org.activityinfo.legacy.shared.exception.CommandException) Month(org.activityinfo.model.type.time.Month) IllegalAccessCommandException(org.activityinfo.legacy.shared.exception.IllegalAccessCommandException)

Aggregations

VoidResult (org.activityinfo.legacy.shared.command.result.VoidResult)22 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)4 MaskingAsyncMonitor (org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor)4 FormDialogCallback (org.activityinfo.ui.client.page.common.dialog.FormDialogCallback)3 Record (com.extjs.gxt.ui.client.store.Record)2 UpdateEntity (org.activityinfo.legacy.shared.command.UpdateEntity)2 UpdateMonthlyReports (org.activityinfo.legacy.shared.command.UpdateMonthlyReports)2 UpdateReportSubscription (org.activityinfo.legacy.shared.command.UpdateReportSubscription)2 UpdateSite (org.activityinfo.legacy.shared.command.UpdateSite)2 UpdateUserPermissions (org.activityinfo.legacy.shared.command.UpdateUserPermissions)2 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)2 FormDialogImpl (org.activityinfo.ui.client.page.common.dialog.FormDialogImpl)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)1 SafeHtmlUtils.fromString (com.google.gwt.safehtml.shared.SafeHtmlUtils.fromString)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 CreateLocation (org.activityinfo.legacy.shared.command.CreateLocation)1 DeleteReport (org.activityinfo.legacy.shared.command.DeleteReport)1