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());
}
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;
}
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);
}
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));
}
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());
}
Aggregations