use of org.activityinfo.model.legacy.KeyGenerator in project activityinfo by bedatadriven.
the class CreateSiteTest method testSiteWithCalculatedIndicators.
@OnDataSet("/dbunit/sites-calculated-indicators.db.xml")
@Test
public void testSiteWithCalculatedIndicators() 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.setProject(new ProjectDTO(1, "SomeProject"));
newSite.setReportingPeriodId(11);
newSite.setIndicatorValue(1, 1);
newSite.setIndicatorValue(2, 2);
// create command
CreateSite cmd = new CreateSite(newSite);
assertThat((Integer) cmd.getProperties().get("locationId"), equalTo(1));
// execute the command
setUser(1);
CreateResult result = execute(cmd);
newSite.setId(result.getNewId());
// try to retrieve what we've created
SiteDTO firstRead = readSite(newSite.getId());
Assert.assertEquals(1d, firstRead.<Object>getIndicatorValue(1));
Assert.assertEquals(2d, firstRead.<Object>getIndicatorValue(2));
Assert.assertEquals(3d, firstRead.<Object>getIndicatorValue(11));
Assert.assertEquals(0.5d, firstRead.<Object>getIndicatorValue(12));
SiteDTO updateSite = new SiteDTO(newSite);
updateSite.setIndicatorValue(1, null);
updateSite.setIndicatorValue(2, null);
// update site
execute(new UpdateSite(newSite, updateSite));
SiteDTO secondRead = readSite(newSite.getId());
// BACHE
Assert.assertEquals(null, secondRead.getIndicatorValue(1));
// BENE
Assert.assertEquals(null, secondRead.getIndicatorValue(2));
Assert.assertEquals(null, secondRead.getIndicatorValue(11));
Assert.assertEquals(null, secondRead.getIndicatorValue(12));
}
use of org.activityinfo.model.legacy.KeyGenerator in project activityinfo by bedatadriven.
the class SiteDTOs method newSite.
public static SiteDTO newSite() {
SiteDTO newSite = new SiteDTO();
newSite.setId(new KeyGenerator().generateInt());
newSite.setActivityId(1);
newSite.setLocationId(1);
newSite.setPartner(new PartnerDTO(1, "Foobar"));
newSite.setReportingPeriodId(new KeyGenerator().generateInt());
newSite.setDate1((new GregorianCalendar(2008, 12, 1)).getTime());
newSite.setDate2((new GregorianCalendar(2009, 1, 3)).getTime());
newSite.setIndicatorValue(1, 996.0);
newSite.setIndicatorValue(2, null);
newSite.setAttributeValue(1, true);
newSite.setAttributeValue(2, false);
newSite.setComments("huba huba");
newSite.setProject(new ProjectDTO(1, "WoeiProject"));
return newSite;
}
use of org.activityinfo.model.legacy.KeyGenerator in project activityinfo by bedatadriven.
the class IndicatorValueTableUpdater method insertReportingPeriod.
public void insertReportingPeriod(QueryExecutor executor) {
// But we are not ready to remove the date1/date2 fields from the reportingperiod table
if (date1 == null) {
date1 = new Date(0);
}
if (date2 == null) {
date2 = new Date(0);
}
reportingPeriodId = new KeyGenerator().generateInt();
executor.update("INSERT INTO reportingperiod (siteId, reportingPeriodId, date1, date2, dateCreated, dateEdited) " + "VALUES (?, ?, ?, ?, ?, ?)", Arrays.asList(siteId, reportingPeriodId, date1, date2, new Date(), new Date()));
}
use of org.activityinfo.model.legacy.KeyGenerator in project activityinfo by bedatadriven.
the class MySqlUpdateTest method creatingActivitiesWithNullaryLocations.
@Test
public void creatingActivitiesWithNullaryLocations() {
int newId = new KeyGenerator().generateInt();
RecordUpdate change = new RecordUpdate();
change.setRecordId(cuid(SITE_DOMAIN, newId).asString());
change.setFormId(activityFormClass(ADVOCACY).asString());
change.setFieldValue("partner", partnerRecordId(1).asString());
change.setFieldValue("date1", "2015-01-01");
change.setFieldValue("date2", "2015-01-31");
Updater updater = updater();
updater.executeChange(change);
query(activityFormClass(ADVOCACY), "_id", "partner");
}
use of org.activityinfo.model.legacy.KeyGenerator in project activityinfo by bedatadriven.
the class MySqlUpdateTest method createForm.
@Test
public void createForm() {
KeyGenerator generator = new KeyGenerator();
int activityId = generator.generateInt();
FormClass formClass = new FormClass(CuidAdapter.activityFormClass(activityId));
formClass.setDatabaseId(1);
formClass.setLabel("New Form");
formClass.addElement(new FormField(CuidAdapter.generateIndicatorId()).setType(TextType.SIMPLE).setLabel("Name").setRequired(true));
catalog.createOrUpdateFormSchema(formClass);
System.out.println("Created activity " + activityId);
// FormClass reform = catalog.getFormClass(formClass.getId());
//
// // Ensure that partner field is automatically added
// FormField partnerField = reform.getField(CuidAdapter.partnerField(activityId));
//
// assertThat(partnerField.getType(), instanceOf(ReferenceType.class));
}
Aggregations