Search in sources :

Example 1 with FormRecord

use of org.activityinfo.model.form.FormRecord in project activityinfo by bedatadriven.

the class ActivityInfoClient method getTypedRecord.

public FormInstance getTypedRecord(FormClass formClass, ResourceId recordId) {
    FormRecord record = getRecord(formClass.getId(), recordId);
    FormInstance instance = FormInstance.toFormInstance(formClass, record);
    return instance;
}
Also used : FormRecord(org.activityinfo.model.form.FormRecord) FormInstance(org.activityinfo.model.form.FormInstance)

Example 2 with FormRecord

use of org.activityinfo.model.form.FormRecord in project activityinfo by bedatadriven.

the class QuerySubRecords method run.

@Override
public List<FormRecord> run() {
    QueryResultIterable<FormRecordEntity> query = ofy().load().type(FormRecordEntity.class).ancestor(FormEntity.key(formClass)).filter("parentRecordId", this.parentRecordId.asString()).iterable();
    List<FormRecord> records = Lists.newArrayList();
    for (FormRecordEntity entity : query) {
        records.add(entity.toFormRecord(formClass));
    }
    return records;
}
Also used : FormRecordEntity(org.activityinfo.store.hrd.entity.FormRecordEntity) FormRecord(org.activityinfo.model.form.FormRecord)

Example 3 with FormRecord

use of org.activityinfo.model.form.FormRecord in project activityinfo by bedatadriven.

the class SyncSetBuilder method buildUpdateArrays.

private List<FormRecord> buildUpdateArrays() {
    FormRecord[] records = new FormRecord[snapshots.size()];
    int i = 0;
    for (FormRecordSnapshotEntity snapshotEntity : snapshots.values()) {
        records[i++] = snapshotEntity.getRecord().toFormRecord(formClass);
    }
    return Arrays.asList(records);
}
Also used : FormRecordSnapshotEntity(org.activityinfo.store.hrd.entity.FormRecordSnapshotEntity) FormRecord(org.activityinfo.model.form.FormRecord)

Example 4 with FormRecord

use of org.activityinfo.model.form.FormRecord in project activityinfo by bedatadriven.

the class FormRecordEntity method toFormRecord.

public FormRecord toFormRecord(FormClass formClass) {
    FormRecord.Builder record = FormRecord.builder();
    record.setFormId(formClass.getId());
    record.setRecordId(getRecordId());
    if (formClass.getParentField().isPresent()) {
        record.setParentRecordId(ResourceId.valueOf(getParentRecordId()));
    }
    for (FormField formField : formClass.getFields()) {
        Object value = fieldValues.getProperty(formField.getName());
        if (value != null) {
            FieldConverter<?> converter = FieldConverters.forType(formField.getType());
            record.setFieldValue(formField.getId(), converter.toFieldValue(value));
        }
    }
    return record.build();
}
Also used : FormRecord(org.activityinfo.model.form.FormRecord) FormField(org.activityinfo.model.form.FormField)

Example 5 with FormRecord

use of org.activityinfo.model.form.FormRecord in project activityinfo by bedatadriven.

the class RecordFetcher method get.

public Optional<FormRecord> get(ResourceId resourceId) {
    FormClass formClass = collection.getFormClass();
    FormRecord.Builder formRecord = FormRecord.builder();
    formRecord.setRecordId(resourceId);
    formRecord.setFormId(formClass.getId());
    IdCollector id = new IdCollector();
    ColumnQueryBuilder query = collection.newColumnQuery();
    query.addResourceId(id);
    query.only(resourceId);
    for (FormField formField : formClass.getFields()) {
        if (hasValues(formField)) {
            query.addField(formField.getId(), new FieldCollector(formField.getId(), formRecord));
        }
    }
    query.execute();
    if (id.value == null) {
        return Optional.absent();
    } else {
        return Optional.of(formRecord.build());
    }
}
Also used : ColumnQueryBuilder(org.activityinfo.store.spi.ColumnQueryBuilder) FormClass(org.activityinfo.model.form.FormClass) FormRecord(org.activityinfo.model.form.FormRecord) FormField(org.activityinfo.model.form.FormField)

Aggregations

FormRecord (org.activityinfo.model.form.FormRecord)8 FormInstance (org.activityinfo.model.form.FormInstance)4 FormField (org.activityinfo.model.form.FormField)3 Test (org.junit.Test)3 FormClass (org.activityinfo.model.form.FormClass)2 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)2 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)1 RecordTransaction (org.activityinfo.model.resource.RecordTransaction)1 RecordUpdate (org.activityinfo.model.resource.RecordUpdate)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 FieldValue (org.activityinfo.model.type.FieldValue)1 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)1 EnumType (org.activityinfo.model.type.enumerated.EnumType)1 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)1 Maybe (org.activityinfo.promise.Maybe)1 FormRecordEntity (org.activityinfo.store.hrd.entity.FormRecordEntity)1 FormRecordSnapshotEntity (org.activityinfo.store.hrd.entity.FormRecordSnapshotEntity)1 Updater (org.activityinfo.store.query.server.Updater)1 ColumnQueryBuilder (org.activityinfo.store.spi.ColumnQueryBuilder)1 FormStorage (org.activityinfo.store.spi.FormStorage)1