Skip to content

Commit

Permalink
Merge pull request #303 from klee-contrib/data-flows-hooks
Browse files Browse the repository at this point in the history
[Jpa] dataflows on y est presque
  • Loading branch information
gideruette authored Sep 20, 2023
2 parents 72b5840 + d3f3a42 commit 0fc0f1e
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 162 deletions.
4 changes: 2 additions & 2 deletions TopModel.Core/Loaders/DataFlowLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ public DataFlow Load(Parser parser)
FlowHook? hook = null;
switch (value)
{
case "beforeFLow": hook = FlowHook.BeforeFlow; break;
case "beforeFlow": hook = FlowHook.BeforeFlow; break;
case "afterSource": hook = FlowHook.AfterSource; break;
case "map": hook = FlowHook.Map; break;
case "beforeTarget": hook = FlowHook.BeforeTarget; break;
case "afterFLow": hook = FlowHook.AfterFlow; break;
case "afterFlow": hook = FlowHook.AfterFlow; break;
}

if (hook != null)
Expand Down
10 changes: 9 additions & 1 deletion TopModel.Generator.Jpa/JpaConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class JpaConfig : GeneratorConfigBase
/// <summary>
/// Listeners à ajouter aux dataflows
/// </summary>
public List<string> DataFlowsListeners { get; set; } = new ();
public List<string> DataFlowsListeners { get; set; } = new();

public override string[] PropertiesWithLangVariableSupport => new[]
{
Expand Down Expand Up @@ -172,6 +172,14 @@ public string GetDataFlowFilePath(DataFlow df, string tag)
$"{df.Name.ToPascalCase()}Flow.java");
}

public string GetDataFlowPartialFilePath(DataFlow df, string tag)
{
return Path.Combine(
OutputDirectory,
ResolveVariables(DataFlowsPath!, tag: tag, module: df.ModelFile.Namespace.ModulePath).ToFilePath(),
$"{df.Name.ToPascalCase()}PartialFlow.java");
}

public string GetEnumFileName(Class classe, string tag)
{
return Path.Combine(
Expand Down
13 changes: 1 addition & 12 deletions TopModel.Generator.Jpa/JpaModelGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,13 @@ private void WriteAnnotations(JavaWriter fw, Class classe, string tag)
{
if (Config.UseJdbc)
{
var table = @$"@Table(name = ""{classe.SqlName}""";
if (Config.ResolveVariables(Config.DbSchema!, tag: tag) != null)
{
table += @$", schema = ""{Config.ResolveVariables(Config.DbSchema!, tag: tag)}""";
}
table += ")";
var table = @$"@Table(name = ""{classe.SqlName.ToLower()}"")";
fw.AddImport($"org.springframework.data.relational.core.mapping.Table");
fw.WriteLine(table);
}
else
{
var table = @$"@Table(name = ""{classe.SqlName}""";
if (Config.DbSchema != null && Config.ResolveVariables(Config.DbSchema, tag: tag) != null)
{
table += @$", schema = ""{Config.ResolveVariables(Config.DbSchema, tag: tag)}""";
}
fw.AddImport($"{javaOrJakarta}.persistence.Table");
if (classe.UniqueKeys.Any())
{
Expand Down
7 changes: 4 additions & 3 deletions TopModel.Generator.Jpa/JpaModelPropertyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private void WriteProperty(JavaWriter fw, Class classe, IFieldProperty property,
fw.WriteLine(1, "@Id");
}

if (classe.IsPersistent && !_config.GetImplementation(property.Domain)!.Annotations
if ((classe.IsPersistent || _config.UseJdbc) && !_config.GetImplementation(property.Domain)!.Annotations
.Where(i =>
classe.IsPersistent && (Target.Persisted & i.Target) > 0
|| !classe.IsPersistent && (Target.Dto & i.Target) > 0)
Expand Down Expand Up @@ -298,12 +298,13 @@ private void WriteProperty(JavaWriter fw, Class classe, IFieldProperty property,
else
{
fw.AddImport("org.springframework.data.relational.core.mapping.Column");
column = $@"@Column(""{property.SqlName}"")";
column = $@"@Column(""{property.SqlName.ToLower()}"")";
}

fw.WriteLine(1, column);
}
else if (property.Required && !property.PrimaryKey && !classe.IsPersistent)

if (property.Required && !property.PrimaryKey && (!classe.IsPersistent || _config.UseJdbc))
{
fw.WriteLine(1, @$"@NotNull");
fw.AddImport($"{javaOrJakarta}.validation.constraints.NotNull");
Expand Down
11 changes: 10 additions & 1 deletion TopModel.Generator.Jpa/SpringClientApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,16 @@ private void WriteUriBuilderMethod(JavaWriter fw, Endpoint endpoint)
indentLevel++;
}

fw.WriteLine(indentLevel, @$"uriBuilder.queryParam(""{p.GetParamName()}"", {p.GetParamName()});");
if (Config.GetType(p).StartsWith("List"))
{
fw.AddImport("java.util.stream.Collectors");
fw.WriteLine(indentLevel, @$"uriBuilder.queryParam(""{p.GetParamName()}"", {p.GetParamName()}.stream().collect(Collectors.joining("","")));");
}
else
{
fw.WriteLine(indentLevel, @$"uriBuilder.queryParam(""{p.GetParamName()}"", {p.GetParamName()});");
}

if (!isRequired)
{
fw.WriteLine(2, @$"}}");
Expand Down
Loading

0 comments on commit 0fc0f1e

Please sign in to comment.