Skip to content
4 changes: 2 additions & 2 deletions src/Cli/ConfigGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3268,7 +3268,7 @@ public static bool TrySimulateAutoentities(AutoConfigSimulateOptions options, Fi

if (runtimeConfig.DataSource.DatabaseType != DatabaseType.MSSQL)
{
_logger.LogError("Autoentities simulation is only supported for MSSQL databases. Current database type: {DatabaseType}.", runtimeConfig.DataSource.DatabaseType);
_logger.LogError("The autoentities simulation is only supported for MSSQL databases. Current database type: {DatabaseType}.", runtimeConfig.DataSource.DatabaseType);
return false;
}

Expand Down Expand Up @@ -3360,7 +3360,7 @@ public static bool TrySimulateAutoentities(AutoConfigSimulateOptions options, Fi
/// <param name="results">The simulation results keyed by filter (definition) name.</param>
private static void WriteSimulationResultsToConsole(Dictionary<string, List<(string EntityName, string SchemaName, string ObjectName)>> results)
{
Console.WriteLine("AutoEntities Simulation Results");
Console.WriteLine("Autoentities Simulation Results");
Console.WriteLine();

foreach ((string filterName, List<(string EntityName, string SchemaName, string ObjectName)> matches) in results)
Expand Down
2 changes: 1 addition & 1 deletion src/Config/ObjectModel/RuntimeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public string GetDataSourceNameFromAutoentityName(string autoentityName)
if (!_autoentityNameToDataSourceName.TryGetValue(autoentityName, out string? autoentityDataSource))
{
throw new DataApiBuilderException(
message: $"{autoentityName} is not a valid autoentity.",
message: $"'{autoentityName}' is not a valid autoentities definition.",
Comment thread
RubenCerna2079 marked this conversation as resolved.
statusCode: HttpStatusCode.NotFound,
subStatusCode: DataApiBuilderException.SubStatusCodes.EntityNotFound);
}
Expand Down
20 changes: 10 additions & 10 deletions src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
foreach ((string autoentityName, Autoentity autoentity) in autoentities)
{
int addedEntities = 0;
JsonArray? resultArray = await QueryAutoentitiesAsync(autoentity);
JsonArray? resultArray = await QueryAutoentitiesAsync(autoentityName, autoentity);
if (resultArray is null)
{
continue;
Expand All @@ -316,7 +316,7 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
if (resultObject is null)
{
throw new DataApiBuilderException(
message: $"Cannot create new entity from autoentity pattern due to an internal error.",
message: $"Cannot create new entity from autoentities definition '{autoentityName}' due to an internal error.",
Comment thread
RubenCerna2079 marked this conversation as resolved.
statusCode: HttpStatusCode.InternalServerError,
subStatusCode: DataApiBuilderException.SubStatusCodes.ErrorInInitialization);
}
Expand All @@ -329,7 +329,7 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona

if (string.IsNullOrWhiteSpace(entityName) || string.IsNullOrWhiteSpace(objectName) || string.IsNullOrWhiteSpace(schemaName))
{
_logger.LogError("Skipping autoentity generation: entity_name or object is null or empty for autoentity pattern '{AutoentityName}'.", autoentityName);
_logger.LogError("Skipping autoentity generation: 'entity_name', 'object', or 'schema' is null or empty for autoentities definition '{autoentityName}'.", autoentityName);
continue;
}

Expand Down Expand Up @@ -357,7 +357,7 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
if (!entities.TryAdd(entityName, generatedEntity) || !runtimeConfig.TryAddGeneratedAutoentityNameToDataSourceName(entityName, autoentityName))
{
throw new DataApiBuilderException(
message: $"Entity with name '{entityName}' already exists. Cannot create new entity from autoentity pattern with definition-name '{autoentityName}'.",
message: $"Entity with name '{entityName}' already exists. Cannot create new entity from autoentities definition '{autoentityName}'.",
statusCode: HttpStatusCode.BadRequest,
subStatusCode: DataApiBuilderException.SubStatusCodes.ErrorInInitialization);
}
Expand All @@ -376,14 +376,14 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona

if (addedEntities == 0)
{
_logger.LogWarning("No new entities were generated from the autoentity {autoentityName} defined in the configuration.", autoentityName);
_logger.LogWarning("No new entities were generated from the autoentities definition '{autoentityName}'.", autoentityName);
}
}

_runtimeConfigProvider.AddMergedEntitiesToConfig(entities);
}

Comment thread
RubenCerna2079 marked this conversation as resolved.
public async Task<JsonArray?> QueryAutoentitiesAsync(Autoentity autoentity)
public async Task<JsonArray?> QueryAutoentitiesAsync(string autoentityName, Autoentity autoentity)
{
string include = string.Join(",", autoentity.Patterns.Include);
string exclude = string.Join(",", autoentity.Patterns.Exclude);
Expand All @@ -396,10 +396,10 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
{ $"{BaseQueryStructure.PARAM_NAME_PREFIX}name_pattern", new(namePattern, null, SqlDbType.NVarChar) }
};

_logger.LogInformation("Query for Autoentities is being executed with the following parameters.");
_logger.LogInformation($"Autoentities include pattern: {include}");
_logger.LogInformation($"Autoentities exclude pattern: {exclude}");
_logger.LogInformation($"Autoentities name pattern: {namePattern}");
_logger.LogDebug("Query for autoentities is being executed with the following parameters.");
_logger.LogDebug("The autoentities definition '{autoentityName}' include pattern: {include}", autoentityName, include);
_logger.LogDebug("The autoentities definition '{autoentityName}' exclude pattern: {exclude}", autoentityName, exclude);
_logger.LogDebug("The autoentities definition '{autoentityName}' name pattern: {namePattern}", autoentityName, namePattern);

JsonArray? resultArray = await QueryExecutor.ExecuteQueryAsync(
sqltext: getAutoentitiesQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ private void GenerateDatabaseObjectForEntities()
/// </summary>
protected virtual Task GenerateAutoentitiesIntoEntities(IReadOnlyDictionary<string, Autoentity>? autoentities)
{
throw new NotSupportedException($"{GetType().Name} does not support Autoentities yet.");
throw new NotSupportedException($"{GetType().Name} does not support autoentities yet.");
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/Service.Tests/Configuration/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5611,7 +5611,7 @@ public async Task TestAutoentitiesAreGeneratedIntoEntities(bool useEntities, int
/// <returns></returns>
[TestCategory(TestCategory.MSSQL)]
[DataTestMethod]
[DataRow("publishers", "uniqueSingularPublisher", "uniquePluralPublishers", "/unique/publisher", "Entity with name 'publishers' already exists. Cannot create new entity from autoentity pattern with definition-name 'PublisherAutoEntity'.", DisplayName = "Autoentities fail due to entity name")]
[DataRow("publishers", "uniqueSingularPublisher", "uniquePluralPublishers", "/unique/publisher", "Entity with name 'publishers' already exists. Cannot create new entity from autoentities definition 'PublisherAutoEntity'.", DisplayName = "Autoentities fail due to entity name")]
[DataRow("UniquePublisher", "publishers", "uniquePluralPublishers", "/unique/publisher", "Entity publishers generates queries/mutation that already exist", DisplayName = "Autoentities fail due to graphql singular type")]
[DataRow("UniquePublisher", "uniqueSingularPublisher", "publishers", "/unique/publisher", "Entity publishers generates queries/mutation that already exist", DisplayName = "Autoentities fail due to graphql plural type")]
[DataRow("UniquePublisher", "uniqueSingularPublisher", "uniquePluralPublishers", "/publishers", "The rest path: publishers specified for entity: publishers is already used by another entity.", DisplayName = "Autoentities fail due to rest path")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ public async Task CheckAutoentitiesQuery(string[] include, string[] exclude, str

// Act
MsSqlMetadataProvider metadataProvider = (MsSqlMetadataProvider)_sqlMetadataProvider;
JsonArray resultArray = await metadataProvider.QueryAutoentitiesAsync(autoentity);
JsonArray resultArray = await metadataProvider.QueryAutoentitiesAsync("autoentity", autoentity);

// Assert
Assert.IsNotNull(resultArray);
Expand Down