Search in sources :

Example 31 with CreateResult

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

the class CustomerCalcIndicatorTest method calculations.

@Test
public void calculations() {
    formClass = createFormClass();
    int activityId = getLegacyIdFromCuid(formClass.getId());
    SiteDTO newSite = newSite(activityId);
    newSite.setIndicatorValue(fieldId("EXP"), 3);
    newSite.setIndicatorValue(fieldId("WATER_ALLOC"), 400);
    newSite.setIndicatorValue(fieldId("PCT_INITIAL"), 50);
    newSite.setIndicatorValue(fieldId("PCT_INITIAL_HARD"), 20);
    newSite.setIndicatorValue(fieldId("PCT_INITIAL_SOFT"), 30);
    CreateResult createSiteResult = execute(new CreateSite(newSite));
    // let the client know the command has succeeded
    newSite.setId(createSiteResult.getNewId());
    PagingLoadResult<SiteDTO> loadResult = execute(GetSites.byId(newSite.getId()));
    Assert.assertEquals(1, loadResult.getData().size());
    SiteDTO siteDTO = loadResult.getData().get(0);
    // WATER_EXP = EXP * (WATER_ALLOC / 100)
    assertThat(indicatorValue(siteDTO, "WATER_EXP"), closeTo(12, 0));
    // INITIAL = WATER_EXP * (PCT_INITIAL / 100)
    assertThat(indicatorValue(siteDTO, "INITIAL"), closeTo(6, 0));
    // INITIAL_HARD = WATER_EXP * (PCT_INITIAL_HARD / 100)
    assertThat(indicatorValue(siteDTO, "INITIAL_HARD"), closeTo(2.4, 0.001));
    // INITIAL_SOFT = WATER_EXP * (PCT_INITIAL_HARD / 100)
    assertThat(indicatorValue(siteDTO, "INITIAL_SOFT"), closeTo(3.6, 0.001));
    // INITIAL_TOTAL = INITIAL + INITIAL_HARD + INITIAL_SOFT
    assertThat(indicatorValue(siteDTO, "INITIAL_TOTAL"), closeTo(12d, 0.001));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) Test(org.junit.Test)

Example 32 with CreateResult

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

the class ActivityTest method newFormWithoutDates.

@Test
public void newFormWithoutDates() {
    // Create an activity in the same way that the Design Presenter does...
    int databaseId = 1;
    ActivityDTO newEntity = new ActivityDTO();
    newEntity.setName("My Form");
    newEntity.set("databaseId", databaseId);
    newEntity.set("classicView", false);
    newEntity.set("reportingFrequency", ActivityFormDTO.REPORT_ONCE);
    newEntity.set("locationTypeId", 2);
    newEntity.set("published", 0);
    CreateResult createResult = execute(new CreateEntity(newEntity));
    // Some definitions...
    int activityId = createResult.getNewId();
    ResourceId formId = CuidAdapter.activityFormClass(activityId);
    ResourceId startDateId = CuidAdapter.field(formId, CuidAdapter.START_DATE_FIELD);
    ResourceId endDateId = CuidAdapter.field(formId, CuidAdapter.END_DATE_FIELD);
    // Now delete the date fields in the form designer...
    FormClass formClass = assertResolves(locator.getFormClass(formId));
    formClass.removeField(startDateId);
    formClass.removeField(endDateId);
    assertResolves(locator.persist(formClass));
    // Now verify that the form class no longer has the date fields
    formClass = assertResolves(locator.getFormClass(formId));
    assertThat(formClass.getFields(), not(hasItem(withId(startDateId))));
    assertThat(formClass.getFields(), not(hasItem(withId(endDateId))));
    // Now submit a new entry without dates...
    FormInstance newInstance = new FormInstance(ResourceId.generateSubmissionId(formId), formId);
    newInstance.set(CuidAdapter.partnerField(activityId), CuidAdapter.partnerRef(databaseId, 1));
    assertResolves(locator.persist(newInstance));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) ResourceId(org.activityinfo.model.resource.ResourceId) CuidAdapter.activityFormClass(org.activityinfo.model.legacy.CuidAdapter.activityFormClass) Test(org.junit.Test)

Example 33 with CreateResult

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

the class ActivityTest method createActivity.

@Test
public void createActivity() {
    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));
    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 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));
    FormClass reform = assertResolves(locator.getFormClass(formClass.getId()));
    assertHasFieldWithLabel(reform, "How old are you?");
    newField.setLabel("How old are you today?");
    // save again
    assertResolves(locator.persist(formClass));
    reform = assertResolves(locator.getFormClass(formClass.getId()));
    assertHasFieldWithLabel(reform, "How old are you today?");
    System.out.println(reform.getFields().toString());
    assertThat(reform.getFields(), hasSize(8));
    List<EnumItem> values = Lists.newArrayList();
    values.add(new EnumItem(EnumItem.generateId(), "Option 1"));
    values.add(new EnumItem(EnumItem.generateId(), "Option 2"));
}
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) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) Test(org.junit.Test)

Example 34 with CreateResult

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

the class AttributeGroupTest method testCreate.

@Test
public void testCreate() throws Exception {
    // execute the command
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("name", "Type de Conflit");
    properties.put("multipleAllowed", true);
    properties.put("activityId", 1);
    CreateEntity cmd = new CreateEntity("AttributeGroup", properties);
    CreateResult result = execute(cmd);
    // check if it has been added
    ActivityFormDTO activity = execute(new GetActivityForm(1));
    AttributeGroupDTO group = activity.getAttributeGroupById(result.getNewId());
    Assert.assertNotNull("attribute group is created", group);
    Assert.assertEquals("name is correct", group.getName(), "Type de Conflit");
    Assert.assertTrue("multiple allowed is set to true", group.isMultipleAllowed());
}
Also used : CreateEntity(org.activityinfo.legacy.shared.command.CreateEntity) AttributeGroupDTO(org.activityinfo.legacy.shared.model.AttributeGroupDTO) CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) ActivityFormDTO(org.activityinfo.legacy.shared.model.ActivityFormDTO) HashMap(java.util.HashMap) GetActivityForm(org.activityinfo.legacy.shared.command.GetActivityForm) Test(org.junit.Test)

Example 35 with CreateResult

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

the class CloneDatabaseTest method cloneWithDifferentCountry.

// https://bedatadriven.atlassian.net/browse/AI-315
// it seems that the problem occurs when there is a classic form with a "Village" location. If you change countries,
// you need to change the locationTypeId to a location type in the new country. Users can change the location type afterwards,
// so I would suggest that we apply a simple rule:
// 
// 1. If there is a location type with the same name in the new country, use that location Type
// 2. if the source locationtype is bound to an adminlevel, choose the first root adminlevel in the new country
// 3. If the source locationtype is the null location type ( = Country) then the use the corresponding null locationtype in the new form
// 4. Otherwise use the "Village" location type in the target country.
@Test
public void cloneWithDifferentCountry() 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(UKRAINE_COUNTRY_ID).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)

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