Search in sources :

Example 51 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class RecordTreeLoader method findChildren.

private void findChildren(Set<NodeKey> children, FormClass schema, FormInstance record) {
    // Add referenced records
    for (FieldValue value : record.getFieldValueMap().values()) {
        if (value instanceof ReferenceValue) {
            for (RecordRef recordRef : ((ReferenceValue) value).getReferences()) {
                children.add(new RecordKey(recordRef));
            }
        }
    }
    // Add sub forms
    for (FormField formField : schema.getFields()) {
        if (formField.getType() instanceof SubFormReferenceType) {
            SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
            children.add(new SubFormKey(record.getRef(), subFormType.getClassId()));
        }
    }
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) FieldValue(org.activityinfo.model.type.FieldValue)

Example 52 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class HierarchyClassImporter method updateInstance.

@Override
public boolean updateInstance(SourceRow row, FormInstance instance) {
    final List<ValidationResult> validationResults = Lists.newArrayList();
    validateInstance(row, validationResults);
    final Map<ResourceId, RecordRef> toSave = Maps.newHashMap();
    for (ValidationResult result : validationResults) {
        if (result.isPersistable() && result.getRef() != null) {
            ResourceId range = result.getRef().getFormId();
            RecordRef value = toSave.get(range);
            if (value == null) {
                toSave.put(range, result.getRef());
            }
        }
    }
    if (!toSave.isEmpty()) {
        instance.set(rootField.getFieldId(), new ReferenceValue(toSave.values()));
        return true;
    }
    return false;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) ValidationResult(org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)

Example 53 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class HierarchyClassImporter method validateInstance.

@Override
public void validateInstance(SourceRow row, List<ValidationResult> results) {
    // Start from the leaf level and work our way up to the parent levels
    for (Level level : levels) {
        InstanceScoreSource scoreSource = scoreSources.get(level.getFormId());
        if (scoreSource != null) {
            InstanceScorer instanceScorer = new InstanceScorer(scoreSource);
            final InstanceScorer.Score score = instanceScorer.score(row);
            final int bestMatchIndex = score.getBestMatchIndex();
            if (bestMatchIndex != -1) {
                for (int i = 0; i < sourceColumns.size(); i++) {
                    String matched = scoreSource.getReferenceValues().get(bestMatchIndex)[i];
                    final ValidationResult converted = ValidationResult.converted(matched, score.getBestScores()[i]);
                    converted.setRef(new RecordRef(level.getFormId(), scoreSource.getReferenceInstanceIds().get(bestMatchIndex)));
                    results.add(converted);
                }
                return;
            }
        }
    }
    for (int i = 0; i < sourceColumns.size(); i++) {
        results.add(ValidationResult.error("No match"));
    }
}
Also used : RecordRef(org.activityinfo.model.type.RecordRef) Level(org.activityinfo.ui.client.component.form.field.hierarchy.Level) ValidationResult(org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)

Example 54 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class SingleClassImporter method validateInstance.

@Override
public void validateInstance(SourceRow row, List<ValidationResult> results) {
    final InstanceScorer.Score score = instanceScorer.score(row);
    final int bestMatchIndex = score.getBestMatchIndex();
    ResourceId instanceId = bestMatchIndex != -1 ? scoreSource.getReferenceInstanceIds().get(bestMatchIndex) : null;
    for (int i = 0; i != sources.size(); ++i) {
        if (score.getImported()[i] == null) {
            if (required) {
                results.add(ValidationResult.error("required missing").setRef(new RecordRef(rangeFormId, instanceId)));
            } else {
                results.add(ValidationResult.missing().setRef(null));
            }
        } else if (bestMatchIndex == -1) {
            results.add(ValidationResult.error("No match"));
        } else {
            String matched = scoreSource.getReferenceValues().get(bestMatchIndex)[i];
            results.add(ValidationResult.converted(matched, score.getBestScores()[i]).setRef(new RecordRef(rangeFormId, instanceId)));
        }
    }
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) RecordRef(org.activityinfo.model.type.RecordRef)

Example 55 with RecordRef

use of org.activityinfo.model.type.RecordRef in project activityinfo by bedatadriven.

the class FormInputViewModelTest method testSerialNumberEdit.

@Test
public void testSerialNumberEdit() {
    IntakeForm intakeForm = setup.getCatalog().getIntakeForm();
    RecordRef ref = intakeForm.getRecords().get(0).getRef();
    FormStructure structure = fetchStructure(ref);
    FormInputViewModelBuilder builder = builderFor(structure);
    FormInputModel model = new FormInputModel(ref);
    FormInputViewModel viewModel = builder.build(model, structure.getExistingRecord());
    assertThat(viewModel.getField(intakeForm.getProtectionCodeFieldId()), equalTo(new SerialNumber(1)));
}
Also used : SerialNumber(org.activityinfo.model.type.SerialNumber) RecordRef(org.activityinfo.model.type.RecordRef) FormInputModel(org.activityinfo.ui.client.input.model.FormInputModel) Test(org.junit.Test)

Aggregations

RecordRef (org.activityinfo.model.type.RecordRef)66 Test (org.junit.Test)31 ResourceId (org.activityinfo.model.resource.ResourceId)26 ReferenceValue (org.activityinfo.model.type.ReferenceValue)26 FormInputModel (org.activityinfo.ui.client.input.model.FormInputModel)14 FormInstance (org.activityinfo.model.form.FormInstance)7 FormTree (org.activityinfo.model.formTree.FormTree)7 LocalDate (org.activityinfo.model.type.time.LocalDate)7 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)6 Optional (com.google.common.base.Optional)5 FieldValue (org.activityinfo.model.type.FieldValue)5 FieldInput (org.activityinfo.ui.client.input.model.FieldInput)5 FormClass (org.activityinfo.model.form.FormClass)4 ResultSet (java.sql.ResultSet)3 FormField (org.activityinfo.model.form.FormField)3 RecordTree (org.activityinfo.model.formTree.RecordTree)3 ColumnSet (org.activityinfo.model.query.ColumnSet)3 ColumnView (org.activityinfo.model.query.ColumnView)3 RecordTransaction (org.activityinfo.model.resource.RecordTransaction)3 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)3