use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class FixSubForm method copyRecords.
private void copyRecords(PrintWriter logger, ResourceId parentFormId, ResourceId subFormId, ResourceId newSubFormId) {
QueryResultIterable<FormRecordEntity> subRecords = ofy().load().type(FormRecordEntity.class).ancestor(FormEntity.key(subFormId)).iterable();
for (FormRecordEntity subRecord : subRecords) {
ResourceId parentRecordId = ResourceId.valueOf(subRecord.getParentRecordId());
if (isSubRecordOf(parentFormId, parentRecordId)) {
logger.println("sub record " + subRecord.getRecordId() + " belongs to " + parentRecordId + " in " + parentFormId);
copyTo(subRecord, newSubFormId);
} else {
logger.println("sub record " + subRecord.getRecordId() + " does not belong");
}
}
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class FormFolder method getChildren.
public List<CatalogEntry> getChildren(ResourceId formId) {
Optional<FormStorage> storage = catalog.getForm(formId);
if (!storage.isPresent()) {
return Collections.emptyList();
}
List<CatalogEntry> entries = new ArrayList<>();
FormClass formClass = storage.get().getFormClass();
for (FormField formField : formClass.getFields()) {
if (formField.getType() instanceof SubFormReferenceType) {
SubFormReferenceType subFormType = (SubFormReferenceType) formField.getType();
ResourceId subFormId = subFormType.getClassId();
CatalogEntry catalogEntry = new CatalogEntry(subFormId.asString(), formField.getLabel(), CatalogEntryType.FORM);
catalogEntry.setLeaf(true);
entries.add(catalogEntry);
}
}
return entries;
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class FormRecordEntity method toFieldValueMap.
public Map<ResourceId, FieldValue> toFieldValueMap(FormClass formClass) {
Map<ResourceId, FieldValue> map = new HashMap<>();
for (FormField formField : formClass.getFields()) {
Object value = fieldValues.getProperty(formField.getName());
if (value != null) {
FieldConverter<?> converter = FieldConverters.forType(formField.getType());
map.put(formField.getId(), converter.toFieldValue(value));
}
}
return map;
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class UpdaterTest method missingValue.
@Test
public void missingValue() throws JsonMappingException {
ResourceId fieldId = ResourceId.valueOf("Q1");
FormClass formClass = new FormClass(ResourceId.valueOf("XYZ123"));
formClass.addElement(new FormField(fieldId).setType(new QuantityType("meters")));
JsonValue fields = createObject();
fields.put("Q1", Json.createNull());
JsonValue change = createObject();
change.put("recordId", "A");
change.put("formId", "XYZ123");
change.put("fields", fields);
TypedRecordUpdate update = Updater.parseChange(formClass, change, userId);
assertTrue(update.getChangedFieldValues().containsKey(fieldId));
}
use of org.activityinfo.model.resource.ResourceId in project activityinfo by bedatadriven.
the class ForeignKeyTest method filtering.
@Test
public void filtering() {
// Build the unfiltered foreign key map
// That maps row indexes to foreign keys
ResourceId formId = ResourceId.valueOf("a00001");
ForeignKeyBuilder builder = new ForeignKeyBuilder(formId, new PendingSlot<ForeignKey>());
builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0272548382"))));
builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0272548382"))));
builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0362622291"))));
builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0362622291"))));
builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0890848243"))));
builder.onNext(new ReferenceValue(new RecordRef(formId, ResourceId.valueOf("s0890848243"))));
ForeignKey fkMap = builder.build();
// Now define a filter that includes only the 4th and 5th rows
BitSet bitSet = new BitSet();
bitSet.set(4);
bitSet.set(5);
TableFilter filter = new TableFilter(bitSet);
// Apply the filter to the ForeignKey map and verify the results
ForeignKey filteredKey = filter.apply(fkMap);
assertThat(filteredKey.getKey(0), equalTo("s0890848243"));
assertThat(filteredKey.getKey(1), equalTo("s0890848243"));
}
Aggregations