Search in sources :

Example 11 with ReferenceValue

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

the class ImportWithMultiClassRangeTest method school.

private Set<ResourceId> school(String name) {
    // Find id of the school with this name
    ResourceId id = null;
    ColumnView nameColumn = resultSet.getColumnView("name");
    ColumnView idColumn = resultSet.getColumnView("id");
    for (int i = 0; i < resultSet.getNumRows(); i++) {
        if (name.equals(nameColumn.getString(i))) {
            id = ResourceId.valueOf(idColumn.getString(i));
            break;
        }
    }
    if (id == null) {
        throw new AssertionError("No school named '" + name + "'");
    }
    Promise<FormInstance> record = locator.getFormInstance(SCHOOL_FORM_CLASS, id);
    ReferenceValue value = (ReferenceValue) record.get().get(CuidAdapter.field(SCHOOL_FORM_CLASS, CuidAdapter.ADMIN_FIELD));
    Set<ResourceId> recordIds = new HashSet<>();
    for (RecordRef recordRef : value.getReferences()) {
        recordIds.add(recordRef.getRecordId());
    }
    return recordIds;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) ColumnView(org.activityinfo.model.query.ColumnView) RecordRef(org.activityinfo.model.type.RecordRef) FormInstance(org.activityinfo.model.form.FormInstance) HashSet(java.util.HashSet)

Example 12 with ReferenceValue

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

the class HrdQueryColumnBuilder method execute.

@Override
public void execute() {
    Query<FormRecordEntity> query = ofy().load().type(FormRecordEntity.class).ancestor(FormEntity.key(formClass));
    for (FormRecordEntity entity : query.iterable()) {
        for (CursorObserver<ResourceId> idObserver : idObservers) {
            idObserver.onNext(entity.getRecordId());
        }
        for (FieldObserver fieldObserver : fieldObservers) {
            fieldObserver.onNext(entity.getFieldValues());
        }
        if (parentFieldObservers != null) {
            ResourceId parentRecordId = ResourceId.valueOf(entity.getParentRecordId());
            RecordRef parentRef = new RecordRef(formClass.getParentFormId().get(), parentRecordId);
            ReferenceValue parent = new ReferenceValue(parentRef);
            for (CursorObserver<FieldValue> parentFieldObserver : parentFieldObservers) {
                parentFieldObserver.onNext(parent);
            }
        }
    }
    for (CursorObserver<?> observer : observers) {
        observer.done();
    }
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) FormRecordEntity(org.activityinfo.store.hrd.entity.FormRecordEntity) RecordRef(org.activityinfo.model.type.RecordRef) FieldValue(org.activityinfo.model.type.FieldValue)

Example 13 with ReferenceValue

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

the class TestingFormQueryBuilder method execute.

@Override
public void execute() {
    for (FormInstance record : records) {
        for (CursorObserver<ResourceId> idObserver : idObservers) {
            idObserver.onNext(record.getId());
        }
        for (CursorObserver<FieldValue> parentObserver : parentObservers) {
            parentObserver.onNext(new ReferenceValue(new RecordRef(formClass.getParentFormId().get(), record.getParentRecordId())));
        }
        for (Map.Entry<ResourceId, CursorObserver<FieldValue>> field : fieldObservers.entries()) {
            ResourceId fieldId = field.getKey();
            FieldValue fieldValue = record.get(fieldId);
            CursorObserver<FieldValue> observer = field.getValue();
            observer.onNext(fieldValue);
        }
    }
    for (CursorObserver<ResourceId> observer : idObservers) {
        observer.done();
    }
    for (CursorObserver<FieldValue> parentObserver : parentObservers) {
        parentObserver.done();
    }
    for (CursorObserver<FieldValue> observer : fieldObservers.values()) {
        observer.done();
    }
}
Also used : CursorObserver(org.activityinfo.store.spi.CursorObserver) ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) FieldValue(org.activityinfo.model.type.FieldValue) FormInstance(org.activityinfo.model.form.FormInstance) Map(java.util.Map)

Example 14 with ReferenceValue

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

the class CreateSiteTest method persistSite.

@Test
public void persistSite() {
    ResourceId locationClassId = CuidAdapter.locationFormClass(1);
    FormInstance location = new FormInstance(CuidAdapter.generateLocationCuid(), locationClassId);
    location.set(field(locationClassId, CuidAdapter.NAME_FIELD), "Virunga");
    location.set(field(locationClassId, CuidAdapter.AXE_FIELD), "Goma - Rutshuru");
    location.set(field(locationClassId, CuidAdapter.GEOMETRY_FIELD), new GeoPoint(27.432, 1.23));
    assertResolves(locator.persist(location));
    int databaseId = 1;
    ResourceId formClassId = CuidAdapter.activityFormClass(1);
    FormInstance instance = new FormInstance(CuidAdapter.generateSiteCuid(), formClassId);
    instance.set(field(formClassId, LOCATION_FIELD), new ReferenceValue(new RecordRef(locationClassId, location.getId())));
    instance.set(field(formClassId, PARTNER_FIELD), CuidAdapter.partnerRef(databaseId, 1));
    instance.set(field(formClassId, START_DATE_FIELD), new LocalDate(2008, 12, 1));
    instance.set(field(formClassId, END_DATE_FIELD), new LocalDate(2009, 1, 3));
    instance.set(indicatorField(1), 996.0);
    instance.set(attributeField(1), new EnumValue(CuidAdapter.attributeId(1), CuidAdapter.attributeField(2)));
    instance.set(commentsField(1), "objection!");
    instance.set(field(formClassId, PROJECT_FIELD), CuidAdapter.projectRef(PROJECT_DOMAIN, 1));
    assertResolves(locator.persist(instance));
}
Also used : GeoPoint(org.activityinfo.model.type.geo.GeoPoint) ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) EnumValue(org.activityinfo.model.type.enumerated.EnumValue) RecordRef(org.activityinfo.model.type.RecordRef) FormInstance(org.activityinfo.model.form.FormInstance) LocalDate(org.activityinfo.model.type.time.LocalDate) GeoPoint(org.activityinfo.model.type.geo.GeoPoint) Test(org.junit.Test)

Example 15 with ReferenceValue

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

the class ResourceLocatorAdaptorTest method getLocation.

@Test
@OnDataSet("/dbunit/jordan-locations.db.xml")
public void getLocation() {
    ResourceId classId = locationFormClass(50512);
    FormInstance instance = assertResolves(locator.getFormInstance(classId, locationInstanceId(1590565828)));
    ReferenceValue adminUnits = (ReferenceValue) instance.get(field(classId, ADMIN_FIELD));
    System.out.println(adminUnits);
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) ReferenceValue(org.activityinfo.model.type.ReferenceValue) FormInstance(org.activityinfo.model.form.FormInstance) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

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