Search in sources :

Example 6 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class FormInputViewModelTest method hiddenSubForm.

/**
 * Test the ViewModel for when the user does not have access to a referenced sub form.
 */
@Test
public void hiddenSubForm() {
    FormClass parentForm = new FormClass(ResourceId.valueOf("PARENT_FORM"));
    parentForm.addField(ResourceId.valueOf("F1")).setLabel("What is your name?").setType(TextType.SIMPLE);
    parentForm.addField(ResourceId.valueOf("F2")).setLabel("What are your secrets?").setType(new SubFormReferenceType(ResourceId.valueOf("SECRET_FORM")));
    FormTreeBuilder treeBuilder = new FormTreeBuilder(new FormMetadataProvider() {

        @Override
        public FormMetadata getFormMetadata(ResourceId formId) {
            if (formId.equals(parentForm.getId())) {
                return FormMetadata.of(1, parentForm, FormPermissions.owner());
            } else {
                return FormMetadata.forbidden(formId);
            }
        }
    });
    FormTree formTree = treeBuilder.queryTree(parentForm.getId());
    FormStore formStore = EasyMock.createMock(FormStore.class);
    EasyMock.replay(formStore);
    FormInputViewModelBuilder viewModelBuilder = new FormInputViewModelBuilder(formStore, formTree, new TestingActivePeriodMemory());
    FormInputViewModel viewModel = viewModelBuilder.build(new FormInputModel(new RecordRef(parentForm.getId(), ResourceId.valueOf("R1"))));
}
Also used : FormMetadataProvider(org.activityinfo.model.formTree.FormMetadataProvider) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) FormTreeBuilder(org.activityinfo.model.formTree.FormTreeBuilder) FormMetadata(org.activityinfo.model.form.FormMetadata) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) TestingFormStore(org.activityinfo.ui.client.store.TestingFormStore) FormStore(org.activityinfo.ui.client.store.FormStore) Test(org.junit.Test)

Example 7 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class FormInputViewModelTest method monthlySubForms.

@Test
public void monthlySubForms() {
    ClinicForm clinicForm = setup.getCatalog().getClinicForm();
    ResourceId consultCountFieldId = clinicForm.getSubForm().getConsultsField().getId();
    FormInputViewModelBuilder builder = builderFor(clinicForm);
    ResourceId parentRecordId = ResourceId.generateId();
    FormInputModel inputModel = new FormInputModel(new RecordRef(clinicForm.getFormId(), parentRecordId));
    FormInputViewModel viewModel = builder.build(inputModel);
    // Get the sub form view model.
    // The active ref should be set to 2017-10 by default.
    ResourceId subFormFieldId = clinicForm.getSubFormField().getId();
    SubFormViewModel subForm = viewModel.getSubForm(subFormFieldId);
    assertThat(subForm, notNullValue());
    RecordRef octoberId = new RecordRef(clinicForm.getSubForm().getFormId(), ResourceId.generatedPeriodSubmissionId(parentRecordId, "2017-10"));
    RecordRef novemberId = new RecordRef(clinicForm.getSubForm().getFormId(), ResourceId.generatedPeriodSubmissionId(parentRecordId, "2017-11"));
    assertThat(subForm.getActiveRecordRef(), equalTo(octoberId));
    // Update a field in the active form
    inputModel = inputModel.updateSubForm(subForm.update(consultCountFieldId, new FieldInput(new Quantity(33))));
    viewModel = builder.build(inputModel);
    FormInputViewModel subFormViewModel = viewModel.getSubForm(subFormFieldId).getActiveSubViewModel();
    assertThat(subFormViewModel.getField(consultCountFieldId), equalTo(new Quantity(33)));
    assertThat(subFormViewModel.isValid(), equalTo(true));
    // Now change the active record to another month
    inputModel = inputModel.updateActiveSubRecord(subFormFieldId, novemberId);
    viewModel = builder.build(inputModel);
    subForm = viewModel.getSubForm(subFormFieldId);
    // At this point, the subform is not valid because required fields are not filled in,
    // but it is also not dirty because we have not changed anything
    assertThat(subForm.getActiveSubViewModel().isValid(), equalTo(false));
    assertThat(subForm.getActiveSubViewModel().isDirty(), equalTo(false));
    assertThat(subForm.getActiveSubViewModel().isPlaceholder(), equalTo(true));
    // Now fill in the required field
    inputModel = inputModel.updateSubForm(subForm.update(consultCountFieldId, new FieldInput(new Quantity(44))));
    viewModel = builder.build(inputModel);
    assertThat(viewModel.getSubForm(subFormFieldId).getActiveRecordRef(), equalTo(novemberId));
    assertThat(viewModel.getSubForm(subFormFieldId).isValid(), equalTo(true));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) RecordRef(org.activityinfo.model.type.RecordRef) Quantity(org.activityinfo.model.type.number.Quantity) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) FieldInput(org.activityinfo.ui.client.input.model.FieldInput) Test(org.junit.Test)

Example 8 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class LookupKeySetTest method overlappingHierarchies.

/**
 * For classical location types especially, a reference field's range might include multiple forms,
 * such as [province, territory, health zone].
 *
 * This means that the user can <i>either</i> select a province, <i>or</i> a territory, <i>or</i>
 * a health zone.
 *
 * In this case, you also have a hierarchy
 * <pre>
 *               Province.Name
 *                 ^         ^
 *                 |         |
 *     Territory.Name     Health Zone.Name
 *        ^
 *        |
 *     Sector.Name
 * </pre>
 *
 * But the record reference depends on which fields are completed. If only province is completed,
 * then the selected record is from province. Otherwise from territory, etc.
 */
@Test
public void overlappingHierarchies() {
    TestingStorageProvider catalog = setup.getCatalog();
    LocaliteForm localiteForm = catalog.getLocaliteForm();
    FormTree formTree = setup.getFormTree(localiteForm.getFormId());
    LookupKeySet lookupKeySet = new LookupKeySet(formTree, localiteForm.getAdminField());
    // The resulting key set should only include 3 keys, not 6
    // because the three different forms in the range overlap
    assertThat(lookupKeySet.getLookupKeys(), hasSize(3));
    assertThat(lookupKeySet.getKey(0).getKeyLabel(), equalTo("Province Name"));
    assertThat(lookupKeySet.getKey(1).getKeyLabel(), equalTo("Territory Name"));
    assertThat(lookupKeySet.getKey(2).getKeyLabel(), equalTo("Zone de Sante Name"));
    // We need the relationships between the forms
    ResourceId provinceId = catalog.getProvince().getFormId();
    ResourceId territoryId = catalog.getTerritory().getFormId();
    assertThat(lookupKeySet.getAncestorForms(provinceId), hasSize(0));
    assertThat(lookupKeySet.getAncestorForms(territoryId), contains(provinceId));
    // Formulas...
    for (LookupKey lookupKey : lookupKeySet.getLeafKeys()) {
        System.out.println(lookupKey.getKeyLabel() + " => " + lookupKey.getKeyFormulas());
    }
}
Also used : LookupKeySet(org.activityinfo.model.formTree.LookupKeySet) FormTree(org.activityinfo.model.formTree.FormTree) ResourceId(org.activityinfo.model.resource.ResourceId) LookupKey(org.activityinfo.model.formTree.LookupKey) Test(org.junit.Test)

Example 9 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class AsyncClientStub method getRecordVersionRange.

@Override
public Promise<FormSyncSet> getRecordVersionRange(String formId, long localVersion, long toVersion) {
    if (!connected) {
        return offlineResult();
    }
    Optional<FormStorage> form = storageProvider.getForm(ResourceId.valueOf(formId));
    if (!form.isPresent()) {
        return Promise.rejected(new RuntimeException("No such form"));
    }
    VersionedFormStorage formStorage = (VersionedFormStorage) form.get();
    return Promise.resolved(formStorage.getVersionRange(localVersion, toVersion, resourceId -> true));
}
Also used : JobResult(org.activityinfo.model.job.JobResult) Promise(org.activityinfo.promise.Promise) UserDatabaseMeta(org.activityinfo.model.database.UserDatabaseMeta) TestingStorageProvider(org.activityinfo.store.testing.TestingStorageProvider) FormRecordUpdateBuilder(org.activityinfo.api.client.FormRecordUpdateBuilder) org.activityinfo.model.form(org.activityinfo.model.form) ResourceId(org.activityinfo.model.resource.ResourceId) NullFormSupervisor(org.activityinfo.store.query.shared.NullFormSupervisor) Analysis(org.activityinfo.model.analysis.Analysis) Optional(com.google.common.base.Optional) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) NullFormScanCache(org.activityinfo.store.query.shared.NullFormScanCache) RecordLockSet(org.activityinfo.model.database.RecordLockSet) NewFormRecordBuilder(org.activityinfo.api.client.NewFormRecordBuilder) ActivityInfoClientAsync(org.activityinfo.api.client.ActivityInfoClientAsync) JobStatus(org.activityinfo.model.job.JobStatus) AnalysisUpdate(org.activityinfo.model.analysis.AnalysisUpdate) FormStorage(org.activityinfo.store.spi.FormStorage) List(java.util.List) ColumnSet(org.activityinfo.model.query.ColumnSet) QueryModel(org.activityinfo.model.query.QueryModel) RecordTransaction(org.activityinfo.model.resource.RecordTransaction) JobDescriptor(org.activityinfo.model.job.JobDescriptor) Maybe(org.activityinfo.promise.Maybe) ColumnSetBuilder(org.activityinfo.store.query.server.ColumnSetBuilder) FormTree(org.activityinfo.model.formTree.FormTree) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage) FormStorage(org.activityinfo.store.spi.FormStorage) VersionedFormStorage(org.activityinfo.store.spi.VersionedFormStorage)

Example 10 with ResourceId

use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.

the class TableToolBar method onNewRecord.

private void onNewRecord(SelectEvent event) {
    ResourceId newRecordId = ResourceId.generateSubmissionId(viewModel.getFormId());
    RecordRef newRecordRef = new RecordRef(viewModel.getFormId(), newRecordId);
    FormDialog dialog = new FormDialog(formStore, newRecordRef);
    dialog.show();
}
Also used : FormDialog(org.activityinfo.ui.client.input.view.FormDialog) ResourceId(org.activityinfo.model.resource.ResourceId) RecordRef(org.activityinfo.model.type.RecordRef)

Aggregations

ResourceId (org.activityinfo.model.resource.ResourceId)198 Test (org.junit.Test)42 FormClass (org.activityinfo.model.form.FormClass)41 FormField (org.activityinfo.model.form.FormField)34 RecordRef (org.activityinfo.model.type.RecordRef)30 JsonValue (org.activityinfo.json.JsonValue)21 FormTree (org.activityinfo.model.formTree.FormTree)18 ReferenceValue (org.activityinfo.model.type.ReferenceValue)17 FieldValue (org.activityinfo.model.type.FieldValue)16 FormInstance (org.activityinfo.model.form.FormInstance)15 HashMap (java.util.HashMap)14 QuantityType (org.activityinfo.model.type.number.QuantityType)13 ColumnSet (org.activityinfo.model.query.ColumnSet)12 QueryModel (org.activityinfo.model.query.QueryModel)12 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)11 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)11 ReferenceType (org.activityinfo.model.type.ReferenceType)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 FormStorage (org.activityinfo.store.spi.FormStorage)10 ArrayList (java.util.ArrayList)9