@Override public String toString() { return "FormField{" + "id=" + id + ", label=" + label + ", type=" + type.getTypeClass().getId() + '}'; }
public FieldValue get(ResourceId fieldId, FieldType fieldType) { FieldValue value = fieldMap.get(fieldId); if(value != null && value.getTypeClass() == fieldType.getTypeClass()) { return value; } else { return null; } }
public FieldTypeClass getTypeClass() { return field.getType().getTypeClass(); }
@Override public FieldType resolveResultType(List<FieldType> argumentTypes) { checkArity(argumentTypes, 3); FieldType conditionType = argumentTypes.get(0); if(!(conditionType instanceof BooleanType)) { throw new ArgumentException(0, "Expected TRUE/FALSE value"); } FieldType trueType = argumentTypes.get(1); FieldType falseType = argumentTypes.get(2); if(trueType.getTypeClass() != falseType.getTypeClass()) { throw new ArgumentException(2, "Must have the same type as the TRUE argument."); } return trueType; }
@Override public FieldType resolveResultType(List<FieldType> argumentTypes) { //must be unary or binary function if(argumentTypes.size() == 1) { if(argumentTypes.get(0) instanceof QuantityType) { QuantityType t = (QuantityType) argumentTypes.get(0); return new QuantityType().setUnits(t.getUnits()); } else { throw new InvalidTypeException("Not Real Valued Argument"); } } else if(argumentTypes.size() == 2) { if(argumentTypes.get(0) instanceof QuantityType && argumentTypes.get(1) instanceof QuantityType) { QuantityType t1 = (QuantityType) argumentTypes.get(0); QuantityType t2 = (QuantityType) argumentTypes.get(1); return new QuantityType().setUnits(applyUnits(t1.getUnits(), t2.getUnits())); } else { throw new InvalidTypeException("Cannot compare types " + argumentTypes.get(0).getTypeClass().getId() + " and " + argumentTypes.get(1).getTypeClass().getId()); } } else { throw new FormulaSyntaxException("The " + getLabel() + "() function expects exactly 1 or 2 argument(s)."); } }
private static FieldValue validateType(FormField field, FieldValue updatedValue) { Preconditions.checkNotNull(field); if(updatedValue != null) { if ( !field.getType().isUpdatable()) { throw new InvalidUpdateException( format("Field %s ('%s') is a field of type '%s' and its value cannot be set. Found %s", field.getId(), field.getLabel(), field.getType().getTypeClass().getId(), updatedValue)); } if (!field.getType().getTypeClass().equals(updatedValue.getTypeClass())) { throw new InvalidUpdateException( format("Updated value for field %s ('%s') has invalid type. Expected %s, found %s.", field.getId(), field.getLabel(), field.getType().getTypeClass().getId(), updatedValue.getTypeClass().getId())); } } return updatedValue; }
private FormElement createField(BodyElement element) { if(Strings.isNullOrEmpty(element.getLabel())) { throw new RuntimeException("Element " + element.getRef() + " has no label"); } InstanceElement instanceElement = instanceElements.get(element.getRef()); Bind bind = bindings.get(element.getRef()); FieldType type = createType(element, bind); FormField field = new FormField(ResourceId.generateFieldId(type.getTypeClass())); field.setCode(buildCode(null, instanceElement).toString()); field.setLabel(element.getLabel()); field.setDescription(element.getHint()); field.setType(type); return field; }
private FieldTypeClass findTypeFromSchema(Activity activity, ResourceId fieldId) { for (ActivityField activityField : activity.getFields()) { if(activityField.getResourceId().equals(fieldId)) { return activityField.getFormField().getType().getTypeClass(); } } return null; }
@Override public FieldValue getValue(TypedFormRecord instance, EvalContext context) { FieldValue fieldValue = instance.get(field.getId(), field.getType().getTypeClass()); if (fieldValue != null) { return fieldValue; } else { // we don't want to get NPE in ComparisonOperator if (field.getType() instanceof QuantityType) { return new Quantity(0); } return NullFieldValue.INSTANCE; } }
public void updateTypeStyles(FieldTypeClass sourceType) { for (Map.Entry<ColumnAction, RadioButton> entry : buttons.entrySet()) { final ColumnAction columnAction = entry.getKey(); if (columnAction instanceof MapExistingAction) { final ImportTarget target = ((MapExistingAction) columnAction).getTarget(); final FieldTypeClass targetType = target.getFormField().getType().getTypeClass(); final RadioButton button = entry.getValue(); button.removeStyleName(ColumnMappingStyles.INSTANCE.typeNotMatched()); button.removeStyleName(ColumnMappingStyles.INSTANCE.typeMatched()); if (targetType == sourceType || (sourceType == FieldTypeClass.FREE_TEXT && targetType == FieldTypeClass.REFERENCE)) { button.addStyleName(ColumnMappingStyles.INSTANCE.typeMatched()); } else { button.addStyleName(ColumnMappingStyles.INSTANCE.typeNotMatched()); } } } } }
} else { FieldType fieldType = parseFieldType(row); FormField newField = addField(formClass, fieldType.getTypeClass(), row); newField.setType(fieldType); if (newField.getType() instanceof ReferenceType) {
private void dump(String indent, FormElementContainer container) { for(FormElement element : container.getElements()) { if(element instanceof FormSection) { System.out.println(indent + element.getLabel()); dump(indent + " ", ((FormSection) element)); } else { FormField field = ((FormField) element); System.out.println(String.format("%s[%s] %s : %s", indent, field.getCode(), field.getLabel(), field.getType().getTypeClass().getId())); } } }
public Promise<Void> setValue(TypedFormRecord instance) { model.setWorkingRootInstance(instance); List<Promise<Void>> tasks = Lists.newArrayList(); for (FieldContainer container : widgetCreator.getContainers().values()) { FormField field = container.getField(); FieldValue value = model.getWorkingRootInstance().get(field.getId(), field.getType()); if (value != null && value.getTypeClass() == field.getType().getTypeClass()) { tasks.add(container.getFieldWidget().setValue(value)); } else { container.getFieldWidget().clearValue(); } container.setValid(); } return Promise.waitAll(tasks).then(new Function<Void, Void>() { @Override public Void apply(Void input) { relevanceHandler.onValueChange(); // invoke relevance handler once values are set return null; } }); }
private boolean validateField(FieldContainer container) { FormField field = container.getField(); FieldValue value = getCurrentValue(field); if (value != null && value.getTypeClass() != field.getType().getTypeClass()) { value = null; } if (!container.isInputValid()) { return false; } if (!container.getFieldWidget().isValid()) { return false; } Optional<Boolean> validatedBuiltInDates = validateBuiltinDates(container, field); if (validatedBuiltInDates.isPresent()) { return validatedBuiltInDates.get(); } if (field.isRequired() && isEmpty(value) && field.isVisible() && !container.getFieldWidget().isReadOnly()) { // if field is not visible user doesn't have chance to fix it container.setInvalid(I18N.CONSTANTS.requiredFieldMessage()); return false; } else { container.setValid(); return true; } }
@Override public JsonValue toJsonObject() { JsonValue object = createObject(); object.put("id", id.asString()); object.put("code", code); object.put("label", label); object.put("description", description); object.put("relevanceCondition", relevanceConditionExpression); object.put("visible", visible); object.put("required", required); object.put("type", type.getTypeClass().getId()); if(key) { object.put("key", true); } if(!superProperties.isEmpty()) { JsonValue superPropertiesArray = Json.createArray(); for (ResourceId superProperty : superProperties) { superPropertiesArray.add(Json.createFromNullable(superProperty.asString())); } object.put("superProperties", superPropertiesArray); } if(type instanceof ParametrizedFieldType) { object.put("typeParameters", ((ParametrizedFieldType) type).getParametersAsJson()); } return object; }
Log.error("Unexpected field type " + type.getTypeClass()); throw new UnsupportedOperationException();
private void insertIndicatorRow(FormField formField, int sortOrder) { SqlInsert insert = SqlInsert.insertInto("indicator"); insert.value("indicatorId", CuidAdapter.getLegacyIdFromCuid(formField.getId())); insert.value("activityId", activityId); insert.value("name", formField.getLabel()); insert.value("nameInExpression", formField.getCode()); insert.value("description", formField.getDescription()); if(formField.getType() instanceof QuantityType) { insert.value("aggregation",((QuantityType) formField.getType()).getAggregation().ordinal()); } else { insert.value("aggregation",0); } insert.value("sortOrder", sortOrder); insert.value("type", formField.getType().getTypeClass().getId()); insert.value("mandatory", formField.isRequired()); if(formField.getType() instanceof QuantityType) { QuantityType quantityType = (QuantityType) formField.getType(); insert.value("units", quantityType.getUnits()); } if(formField.getType() instanceof CalculatedFieldType) { CalculatedFieldType type = (CalculatedFieldType) formField.getType(); insert.value("calculatedAutomatically", true); insert.value("expression", type.getExpression()); } insert.execute(executor); }
private void assertFormClass(FormClass sourceFormClass, FormClass targetFormClass) { assertNotEquals(sourceFormClass.getId(), targetFormClass.getId()); assertEquals(sourceFormClass.getLabel(), targetFormClass.getLabel()); assertEquals(sourceFormClass.getDescription(), targetFormClass.getDescription()); // fields for (FormField sourceField : sourceFormClass.getFields()) { FormField targetField = (FormField) elementByName(targetFormClass.getElements(), sourceField.getLabel()); assertNotEquals(sourceField.getId(), targetField.getId()); assertEquals(sourceField.getDescription(), targetField.getDescription()); assertEquals(sourceField.getCode(), targetField.getCode()); assertEquals(sourceField.getRelevanceConditionExpression(), targetField.getRelevanceConditionExpression()); assertEquals(sourceField.getType().getTypeClass(), targetField.getType().getTypeClass()); // todo if (sourceField.getType() instanceof ReferenceType) { // need something more sophisticated to check equality of ReferenceType } else if (sourceField.getType() instanceof EnumType) { // need something more sophisticated to check equality of ReferenceType } } // sections for (FormSection sourceSection : sourceFormClass.getSections()) { FormSection targetSection = (FormSection) elementByName(targetFormClass.getElements(), sourceSection.getLabel()); assertNotEquals(sourceSection.getId(), targetSection.getId()); assertEquals(sourceSection.getLabel(), targetSection.getLabel()); } }