Search in sources :

Example 11 with Updater

use of org.activityinfo.store.query.server.Updater in project activityinfo by bedatadriven.

the class HrdCatalogTest method createResource.

@Test
public void createResource() {
    FormClass formClass = new FormClass(ResourceId.generateId());
    formClass.setParentFormId(ResourceId.valueOf("foo"));
    formClass.setLabel("NFI Distributions");
    FormField nameField = formClass.addField(ResourceId.generateId()).setLabel("Village name").setCode("VILLAGE").setType(TextType.SIMPLE);
    HrdStorageProvider catalog = new HrdStorageProvider();
    Updater updater = new Updater(catalog, userId, new BlobAuthorizerStub(), new HrdSerialNumberProvider());
    catalog.create(formClass);
    String[] villageNames = new String[] { "Rutshuru", "Beni", "Goma" };
    for (String villageName : villageNames) {
        TypedRecordUpdate update = new TypedRecordUpdate();
        update.setUserId(userId);
        update.setFormId(formClass.getId());
        update.setRecordId(ResourceId.generateSubmissionId(formClass));
        update.set(nameField.getId(), TextValue.valueOf(villageName));
        updater.execute(update);
    }
    QueryModel queryModel = new QueryModel(formClass.getId());
    queryModel.selectResourceId().as("id");
    queryModel.selectField("VILLAGE").as("village");
    ColumnSetBuilder builder = new ColumnSetBuilder(catalog, new NullFormSupervisor());
    ColumnSet columnSet = builder.build(queryModel);
    System.out.println(columnSet);
}
Also used : ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) FormClass(org.activityinfo.model.form.FormClass) Updater(org.activityinfo.store.query.server.Updater) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) FormField(org.activityinfo.model.form.FormField) Test(org.junit.Test)

Example 12 with Updater

use of org.activityinfo.store.query.server.Updater in project activityinfo by bedatadriven.

the class ActivityInfoClientAsyncStub method createRecord.

@Override
public Promise<Void> createRecord(String formId, NewFormRecordBuilder query) {
    try {
        FormStorageProvider catalog = newCatalog();
        Updater updater = new Updater(catalog, currentUserId(), blobAuthorizer, new SerialNumberProviderStub());
        updater.create(ResourceId.valueOf(formId), query.toJsonObject());
        return Promise.resolved(null);
    } catch (Exception e) {
        return Promise.rejected(e);
    }
}
Also used : FormStorageProvider(org.activityinfo.store.spi.FormStorageProvider) Updater(org.activityinfo.store.query.server.Updater)

Example 13 with Updater

use of org.activityinfo.store.query.server.Updater in project activityinfo by bedatadriven.

the class MySqlUpdateTest method updateSiteWithMultipleProperties.

@Test
public void updateSiteWithMultipleProperties() {
    RecordUpdate changeObject = new RecordUpdate();
    changeObject.setRecordId("s0000000001");
    changeObject.setFormId(activityFormClass(1).asString());
    changeObject.setFieldValue("partner", partnerRecordId(2).asString());
    changeObject.setFieldValue("BENE", 2100);
    changeObject.setFieldValue(attributeGroupField(1).asString(), "Deplacement");
    Updater updater = updater();
    updater.executeChange(changeObject);
    query(activityFormClass(1), "_id", "partner.label", "BENE", "cause");
    assertThat(column("_id"), hasValues("s0000000001", "s0000000002", "s0000000003"));
    assertThat(column("partner.label"), hasValues("Solidarites", "NRC", "Solidarites"));
    assertThat(column("BENE"), hasValues(2100, 3600, 10000));
    assertThat(column("cause"), hasValues("Deplacement", "Deplacement", "Catastrophe Naturelle"));
}
Also used : RecordUpdate(org.activityinfo.model.resource.RecordUpdate) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Updater(org.activityinfo.store.query.server.Updater) Test(org.junit.Test)

Example 14 with Updater

use of org.activityinfo.store.query.server.Updater in project activityinfo by bedatadriven.

the class MySqlUpdateTest method updateSiteWithMultiAttributes.

@Test
public void updateSiteWithMultiAttributes() {
    RecordUpdate changeObject = new RecordUpdate();
    changeObject.setRecordId("s0000000001");
    changeObject.setFormId(activityFormClass(1).asString());
    changeObject.setFieldValue(attributeGroupField(1).asString(), "Deplacement");
    changeObject.setFieldValue(attributeGroupField(2).asString(), "Casserole");
    Updater updater = updater();
    updater.executeChange(changeObject);
    query(activityFormClass(1), "_id", "cause", "[contenu du kit]");
    assertThat(column("_id"), hasValues("s0000000001", "s0000000002", "s0000000003"));
    assertThat(column("cause"), hasValues("Deplacement", "Deplacement", "Catastrophe Naturelle"));
}
Also used : RecordUpdate(org.activityinfo.model.resource.RecordUpdate) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Updater(org.activityinfo.store.query.server.Updater) Test(org.junit.Test)

Example 15 with Updater

use of org.activityinfo.store.query.server.Updater in project activityinfo by bedatadriven.

the class MySqlUpdateTest method testSingleSiteResource.

@Test
public void testSingleSiteResource() throws IOException {
    int databaseId = 1;
    ResourceId formId = CuidAdapter.activityFormClass(1);
    TypedRecordUpdate update = new TypedRecordUpdate();
    update.setUserId(userId);
    update.setFormId(formId);
    update.setRecordId(cuid(SITE_DOMAIN, 1));
    update.set(field(formId, PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 2));
    update.set(indicatorField(1), new Quantity(900));
    update.set(attributeGroupField(1), new EnumValue(attributeId(CATASTROPHE_NATURELLE_ID)));
    Updater updater = updater();
    updater.execute(update);
    query(CuidAdapter.activityFormClass(1), "_id", "partner", "BENE", "cause");
    assertThat(column("_id"), hasValues(cuid(SITE_DOMAIN, 1), cuid(SITE_DOMAIN, 2), cuid(SITE_DOMAIN, 3)));
    assertThat(column("partner"), hasValues(partnerRecordId(2), partnerRecordId(1), partnerRecordId(2)));
    assertThat(column("BENE"), hasValues(900, 3600, 10000));
    assertThat(column("cause"), hasValues("Catastrophe Naturelle", "Deplacement", "Catastrophe Naturelle"));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) Updater(org.activityinfo.store.query.server.Updater) Quantity(org.activityinfo.model.type.number.Quantity) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Test(org.junit.Test)

Aggregations

Updater (org.activityinfo.store.query.server.Updater)19 Test (org.junit.Test)13 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)12 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)11 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)3 ResourceId (org.activityinfo.model.resource.ResourceId)2 FormStorageProvider (org.activityinfo.store.spi.FormStorageProvider)2 JsonValue (org.activityinfo.json.JsonValue)1 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 FormInstance (org.activityinfo.model.form.FormInstance)1 FormRecord (org.activityinfo.model.form.FormRecord)1 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 QueryModel (org.activityinfo.model.query.QueryModel)1 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)1 Quantity (org.activityinfo.model.type.number.Quantity)1 HrdSerialNumberProvider (org.activityinfo.store.hrd.HrdSerialNumberProvider)1 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)1 InvalidUpdateException (org.activityinfo.store.query.server.InvalidUpdateException)1