Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use table name for entity merging in xml generation, exclude "status" field from Entity status detection #26

Merged
merged 2 commits into from
Jul 4, 2022
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
2 changes: 1 addition & 1 deletion api/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (s *XMLService) GenerateEntity(table, namespace string) (*mfd.Entity, error
}

for _, entity := range entities {
exiting := s.CurrentProject.Entity(entity.GoName)
exiting := s.CurrentProject.EntityByTable(entity.PGFullName)

// adding to project
entity := xml.PackEntity(namespace, entity, exiting, s.CurrentProject.CustomTypes)
Expand Down
2 changes: 1 addition & 1 deletion generators/xml/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (g *Generator) Generate() (err error) {
}

for _, entity := range entities {
exiting := project.Entity(entity.GoName)
exiting := project.EntityByTable(entity.PGFullName)
if exiting != nil {
set.Prepend(exiting.Namespace)
}
Expand Down
5 changes: 4 additions & 1 deletion generators/xml/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ func PackEntity(namespace string, entity model.Entity, existing *mfd.Entity, new
// processing all columns
var attributes mfd.Attributes
var searches mfd.Searches
name := entity.GoName

if existing != nil {
attributes = existing.Attributes
searches = existing.Searches
name = existing.Name
}

hasAlias := false
Expand Down Expand Up @@ -54,7 +57,7 @@ func PackEntity(namespace string, entity model.Entity, existing *mfd.Entity, new
}

mfdEntity := &mfd.Entity{
Name: entity.GoName,
Name: name,
Namespace: namespace,
Table: entity.PGFullName,
Attributes: attributes,
Expand Down
27 changes: 24 additions & 3 deletions mfd/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,17 @@ func (p *Project) Entity(entity string) *Entity {
return nil
}

// Entity returns mfd.VTEntity by its name
// EntityByTable returns mfd.Entity by its table
func (p *Project) EntityByTable(table string) *Entity {
for _, n := range p.Namespaces {
if e := n.EntityByTable(table); e != nil {
return e
}
}
return nil
}

// VTEntity returns mfd.VTEntity by its name
func (p *Project) VTEntity(entity string) *VTEntity {
for _, n := range p.VTNamespaces {
if e := n.VTEntity(entity); e != nil {
Expand Down Expand Up @@ -460,6 +470,17 @@ func (n *Namespace) Entity(entity string) *Entity {
return nil
}

// EntityByTable returns mfd.Entity by table name
func (n *Namespace) EntityByTable(table string) *Entity {
for _, e := range n.Entities {
if e.Table == table {
return e
}
}

return nil
}

// EntityIndex returns mfd.Entity index by its name
func (n *Namespace) EntityIndex(entity string) int {
for i, e := range n.Entities {
Expand Down Expand Up @@ -684,7 +705,7 @@ func (a *Attribute) IsIDsArray() bool {
return strings.HasSuffix(a.Name, util.IDs) && a.IsArray
}

// Attribute is xml element
// Search is xml element
type Search struct {
XMLName xml.Name `xml:"Search" json:"-"`
Name string `xml:"Name,attr" json:"name"`
Expand All @@ -706,7 +727,7 @@ func (s *Search) ForeignAttribute() (entity, attribute string) {
}

func IsStatus(name string) bool {
return strings.ToLower(name) == "statusid" || strings.ToLower(name) == "status" || strings.ToLower(name) == "status_id"
return strings.ToLower(name) == "statusid" || strings.ToLower(name) == "status_id"
}

func IsArraySearch(search string) bool {
Expand Down