From cc58327f26b86030607b5ea8cc21c95fb1826b6e Mon Sep 17 00:00:00 2001 From: "Md. Alim Ul Karim" <alim.karim@evatix.com> Date: Mon, 21 Jun 2021 12:54:57 +0600 Subject: [PATCH] hotfix/v0.5.8 hotfix/v0.5.8 --- coreinstruction/BaseSpecPlusRequestIds.go | 31 ++++++++++++++ coreinstruction/BaseTags.go | 19 +++++++-- coreinstruction/IdentifierWithIsGlobal.go | 4 ++ coreinstruction/Specification.go | 50 +++++++++++++++++++++++ 4 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 coreinstruction/BaseSpecPlusRequestIds.go diff --git a/coreinstruction/BaseSpecPlusRequestIds.go b/coreinstruction/BaseSpecPlusRequestIds.go new file mode 100644 index 00000000..d6edb8ed --- /dev/null +++ b/coreinstruction/BaseSpecPlusRequestIds.go @@ -0,0 +1,31 @@ +package coreinstruction + +type BaseSpecPlusRequestIds struct { + Specification *Specification `json:"Specification,omitempty"` + RequestIds *IdentifierWithIsGlobal `json:"RequestIds,omitempty"` +} + +func NewBaseSpecPlusRequestIds( + spec *Specification, + reqIds *IdentifierWithIsGlobal, +) *BaseSpecPlusRequestIds { + return &BaseSpecPlusRequestIds{ + Specification: spec, + RequestIds: reqIds, + } +} + +func (b *BaseSpecPlusRequestIds) HasSpec() bool { + return b != nil && b.Specification != nil +} + +func (b *BaseSpecPlusRequestIds) HasRequestIds() bool { + return b != nil && b.RequestIds != nil +} + +func (b *BaseSpecPlusRequestIds) Clone() *BaseSpecPlusRequestIds { + return &BaseSpecPlusRequestIds{ + Specification: b.Specification.Clone(), + RequestIds: b.RequestIds.Clone(), + } +} diff --git a/coreinstruction/BaseTags.go b/coreinstruction/BaseTags.go index 241c6e32..cbc773c4 100644 --- a/coreinstruction/BaseTags.go +++ b/coreinstruction/BaseTags.go @@ -12,10 +12,23 @@ type BaseTags struct { Tags *[]string `json:"Tags,omitempty"` } -func NewTags(tags *[]string) *BaseTags { +func NewTagsPtr(tags *[]string) *BaseTags { + if tags == nil || len(*tags) == 0 { + return NewTags(nil) + } + + return NewTags(*tags) +} + +func NewTags(tags []string) *BaseTags { + if len(tags) == 0 { + return &BaseTags{ + Tags: &[]string{}, + } + } + return &BaseTags{ - tagsHashset: nil, - Tags: tags, + Tags: &tags, } } diff --git a/coreinstruction/IdentifierWithIsGlobal.go b/coreinstruction/IdentifierWithIsGlobal.go index 934722cf..b0ca49a3 100644 --- a/coreinstruction/IdentifierWithIsGlobal.go +++ b/coreinstruction/IdentifierWithIsGlobal.go @@ -18,6 +18,10 @@ func NewIdentifierWithIsGlobal( } func (receiver *IdentifierWithIsGlobal) Clone() *IdentifierWithIsGlobal { + if receiver == nil { + return nil + } + return &IdentifierWithIsGlobal{ BaseIdentifier: *receiver.BaseIdentifier.Clone(), IsGlobal: receiver.IsGlobal, diff --git a/coreinstruction/Specification.go b/coreinstruction/Specification.go index c0776ede..fa097ec3 100644 --- a/coreinstruction/Specification.go +++ b/coreinstruction/Specification.go @@ -7,6 +7,56 @@ type Specification struct { flatSpec *FlatSpecification } +func NewSpecificationSimple( + id, + display, + typeName string, +) *Specification { + return &Specification{ + BaseIdDisplayType: BaseIdDisplayType{ + BaseIdentifier: BaseIdentifier{Id: id}, + BaseDisplay: BaseDisplay{display}, + BaseType: BaseType{typeName}, + }, + BaseTags: *NewTags(nil), + BaseIsGlobal: BaseIsGlobal{false}, + } +} + +func NewSpecificationSimpleGlobal( + id, + display, + typeName string, +) *Specification { + return &Specification{ + BaseIdDisplayType: BaseIdDisplayType{ + BaseIdentifier: BaseIdentifier{Id: id}, + BaseDisplay: BaseDisplay{display}, + BaseType: BaseType{typeName}, + }, + BaseTags: *NewTags(nil), + BaseIsGlobal: BaseIsGlobal{true}, + } +} + +func NewSpecification( + id, + display, + typeName string, + tags []string, + isGlobal bool, +) *Specification { + return &Specification{ + BaseIdDisplayType: BaseIdDisplayType{ + BaseIdentifier: BaseIdentifier{Id: id}, + BaseDisplay: BaseDisplay{display}, + BaseType: BaseType{typeName}, + }, + BaseTags: *NewTags(tags), + BaseIsGlobal: BaseIsGlobal{isGlobal}, + } +} + func (r *Specification) Clone() *Specification { return &Specification{ BaseIdDisplayType: BaseIdDisplayType{ -- GitLab