Search in sources :

Example 1 with SerialNumberType

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();
}
Also used : SerialNumberType(org.activityinfo.model.type.SerialNumberType) ReferenceType(org.activityinfo.model.type.ReferenceType) AttachmentUploadFieldWidget(org.activityinfo.ui.client.component.form.field.attachment.AttachmentUploadFieldWidget) ImageUploadFieldWidget(org.activityinfo.ui.client.component.form.field.attachment.ImageUploadFieldWidget) NarrativeType(org.activityinfo.model.type.NarrativeType) EnumType(org.activityinfo.model.type.enumerated.EnumType) CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) AttachmentType(org.activityinfo.model.type.attachment.AttachmentType) BooleanType(org.activityinfo.model.type.primitive.BooleanType) LocalDateIntervalType(org.activityinfo.model.type.time.LocalDateIntervalType) FieldType(org.activityinfo.model.type.FieldType) CalculatedFieldType(org.activityinfo.model.type.expr.CalculatedFieldType) TextType(org.activityinfo.model.type.primitive.TextType) GeoPointType(org.activityinfo.model.type.geo.GeoPointType) QuantityType(org.activityinfo.model.type.number.QuantityType) LocalDateType(org.activityinfo.model.type.time.LocalDateType) BarcodeType(org.activityinfo.model.type.barcode.BarcodeType)

Example 2 with SerialNumberType

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);
}
Also used : SerialNumberType(org.activityinfo.model.type.SerialNumberType) UiHandler(com.google.gwt.uibinder.client.UiHandler)

Example 3 with SerialNumberType

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");
}
Also used : SerialNumber(org.activityinfo.model.type.SerialNumber) ActivityInfoClient(org.activityinfo.client.ActivityInfoClient) FormClass(org.activityinfo.model.form.FormClass) ColumnView(org.activityinfo.model.query.ColumnView) ColumnSet(org.activityinfo.model.query.ColumnSet) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) FormField(org.activityinfo.model.form.FormField) SerialNumberType(org.activityinfo.model.type.SerialNumberType) QueryModel(org.activityinfo.model.query.QueryModel) Test(org.junit.Test)

Example 4 with SerialNumberType

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)));
}
Also used : SerialNumber(org.activityinfo.model.type.SerialNumber) ActivityInfoClient(org.activityinfo.client.ActivityInfoClient) FormClass(org.activityinfo.model.form.FormClass) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) FormField(org.activityinfo.model.form.FormField) SerialNumberType(org.activityinfo.model.type.SerialNumberType) Test(org.junit.Test)

Example 5 with SerialNumberType

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)));
}
Also used : SerialNumber(org.activityinfo.model.type.SerialNumber) FormClass(org.activityinfo.model.form.FormClass) JsonValue(org.activityinfo.json.JsonValue) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) FormField(org.activityinfo.model.form.FormField) SerialNumberType(org.activityinfo.model.type.SerialNumberType) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Test(org.junit.Test)

Aggregations

SerialNumberType (org.activityinfo.model.type.SerialNumberType)7 SerialNumber (org.activityinfo.model.type.SerialNumber)5 FormClass (org.activityinfo.model.form.FormClass)4 FormField (org.activityinfo.model.form.FormField)4 FormInstance (org.activityinfo.model.form.FormInstance)4 FieldValue (org.activityinfo.model.type.FieldValue)4 Test (org.junit.Test)4 ActivityInfoClient (org.activityinfo.client.ActivityInfoClient)2 JsonValue (org.activityinfo.json.JsonValue)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 UiHandler (com.google.gwt.uibinder.client.UiHandler)1 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)1 ColumnSet (org.activityinfo.model.query.ColumnSet)1 ColumnView (org.activityinfo.model.query.ColumnView)1 QueryModel (org.activityinfo.model.query.QueryModel)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 FieldType (org.activityinfo.model.type.FieldType)1 NarrativeType (org.activityinfo.model.type.NarrativeType)1 ReferenceType (org.activityinfo.model.type.ReferenceType)1 AttachmentType (org.activityinfo.model.type.attachment.AttachmentType)1