Skip to content

Commit

Permalink
[#68] Integrate Model Orphans Reporting (#69)
Browse files Browse the repository at this point in the history
* [#68] Integrate Model Orphans Reporting
  • Loading branch information
danielsiegl authored Feb 13, 2025
1 parent 7a96cb4 commit b0eee07
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/TestModelCheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
./LemonTree.Pipeline.Tools.ModelCheck --model "${{inputs.model-path}}" --tablesize --out "./output.md"
}
elseif ('${{runner.os}}' -eq 'Windows') {
./LemonTree.Pipeline.Tools.ModelCheck.exe --model "${{inputs.model-path}}" --tablesize --out "./output.md"
./LemonTree.Pipeline.Tools.ModelCheck.exe --model "${{inputs.model-path}}" --tablesize --orphans --out "./output.md"
}
else {
Write-Output "${{runner.os}} is not supported"
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ on:
release:
types: [created]

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write
deployments: write

jobs:
prepareVersion:
runs-on: windows-latest
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,6 @@ src/Models/GPUCache/data_2
src/Models/GPUCache/data_3
src/Models/GPUCache/index
*.ldb
/.obsidian/appearance.json
/.obsidian/core-plugins.json
/.obsidian/workspace.json
1 change: 1 addition & 0 deletions .obsidian/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@ https://nexus.lieberlieber.com/#browse/browse:lemontree-pipeline-tools
Used to check Models for LemonTree Readiness.
https://nexus.lieberlieber.com/repository/lemontree-pipeline-tools/LemonTree.Pipeline.Tools.ModelCheck.exe

### Commandline Reference

```
--Out File to output .md e.g.: 'out.md'
--NoCompact If set the Checks that compact the Model are not run!
--FailOnErrors If set the Exitcode will be 2 if there is at least on Check of Status Error!
--FailOnWarnings If set the Exitcode will be 1 if there is at least on Check of Status Warning!
--TableSize If set the size of the tables in the database will be reported!
--Orphans If set Model Orphans will be reported!
--Model Required. The 'Model' used for the operation.
--help Display this help screen.
--version Display version information.
```

### Powershell Example:
```
Expand Down
64 changes: 58 additions & 6 deletions src/LemonTree.Pipeline.Tools.ModelCheck/Checks/Checks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,10 @@ select count(t_object.Object_Type) as ['Count'], t_object.Object_Type as ['Measu

result.Level = IssueLevel.Information;
result.Title = "Project Statistics";
result.Detail = "Executed Project Statistics on Model";



result.Detail = ToMD(resultTable.DefaultView.ToTable(), header: true);
result.Markdown = ToMD(resultTable.DefaultView.ToTable(), header: true);


#endregion
Expand All @@ -431,11 +431,8 @@ internal static Issue CheckTableSize(string model)
//resultTable.DefaultView.Sort = "table_size";
resultTable.Columns[1].ColumnName = "table_size (bytes)";

Console.WriteLine(ToMD(resultTable, header: true));

#endregion


#region process result table and calculate Issue number


Expand All @@ -447,10 +444,65 @@ internal static Issue CheckTableSize(string model)

result.Level = IssueLevel.Information;
result.Title = "Table Statistics (all >32)";
result.Detail = $"Found {resultTable.Rows.Count} Tables bigger 32";


result.Markdown = ToMD(resultTable.DefaultView.ToTable(), header: true);


#endregion

return result;
}

internal static Issue CheckModelOrphans(string model)
{
#region get result table

const string statisticSql = @"
SELECT ea_guid AS CLASSGUID, Object_Type AS CLASSTYPE, t_object.*
FROM t_object
WHERE t_object.Object_Type <> 'Package'
AND t_object.Object_ID NOT IN (SELECT t_diagramobjects.Object_ID FROM t_diagramobjects)
AND t_object.Object_ID NOT IN (SELECT t_object.Classifier FROM t_object WHERE t_object.Classifier <> 0)
AND t_object.Object_ID NOT IN (SELECT a.Object_ID FROM t_object AS a JOIN t_object AS b ON b.PDATA1 = a.ea_guid)
AND t_object.Object_ID NOT IN (SELECT CAST(t_attribute.Classifier AS INTEGER) FROM t_attribute WHERE t_attribute.Classifier <> '0' AND t_attribute.Classifier <> '')
AND t_object.Object_ID NOT IN (SELECT CAST(t_operation.Classifier AS INTEGER) FROM t_operation WHERE t_operation.Classifier <> '0' AND t_operation.Classifier <> '')
AND t_object.Object_ID NOT IN (SELECT CAST(t_operationparams.Classifier AS INTEGER) FROM t_operationparams WHERE t_operationparams.Classifier <> '0' AND t_operationparams.Classifier <> '')
AND t_object.Object_ID NOT IN (SELECT t_connector.Start_Object_ID FROM t_connector)
AND t_object.Object_ID NOT IN (SELECT t_connector.End_Object_ID FROM t_connector)
AND t_object.Object_ID NOT IN (SELECT t_object.ParentID FROM t_object)
AND t_object.Object_ID NOT IN (SELECT t_object.Object_ID FROM t_xref JOIN t_object ON t_xref.Description LIKE '%' || t_object.ea_guid || '%' WHERE t_xref.Name = 'MOFProps')
AND t_object.ea_guid NOT IN (SELECT t_operation.Behaviour FROM t_operation WHERE t_operation.Behaviour <> '')
AND t_object.Object_ID NOT IN (SELECT CAST(t_connector.PDATA1 AS INTEGER) FROM t_connector WHERE t_connector.Connector_Type = 'Association' AND t_connector.SubType = 'Class');
";

var resultTable = ModelAccess.RunSql(statisticSql);

#endregion

#region process result table and calculate Issue number


result.Detail = ToMD(resultTable.DefaultView.ToTable(), header: true);
#endregion

#region set Issue Level

Issue result = new Issue();

result.Level = IssueLevel.Information;
result.Title = "Model Orphans Statistics";


if (resultTable.Rows.Count > 0)
{
result.Markdown = ToMD(resultTable.DefaultView.ToTable(), header: true);
result.Detail = $"Found {resultTable.Rows.Count} Orphans in Model";
}
else
{
result.Detail = "No Orphans found in Model!";
}


#endregion
Expand Down
2 changes: 2 additions & 0 deletions src/LemonTree.Pipeline.Tools.ModelCheck/Checks/Issue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ internal class Issue
internal string Detail { get; set; }
internal string Title { get; set; }

internal string Markdown { get; set; }

internal string Symbol
{
get
Expand Down
2 changes: 0 additions & 2 deletions src/LemonTree.Pipeline.Tools.ModelCheck/Checks/Issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ internal string ToMd()
var mySortedList = this.OrderBy(x => x.Level);
foreach (Issue issue in mySortedList)
{


sb.AppendLine($"|{issue.Symbol}|{issue.Level}|{issue.Title}|{issue.Detail}|");
}
return sb.ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ internal class ModelCheckOptions:BaseOptions

[Option("TableSize", Required = false, HelpText = "If set the size of the tables in the database will be reported!")]
public bool TableSize { get; set; }

[Option("Orphans", Required = false, HelpText = "If set Model Orphans will be reported!")]
public bool Orphans { get; set; }
}
}
47 changes: 31 additions & 16 deletions src/LemonTree.Pipeline.Tools.ModelCheck/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,39 +69,54 @@ private static int RunModelCheck(ModelCheckOptions opts)
issues.AddIfNotNull(Checks.Checks.CheckStrippedCompact(opts.Model));
}


// issues.WriteOutPut(Checks.Checks.CheckProjectStatitics(opts.Model));


Console.WriteLine(issues.ToString());

StringBuilder sb = new StringBuilder();
sb.AppendLine(issues.ToMd());
sb.AppendLine("# Project Statistics");
sb.AppendLine(Checks.Checks.CheckProjectStatitics(opts.Model).Detail);

Issue resultTableSize = null;
if (opts.TableSize == true)
{
if (ModelAccess.IsSqlLite())
{
sb.AppendLine(Checks.Checks.CheckTableSize(opts.Model).Detail);
resultTableSize = Checks.Checks.CheckTableSize(opts.Model);

issues.AddIfNotNull(resultTableSize);
}
else
{
Console.WriteLine("Talbesize reporting only supported for SqlLite!");
}
}


Issue resultOrphans = null;
if (opts.Orphans == true)
{
if (ModelAccess.IsSqlLite())
{
resultOrphans = Checks.Checks.CheckModelOrphans(opts.Model);
issues.AddIfNotNull(resultOrphans);
}
else
{
Console.WriteLine("Orphans reporting only supported for SqlLite!");
}
}

Console.WriteLine(issues.ToString());
StringBuilder sb = new StringBuilder();
sb.AppendLine(issues.ToMd());
sb.AppendLine("# Project Statistics");
sb.AppendLine(Checks.Checks.CheckProjectStatitics(opts.Model).Markdown);
if (resultTableSize != null)
{
sb.AppendLine(resultTableSize.Markdown);
}
if (resultOrphans != null)
{
sb.AppendLine(resultOrphans.Markdown);
}

if (opts.Out != null)
{
File.WriteAllText(opts.Out, sb.ToString());
File.WriteAllText(opts.Out, sb.ToString());
}



if (opts.FailOnErrors == true)
{
if (issues.HasErrors())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"profiles": {
"LemonTree.Pipeline.Tools.ModelCheck": {
"commandName": "Project",
"commandLineArgs": "--model models\\model.qeax --tablesize"
"commandLineArgs": "--model models\\model.qeax --tablesize --orphans"
},
"ExampleModel": {
"commandName": "Project",
"commandLineArgs": "--model \"C:\\repos\\SixthForth\\lemontree_demo\\EAExample.qeax\" --tablesize --orphans"
}
}
}

0 comments on commit b0eee07

Please sign in to comment.