Search in sources :

Example 16 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class PartnerTest method testAddPartner.

@Test
public void testAddPartner() {
    PartnerDTO newPartner = new PartnerDTO();
    newPartner.setName("Solidarites");
    CreateResult cr = execute(new UpdatePartner(PEAR_PLUS_DB_ID, newPartner));
    assertThat(cr.getNewId(), not(equalTo(SOL_ID)));
    SchemaDTO schema = execute(new GetSchema());
    PartnerDTO partner = schema.getDatabaseById(PEAR_PLUS_DB_ID).getPartnerById(cr.getNewId());
    Assert.assertNotNull(partner);
    Assert.assertEquals(newPartner.getName(), partner.getName());
}
Also used : PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) DuplicateCreateResult(org.activityinfo.legacy.shared.command.result.DuplicateCreateResult) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) Test(org.junit.Test)

Example 17 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class GetActivityFormsHandler method execute.

@Override
public void execute(GetActivityForms command, final ExecutionContext context, final AsyncCallback<ActivityFormResults> callback) {
    composeQuery(command.getFilter()).execute(context.getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, final SqlResultSet results) {
            context.execute(new GetSchema(), new AsyncCallback<SchemaDTO>() {

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

                @Override
                public void onSuccess(SchemaDTO schema) {
                    LOGGER.log(Level.INFO, "Forms matching filter: " + results.getRows().size());
                    final List<Promise<ActivityFormDTO>> pending = new ArrayList<>();
                    for (SqlResultSetRow row : results.getRows()) {
                        int activityId = row.getInt("activityId");
                        boolean visible = (schema.getActivityById(activityId) != null);
                        if (visible) {
                            pending.add(fetchForm(context, activityId));
                        }
                    }
                    LOGGER.log(Level.INFO, "Forms pending: " + pending.size());
                    Promise.waitAll(pending).then(new Function<Void, ActivityFormResults>() {

                        @Nullable
                        @Override
                        public ActivityFormResults apply(@Nullable Void aVoid) {
                            LOGGER.log(Level.INFO, "Form loading completed.");
                            List<ActivityFormDTO> forms = new ArrayList<>();
                            for (Promise<ActivityFormDTO> pendingForm : pending) {
                                forms.add(pendingForm.get());
                            }
                            return new ActivityFormResults(forms);
                        }
                    }).then(callback);
                }
            });
        }
    });
}
Also used : ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) ActivityFormResults(org.activityinfo.legacy.shared.command.result.ActivityFormResults) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) Promise(org.activityinfo.promise.Promise) Function(com.google.common.base.Function) SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) Nullable(javax.annotation.Nullable)

Example 18 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class SchemaImporterV2Test method doImport.

private UserDatabaseDTO doImport(String resourceName) throws IOException {
    Map<String, Object> dbProps = Maps.newHashMap();
    dbProps.put("name", "Syria");
    dbProps.put("countryId", 1);
    int databaseId = execute(new CreateEntity("UserDatabase", dbProps)).getNewId();
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO db = schema.getDatabaseById(databaseId);
    if (db == null) {
        throw new AssertionError("database not created");
    }
    SchemaImporterV2 importer = new SchemaImporterV2(getDispatcher(), db, warningTemplates());
    importer.setProgressListener(new SchemaImporterV2.ProgressListener() {

        @Override
        public void submittingBatch(int batchNumber, int batchCount) {
            System.out.println("Submitting batch " + batchNumber + " of " + batchCount);
        }
    });
    boolean success = importer.parseColumns(source(resourceName));
    if (success) {
        importer.processRows();
    }
    for (SafeHtml warning : importer.getWarnings()) {
        System.err.println(warning);
    }
    if (!success) {
        throw new AssertionError("there were fatal errors");
    }
    importer.persist(new AsyncCallback<Void>() {

        @Override
        public void onSuccess(Void result) {
            System.out.println("Success");
        }

        @Override
        public void onFailure(Throwable caught) {
            throw new AssertionError(caught);
        }
    });
    return execute(new GetSchema()).getDatabaseById(databaseId);
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Example 19 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class CreateDatabaseTest method createWithSpecificCountry.

@Test
@OnDataSet("/dbunit/multicountry.db.xml")
public void createWithSpecificCountry() throws CommandException {
    UserDatabaseDTO db = new UserDatabaseDTO();
    db.setName("Warchild Haiti");
    db.setFullName("Warchild Haiti");
    setUser(1);
    CreateEntity cmd = new CreateEntity(db);
    cmd.getProperties().put("countryId", 2);
    CreateResult cr = execute(cmd);
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
    assertNotNull(newdb);
    assertThat(newdb.getCountry(), is(notNullValue()));
    assertThat(newdb.getCountry().getName(), is(equalTo("Haiti")));
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 20 with SchemaDTO

use of org.activityinfo.legacy.shared.model.SchemaDTO in project activityinfo by bedatadriven.

the class DeleteTest method testDeleteActivity.

@Test
public void testDeleteActivity() throws CommandException {
    ActivityFormDTO form = execute(new GetActivityForm(1));
    execute(new Delete(form));
    execute(new Delete("Activity", 4));
    SchemaDTO schema = execute(new GetSchema());
    assertNull("delete by entity reference", schema.getActivityById(1));
    assertNull("delete by id", schema.getActivityById(4));
}
Also used : Delete(org.activityinfo.legacy.shared.command.Delete) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) Test(org.junit.Test)

Aggregations

SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)29 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)22 Test (org.junit.Test)19 UserDatabaseDTO (org.activityinfo.legacy.shared.model.UserDatabaseDTO)9 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)7 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)4 ActivityFormDTO (org.activityinfo.legacy.shared.model.ActivityFormDTO)4 OnDataSet (org.activityinfo.server.database.OnDataSet)4 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)3 GetActivityForm (org.activityinfo.legacy.shared.command.GetActivityForm)3 ActivityDTO (org.activityinfo.legacy.shared.model.ActivityDTO)3 Function (com.google.common.base.Function)2 Delete (org.activityinfo.legacy.shared.command.Delete)2 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)2 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)2 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)2 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)2 User (org.activityinfo.server.database.hibernate.entity.User)2 CacheResult (org.activityinfo.ui.client.dispatch.remote.cache.CacheResult)2 Before (org.junit.Before)2