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