Search in sources :

Example 1 with TextValue

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;
    }
}
Also used : FormulaNode(org.activityinfo.model.formula.FormulaNode) TextValue(org.activityinfo.model.type.primitive.TextValue) FieldValue(org.activityinfo.model.type.FieldValue) JsonMappingException(org.activityinfo.json.JsonMappingException)

Example 2 with TextValue

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;
}
Also used : TextValue(org.activityinfo.model.type.primitive.TextValue) InputMask(org.activityinfo.model.type.primitive.InputMask)

Aggregations

TextValue (org.activityinfo.model.type.primitive.TextValue)2 JsonMappingException (org.activityinfo.json.JsonMappingException)1 FormulaNode (org.activityinfo.model.formula.FormulaNode)1 FieldValue (org.activityinfo.model.type.FieldValue)1 InputMask (org.activityinfo.model.type.primitive.InputMask)1