use of org.activityinfo.legacy.shared.command.GetSchema in project activityinfo by bedatadriven.
the class SiteAdminTreeLoaderTest method load.
@Test
public void load() {
DispatcherStub dispatcher = new DispatcherStub();
dispatcher.setResult(new GetSchema(), DTOs.PEAR.SCHEMA);
dispatcher.setResult(new GetAdminEntities(1), DTOs.PROVINCES);
SiteAdminTreeLoader loader = new SiteAdminTreeLoader(dispatcher, new AdminGroupingModel(1));
new TreeStore<ModelData>(loader);
loader.load();
}
use of org.activityinfo.legacy.shared.command.GetSchema in project activityinfo by bedatadriven.
the class UpdatePartnerHandlerTest method modifyShared.
@Test
public void modifyShared() {
SchemaDTO schema = execute(new GetSchema());
UserDatabaseDTO nfiDatabase = schema.getDatabaseById(NFI_DATABASE);
UserDatabaseDTO healthDatabase = schema.getDatabaseById(HEALTH_DATABASE);
// The "Default" partner starts out being shared between the two database.
PartnerDTO nfiDefaultPartner = nfiDatabase.getDefaultPartner().get();
PartnerDTO healthDefaultPartner = healthDatabase.getDefaultPartner().get();
assertThat(nfiDefaultPartner.getId(), equalTo(healthDefaultPartner.getId()));
// If I update the name of "Default" partner for my database, a copy should
// be created.
PartnerDTO updatedPartner = new PartnerDTO(nfiDefaultPartner.getId(), "Solidarites");
updatedPartner.setFullName("Solidarites International");
execute(new UpdatePartner(1, updatedPartner));
// Now we should have two distinct partner objects
schema = execute(new GetSchema());
nfiDatabase = schema.getDatabaseById(NFI_DATABASE);
healthDatabase = schema.getDatabaseById(HEALTH_DATABASE);
assertThat(nfiDatabase.getPartners(), containsInAnyOrder(hasProperty("name", equalTo("Solidarites")), hasProperty("name", equalTo("NRC"))));
assertThat(healthDatabase.getPartners(), contains(hasProperty("name", equalTo("Default"))));
// Users in the NFI database should be reassigned to the new NRC partner object
UserResult nfiUsers = execute(new GetUsers(NFI_DATABASE));
Optional<UserPermissionDTO> bavon = nfiUsers.getData().stream().filter(u -> u.getEmail().equals("bavon@nrc.org")).findAny();
Optional<UserPermissionDTO> lisa = nfiUsers.getData().stream().filter(u -> u.getEmail().equals("lisa@solidarites")).findAny();
// Bavon should stay as NRC
assertThat(bavon.get().getPartner(), hasProperty("name", equalTo("NRC")));
// Lisa should be moved to the new Solidarites partner
assertThat(lisa.get().getPartner(), hasProperty("name", equalTo("Solidarites")));
// Users in the Health database should be unaffected
UserResult healthUsers = execute(new GetUsers(HEALTH_DATABASE));
Optional<UserPermissionDTO> bavonInHealth = healthUsers.getData().stream().filter(u -> u.getEmail().equals("bavon@nrc.org")).findAny();
assertThat(bavonInHealth.get().getPartner(), hasProperty("name", equalTo("Default")));
// Sites in the NFI database should be update to point to the new partner
SiteDTO nfiSite1 = execute(GetSites.byId(1)).getData().get(0);
SiteDTO nfiSite3 = execute(GetSites.byId(3)).getData().get(0);
assertThat(nfiSite1.getPartner(), hasProperty("name", equalTo("Solidarites")));
assertThat(nfiSite3.getPartner(), hasProperty("name", equalTo("NRC")));
// Sites in the Health database should be unaffected
SiteDTO healthSite4 = execute(GetSites.byId(4)).getData().get(0);
assertThat(healthSite4.getPartner(), hasProperty("name", equalTo("Default")));
}
use of org.activityinfo.legacy.shared.command.GetSchema 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();
}
use of org.activityinfo.legacy.shared.command.GetSchema in project activityinfo by bedatadriven.
the class LinkIndicatorTest method setUser.
@Before
public void setUser() {
setUser(DATABASE_OWNER);
/*
* Initial data load
*/
SchemaDTO schema = execute(new GetSchema());
db = schema.getDatabaseById(1);
}
use of org.activityinfo.legacy.shared.command.GetSchema in project activityinfo by bedatadriven.
the class LockedPeriodTest method createForFolder.
@Test
public void createForFolder() {
setUser(1);
LockedPeriodDTO dto = new LockedPeriodDTO();
dto.setName("NFI ");
dto.setFromDate(new LocalDate(2011, 1, 1));
dto.setToDate(new LocalDate(2011, 1, 31));
dto.setEnabled(true);
CreateLockedPeriod create = new CreateLockedPeriod(dto);
create.setFolderId(1);
execute(create);
// Now verify that they appear
SchemaDTO schema = execute(new GetSchema());
assertThat(schema.getDatabaseById(1).getFolderById(1).getLockedPeriods(), Matchers.hasSize(1));
LockedPeriodSet locks = new LockedPeriodSet(schema);
assertTrue(locks.isActivityLocked(1, new LocalDate(2011, 1, 1)));
// Verify that the new code works too...
DatabaseProviderImpl provider = new DatabaseProviderImpl(Providers.of(em));
UserDatabaseMeta metadata = provider.getDatabaseMetadata(CuidAdapter.databaseId(1), 1);
ArrayList<RecordLock> folderLocks = Lists.newArrayList(metadata.getEffectiveLocks(CuidAdapter.folderId(1)));
ArrayList<RecordLock> formLocks = Lists.newArrayList(metadata.getEffectiveLocks(CuidAdapter.activityFormClass(1)));
assertThat(folderLocks, Matchers.hasSize(2));
assertThat(formLocks, Matchers.hasSize(3));
}
Aggregations