use of org.activityinfo.model.type.SerialNumberType in project activityinfo by bedatadriven.
the class FormFieldWidgetFactory method createWidget.
public Promise<? extends FormFieldWidget> createWidget(FormClass formClass, FormField field, FieldUpdater valueUpdater) {
FieldType type = field.getType();
if (type instanceof QuantityType) {
return Promise.resolved(new QuantityFieldWidget((QuantityType) type, valueUpdater));
} else if (type instanceof SerialNumberType) {
return Promise.resolved(new SerialNumberFieldWidget((SerialNumberType) type));
} else if (type instanceof NarrativeType) {
return Promise.resolved(new NarrativeFieldWidget(valueUpdater));
} else if (type instanceof TextType) {
return Promise.resolved(new TextFieldWidget((TextType) type, valueUpdater));
} else if (type instanceof CalculatedFieldType) {
return Promise.resolved(new CalculatedFieldWidget(valueUpdater));
} else if (type instanceof LocalDateType) {
return Promise.resolved(new DateFieldWidget(valueUpdater));
} else if (type instanceof LocalDateIntervalType) {
return Promise.resolved(new DateIntervalFieldWidget(valueUpdater));
} else if (type instanceof GeoPointType) {
return Promise.resolved(new GeographicPointWidget(valueUpdater));
} else if (type instanceof EnumType) {
return Promise.resolved(new EnumFieldWidget((EnumType) field.getType(), valueUpdater, fieldWidgetMode));
} else if (type instanceof BooleanType) {
return Promise.resolved(new BooleanFieldWidget(valueUpdater));
} else if (type instanceof AttachmentType) {
AttachmentType attachmentType = (AttachmentType) type;
if (attachmentType.getKind() == AttachmentType.Kind.IMAGE) {
return Promise.resolved(new ImageUploadFieldWidget(formClass.getId(), valueUpdater, fieldWidgetMode));
} else {
return Promise.resolved(new AttachmentUploadFieldWidget(formClass.getId(), valueUpdater, fieldWidgetMode));
}
} else if (type instanceof ReferenceType) {
return createReferenceWidget(field, valueUpdater);
} else if (type instanceof BarcodeType) {
return Promise.resolved(new BarcodeFieldWidget(valueUpdater));
}
Log.error("Unexpected field type " + type.getTypeClass());
throw new UnsupportedOperationException();
}
use of org.activityinfo.model.type.SerialNumberType in project activityinfo by bedatadriven.
the class SerialNumberTypeEditor method onFormulaChange.
@UiHandler("prefixFormulaBox")
public void onFormulaChange(KeyUpEvent event) {
String updatedFormula = prefixFormulaBox.getValue();
SerialNumberType updatedType = currentType().withPrefixFormula(updatedFormula);
updateType(updatedType);
validateFormula(updatedFormula);
}
use of org.activityinfo.model.type.SerialNumberType in project activityinfo by bedatadriven.
the class SerialNumberTest method testWithPrefix.
@Test
public void testWithPrefix() {
TestDatabase database = harness.createDatabase();
ActivityInfoClient client = harness.client();
FormClass formClass = new FormClass(harness.newFormId());
formClass.setLabel("Test Prefix");
formClass.setDatabaseId(database.getId());
FormField partnerField = CuidAdapter.partnerField(formClass);
formClass.addElement(partnerField);
FormField provinceField = formClass.addField(harness.newFieldId()).setType(TextType.SIMPLE).setLabel("Province Code").setCode("PROVINCE").setRequired(true);
FormField fileNumberField = formClass.addField(harness.newFieldId()).setCode("SN").setType(new SerialNumberType("PROVINCE", 5)).setLabel("Record Number");
client.createForm(formClass);
FormInstance kunduz1 = new FormInstance(harness.newRecordId(), formClass.getId());
kunduz1.set(provinceField.getId(), "KUNDUZ");
kunduz1.set(partnerField.getId(), database.getDefaultPartner());
client.createRecord(kunduz1);
FormInstance kunduz2 = new FormInstance(harness.newRecordId(), formClass.getId());
kunduz2.set(provinceField.getId(), "KUNDUZ");
kunduz2.set(partnerField.getId(), database.getDefaultPartner());
client.createRecord(kunduz2);
FormInstance takhar = new FormInstance(harness.newRecordId(), formClass.getId());
takhar.set(provinceField.getId(), "TAKHAR");
takhar.set(partnerField.getId(), database.getDefaultPartner());
client.createRecord(takhar);
// Verify that the serial numbers have been assigned
kunduz1 = client.getTypedRecord(formClass, kunduz1.getId());
kunduz2 = client.getTypedRecord(formClass, kunduz2.getId());
takhar = client.getTypedRecord(formClass, takhar.getId());
assertThat(kunduz1.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("KUNDUZ", 1)));
assertThat(kunduz2.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("KUNDUZ", 2)));
assertThat(takhar.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber("TAKHAR", 1)));
// Now verify that we can query a table with serial numbers
QueryModel queryModel = new QueryModel(formClass.getId());
queryModel.selectResourceId().as("id");
queryModel.selectField("SN");
ColumnSet columnSet = client.queryTable(queryModel);
ColumnView sn = columnSet.getColumnView("SN");
}
use of org.activityinfo.model.type.SerialNumberType in project activityinfo by bedatadriven.
the class SerialNumberTest method simpleTest.
@Test
public void simpleTest() {
TestDatabase database = harness.createDatabase();
ActivityInfoClient client = harness.client();
FormClass formClass = new FormClass(harness.newFormId());
formClass.setLabel("Test Form");
formClass.setDatabaseId(database.getId());
FormField partnerField = CuidAdapter.partnerField(formClass);
formClass.addElement(partnerField);
FormField fileNumberField = formClass.addField(harness.newFieldId()).setType(new SerialNumberType()).setLabel("Record Number");
FormField nameField = formClass.addField(harness.newFieldId()).setType(TextType.SIMPLE).setLabel("Name");
client.createForm(formClass);
FormInstance record1 = new FormInstance(harness.newRecordId(), formClass.getId());
record1.set(nameField.getId(), "Sue");
record1.set(partnerField.getId(), database.getDefaultPartner());
FormInstance record2 = new FormInstance(harness.newRecordId(), formClass.getId());
record2.set(nameField.getId(), "Bob");
record2.set(partnerField.getId(), database.getDefaultPartner());
client.createRecord(record1);
client.createRecord(record2);
record1 = client.getTypedRecord(formClass, record1.getId());
record2 = client.getTypedRecord(formClass, record2.getId());
assertThat(record1.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber(1)));
assertThat(record2.get(fileNumberField.getId()), equalTo((FieldValue) new SerialNumber(2)));
}
use of org.activityinfo.model.type.SerialNumberType in project activityinfo by bedatadriven.
the class UpdaterTest method serialNumber.
@Test
public void serialNumber() throws JsonMappingException {
FormClass formClass = new FormClass(ResourceId.valueOf("FORM1"));
formClass.addField(ResourceId.valueOf("FIELD0")).setType(TextType.SIMPLE).setLabel("Province Code").setCode("PROVINCE").setRequired(true);
FormField serialNumberField = formClass.addField(ResourceId.valueOf("FIELD1")).setType(new SerialNumberType("PROVINCE", 5)).setRequired(true).setLabel("File Number").setCode("SN");
JsonValue fields = Json.createObject();
fields.put("PROVINCE", "KUNDUZ");
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "FORM1");
change.put("fields", fields);
TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
FormInstance effectiveRecord = updater.computeEffectiveRecord(formClass, Optional.<FormRecord>absent(), update);
updater.generateSerialNumber(formClass, serialNumberField, effectiveRecord, update);
FieldValue serialValue = update.getChangedFieldValues().get(serialNumberField.getId());
assertThat(serialValue, equalTo((FieldValue) new SerialNumber("KUNDUZ", 1)));
}
Aggregations