diff --git a/TopModel.Generator.Jpa/JpaModelConstructorGenerator.cs b/TopModel.Generator.Jpa/JpaModelConstructorGenerator.cs index 2ff39f51..1ef5f042 100644 --- a/TopModel.Generator.Jpa/JpaModelConstructorGenerator.cs +++ b/TopModel.Generator.Jpa/JpaModelConstructorGenerator.cs @@ -46,8 +46,8 @@ public void WriteEnumConstructor(JavaWriter fw, Class classe, List availa foreach (var prop in classe.GetProperties(availableClasses).OfType() .Where(p => p != codeProperty)) { - var isString = _config.GetType((IFieldProperty)prop) == "String"; - var value = refValue.Value.ContainsKey((IFieldProperty)prop) ? refValue.Value[(IFieldProperty)prop] : "null"; + var isString = _config.GetType(prop) == "String"; + var value = refValue.Value.ContainsKey(prop) ? refValue.Value[prop] : "null"; if (prop is AssociationProperty ap && codeProperty.PrimaryKey && ap.Association.Values.Any(r => r.Value.ContainsKey(ap.Property) && r.Value[ap.Property] == value)) { value = ap.Association.NamePascal + "." + value; diff --git a/TopModel.Generator.Sql/Procedural/AbstractSchemaGenerator.cs b/TopModel.Generator.Sql/Procedural/AbstractSchemaGenerator.cs index c1b004a7..94169867 100644 --- a/TopModel.Generator.Sql/Procedural/AbstractSchemaGenerator.cs +++ b/TopModel.Generator.Sql/Procedural/AbstractSchemaGenerator.cs @@ -17,11 +17,13 @@ public abstract class AbstractSchemaGenerator private readonly SqlConfig _config; private readonly ILogger _logger; + private readonly ModelConfig _modelConfig; - public AbstractSchemaGenerator(SqlConfig config, ILogger logger) + public AbstractSchemaGenerator(SqlConfig config, ILogger logger, ModelConfig modelConfig) { _config = config; _logger = logger; + _modelConfig = modelConfig; } protected ProceduralSqlConfig Config => _config.Procedural!; @@ -200,6 +202,11 @@ protected static string CheckIdentifierLength(string identifier) { definition.TryGetValue(property, out var value); nameValueDict[property.SqlName] = _config.GetValue(property, availableClasses, value); + + if (_modelConfig.I18n.TranslateReferences && modelClass.DefaultProperty == property && !_config.CanClassUseEnums(modelClass, prop: property)) + { + nameValueDict[property.SqlName] = $@"""{initItem.ResourceKey}"""; + } } } diff --git a/TopModel.Generator.Sql/Procedural/PostgreSchemaGenerator.cs b/TopModel.Generator.Sql/Procedural/PostgreSchemaGenerator.cs index 22fb8540..5c923de7 100644 --- a/TopModel.Generator.Sql/Procedural/PostgreSchemaGenerator.cs +++ b/TopModel.Generator.Sql/Procedural/PostgreSchemaGenerator.cs @@ -8,8 +8,8 @@ namespace TopModel.Generator.Sql.Procedural; /// public class PostgreSchemaGenerator : AbstractSchemaGenerator { - public PostgreSchemaGenerator(SqlConfig config, ILogger logger) - : base(config, logger) + public PostgreSchemaGenerator(SqlConfig config, ILogger logger, ModelConfig modelConfig) + : base(config, logger, modelConfig) { } diff --git a/TopModel.Generator.Sql/Procedural/ProceduralSqlGenerator.cs b/TopModel.Generator.Sql/Procedural/ProceduralSqlGenerator.cs index fc8b9b2a..90c66d11 100644 --- a/TopModel.Generator.Sql/Procedural/ProceduralSqlGenerator.cs +++ b/TopModel.Generator.Sql/Procedural/ProceduralSqlGenerator.cs @@ -10,12 +10,15 @@ public class ProceduralSqlGenerator : GeneratorBase { private readonly ILogger _logger; + private ModelConfig _modelConfig; + private AbstractSchemaGenerator? _schemaGenerator; - public ProceduralSqlGenerator(ILogger logger) + public ProceduralSqlGenerator(ILogger logger, ModelConfig modelConfig) : base(logger) { _logger = logger; + _modelConfig = modelConfig; } public override string Name => "ProceduralSqlGen"; @@ -36,8 +39,8 @@ private AbstractSchemaGenerator SchemaGenerator get { _schemaGenerator ??= Config.TargetDBMS == TargetDBMS.Postgre - ? new PostgreSchemaGenerator(Config, _logger) - : new SqlServerSchemaGenerator(Config, _logger); + ? new PostgreSchemaGenerator(Config, _logger, _modelConfig) + : new SqlServerSchemaGenerator(Config, _logger, _modelConfig); return _schemaGenerator; } diff --git a/TopModel.Generator.Sql/Procedural/SqlServerSchemaGenerator.cs b/TopModel.Generator.Sql/Procedural/SqlServerSchemaGenerator.cs index b39ae985..729d0bb0 100644 --- a/TopModel.Generator.Sql/Procedural/SqlServerSchemaGenerator.cs +++ b/TopModel.Generator.Sql/Procedural/SqlServerSchemaGenerator.cs @@ -8,8 +8,8 @@ namespace TopModel.Generator.Sql.Procedural; /// public class SqlServerSchemaGenerator : AbstractSchemaGenerator { - public SqlServerSchemaGenerator(SqlConfig config, ILogger logger) - : base(config, logger) + public SqlServerSchemaGenerator(SqlConfig config, ILogger logger, ModelConfig modelConfig) + : base(config, logger, modelConfig) { } diff --git a/samples/generators/pg/src/04_references.sql b/samples/generators/pg/src/04_references.sql index d26e3d27..424fbb42 100644 --- a/samples/generators/pg/src/04_references.sql +++ b/samples/generators/pg/src/04_references.sql @@ -8,18 +8,18 @@ -- Description : Script d'insertion des données de références -- =========================================================================================== /** Initialisation de la table TYPE_DROIT **/ -INSERT INTO TYPE_DROIT(TDR_CODE, TDR_LIBELLE) VALUES('READ', 'Lecture'); -INSERT INTO TYPE_DROIT(TDR_CODE, TDR_LIBELLE) VALUES('WRITE', 'Ecriture'); -INSERT INTO TYPE_DROIT(TDR_CODE, TDR_LIBELLE) VALUES('ADMIN', 'Administration'); +INSERT INTO TYPE_DROIT(TDR_CODE, TDR_LIBELLE) VALUES('READ', "securite.profil.typeDroit.values.Read"); +INSERT INTO TYPE_DROIT(TDR_CODE, TDR_LIBELLE) VALUES('WRITE', "securite.profil.typeDroit.values.Write"); +INSERT INTO TYPE_DROIT(TDR_CODE, TDR_LIBELLE) VALUES('ADMIN', "securite.profil.typeDroit.values.Admin"); /** Initialisation de la table DROIT **/ -INSERT INTO DROIT(DRO_CODE, DRO_LIBELLE, TDR_CODE) VALUES('CREATE', 'Création', 'WRITE'); -INSERT INTO DROIT(DRO_CODE, DRO_LIBELLE, TDR_CODE) VALUES('READ', 'Lecture', 'READ'); -INSERT INTO DROIT(DRO_CODE, DRO_LIBELLE, TDR_CODE) VALUES('UPDATE', 'Mise à jour', 'WRITE'); -INSERT INTO DROIT(DRO_CODE, DRO_LIBELLE, TDR_CODE) VALUES('DELETE', 'Suppression', 'ADMIN'); +INSERT INTO DROIT(DRO_CODE, DRO_LIBELLE, TDR_CODE) VALUES('CREATE', "securite.profil.droit.values.Create", 'WRITE'); +INSERT INTO DROIT(DRO_CODE, DRO_LIBELLE, TDR_CODE) VALUES('READ', "securite.profil.droit.values.Read", 'READ'); +INSERT INTO DROIT(DRO_CODE, DRO_LIBELLE, TDR_CODE) VALUES('UPDATE', "securite.profil.droit.values.Update", 'WRITE'); +INSERT INTO DROIT(DRO_CODE, DRO_LIBELLE, TDR_CODE) VALUES('DELETE', "securite.profil.droit.values.Delete", 'ADMIN'); /** Initialisation de la table TYPE_UTILISATEUR **/ -INSERT INTO TYPE_UTILISATEUR(TUT_CODE, TUT_LIBELLE) VALUES('ADMIN', 'Administrateur'); -INSERT INTO TYPE_UTILISATEUR(TUT_CODE, TUT_LIBELLE) VALUES('GEST', 'Gestionnaire'); -INSERT INTO TYPE_UTILISATEUR(TUT_CODE, TUT_LIBELLE) VALUES('CLIENT', 'Client'); +INSERT INTO TYPE_UTILISATEUR(TUT_CODE, TUT_LIBELLE) VALUES('ADMIN', "securite.utilisateur.typeUtilisateur.values.Admin"); +INSERT INTO TYPE_UTILISATEUR(TUT_CODE, TUT_LIBELLE) VALUES('GEST', "securite.utilisateur.typeUtilisateur.values.Gestionnaire"); +INSERT INTO TYPE_UTILISATEUR(TUT_CODE, TUT_LIBELLE) VALUES('CLIENT', "securite.utilisateur.typeUtilisateur.values.Client"); diff --git a/samples/generators/pg/topmodel.config b/samples/generators/pg/topmodel.config index b087fd5f..b22858a0 100644 --- a/samples/generators/pg/topmodel.config +++ b/samples/generators/pg/topmodel.config @@ -1,8 +1,10 @@ -# yaml-language-server: $schema=./topmodel.config.schema.json +# yaml-language-server: $schema=./topmodel.config.schema.json --- app: pg modelRoot: ../../model lockFileName: pg.topmodel.lock +i18n: + translateReferences: true sql: - tags: - back