private void ValidateTemplateStepInput(TemplateStepInputCreate stepInput, ModelErrorDictionary stepErrors, IEnumerable <object> stepInputErrorPath, bool isOnlyInput) { if (isOnlyInput) { if (!string.IsNullOrEmpty(stepInput.Name)) { stepErrors.Add("Must be empty if there is only one input for the step", stepInputErrorPath.Concat(nameof(TemplateStepInputCreate.Name))); } if (!string.IsNullOrEmpty(stepInput.Description)) { stepErrors.Add("Must be empty if there is only one input for the step", stepInputErrorPath.Concat(nameof(TemplateStepInputCreate.Description))); } } else { if (string.IsNullOrEmpty(stepInput.Key)) { stepErrors.Add("Required if there is more than one input for the step", stepInputErrorPath.Concat(nameof(TemplateStepInputCreate.Key))); } if (string.IsNullOrEmpty(stepInput.Name)) { stepErrors.Add("Required if there is more than one input for the step", stepInputErrorPath.Concat(nameof(TemplateStepInputCreate.Name))); } if (string.IsNullOrEmpty(stepInput.Description)) { stepErrors.Add("Required if there is more than one input for the step", stepInputErrorPath.Concat(nameof(TemplateStepInputCreate.Description))); } } }
private void ValidateTemplateStepInputs(TemplateStepCreate step, ModelErrorDictionary stepErrors, IEnumerable <object> stepErrorPath) { var stepInputsErrorPath = stepErrorPath.Concat(nameof(TemplateStepCreate.Inputs)); step.Inputs .ToIndexedLookup(i => i.Key) .Where(g => g.Count() > 1) .SelectMany(g => g.AsEnumerable()) .ForEach(indexedStepInput => { stepErrors.Add( $"An input with the id {indexedStepInput.Element.Key} already exists in this step (case-insensitive)", stepInputsErrorPath.Concat(new object[] { indexedStepInput.Index })); }); var isOnlyInput = step.Inputs.Count() == 1; step.Inputs.ForEach((stepInput, stepInputIndex) => ValidateTemplateStepInput( stepInput, stepErrors, stepInputsErrorPath.Concat(stepInputIndex), isOnlyInput)); }
private void AddInputValueError(ModelErrorDictionary errors, string error, string templateStepInputId) { errors.Add(error, $"{nameof(DocumentCreate.InputValues)}[\"{templateStepInputId}\"]"); }
private void ValidateTemplateStep(TemplateCreate create, string stepId, Dictionary <string, IndexedElement <TemplateStepCreate> > stepsById, ModelErrorDictionary stepErrors) { var indexedStep = stepsById[stepId]; var step = indexedStep.Element; var stepIndex = indexedStep.Index; var stepErrorPath = new object[] { nameof(TemplateCreate.Steps), stepIndex }; var isParentStep = stepsById.Any(kvp => kvp.Key.StartsWith(stepId) && kvp.Value.Index != stepIndex); if (!isParentStep && !step.Inputs.Any()) { // Steps that do not have child steps must have inputs. // FUTURE: Maybe we want to add "informational" steps, with no inputs. stepErrors.Add("Step must have at least one inputs", stepErrorPath); } var stepConditionsErrorPath = stepErrorPath.Concat(nameof(TemplateStepCreate.Conditions)); step.Conditions.ForEach((condition, conditionIndex) => { var stepConditionErrorPath = stepConditionsErrorPath.Concat(conditionIndex); var stepConditionTypeErrorPath = stepConditionErrorPath.Concat(nameof(TemplateStepCondition.Type)); var stepConditionTypeDataErrorPath = stepConditionErrorPath.Concat(nameof(TemplateStepCondition.TypeData)); if (condition.Type == TemplateComponentConditionType.EqualsPreviousInputValue) { var previousInputIdErrorPath = stepConditionTypeDataErrorPath.Concat(nameof(TemplateStepConditionTypeData_EqualsPreviousInputValue.PreviousInputId)); var previousInputValueErrorPath = stepConditionTypeDataErrorPath.Concat(nameof(TemplateStepConditionTypeData_EqualsPreviousInputValue.PreviousInputValue)); var previousInputId = DynamicUtility.Unwrap <string>(() => condition.TypeData.PreviousInputId); var(previousInputSuccess, previousInputError, previousInput) = GetPreviousInputReference(stepId, previousInputId, stepsById); if (previousInputSuccess) { if (previousInput.Type == TemplateStepInputType.Checkbox) { try { DynamicUtility.UnwrapValue <bool>(() => condition.TypeData.PreviousInputValue); } catch (RuntimeBinderException) { stepErrors.Add("Expected boolean", previousInputValueErrorPath); } } else if (previousInput.Type == TemplateStepInputType.Radio) { try { DynamicUtility.Unwrap <string>(() => condition.TypeData.PreviousInputValue); } catch (RuntimeBinderException) { throw; } } else { stepErrors.Add("Type of previous input is not supported for conditions", previousInputValueErrorPath); } } else { stepErrors.Add(previousInputError, previousInputIdErrorPath); } } else if (condition.Type == TemplateComponentConditionType.IsDocumentSigned) { if (!create.IsSignable) { stepErrors.Add("Step condition cannot be on document signing if the template does not allow signing", stepConditionTypeErrorPath); } } }); ValidateTemplateStepInputs(step, stepErrors, stepErrorPath); }