Search in sources :

Example 31 with RecordRef

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

the class MySqlHistoryTest method locationChange.

@Test
public void locationChange() throws SQLException {
    MySqlRecordHistoryBuilder builder = new MySqlRecordHistoryBuilder(catalog);
    RecordHistory array = builder.build(new RecordRef(CuidAdapter.activityFormClass(33), CuidAdapter.cuid(CuidAdapter.SITE_DOMAIN, 968196924)));
    System.out.println(Json.stringify(Json.toJson(array), 2));
}
Also used : RecordRef(org.activityinfo.model.type.RecordRef) RecordHistory(org.activityinfo.model.form.RecordHistory) Test(org.junit.Test)

Example 32 with RecordRef

use of org.activityinfo.model.type.RecordRef 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 33 with RecordRef

use of org.activityinfo.model.type.RecordRef 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 34 with RecordRef

use of org.activityinfo.model.type.RecordRef 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 35 with RecordRef

use of org.activityinfo.model.type.RecordRef 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)

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