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