use of org.activityinfo.model.type.ReferenceValue in project activityinfo by bedatadriven.
the class AdminColumnBuilder method emit.
private void emit(int[] adminEntity) {
// From the beginning, AI has always stored *all* admin level members in the
// locationadminlink table to make it easier to query
// This denormalized form, however, is not what we want with the new model,
// so we need to eliminate the redundant information
boolean nonNull = false;
for (int i = 0; i < adminEntity.length; i++) {
if (adminEntity[i] != 0) {
nonNull = true;
int parentIndex = adminParentMap[i];
if (parentIndex != -1) {
// remove the parent from the result -- it is redundant information
adminEntity[parentIndex] = 0;
}
}
}
// Now emit the field value
if (nonNull) {
Set<RecordRef> entityIds = new HashSet<>();
for (int i = 0; i < adminEntity.length; i++) {
int entityId = adminEntity[i];
if (entityId != 0) {
entityIds.add(new RecordRef(adminLevelFormIds[i], CuidAdapter.entity(entityId)));
}
}
emit(new ReferenceValue(entityIds));
} else {
emit(ReferenceValue.EMPTY);
}
}
use of org.activityinfo.model.type.ReferenceValue in project activityinfo by bedatadriven.
the class ReferenceConverter method toParameters.
@Override
public Collection<Integer> toParameters(FieldValue value) {
ReferenceValue referenceValue = (ReferenceValue) value;
ResourceId resourceId = referenceValue.getOnlyReference().getRecordId();
Preconditions.checkArgument(resourceId.getDomain() == domain, "id %s does not match expected domain %s", resourceId.asString(), Character.toString(domain));
return Collections.singleton(CuidAdapter.getLegacyIdFromCuid(resourceId));
}
use of org.activityinfo.model.type.ReferenceValue 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.ReferenceValue 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.ReferenceValue in project activityinfo by bedatadriven.
the class SingleClassImporter method updateInstance.
@Override
public boolean updateInstance(SourceRow row, FormInstance instance) {
final List<ValidationResult> validationResults = Lists.newArrayList();
validateInstance(row, validationResults);
for (ValidationResult result : validationResults) {
if (result.isPersistable() && result.getRef() != null) {
instance.set(fieldId, new ReferenceValue(result.getRef()));
break;
}
}
return true;
}
Aggregations