Search in sources :

Example 76 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class HrdStorageProvider method getFormClasses.

@Override
public Map<ResourceId, FormClass> getFormClasses(Collection<ResourceId> formIds) {
    Set<Key<FormSchemaEntity>> toLoad = new HashSet<>();
    for (ResourceId formId : formIds) {
        toLoad.add(FormSchemaEntity.key(formId));
    }
    Map<Key<FormSchemaEntity>, FormSchemaEntity> entityMap = ObjectifyService.ofy().load().keys(toLoad);
    Map<ResourceId, FormClass> formClassMap = new HashMap<>();
    for (FormSchemaEntity formSchema : entityMap.values()) {
        formClassMap.put(formSchema.getFormId(), formSchema.readFormClass());
    }
    return formClassMap;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FormSchemaEntity(org.activityinfo.store.hrd.entity.FormSchemaEntity) Key(com.googlecode.objectify.Key)

Example 77 with FormClass

use of org.activityinfo.model.form.FormClass 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 78 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class FieldWidgetContainer method removeFromForm.

public void removeFromForm() {
    fieldPanel.getFocusPanel().removeFromParent();
    // get root or subform formclass
    FormClass formClass = (FormClass) formDesigner.getModel().getElementContainer(parentId);
    formClass.remove(formField);
}
Also used : FormClass(org.activityinfo.model.form.FormClass)

Example 79 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class AdminDimBinding method getColumnQuery.

@Override
public List<ColumnModel> getColumnQuery(FormTree formTree) {
    ResourceId levelClassId = adminLevelFormClass(model.getLevelId());
    Optional<FormClass> adminClass = formTree.getFormClassIfPresent(levelClassId);
    if (adminClass.isPresent()) {
        ColumnModel id = new ColumnModel();
        id.setFormula(new CompoundExpr(levelClassId, ColumnModel.ID_SYMBOL));
        id.setId(idColumn);
        ColumnModel label = new ColumnModel();
        label.setFormula(new FieldPath(levelClassId, field(levelClassId, NAME_FIELD)));
        label.setId(labelColumn);
        return Arrays.asList(id, label);
    } else {
        return Collections.emptyList();
    }
}
Also used : CompoundExpr(org.activityinfo.model.formula.CompoundExpr) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) FieldPath(org.activityinfo.model.formTree.FieldPath) ColumnModel(org.activityinfo.model.query.ColumnModel)

Example 80 with FormClass

use of org.activityinfo.model.form.FormClass in project activityinfo by bedatadriven.

the class RelevanceExpressionTest method createFormClass.

private static FormClass createFormClass() {
    EnumItem male = new EnumItem(ResourceId.generateId(), "Male");
    EnumItem female = new EnumItem(ResourceId.generateId(), "Female");
    EnumItem pregnantYes = new EnumItem(ResourceId.generateId(), "Yes");
    EnumItem pregnantNo = new EnumItem(ResourceId.generateId(), "No");
    FormField genderField = new FormField(GENDER_FIELD_ID);
    genderField.setLabel("Gender");
    genderField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(male, female)));
    FormField pregnantField = new FormField(PREGNANT_FIELD_ID);
    pregnantField.setLabel("are you currently pregnant?");
    pregnantField.setType(new EnumType(Cardinality.SINGLE, Arrays.asList(pregnantYes, pregnantNo)));
    FormField textField = new FormField(TEXT_FIELD_ID);
    textField.setLabel("Text");
    textField.setType(TextType.SIMPLE);
    FormField quantityField = new FormField(QUANTITY_FIELD_ID);
    quantityField.setLabel("Quantity");
    quantityField.setType(QuantityType.TYPE_CLASS.createType());
    final FormClass formClass = new FormClass(CuidAdapter.activityFormClass(1));
    formClass.addElement(genderField);
    formClass.addElement(pregnantField);
    formClass.addElement(textField);
    formClass.addElement(quantityField);
    return formClass;
}
Also used : EnumType(org.activityinfo.model.type.enumerated.EnumType) FormClass(org.activityinfo.model.form.FormClass) EnumItem(org.activityinfo.model.type.enumerated.EnumItem) FormField(org.activityinfo.model.form.FormField)

Aggregations

FormClass (org.activityinfo.model.form.FormClass)109 FormField (org.activityinfo.model.form.FormField)49 ResourceId (org.activityinfo.model.resource.ResourceId)41 Test (org.junit.Test)38 QuantityType (org.activityinfo.model.type.number.QuantityType)20 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)19 FormInstance (org.activityinfo.model.form.FormInstance)14 EnumType (org.activityinfo.model.type.enumerated.EnumType)12 JsonValue (org.activityinfo.json.JsonValue)11 FormTree (org.activityinfo.model.formTree.FormTree)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 ColumnSet (org.activityinfo.model.query.ColumnSet)8 QueryModel (org.activityinfo.model.query.QueryModel)8 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)8 FieldValue (org.activityinfo.model.type.FieldValue)7 Quantity (org.activityinfo.model.type.number.Quantity)7 FormTreeBuilder (org.activityinfo.model.formTree.FormTreeBuilder)6 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)6 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)6 ColumnView (org.activityinfo.model.query.ColumnView)5