Skip to content

Commit

Permalink
INFM-137 only new if extends has relations
Browse files Browse the repository at this point in the history
  • Loading branch information
oleanders committed Jun 12, 2023
1 parent 1ffdf1d commit b3f75aa
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
28 changes: 26 additions & 2 deletions common/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/FINTLabs/fint-model/common/document"
"github.com/FINTLabs/fint-model/common/types"
"github.com/FINTLabs/fint-model/common/utils"
"github.com/antchfx/xquery/xml"
xmlquery "github.com/antchfx/xquery/xml"
)

func GetClasses(owner string, repo string, tag string, filename string, force bool) ([]*types.Class, map[string]types.Import, map[string][]*types.Class, map[string][]*types.Class) {
Expand All @@ -33,6 +33,7 @@ func GetClasses(owner string, repo string, tag string, filename string, force bo
class.Extends = getExtends(doc, c)
class.Attributes = getAttributes(c)
class.Relations = getAssociations(doc, c)
class.ExtendsRelations = getExtendsAssociations(doc, c)
class.Package = getPackagePath(c, doc)
class.Namespace = getNamespacePath(c, doc)
class.Identifiable = identifiable(class.Attributes)
Expand Down Expand Up @@ -311,8 +312,31 @@ func getAssociations(doc *xmlquery.Node, c *xmlquery.Node) []types.Association {
return assocs
}

func replaceNO(s string) string {
func getExtendsAssociations(doc *xmlquery.Node, c *xmlquery.Node) bool {

generalizationTargets := xmlquery.Find(doc, fmt.Sprintf("//connectors/connector/properties[@ea_type='Generalization']/../source[@idref='%s']/../target[@idref]", c.SelectAttr("idref")))

if len(generalizationTargets) == 1 && len(generalizationTargets[0].SelectAttr("idref")) > 0 {
idref := generalizationTargets[0].SelectAttr("idref")
associationQuery := [...]string{
fmt.Sprintf("//connectors/connector/properties[@ea_type='Association']/../source[@idref='%s']/../target/role", idref),
fmt.Sprintf("//connectors/connector/properties[@ea_type='Association']/../target[@idref='%s']/../source/role", idref),
}

for _, query := range associationQuery {
for _, r := range xmlquery.Find(doc, query) {
if len(r.SelectAttr("name")) > 0 {
return true
}
}
}

}

return false
}

func replaceNO(s string) string {
r := strings.Replace(s, "æ", "a", -1)
r = strings.Replace(r, "ø", "o", -1)
r = strings.Replace(r, "å", "a", -1)
Expand Down
35 changes: 18 additions & 17 deletions common/types/class.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package types

type Class struct {
Name string
Abstract bool
Deprecated bool
Extends string
Package string
Imports []string
Namespace string
Using []string
Documentation string
Attributes []Attribute
Relations []Association
Resources []Attribute
Resource bool
ExtendsResource bool
Identifiable bool
GitTag string
Stereotype string
Name string
Abstract bool
Deprecated bool
Extends string
Package string
Imports []string
Namespace string
Using []string
Documentation string
Attributes []Attribute
Relations []Association
ExtendsRelations bool
Resources []Attribute
Resource bool
ExtendsResource bool
Identifiable bool
GitTag string
Stereotype string
}
2 changes: 1 addition & 1 deletion generate/cs/cs_class_tpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace {{ .Namespace }}
{
{{- if .Relations }}
{{ $c := sub (len .Relations) 1 -}}
public {{ if .Extends -}} new {{ end -}} enum Relasjonsnavn
public {{ if .ExtendsRelations -}} new {{ end -}} enum Relasjonsnavn
{
{{- range $i, $rel := .Relations }}
{{ $rel.Name | upperCase }}{{if ne $i $c }},{{ end -}}
Expand Down

0 comments on commit b3f75aa

Please sign in to comment.