Search in sources :

Example 6 with GetActivityForm

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

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

the class AttributeGroupTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    // change the name of an entity group
    ActivityFormDTO activity = execute(new GetActivityForm(1));
    AttributeGroupDTO group = activity.getAttributeGroups().get(0);
    group.setName("Foobar");
    Map<String, Object> changes = new HashMap<String, Object>();
    changes.put("name", group.getName());
    execute(new UpdateEntity(group, changes));
    // reload data
    activity = execute(new GetActivityForm(1));
    // verify the property has been duly changed
    assertThat(activity.getAttributeGroups().get(0).getName(), equalTo(group.getName()));
}
Also used : AttributeGroupDTO(org.activityinfo.legacy.shared.model.AttributeGroupDTO) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) UpdateEntity(org.activityinfo.legacy.shared.command.UpdateEntity) HashMap(java.util.HashMap) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) Test(org.junit.Test)

Example 8 with GetActivityForm

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

the class DeleteTest method testDeleteIndicator.

@Test
public void testDeleteIndicator() throws CommandException {
    int activityId = 1;
    int indicatorId = 1;
    execute(new Delete("Indicator", indicatorId));
    ActivityFormDTO form = execute(new GetActivityForm(activityId));
    assertNull(form.getIndicatorById(indicatorId));
    PagingResult<SiteDTO> sites = execute(GetSites.byId(1));
    assertNull(sites.getData().get(0).getIndicatorValue(1));
}
Also used : Delete(org.activityinfo.legacy.shared.command.Delete) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) Test(org.junit.Test)

Example 9 with GetActivityForm

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

the class SchemaImporterV2Test method southSudan.

@Test
public void southSudan() throws IOException {
    UserDatabaseDTO db = doImport("schema_1321.csv");
    int activityId = db.getActivities().get(0).getId();
    ActivityFormDTO h2 = execute(new GetActivityForm(activityId));
    assertThat(h2.getName(), equalTo("H2"));
    assertThat(h2.getCategory(), equalTo("Health"));
}
Also used : ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) Test(org.junit.Test)

Example 10 with GetActivityForm

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

the class ExportIntegrationTest method fullTest.

@Test
public void fullTest() throws Throwable {
    User user = new User();
    user.setId(1);
    user.setName("Alex");
    SchemaDTO schema = execute(new GetSchema());
    TaskContext context = new TaskContext(getDispatcherSync(), new NullStorageProvider(), "XYZ");
    SiteExporter export = new SiteExporter(context);
    for (UserDatabaseDTO db : schema.getDatabases()) {
        for (ActivityDTO activity : db.getActivities()) {
            export.export(execute(new GetActivityForm(activity)), new Filter());
        }
    }
    File outputDir = new File("target/report-test/");
    outputDir.mkdirs();
    FileOutputStream fos = new FileOutputStream("target/report-test/ExportTest.xls");
    export.getBook().write(fos);
    fos.close();
}
Also used : SiteExporter(org.activityinfo.server.endpoint.export.SiteExporter) User(org.activityinfo.server.database.hibernate.entity.User) TaskContext(org.activityinfo.server.endpoint.export.TaskContext) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) Filter(org.activityinfo.legacy.shared.command.Filter) FileOutputStream(java.io.FileOutputStream) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) File(java.io.File) NullStorageProvider(org.activityinfo.server.report.NullStorageProvider) Test(org.junit.Test)

Aggregations

GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)16 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)10 Test (org.junit.Test)8 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)6 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)4 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)3 Delete (org.activityinfo.legacy.shared.command.Delete)3 AttributeGroupDTO (org.activityinfo.legacy.shared.model.AttributeGroupDTO)3 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)3 HashMap (java.util.HashMap)2 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 MaskingAsyncMonitor (org.activityinfo.ui.client.dispatch.monitor.MaskingAsyncMonitor)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 StreamResult (javax.xml.transform.stream.StreamResult)1 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)1 Filter (org.activityinfo.legacy.shared.command.Filter)1 UpdateEntity (org.activityinfo.legacy.shared.command.UpdateEntity)1 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)1 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)1