Search in sources :

Example 6 with GetSchema

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

the class ExportAuditLogExecutor method execute.

@Override
public ExportResult execute(ExportAuditLog descriptor) throws IOException {
    UserDatabaseDTO db = dispatcher.execute(new GetSchema()).getDatabaseById(descriptor.getDatabaseId());
    GeneratedResource export = storageProvider.create("text/csv;charset=UTF-8", String.format("AuditLog_%d_%s.csv", db.getId(), Filenames.timestamp()));
    try (CsvWriter writer = new CsvWriter(new OutputStreamWriter(export.openOutputStream(), Charsets.UTF_8))) {
        AuditLogWriter logWriter = new AuditLogWriter(entityManager.get(), db, writer);
        for (ActivityDTO activityDTO : db.getActivities()) {
            logWriter.writeForm(catalog, activityDTO.getFormId());
        }
    }
    return new ExportResult(export.getDownloadUri());
}
Also used : CsvWriter(org.activityinfo.server.endpoint.rest.CsvWriter) UserDatabaseDTO(org.activityinfo.legacy.shared.model.UserDatabaseDTO) OutputStreamWriter(java.io.OutputStreamWriter) GeneratedResource(org.activityinfo.server.generated.GeneratedResource) ActivityDTO(org.activityinfo.legacy.shared.model.ActivityDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) ExportResult(org.activityinfo.model.job.ExportResult)

Example 7 with GetSchema

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

the class CloneDatabaseTest method assertDbCloned.

private UserDatabaseDTO assertDbCloned(int newDbId, int sourceDbId, CloneDatabase cloneDatabase) {
    assertNotEquals(newDbId, sourceDbId);
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO sourceDb = schema.getDatabaseById(sourceDbId);
    UserDatabaseDTO targetDb = schema.getDatabaseById(newDbId);
    assertEquals(targetDb.getName(), "PearClone");
    assertEquals(targetDb.getFullName(), "PearClone Description");
    assertFormClassesCloned(sourceDb, targetDb);
    if (cloneDatabase.isCopyPartners()) {
        for (PartnerDTO sourcePartner : sourceDb.getPartners()) {
            String name = sourcePartner.get("name");
            if (name.equals("Default")) {
                continue;
            }
            PartnerDTO targetPartner = entityByName(targetDb.getPartners(), name);
            assertThat("partner " + name + " has same id", sourcePartner.getId(), equalTo(targetPartner.getId()));
        }
    }
    if (cloneDatabase.isCopyUserPermissions()) {
    // todo
    }
    if (cloneDatabase.isCopyData()) {
    // todo assert data
    }
    return targetDb;
}
Also used : GetSchema(org.activityinfo.legacy.shared.command.GetSchema)

Example 8 with GetSchema

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

the class CloneDatabaseTest method cloneWithoutDataCopy.

@Test
public void cloneWithoutDataCopy() throws CommandException {
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO pearDb = schema.getDatabaseById(PEAR_DATABASE_ID);
    CloneDatabase cloneDatabase = new CloneDatabase().setSourceDatabaseId(pearDb.getId()).setCopyData(false).setCopyPartners(true).setCopyUserPermissions(true).setCountryId(pearDb.getCountry().getId()).setName("PearClone").setDescription("PearClone Description");
    CreateResult cloneResult = execute(cloneDatabase);
    assertNotEquals(cloneResult.getNewId(), pearDb.getId());
    assertDbCloned(cloneResult.getNewId(), pearDb.getId(), cloneDatabase);
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) CloneDatabase(org.activityinfo.legacy.shared.command.CloneDatabase) Test(org.junit.Test)

Example 9 with GetSchema

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

the class CreateDatabaseTest method testCreate.

@Test
@OnDataSet("/dbunit/sites-simple1.db.xml")
public void testCreate() throws CommandException {
    UserDatabaseDTO db = new UserDatabaseDTO();
    db.setName("RIMS");
    db.setFullName("Reintegration Management Information System");
    CreateResult cr = execute(new CreateEntity(db));
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO newdb = schema.getDatabaseById(cr.getNewId());
    assertNotNull(newdb);
    assertEquals(db.getName(), newdb.getName());
    assertEquals(db.getFullName(), newdb.getFullName());
    assertNotNull(newdb.getCountry());
    assertEquals("Alex", newdb.getOwnerName());
    assertThat(newdb.getPartners(), hasSize(1));
}
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 10 with GetSchema

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

the class DeleteTest method testDeleteLocationType.

@Test
public void testDeleteLocationType() throws CommandException {
    int locationTypeId = 4;
    SchemaDTO schema = execute(new GetSchema());
    // assert location type exists
    assertNotNull(schema.getLocationTypeById(locationTypeId));
    execute(new Delete("LocationType", locationTypeId));
    schema = execute(new GetSchema());
    // assert "delete" flag is set
    assertTrue(schema.getLocationTypeById(locationTypeId).isDeleted());
}
Also used : Delete(org.activityinfo.legacy.shared.command.Delete) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) Test(org.junit.Test)

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