Search in sources :

Example 11 with CreateResult

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

the class ActivityTest method orderIndicatorsActivities.

@Test
public void orderIndicatorsActivities() {
    SchemaDTO schema = execute(new GetSchema());
    UserDatabaseDTO db = schema.getDatabaseById(1);
    LocationTypeDTO locType = schema.getCountryById(1).getLocationTypes().get(0);
    ActivityFormDTO act = new ActivityFormDTO();
    act.setName("Household Survey");
    act.setLocationType(locType);
    act.setReportingFrequency(ActivityFormDTO.REPORT_ONCE);
    CreateResult createResult = execute(CreateEntity.Activity(db, act));
    ResourceId classId = activityFormClass(createResult.getNewId());
    FormClass formClass = assertResolves(locator.getFormClass(classId));
    // create three new fields with an order that mixes "attributes" and "indicators"
    FormField newField = new FormField(ResourceId.generateFieldId(QuantityType.TYPE_CLASS));
    newField.setLabel("How old are you?");
    newField.setType(new QuantityType().setUnits("years"));
    formClass.addElement(newField);
    FormField newGenderField = new FormField(ResourceId.generateFieldId(EnumType.TYPE_CLASS));
    newGenderField.setLabel("Gender");
    EnumItem male = new EnumItem(EnumItem.generateId(), "Male");
    EnumItem female = new EnumItem(EnumItem.generateId(), "Female");
    newGenderField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(male, female)));
    formClass.addElement(newGenderField);
    FormField newTextField = new FormField(ResourceId.generateFieldId(TextType.TYPE_CLASS));
    newTextField.setLabel("What is your name?");
    newTextField.setType(TextType.SIMPLE);
    formClass.addElement(newTextField);
    assertResolves(locator.persist(formClass));
    TFormClass reform = new TFormClass(assertResolves(locator.getFormClass(formClass.getId())));
    System.out.println(Joiner.on("\n").join(reform.getFormClass().getFields()));
    int a = reform.indexOfField("How old are you?");
    int b = reform.indexOfField("Gender");
    int c = reform.indexOfField("What is your name?");
    assertTrue(a < b && b < c);
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) EnumType(org.activityinfo.model.type.enumerated.EnumType) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) Test(org.junit.Test)

Example 12 with CreateResult

use of org.activityinfo.legacy.shared.command.result.CreateResult 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 13 with CreateResult

use of org.activityinfo.legacy.shared.command.result.CreateResult 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 14 with CreateResult

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

the class CreateSiteTest method testAllAttribsFalse.

@Test
public void testAllAttribsFalse() throws CommandException {
    // create a new detached, client model
    SiteDTO newSite = new SiteDTO();
    newSite.setId(new KeyGenerator().generateInt());
    newSite.setActivityId(1);
    newSite.setLocationId(1);
    newSite.setPartner(new PartnerDTO(1, "Foobar"));
    newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
    newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
    newSite.setLocationName("Virunga");
    newSite.setAttributeValue(1, false);
    newSite.setAttributeValue(2, false);
    newSite.setProject(new ProjectDTO(1, "SomeProject"));
    // create command
    CreateSite cmd = new CreateSite(newSite);
    assertThat((Integer) cmd.getProperties().get("locationId"), equalTo(1));
    // execute the command
    setUser(1);
    CreateResult result = execute(cmd);
    // let the client know the command has succeeded
    newSite.setId(result.getNewId());
    // try to retrieve what we've created
    SiteDTO secondRead = readSite(newSite.getId());
    // confirm that the changes are there
    Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(1));
    Assert.assertEquals("site.attribute[2]", false, secondRead.getAttributeValue(2));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) GregorianCalendar(java.util.GregorianCalendar) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) CreateSite(org.activityinfo.legacy.shared.command.CreateSite) Test(org.junit.Test)

Example 15 with CreateResult

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

the class CreateSiteTest method test.

@Test
public void test() throws CommandException {
    LocationDTO location = LocationDTOs.newLocation();
    execute(new CreateLocation(location));
    SiteDTO newSite = SiteDTOs.newSite();
    newSite.setLocation(location);
    CreateSite cmd = new CreateSite(newSite);
    setUser(1);
    CreateResult result = execute(cmd);
    newSite.setId(result.getNewId());
    assertThat(result.getNewId(), not(equalTo(0)));
    SiteDTO secondRead = readSite(newSite.getId());
    SiteDTOs.validateNewSite(secondRead);
}
Also used : CreateLocation(org.activityinfo.legacy.shared.command.CreateLocation) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) CreateSite(org.activityinfo.legacy.shared.command.CreateSite) Test(org.junit.Test)

Aggregations

CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)46 Test (org.junit.Test)26 Date (java.util.Date)9 GetSchema (org.activityinfo.legacy.shared.command.GetSchema)7 UpdatePartner (org.activityinfo.legacy.shared.command.UpdatePartner)7 DuplicateCreateResult (org.activityinfo.legacy.shared.command.result.DuplicateCreateResult)7 OnDataSet (org.activityinfo.server.database.OnDataSet)6 CreateSite (org.activityinfo.legacy.shared.command.CreateSite)5 PartnerDTO (org.activityinfo.legacy.shared.model.PartnerDTO)5 CreateEntity (org.activityinfo.legacy.shared.command.CreateEntity)4 SchemaDTO (org.activityinfo.legacy.shared.model.SchemaDTO)4 TargetDTO (org.activityinfo.legacy.shared.model.TargetDTO)4 CuidAdapter.activityFormClass (org.activityinfo.model.legacy.CuidAdapter.activityFormClass)4 ResourceId (org.activityinfo.model.resource.ResourceId)4 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)3 GregorianCalendar (java.util.GregorianCalendar)3 CloneDatabase (org.activityinfo.legacy.shared.command.CloneDatabase)3 ProjectDTO (org.activityinfo.legacy.shared.model.ProjectDTO)3 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)3 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)3