public ResourceId getId() { return typedFormRecord.getId(); }
public Optional<TypedFormRecord> getSubformValueInstance(FormClass subformClass, TypedFormRecord rootInstance, String keyId) { Set<TypedFormRecord> typedFormRecords = subFormInstances.get(new SubformValueKey(subformClass, rootInstance)); if (typedFormRecords != null) { for (TypedFormRecord instance : typedFormRecords) { if (instance.getId().asString().endsWith(keyId)) { return Optional.of(instance); } } } return Optional.absent(); }
private void ensureWeHaveOwnCopy() { if(records == null) { records = new ArrayList<>(); for (TypedFormRecord record : testForm.getRecords()) { records.add(record.copy()); } index = new HashMap<>(); for (TypedFormRecord record : records) { index.put(record.getId(), record); } } }
@Override public ResourceId get() { int index = random.nextInt(parentForm.getRecords().size()); return parentForm.getRecords().get(index).getId(); } }
public RefKeyGenerator(TestForm rangeForm) { List<RecordRef> range = new ArrayList<>(); for (TypedFormRecord record : rangeForm.getRecords()) { range.add(new RecordRef(rangeForm.getFormId(), record.getId())); } Collections.shuffle(range, new Random(19993345L)); this.stream = range.iterator(); }
public TypedFormRecord copy() { final TypedFormRecord copy = new TypedFormRecord(getId(), getFormId()); copy.fieldMap.putAll(fieldMap); return copy; }
private List<TypedFormRecord> getInstancesToPersist() { final List<TypedFormRecord> toPersist = Lists.newArrayList(); for (TypedFormRecord instance : model.getChangedInstances()) { if (!instance.isEmpty("classId", "keyId", "sort")) { if (instance.getId().getDomain() == ResourceId.GENERATED_ID_DOMAIN) { ResourceId.checkSubmissionId(instance.getId()); } toPersist.add(instance); } } return toPersist; }
public RecordRef getRef() { return new RecordRef(getFormId(), getId()); }
@Override public void add(TypedRecordUpdate update) { TypedFormRecord newRecord = new TypedFormRecord(update.getRecordId(), update.getFormId()); for (Map.Entry<ResourceId, FieldValue> entry : update.getChangedFieldValues().entrySet()) { newRecord.set(entry.getKey(), entry.getValue()); } ensureWeHaveOwnCopy(); records.add(newRecord); index.put(newRecord.getId(), newRecord); version++; }
public ReferenceSuggestion(TypedFormRecord instance) { this.label = FormInstanceLabeler.getLabel(instance); this.ref = new RecordRef(instance.getFormId(), instance.getId()); }
private TypedFormRecord newValueInstance() { TypedFormRecord newInstance = new TypedFormRecord(ResourceId.generateSubmissionId(subForm.getId()), subForm.getId()); newInstance.setParentRecordId(formModel.getWorkingRootInstance().getId()); FormModel.SubformValueKey key = key(); Set<TypedFormRecord> instances = formModel.getSubFormInstances().get(key); if (instances == null) { instances = Sets.newHashSet(); formModel.getSubFormInstances().put(key, instances); } instances.add(newInstance); formModel.getChangedInstances().add(newInstance); return newInstance; }
public static FormRecord fromInstance(TypedFormRecord instance) { FormRecord record = new FormRecord(); record.recordId = instance.getId().asString(); record.formId = instance.getFormId().asString(); record.fields = createObject(); for (Map.Entry<ResourceId, FieldValue> entry : instance.getFieldValueMap().entrySet()) { String field = entry.getKey().asString(); if(!field.equals("classId")) { if(entry.getValue() != null) { record.fields.put(field, entry.getValue().toJson()); } } } return record; }
@Test public void stringComparatorTest() { List<TypedFormRecord> list = testList(); Collections.sort(list, FormInstanceComparators.stringComparator(ResourceId.valueOf("key2"))); assertEquals("2", list.get(0).getId().asString()); assertEquals("3", list.get(1).getId().asString()); assertEquals("1", list.get(2).getId().asString()); }
@Test public void doubleComparatorTest() { List<TypedFormRecord> list = testList(); Collections.sort(list, FormInstanceComparators.doubleComparator(ResourceId.valueOf("key1"))); assertEquals("3", list.get(0).getId().asString()); assertEquals("2", list.get(1).getId().asString()); assertEquals("1", list.get(2).getId().asString()); }
public String label(TypedFormRecord record) { if(fieldId.getName().equals(ColumnModel.RECORD_ID_SYMBOL)) { return record.getId().asString(); } FieldValue fieldValue = record.get(ResourceId.valueOf(fieldId.getName())); if(fieldValue == null) { return record.getId().asString(); } if(fieldValue instanceof SerialNumber) { SerialNumberType type = new SerialNumberType(); return type.format(((SerialNumber) fieldValue)); } else { return ((HasStringValue) fieldValue).asString(); } }
public Choice toChoice(TypedFormRecord instance) { if(isRoot()) { return new Choice(getFormId(), instance.getId(), instance.getString(labelFieldId)); } else { ReferenceValue parentRefValue = (ReferenceValue) instance.get(parentFieldId); RecordRef parentRef = parentRefValue.getOnlyReference(); return new Choice(getFormId(), instance.getId(), instance.getString(labelFieldId), parentRef); } } }
public JsonValue toJsonObject() { JsonValue fields = createObject(); for (Map.Entry<ResourceId, FieldValue> entry : fieldMap.entrySet()) { if(entry.getValue() != null) { fields.put(entry.getKey().asString(), entry.getValue().toJson()); } } JsonValue object = createObject(); object.put("formId", getFormId().asString()); object.put("recordId", getId().asString()); object.put("fieldValues", fields); return object; }
public Promise<List<TypedFormRecord>> load(final FormClass subForm) { return model.getLocator().getSubFormInstances(subForm.getId(), model.getWorkingRootInstance().getId()) .then(new Function<List<TypedFormRecord>, List<TypedFormRecord>>() { @Override public List<TypedFormRecord> apply(List<TypedFormRecord> instanceList) { model.getSubFormInstances().put(new FormModel.SubformValueKey(subForm, model.getWorkingRootInstance()), Sets.newHashSet(instanceList)); persisted.addAll(instanceList); return instanceList; } }); }
private ValueSource lookupSymbol(String symbolName) { if (typedFormRecord.getFormId().asString().equals(symbolName)) { return new ConstantValue(TextValue.valueOf(typedFormRecord.getId().asString())); } ValueSource valueSource = symbolMap.get(symbolName); if (valueSource == null) { // todo : we must fix it, here as temporary solution if symbol name can't be resolved we consider it as ReferenceValue return new ConstantValue(new EnumValue(ResourceId.valueOf(symbolName))); } return valueSource; } }
public RecordTransactionBuilder create(TypedFormRecord record) { RecordUpdate update = new RecordUpdate(); update.setFormId(record.getFormId()); update.setRecordId(record.getId()); update.setFields(FormRecord.fromInstance(record).getFields()); updates.add(update); return this; }