/** * Verify that all required fields are provided for new resources */ private static void validateRequiredFields(FormClass formClass, Optional<FormRecord> existingResource, TypedRecordUpdate update) { if(!existingResource.isPresent()) { for (FormField formField : formClass.getFields()) { if (formField.isRequired() && formField.isVisible() && formField.getType().isUpdatable() && !isProvided(formField, existingResource, update)) { throw new InvalidUpdateException("Required field '%s' [%s] is missing from record with schema %s", formField.getCode(), formField.getId(), formClass.getId().asString()); } } } }
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; }
JsonValue fieldValues = jsonObject.get("fieldValues"); for (FormField formField : formClass.getFields()) { if(formField.getType().isUpdatable()) { if (fieldValues.hasKey(formField.getName())) { JsonValue updatedValueElement = fieldValues.get(formField.getName());