Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -502,7 +502,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.",
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.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the bug #3264 , the message should be:

Cannot create new entity from autoentities member 'autoentityName' due to an internal error

whereas the other bug says it should be definition.
Clarify that there is a discrepancy in expectation. I do think definition is the right term to use.

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 All @@ -356,7 +356,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 @@ -375,14 +375,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);
}

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 @@ -395,10 +395,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}");
_logger.LogDebug($"The autoentities definition '{autoentityName}' exclude pattern: {exclude}");
_logger.LogDebug($"The autoentities definition '{autoentityName}' name pattern: {namePattern}");

JsonArray? resultArray = await QueryExecutor.ExecuteQueryAsync(
sqltext: getAutoentitiesQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,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.");
}

protected void PopulateDatabaseObjectForEntity(
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