Skip to content
Merged
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
17 changes: 13 additions & 4 deletions common/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,22 @@ func getAssociations(doc *xmlquery.Node, c *xmlquery.Node) []types.Association {
continue
}

assoc := buildAssociation(doc, relationElement, q.Role, isParent)
connector := relationElement.Parent.Parent
isSource := isStructuralSource(connector, classId)

assoc := buildAssociation(doc, relationElement, q.Role, isParent, isSource)
assocs = append(assocs, assoc)
}
}
return assocs
}

func buildAssociation(doc *xmlquery.Node, rel *xmlquery.Node, role types.AssociationRole, isParent bool) types.Association {
func isStructuralSource(connector *xmlquery.Node, classId string) bool {
structuralSourceID := connector.SelectElement("source").SelectAttr("idref")
return structuralSourceID == classId
}

func buildAssociation(doc *xmlquery.Node, rel *xmlquery.Node, role types.AssociationRole, isParent bool, isSource bool) types.Association {
targetId := rel.Parent.SelectAttr("idref")
targetClassElement := findClassElementByID(doc, targetId)

Expand All @@ -477,11 +485,12 @@ func buildAssociation(doc *xmlquery.Node, rel *xmlquery.Node, role types.Associa
Multiplicity: rel.SelectElement("../type").SelectAttr("multiplicity"),
Package: getPackagePath(targetClassElement, doc),
Deprecated: rel.SelectElement("../../tags/tag[@name='DEPRECATED']") != nil,
Source: getAssociationSource(rel, role, isParent),
InverseName: getAssociationInverseName(rel, role, isParent),
IsSource: isSource,
}
}

func getAssociationSource(rel *xmlquery.Node, role types.AssociationRole, isParent bool) string {
func getAssociationInverseName(rel *xmlquery.Node, role types.AssociationRole, isParent bool) string {
direction := rel.SelectElement("../../properties").SelectAttr("direction")

if direction != "Bi-Directional" || isParent {
Expand Down
3 changes: 2 additions & 1 deletion common/types/association.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package types
type Association struct {
Name string
Target string
Source string
InverseName string
Package string
Deprecated bool
Multiplicity string
IsSource bool
}
12 changes: 9 additions & 3 deletions generate/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,17 @@ var funcMap = template.FuncMap{
return multiplicity
}
},
"resolveSource": func(source string) string {
if source == "" {
"resolveInverseName": func(inverseName string) string {
if inverseName == "" {
return "null"
}
return strconv.Quote(source)
return strconv.Quote(inverseName)
},
"resolveSource": func(inverseName string, isSource bool) string {
if inverseName == "" {
return "null"
}
return strconv.FormatBool(isSource)
},
"modelRename": func(s string) string {
if s == "FintMainObject" {
Expand Down
6 changes: 4 additions & 2 deletions generate/java/java_class_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ public {{- if .Abstract }} abstract {{- end }} class {{ .Name }} {{ if .Extends
@Getter
public enum Relasjonsnavn implements FintRelation {
{{- range $i, $rel := .Relations }}
{{ upperCase $rel.Name }}("{{ $rel.Name }}", "{{ $rel.Package }}.{{ $rel.Target }}", {{ resolveMultiplicity $rel.Multiplicity }}, {{ resolveSource $rel.Source }}){{ if ne $i $c }},{{ else }};{{ end -}}
{{ upperCase $rel.Name }}("{{ $rel.Name }}", "{{ $rel.Package }}.{{ $rel.Target }}", {{ resolveMultiplicity $rel.Multiplicity }}, {{ resolveSource $rel.InverseName $rel.IsSource }}, {{ resolveInverseName $rel.InverseName }}){{ if ne $i $c }},{{ else }};{{ end -}}
{{ end }}

private final String name;
private final String packageName;
private final FintMultiplicity multiplicity;
private final String inverseName;
private final Boolean isSource;

private Relasjonsnavn(String name, String packageName, FintMultiplicity multiplicity, String inverseName) {
private Relasjonsnavn(String name, String packageName, FintMultiplicity multiplicity, Boolean isSource, String inverseName) {
this.name = name;
this.packageName = packageName;
this.multiplicity = multiplicity;
this.inverseName = inverseName;
this.isSource = isSource;
}
}
{{ end -}}
Expand Down