Search in sources :

Example 66 with ResourceId

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");
        }
    }
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) FormRecordEntity(org.activityinfo.store.hrd.entity.FormRecordEntity)

Example 67 with ResourceId

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;
}
Also used : SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormStorage(org.activityinfo.store.spi.FormStorage) ResourceId(org.activityinfo.model.resource.ResourceId) FormClass(org.activityinfo.model.form.FormClass) CatalogEntry(org.activityinfo.model.form.CatalogEntry) ArrayList(java.util.ArrayList) FormField(org.activityinfo.model.form.FormField)

Example 68 with ResourceId

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;
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) HashMap(java.util.HashMap) FieldValue(org.activityinfo.model.type.FieldValue) FormField(org.activityinfo.model.form.FormField)

Example 69 with ResourceId

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));
}
Also used : ResourceId(org.activityinfo.model.resource.ResourceId) QuantityType(org.activityinfo.model.type.number.QuantityType) FormClass(org.activityinfo.model.form.FormClass) JsonValue(org.activityinfo.json.JsonValue) FormField(org.activityinfo.model.form.FormField) TypedRecordUpdate(org.activityinfo.store.spi.TypedRecordUpdate) Test(org.junit.Test)

Example 70 with ResourceId

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"));
}
Also used : ForeignKeyBuilder(org.activityinfo.store.query.server.join.ForeignKeyBuilder) ResourceId(org.activityinfo.model.resource.ResourceId) TableFilter(org.activityinfo.store.query.shared.TableFilter) ReferenceValue(org.activityinfo.model.type.ReferenceValue) RecordRef(org.activityinfo.model.type.RecordRef) BitSet(java.util.BitSet) ForeignKey(org.activityinfo.store.query.shared.columns.ForeignKey) Test(org.junit.Test)

Aggregations

ResourceId (org.activityinfo.model.resource.ResourceId)198 Test (org.junit.Test)42 FormClass (org.activityinfo.model.form.FormClass)41 FormField (org.activityinfo.model.form.FormField)34 RecordRef (org.activityinfo.model.type.RecordRef)30 JsonValue (org.activityinfo.json.JsonValue)21 FormTree (org.activityinfo.model.formTree.FormTree)18 ReferenceValue (org.activityinfo.model.type.ReferenceValue)17 FieldValue (org.activityinfo.model.type.FieldValue)16 FormInstance (org.activityinfo.model.form.FormInstance)15 HashMap (java.util.HashMap)14 QuantityType (org.activityinfo.model.type.number.QuantityType)13 ColumnSet (org.activityinfo.model.query.ColumnSet)12 QueryModel (org.activityinfo.model.query.QueryModel)12 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)11 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)11 ReferenceType (org.activityinfo.model.type.ReferenceType)10 EnumItem (org.activityinfo.model.type.enumerated.EnumItem)10 FormStorage (org.activityinfo.store.spi.FormStorage)10 ArrayList (java.util.ArrayList)9