Skip to content

Commit

Permalink
altinnrowid field (#12450)
Browse files Browse the repository at this point in the history
* altinnrowid field

* move AltinnRowId to top
  • Loading branch information
mirkoSekulic authored Mar 6, 2024
1 parent d0e8cfe commit 54bc31f
Show file tree
Hide file tree
Showing 10 changed files with 857 additions and 547 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ private void CreateModelFromMetadataRecursive(Dictionary<string, string> classes
classBuilder.AppendLine(Indent() + "public class " + parentElement.TypeName);
classBuilder.AppendLine(Indent() + "{");


if (ShouldWriteAltinnRowId(parentElement, serviceMetadata.Elements.Values.ToList()))
{
WriteAltinnRowId(classBuilder);
}

int elementOrder = 0;

foreach (ElementMetadata element in serviceMetadata.Elements.Select(e => e.Value).Where(ele => ele.ParentElement == parentElement.ID))
Expand Down Expand Up @@ -448,5 +454,25 @@ private void WriteShouldSerializeMethod(StringBuilder classBuilder, string propN
classBuilder.AppendLine(Indent(2) + "}");
classBuilder.AppendLine();
}

private bool ShouldWriteAltinnRowId(ElementMetadata element, List<ElementMetadata> allElements) =>
allElements.Any(e =>
e.TypeName == element.TypeName && e.MaxOccurs > 1);

private void WriteAltinnRowId(StringBuilder classBuilder)
{
classBuilder.AppendLine(Indent(2) + "[XmlAttribute(\"altinnRowId\")]");
classBuilder.AppendLine(Indent(2) + "[JsonPropertyName(\"altinnRowId\")]");
classBuilder.AppendLine(Indent(2) +
"[System.Text.Json.Serialization.JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]");
classBuilder.AppendLine(Indent(2) + "[Newtonsoft.Json.JsonIgnore]");
classBuilder.AppendLine(Indent(2) + "public Guid AltinnRowId { get; set; }");
classBuilder.AppendLine("");
classBuilder.AppendLine(Indent(2) + "public bool ShouldSerializeAltinnRowId()");
classBuilder.AppendLine(Indent(2) + "{");
classBuilder.AppendLine(Indent(3) + "return AltinnRowId != default;");
classBuilder.AppendLine(Indent(2) + "}");
classBuilder.AppendLine();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task GivenApp_ShouldProduce_CorrectNamespace(string modelPath, stri
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
// get the csharp model from repo
string csharpModel = TestDataHelper.GetFileFromRepo(org, targetRepo, developer, expectedModelPath);
csharpModel.Should().Contain($"namespace {expectedNamespace}\n{{");
csharpModel.Should().Contain($"namespace {expectedNamespace}{Environment.NewLine}{{");

string applicationMetadataContent = TestDataHelper.GetFileFromRepo(org, targetRepo, developer, "App/config/applicationmetadata.json");
var applicationMetadata = JsonSerializer.Deserialize<ApplicationMetadata>(applicationMetadataContent, JsonSerializerOptions);
Expand Down
Loading

0 comments on commit 54bc31f

Please sign in to comment.