Search in sources :

Example 26 with ReferenceValue

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);
    }
}
Also used : ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef)

Example 27 with ReferenceValue

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));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue)

Example 28 with ReferenceValue

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()));
        }
    }
}
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 29 with ReferenceValue

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;
}
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 30 with ReferenceValue

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;
}
Also used : ReferenceValue(org.activityinfo.model.type.ReferenceValue) ValidationResult(org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)

Aggregations

ReferenceValue (org.activityinfo.model.type.ReferenceValue)31 RecordRef (org.activityinfo.model.type.RecordRef)26 ResourceId (org.activityinfo.model.resource.ResourceId)17 Test (org.junit.Test)11 FormInstance (org.activityinfo.model.form.FormInstance)7 FieldValue (org.activityinfo.model.type.FieldValue)7 LocalDate (org.activityinfo.model.type.time.LocalDate)4 ResultSet (java.sql.ResultSet)3 OnDataSet (org.activityinfo.server.database.OnDataSet)3 ForeignKeyBuilder (org.activityinfo.store.query.server.join.ForeignKeyBuilder)3 ForeignKey (org.activityinfo.store.query.shared.columns.ForeignKey)3 SQLException (java.sql.SQLException)2 Set (java.util.Set)2 FormClass (org.activityinfo.model.form.FormClass)2 LookupKeySet (org.activityinfo.model.formTree.LookupKeySet)2 RecordTree (org.activityinfo.model.formTree.RecordTree)2 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)2 Maybe (org.activityinfo.promise.Maybe)2 ValidationResult (org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)2 BitSet (java.util.BitSet)1