Search in sources :

Example 6 with KeyGenerator

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));
}
Also used : CreateResult(org.activityinfo.legacy.shared.command.result.CreateResult) GregorianCalendar(java.util.GregorianCalendar) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) UpdateSite(org.activityinfo.legacy.shared.command.UpdateSite) CreateSite(org.activityinfo.legacy.shared.command.CreateSite) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 7 with KeyGenerator

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;
}
Also used : ProjectDTO(org.activityinfo.legacy.shared.model.ProjectDTO) PartnerDTO(org.activityinfo.legacy.shared.model.PartnerDTO) GregorianCalendar(java.util.GregorianCalendar) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator)

Example 8 with KeyGenerator

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()));
}
Also used : KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) LocalDate(org.activityinfo.model.type.time.LocalDate)

Example 9 with KeyGenerator

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");
}
Also used : RecordUpdate(org.activityinfo.model.resource.RecordUpdate) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Updater(org.activityinfo.store.query.server.Updater) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Example 10 with KeyGenerator

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));
}
Also used : FormClass(org.activityinfo.model.form.FormClass) KeyGenerator(org.activityinfo.model.legacy.KeyGenerator) FormField(org.activityinfo.model.form.FormField) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Aggregations

KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)18 Test (org.junit.Test)9 FormClass (org.activityinfo.model.form.FormClass)6 FormField (org.activityinfo.model.form.FormField)6 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)6 FormInstance (org.activityinfo.model.form.FormInstance)5 ResourceId (org.activityinfo.model.resource.ResourceId)4 GregorianCalendar (java.util.GregorianCalendar)3 CreateSite (org.activityinfo.legacy.shared.command.CreateSite)3 CreateResult (org.activityinfo.legacy.shared.command.result.CreateResult)3 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)3 FieldValue (org.activityinfo.model.type.FieldValue)3 LocalDate (org.activityinfo.model.type.time.LocalDate)3 OnDataSet (org.activityinfo.server.database.OnDataSet)3 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 RecordTransactionBuilder (org.activityinfo.model.resource.RecordTransactionBuilder)2 AttachmentValue (org.activityinfo.model.type.attachment.AttachmentValue)2 Quantity (org.activityinfo.model.type.number.Quantity)2 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)2 Optional (com.google.common.base.Optional)1