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));
}
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;
}
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();
}
}
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();
}
}
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));
}
Aggregations