Search in sources :

Example 21 with GetSchema

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();
}
Also used : AdminGroupingModel(org.activityinfo.ui.client.page.entry.grouping.AdminGroupingModel) TreeStore(com.extjs.gxt.ui.client.store.TreeStore) DispatcherStub(org.activityinfo.ui.client.dispatch.DispatcherStub) GetAdminEntities(org.activityinfo.legacy.shared.command.GetAdminEntities) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) Test(org.junit.Test)

Example 22 with GetSchema

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")));
}
Also used : CommandTestCase2(org.activityinfo.server.command.CommandTestCase2) RunWith(org.junit.runner.RunWith) IsEqual.equalTo(org.hamcrest.core.IsEqual.equalTo) org.activityinfo.legacy.shared.model(org.activityinfo.legacy.shared.model) Matchers(org.hamcrest.Matchers) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) GetUsers(org.activityinfo.legacy.shared.command.GetUsers) Assert.assertThat(org.junit.Assert.assertThat) GetSites(org.activityinfo.legacy.shared.command.GetSites) InjectionSupport(org.activityinfo.fixtures.InjectionSupport) Optional(java.util.Optional) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UserResult(org.activityinfo.legacy.shared.command.result.UserResult) GetUsers(org.activityinfo.legacy.shared.command.GetUsers) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UpdatePartner(org.activityinfo.legacy.shared.command.UpdatePartner) Test(org.junit.Test)

Example 23 with GetSchema

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

Example 24 with GetSchema

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);
}
Also used : SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) Before(org.junit.Before)

Example 25 with GetSchema

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));
}
Also used : DatabaseProviderImpl(org.activityinfo.server.endpoint.rest.DatabaseProviderImpl) RecordLock(org.activityinfo.model.database.RecordLock) LockedPeriodSet(org.activityinfo.legacy.shared.model.LockedPeriodSet) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) SchemaDTO(org.activityinfo.legacy.shared.model.SchemaDTO) GetSchema(org.activityinfo.legacy.shared.command.GetSchema) UserDatabaseMeta(org.activityinfo.model.database.UserDatabaseMeta) CreateLockedPeriod(org.activityinfo.legacy.shared.command.CreateLockedPeriod) LockedPeriodDTO(org.activityinfo.legacy.shared.model.LockedPeriodDTO) 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