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