/// <summary> /// Checks if a data in a <see cref="SubmittableParameterValue"/> should be written to a ValueSet if found. /// </summary> /// <param name="submittableParameterValue">The <see cref="SubmittableParameterValue"/></param> /// <param name="option">The <see cref="Option"/> used to check if writing a value is allowed</param> /// <returns>true is write is allowed, otherwise false</returns> public bool ValueSetWriteAllowed(SubmittableParameterValue submittableParameterValue, Option option) { var currentOptionPath = ReportingUtilities.ConvertToOptionPath(submittableParameterValue.Path, option); if (submittableParameterValue.IsExactOptionPath) { //Option should be defined in SubmittableParameterValue. Does the Option match the expected value based on the current Option? return(submittableParameterValue.Path == currentOptionPath); } return(true); }
/// <summary> /// Try to create/change a <see cref="ProcessedValueSet"/> for a <see cref="Parameter"/>, <see cref="ParameterOverride"/>, or <see cref="ParameterSubscription"/> /// found by searching for a specific <see cref="NestedParameter.Path"/>. /// </summary> /// <param name="option"> /// The <see cref="Option"/> to be used. /// </param> /// <param name="allNestedParameters"> /// An <see cref="IEnumerable{NestedParameter}"/> that contains all nested parameters for a specific ProductTree. /// </param> /// <param name="ownedNestedParameters"> /// An <see cref="IEnumerable{NestedParameter}"/> that contains only the nested parameters for a specific ProductTree /// that are available to a specific <see cref="DomainOfExpertise"/>. /// </param> /// <param name="submittableParameterValue"> /// The <see cref="SubmittableParameterValue"/> that contains /// </param> /// <param name="processedValueSets">A <see cref="Dictionary{Guid, ProcessedValueSet}"/> that contains all <see cref="ProcessedValueSet"/> found until now.</param> /// <param name="errorText"> /// A <see cref="string"/> that contains information about problems that occured during the process. /// </param> /// <returns> /// true if <see cref="NestedParameter.Path"/> was found and the <see cref="ProcessedValueSet"/> was succesfully created and processed, otherwise false. /// </returns> public bool TryGetProcessedValueSet(Option option, IEnumerable <NestedParameter> allNestedParameters, IEnumerable <NestedParameter> ownedNestedParameters, SubmittableParameterValue submittableParameterValue, ref Dictionary <Guid, ProcessedValueSet> processedValueSets, out string errorText) { if (!this.ValueSetWriteAllowed(submittableParameterValue, option)) { // This value should not be written, but in this case no error should be returned as it is as expected errorText = ""; return(true); } var path = ReportingUtilities.ConvertToOptionPath(submittableParameterValue.Path, option); var nestedParameters = option.GetNestedParameterValueSetsByPath(path, allNestedParameters).ToList(); if (nestedParameters.Count == 0) { errorText = $"Path {path} was not found in Product Tree for Option {option.ShortName}"; return(false); } nestedParameters = option.GetNestedParameterValueSetsByPath(path, ownedNestedParameters).ToList(); if (nestedParameters.Count == 0) { errorText = $"Domain {this.IterationDependentDataCollector.DomainOfExpertise.Name} does not have access to Path {path}."; return(false); } if (nestedParameters.Count > 1) { errorText = $"Multiple parameters found for Path {path}. Cannot write the value back to the model."; return(false); } var nestedParameter = nestedParameters.Single(); if (nestedParameter.AssociatedParameter.ParameterType.NumberOfValues > 1) { errorText = $"ParameterType {nestedParameter.AssociatedParameter.ParameterType.Name} is of a compound parameter type. Writing back values to the model for Compound parameter types is currently not supported."; return(false); } if (!this.IterationDependentDataCollector.Session.PermissionService.CanWrite(nestedParameter.AssociatedParameter)) { errorText = $"Domain {this.IterationDependentDataCollector.DomainOfExpertise.Name} does not have write access to Path {path}."; return(false); } if (nestedParameter.AssociatedParameter is ParameterOrOverrideBase parameterOrOverrideBase && nestedParameter.ValueSet is ParameterValueSetBase parameterValueSetBase) { var processedValueSet = this.ProcessValueSet(parameterValueSetBase, parameterOrOverrideBase, 0, submittableParameterValue.Text, ref processedValueSets, null, out errorText); return(processedValueSet.ValidationResult == ValidationResultKind.Valid); } if (nestedParameter.AssociatedParameter is ParameterSubscription parameterSubscription && nestedParameter.ValueSet is ParameterSubscriptionValueSet parameterSubscriptionValueSet) { var processedValueSet = this.ProcessValueSet(parameterSubscriptionValueSet, parameterSubscription, 0, submittableParameterValue.Text, ref processedValueSets, null, out errorText); return(processedValueSet.ValidationResult == ValidationResultKind.Valid); } errorText = $"Update Path {path} failed due to unexpected valueSet type: {nestedParameter.ValueSet.GetType()}"; return(false); }