private static bool TryGetUpdatedSourceObjectWithOptions()

in src/Cli/ConfigGenerator.cs [1444:1525]


        private static bool TryGetUpdatedSourceObjectWithOptions(
            UpdateOptions options,
            Entity entity,
            [NotNullWhen(true)] out EntitySource? updatedSourceObject)
        {
            updatedSourceObject = null;
            string updatedSourceName = options.Source ?? entity.Source.Object;
            string[]? updatedKeyFields = entity.Source.KeyFields;
            EntitySourceType? updatedSourceType = entity.Source.Type;
            Dictionary<string, object>? updatedSourceParameters = entity.Source.Parameters;

            // If SourceType provided by user is null,
            // no update is required.
            if (options.SourceType is not null)
            {
                if (!EnumExtensions.TryDeserialize(options.SourceType, out EntitySourceType? deserializedEntityType))
                {
                    _logger.LogError(EnumExtensions.GenerateMessageForInvalidInput<EntitySourceType>(options.SourceType));
                    return false;
                }

                updatedSourceType = (EntitySourceType)deserializedEntityType;

                if (IsStoredProcedureConvertedToOtherTypes(entity, options) || IsEntityBeingConvertedToStoredProcedure(entity, options))
                {
                    _logger.LogWarning(
                        "Stored procedures can be configured only with '{storedProcedureAction}' action whereas tables/views are configured with CRUD actions. Update the actions configured for all the roles for this entity.",
                        EntityActionOperation.Execute);
                }
            }

            // No need to validate parameter and key field usage when there are no changes to the source object defined in 'options'
            if ((options.SourceType is not null
                || (options.SourceParameters is not null && options.SourceParameters.Any())
                || (options.SourceKeyFields is not null && options.SourceKeyFields.Any()))
                && !VerifyCorrectPairingOfParameterAndKeyFieldsWithType(
                    updatedSourceType,
                    options.SourceParameters,
                    options.SourceKeyFields))
            {
                return false;
            }

            // Changing source object from stored-procedure to table/view
            // should automatically update the parameters to be null.
            // Similarly from table/view to stored-procedure, key-fields
            // should be marked null.
            if (EntitySourceType.StoredProcedure.Equals(updatedSourceType))
            {
                updatedKeyFields = null;
            }
            else
            {
                updatedSourceParameters = null;
            }

            // If given SourceParameter is null or is Empty, no update is required.
            // Else updatedSourceParameters will contain the parsed dictionary of parameters.
            if (options.SourceParameters is not null && options.SourceParameters.Any() &&
                !TryParseSourceParameterDictionary(options.SourceParameters, out updatedSourceParameters))
            {
                return false;
            }

            if (options.SourceKeyFields is not null && options.SourceKeyFields.Any())
            {
                updatedKeyFields = options.SourceKeyFields.ToArray();
            }

            // Try Creating Source Object with the updated values.
            if (!TryCreateSourceObject(
                    updatedSourceName,
                    updatedSourceType,
                    updatedSourceParameters,
                    updatedKeyFields,
                    out updatedSourceObject))
            {
                return false;
            }

            return true;
        }