use of org.activityinfo.model.type.primitive.TextValue in project activityinfo by bedatadriven.
the class Updater method computeSerialNumberPrefix.
private String computeSerialNumberPrefix(FormClass formClass, SerialNumberType type, FormInstance effectiveRecord) {
if (!type.hasPrefix()) {
return null;
}
try {
FormEvalContext evalContext = new FormEvalContext(formClass);
evalContext.setInstance(effectiveRecord);
FormulaNode formula = FormulaParser.parse(type.getPrefixFormula());
FieldValue prefixValue = formula.evaluate(evalContext);
if (prefixValue instanceof TextValue) {
return ((TextValue) prefixValue).asString();
} else {
throw new IllegalStateException("Prefix " + type.getPrefixFormula() + " resolves to type " + prefixValue.getTypeClass().getId());
}
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Failed to compute prefix for serial number", e);
return null;
}
}
use of org.activityinfo.model.type.primitive.TextValue in project activityinfo by bedatadriven.
the class InputMaskGenerator method get.
@Override
public FieldValue get() {
if (random.nextDouble() < probabilityMissing) {
return null;
}
if (random.nextDouble() < probabilityDuplicate) {
return previous.get(random.nextInt(previous.size()));
}
StringBuilder s = new StringBuilder();
for (InputMask.Atom atom : inputMask.getAtoms()) {
atom.appendRandom(random, s);
}
TextValue textValue = TextValue.valueOf(s.toString());
previous.add(textValue);
return textValue;
}
Aggregations