Search in sources :

Example 1 with GetSchema

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

the class MonthlyReportsPanel method loadSite.

private void loadSite(final SiteDTO site) {
    this.currentSiteId = site.getId();
    this.grid.getStore().removeAll();
    MaskingAsyncMonitor monitor = new MaskingAsyncMonitor(this, I18N.CONSTANTS.loading());
    service.execute(new GetSchema(), monitor).thenDo(schema -> {
        service.execute(new GetActivityForm(site.getActivityId()), monitor).thenDo(activity -> {
            currentActivity = activity;
            populateGrid(site, schema);
        });
    });
}
Also used : MaskingAsyncMonitor(org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm)

Example 2 with GetSchema

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

the class DefaultColumnModelProvider method fetchColumnModels.

@Override
public void fetchColumnModels(final Filter filter, final GroupingModel grouping, final AsyncCallback<ColumnModel> callback) {
    if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Activity)) {
        final int activityId = filter.getRestrictedCategory(DimensionType.Activity);
        dispatcher.execute(new GetActivityForm(activityId)).then(new AsyncCallback<ActivityFormDTO>() {

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

            @Override
            public void onSuccess(ActivityFormDTO activity) {
                dispatcher.execute(new GetSchema()).then(new AsyncCallback<SchemaDTO>() {

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

                    @Override
                    public void onSuccess(SchemaDTO schema) {
                        callback.onSuccess(forSingleActivity(grouping, schema.getDatabaseById(activity.getDatabaseId()), activity));
                    }
                });
            }
        });
    } else {
        dispatcher.execute(new GetSchema()).then(new AsyncCallback<SchemaDTO>() {

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

            @Override
            public void onSuccess(SchemaDTO result) {
                if (filter.isDimensionRestrictedToSingleCategory(DimensionType.Database)) {
                    UserDatabaseDTO singleDatabase = result.getDatabaseById(filter.getRestrictedCategory(DimensionType.Database));
                    callback.onSuccess(forSingleDatabase(grouping, singleDatabase));
                } else {
                    callback.onSuccess(forMultipleDatabases(grouping, result));
                }
            }
        });
    }
}
Also used : ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO)

Example 3 with GetSchema

use of org.activityinfo.legacy.shared.command.GetSchema 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 4 with GetSchema

use of org.activityinfo.legacy.shared.command.GetSchema 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 5 with GetSchema

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

the class FormLister method formList.

public Response formList(UriInfo uri, Optional<Integer> dbIdFilter) throws Exception {
    AuthenticatedUser user = authProvider.get();
    LOGGER.finer("ODK form list requested by " + user.getEmail() + " (" + user.getId() + ")");
    SchemaDTO schema = dispatcher.execute(new GetSchema());
    XFormList formList = new XFormList();
    for (UserDatabaseDTO db : schema.getDatabases()) {
        if (dbIdFilter.isPresent() && db.getId() != dbIdFilter.get()) {
            // skip
            continue;
        }
        if (db.isEditAllowed()) {
            for (ActivityDTO activity : db.getActivities()) {
                if (hasAdminLevelLocation(activity)) {
                    // Admin Level Locations are invalid for ODK forms - do not show
                    continue;
                }
                XFormListItem form = new XFormListItem();
                form.setName(db.getName() + " / " + activity.getName());
                form.setFormId("activityinfo.org:" + activity.getId());
                form.setVersion(getVersion());
                form.setDownloadUrl(uri.getBaseUriBuilder().path(XFormResources.class).path(Integer.toString(activity.getId())).path("xform").build());
                formList.getItems().add(form);
            }
        }
    }
    return OpenRosaResponse.build(formList);
}
Also used : XFormList(org.activityinfo.io.xform.formList.XFormList) XFormListItem(org.activityinfo.io.xform.formList.XFormListItem) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Aggregations

GetSchema (org.activityinfo.legacy.shared.command.GetSchema)42 Test (org.junit.Test)27 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)22 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)11 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)9 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)7 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)6 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)4 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)4 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)4 CloneDatabase (org.activityinfo.legacy.shared.command.CloneDatabase)3 OnDataSet (org.activityinfo.server.database.OnDataSet)3 Delete (org.activityinfo.legacy.shared.command.Delete)2 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)2 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)2 CacheResult (org.activityinfo.ui.client.dispatch.remote.cache.CacheResult)2 NullCallback (com.bedatadriven.rebar.async.NullCallback)1 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 BaseListLoadResult (com.extjs.gxt.ui.client.data.BaseListLoadResult)1 TreeStore (com.extjs.gxt.ui.client.store.TreeStore)1