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