Documentation
¶
Overview ¶
Package builder provides utilities for constructing complex AAS (Asset Administration Shell) data structures from database query results.
Package builder provides utilities for constructing complex AAS (Asset Administration Shell) Author: Aaron Zielstorff ( Fraunhofer IESE ), Jannik Fried ( Fraunhofer IESE )
Package builder provides utilities for constructing complex AAS (Asset Administration Shell) data structures from database query results.
Package builder provides utilities for constructing complex AAS (Asset Administration Shell) Author: Aaron Zielstorff ( Fraunhofer IESE ), Jannik Fried ( Fraunhofer IESE )
Package builder provides utilities for constructing complex AAS (Asset Administration Shell) data structures from database query results.
Package builder provides utilities for converting SQL query results into Go data structures. It contains types and functions to handle the transformation of database rows into BaSyx-compliant data models, including handling of complex nested structures like references, language strings, and embedded data specifications.
Index ¶
- func BuildAdministration(adminRow model.AdministrationRow) (*types.AdministrativeInformation, error)
- func ParseAdministrationRow(row json.RawMessage) (*model.AdministrationRow, error)
- func ParseExtensionRows(row json.RawMessage) ([]model.ExtensionRow, error)
- func ParseLangStringDefinitionTypeIec61360(descriptions json.RawMessage) ([]types.ILangStringDefinitionTypeIEC61360, error)
- func ParseLangStringNameType(displayNames json.RawMessage) ([]types.ILangStringNameType, error)
- func ParseLangStringPreferredNameTypeIec61360(descriptions json.RawMessage) ([]types.ILangStringPreferredNameTypeIEC61360, error)
- func ParseLangStringShortNameTypeIec61360(descriptions json.RawMessage) ([]types.ILangStringShortNameTypeIEC61360, error)
- func ParseLangStringTextType(descriptions json.RawMessage) ([]types.ILangStringTextType, error)
- func ParseQualifiersRow(row json.RawMessage) ([]model.QualifierRow, error)
- func ParseReferences(row json.RawMessage, referenceBuilderRefs map[int64]*ReferenceBuilder, ...) ([]types.IReference, error)
- func ParseReferencesFromRows(semanticIDData []model.ReferenceRow, ...) []types.IReference
- func ParseReferredReferences(row json.RawMessage, referenceBuilderRefs map[int64]*ReferenceBuilder, ...) error
- func ParseReferredReferencesFromRows(semanticIDData []model.ReferredReferenceRow, ...) error
- type ArrayToken
- type EmbeddedDataSpecificationsBuilder
- func (edsb *EmbeddedDataSpecificationsBuilder) Build() []types.IEmbeddedDataSpecification
- func (edsb *EmbeddedDataSpecificationsBuilder) BuildContentsIec61360(iecRows json.RawMessage) error
- func (edsb *EmbeddedDataSpecificationsBuilder) BuildReferences(edsReferenceRows json.RawMessage, edsReferredReferenceRows json.RawMessage) error
- type ExtensionsBuilder
- func (b *ExtensionsBuilder) AddExtension(extensionDbID int64, name string, valueType string, value string, position int) (*ExtensionsBuilder, error)
- func (b *ExtensionsBuilder) AddRefersTo(extensionDbID int64, refersToRows json.RawMessage, ...) (*ExtensionsBuilder, error)
- func (b *ExtensionsBuilder) AddSemanticID(extensionDbID int64, semanticIDRows json.RawMessage, ...) (*ExtensionsBuilder, error)
- func (b *ExtensionsBuilder) AddSupplementalSemanticIDs(extensionDbID int64, supplementalSemanticIDsRows json.RawMessage, ...) (*ExtensionsBuilder, error)
- func (b *ExtensionsBuilder) Build() []types.IExtension
- type QualifiersBuilder
- func (b *QualifiersBuilder) AddQualifier(qualifierDbID int64, qType string, valueType int64, value string, position int, ...) (*QualifiersBuilder, error)
- func (b *QualifiersBuilder) AddSemanticID(qualifierDbID int64, semanticIDRows json.RawMessage, ...) (*QualifiersBuilder, error)
- func (b *QualifiersBuilder) AddSupplementalSemanticIDs(qualifierDbID int64, supplementalSemanticIDsRows json.RawMessage, ...) (*QualifiersBuilder, error)
- func (b *QualifiersBuilder) AddValueID(qualifierDbID int64, valueIDRows json.RawMessage, ...) (*QualifiersBuilder, error)
- func (b *QualifiersBuilder) Build() []types.IQualifier
- type ReferenceBuilder
- func (rb *ReferenceBuilder) BuildNestedStructure()
- func (rb *ReferenceBuilder) CreateKey(keyID int64, keyType types.KeyTypes, keyValue string)
- func (rb *ReferenceBuilder) CreateReferredSemanticID(referredSemanticIDDbID int64, parentID int64, ...) *ReferenceBuilder
- func (rb *ReferenceBuilder) CreateReferredSemanticIDKey(referredSemanticIDDbID int64, keyID int64, keyType types.KeyTypes, ...) error
- func (rb *ReferenceBuilder) SetReferredSemanticID(referredSemanticID types.IReference)
- type ReferenceMetadata
- type SimpleToken
- type SubmodelElementBuilder
- type Token
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildAdministration ¶
func BuildAdministration(adminRow model.AdministrationRow) (*types.AdministrativeInformation, error)
BuildAdministration constructs an AdministrativeInformation object from database query results. It processes administrative metadata including version, revision, template ID, creator references, and embedded data specifications.
The function handles the complexity of building nested reference structures for the creator field and processes IEC 61360 data specifications with their hierarchical reference trees.
Parameters:
- adminRow: An AdministrationRow containing administrative data from the database, including version information, creator references, and embedded data specifications
Returns:
- *model.AdministrativeInformation: A pointer to the constructed administrative information object with all nested references and data specifications properly built
- error: An error if reference parsing fails, nil otherwise. Note that errors during embedded data specification building are logged but do not cause the function to fail
Example:
admin, err := BuildAdministration(adminRow)
if err != nil {
log.Printf("Failed to build administration: %v", err)
}
func ParseAdministrationRow ¶
func ParseAdministrationRow(row json.RawMessage) (*model.AdministrationRow, error)
ParseAdministrationRow parses administrative information from JSON into an AdministrationRow object.
This function unmarshals JSON-encoded administrative data from the database. Since administrative information is typically singular for an element, it returns a pointer to a single AdministrationRow object or nil if no data is present.
Parameters:
- row: JSON-encoded array of AdministrationRow objects from the database
Returns:
- *AdministrationRow: Pointer to the parsed AdministrationRow object, or nil if no data
- error: An error if JSON unmarshalling fails
Note: The function expects an array in JSON format but returns only the first element, as administrative information is singular per element.
func ParseExtensionRows ¶
func ParseExtensionRows(row json.RawMessage) ([]model.ExtensionRow, error)
ParseExtensionRows parses extension data from JSON into ExtensionRow objects.
This function unmarshals JSON-encoded extension data from the database into a slice of ExtensionRow objects. Each row represents a single extension with its associated semantic IDs, supplemental semantic IDs, and references stored as nested JSON.
Parameters:
- row: JSON-encoded array of ExtensionRow objects from the database
Returns:
- []ExtensionRow: Slice of parsed ExtensionRow objects
- error: An error if JSON unmarshalling fails
func ParseLangStringDefinitionTypeIec61360 ¶
func ParseLangStringDefinitionTypeIec61360(descriptions json.RawMessage) ([]types.ILangStringDefinitionTypeIEC61360, error)
ParseLangStringDefinitionTypeIec61360 parses localized definitions for IEC 61360 data specifications from JSON data.
This function converts JSON-encoded language-specific definition data from the database into a slice of LangStringDefinitionTypeIec61360 objects. It removes internal database IDs from the data before creating the Go structures.
Parameters:
- descriptions: JSON-encoded array of objects containing id, text, and language fields
Returns:
- []model.LangStringDefinitionTypeIec61360: Slice of parsed language-specific definition objects
- error: An error if JSON unmarshalling fails or if required fields are missing
The function handles empty input by returning an empty slice. It uses panic recovery to handle runtime errors during type assertions. Only objects with an 'id' field are processed to ensure data integrity.
func ParseLangStringNameType ¶
func ParseLangStringNameType(displayNames json.RawMessage) ([]types.ILangStringNameType, error)
ParseLangStringNameType parses localized name strings from JSON data.
This function converts JSON-encoded language-specific name data from the database into a slice of LangStringNameType objects. It removes internal database IDs from the data before creating the Go structures.
Parameters:
- displayNames: JSON-encoded array of objects containing id, text, and language fields
Returns:
- []model.LangStringNameType: Slice of parsed language-specific name objects
- error: An error if JSON unmarshalling fails or if required fields are missing
The function:
- Unmarshals JSON into temporary map structures
- Removes the internal 'id' field used for database relationships
- Creates LangStringNameType objects with text and language fields
- Uses panic recovery to handle runtime errors during type assertions
Note: Only objects with an 'id' field are processed to ensure data integrity.
func ParseLangStringPreferredNameTypeIec61360 ¶
func ParseLangStringPreferredNameTypeIec61360(descriptions json.RawMessage) ([]types.ILangStringPreferredNameTypeIEC61360, error)
ParseLangStringPreferredNameTypeIec61360 parses localized preferred names for IEC 61360 data specifications from JSON data.
This function converts JSON-encoded language-specific preferred name data from the database into a slice of LangStringPreferredNameTypeIec61360 objects. It removes internal database IDs from the data before creating the Go structures.
Parameters:
- descriptions: JSON-encoded array of objects containing id, text, and language fields
Returns:
- []model.LangStringPreferredNameTypeIec61360: Slice of parsed language-specific preferred name objects
- error: An error if JSON unmarshalling fails or if required fields are missing
The function handles empty input by returning an empty slice. It uses panic recovery to handle runtime errors during type assertions. Only objects with an 'id' field are processed to ensure data integrity.
func ParseLangStringShortNameTypeIec61360 ¶
func ParseLangStringShortNameTypeIec61360(descriptions json.RawMessage) ([]types.ILangStringShortNameTypeIEC61360, error)
ParseLangStringShortNameTypeIec61360 parses localized short names for IEC 61360 data specifications from JSON data.
This function converts JSON-encoded language-specific short name data from the database into a slice of LangStringShortNameTypeIec61360 objects. It removes internal database IDs from the data before creating the Go structures.
Parameters:
- descriptions: JSON-encoded array of objects containing id, text, and language fields
Returns:
- []model.LangStringShortNameTypeIec61360: Slice of parsed language-specific short name objects
- error: An error if JSON unmarshalling fails or if required fields are missing
The function handles empty input by returning an empty slice. It uses panic recovery to handle runtime errors during type assertions. Only objects with an 'id' field are processed to ensure data integrity.
func ParseLangStringTextType ¶
func ParseLangStringTextType(descriptions json.RawMessage) ([]types.ILangStringTextType, error)
ParseLangStringTextType parses localized text strings from JSON data.
This function converts JSON-encoded language-specific text data (such as descriptions) from the database into a slice of LangStringTextType objects. It removes internal database IDs from the data before creating the Go structures.
Parameters:
- descriptions: JSON-encoded array of objects containing id, text, and language fields
Returns:
- []model.LangStringTextType: Slice of parsed language-specific text objects
- error: An error if JSON unmarshalling fails or if required fields are missing
The function:
- Unmarshals JSON into temporary map structures
- Removes the internal 'id' field used for database relationships
- Creates LangStringTextType objects with text and language fields
- Uses panic recovery to handle runtime errors during type assertions
Note: Only objects with an 'id' field are processed to ensure data integrity. This function is similar to ParseLangStringNameType but produces LangStringTextType objects which may have different validation rules or usage contexts.
func ParseQualifiersRow ¶
func ParseQualifiersRow(row json.RawMessage) ([]model.QualifierRow, error)
ParseQualifiersRow parses qualifier data from JSON into QualifierRow objects.
This function unmarshals JSON-encoded qualifier data from the database into a slice of QualifierRow objects. Each row represents a single qualifier with its associated semantic IDs, value IDs, and supplemental semantic IDs stored as nested JSON.
Parameters:
- row: JSON-encoded array of QualifierRow objects from the database
Returns:
- []QualifierRow: Slice of parsed QualifierRow objects
- error: An error if JSON unmarshalling fails
func ParseReferences ¶
func ParseReferences(row json.RawMessage, referenceBuilderRefs map[int64]*ReferenceBuilder, mu *sync.RWMutex) ([]types.IReference, error)
ParseReferences parses reference data from JSON and creates Reference objects.
This function unmarshals JSON-encoded ReferenceRow data and delegates to ParseReferencesFromRows for the actual parsing logic. Multiple rows with the same ReferenceID are aggregated into a single Reference object with multiple Keys.
Parameters:
- row: JSON-encoded array of ReferenceRow objects from the database
- referenceBuilderRefs: Map that tracks reference IDs to their corresponding ReferenceBuilder instances. This map is populated by this function and can be used later for processing referred references.
- mu: Optional mutex for concurrent access protection. If nil, no locking is performed.
Returns:
- []*model.Reference: Slice of parsed Reference objects. Each Reference contains all its associated Keys.
- error: An error if JSON unmarshalling fails. Nil key data is logged as warnings but does not cause failure.
func ParseReferencesFromRows ¶
func ParseReferencesFromRows(semanticIDData []model.ReferenceRow, referenceBuilderRefs map[int64]*ReferenceBuilder, mu *sync.RWMutex) []types.IReference
ParseReferencesFromRows parses reference data from already unmarshalled ReferenceRow objects.
This function processes an array of ReferenceRow objects and builds complete Reference objects with their associated Keys. Multiple rows with the same ReferenceID are aggregated into a single Reference object with multiple Keys.
Parameters:
- semanticIdData: Slice of already unmarshalled ReferenceRow objects
- referenceBuilderRefs: Map that tracks reference IDs to their corresponding ReferenceBuilder instances. This map is populated by this function and can be used later for processing referred references.
- mu: Optional mutex for concurrent access protection. If nil, no locking is performed.
Returns:
- []*model.Reference: Slice of parsed Reference objects. Each Reference contains all its associated Keys.
The function:
- Groups multiple rows with the same ReferenceID into a single Reference
- Creates new ReferenceBuilder instances for each unique ReferenceId
- Validates key data completeness (KeyID, KeyType, KeyValue)
- Returns only the unique references (one per ReferenceID)
func ParseReferredReferences ¶
func ParseReferredReferences(row json.RawMessage, referenceBuilderRefs map[int64]*ReferenceBuilder, mu *sync.RWMutex) error
ParseReferredReferences parses referred reference data from JSON and populates the reference builder map.
This function unmarshals JSON-encoded ReferredReferenceRow data and delegates to ParseReferredReferencesFromRows for the actual parsing logic.
Parameters:
- row: JSON-encoded array of ReferredReferenceRow objects from the database
- referenceBuilderRefs: Map of reference IDs to their corresponding ReferenceBuilder instances. This map is used to look up parent references and must be pre-populated with root references.
- mu: Optional mutex for concurrent access protection. If nil, no locking is performed.
Returns:
- error: An error if JSON unmarshalling fails or if a parent reference is not found in the map. Nil references or keys are logged as warnings but do not cause the function to fail.
func ParseReferredReferencesFromRows ¶
func ParseReferredReferencesFromRows(semanticIDData []model.ReferredReferenceRow, referenceBuilderRefs map[int64]*ReferenceBuilder, mu *sync.RWMutex) error
ParseReferredReferencesFromRows parses referred reference data from already unmarshalled ReferredReferenceRow objects.
This function handles the complex case where references point to other references (referred references). It validates that parent references exist in the builder map before creating child references, ensuring referential integrity in the hierarchical structure.
Parameters:
- semanticIdData: Slice of already unmarshalled ReferredReferenceRow objects
- referenceBuilderRefs: Map of reference IDs to their corresponding ReferenceBuilder instances. This map is used to look up parent references and must be pre-populated with root references.
- mu: Optional mutex for concurrent access protection. If nil, no locking is performed.
Returns:
- error: An error if a parent reference is not found in the map. Nil references or keys are logged as warnings but do not cause the function to fail.
The function performs the following validations:
- Skips entries with nil RootReference, ReferenceID, ParentReference, or ReferenceType
- Verifies parent references exist in the builder map
- Ensures key data (KeyID, KeyType, KeyValue) is complete
Types ¶
type ArrayToken ¶
ArrayToken represents a token with an array index, such as "foo[3]". An Index value of -1 indicates a wildcard index ("[]").
func (ArrayToken) GetName ¶
func (ap ArrayToken) GetName() string
GetName returns the array name without the index.
type EmbeddedDataSpecificationsBuilder ¶
type EmbeddedDataSpecificationsBuilder struct {
// contains filtered or unexported fields
}
EmbeddedDataSpecificationsBuilder constructs EmbeddedDataSpecification objects from flattened database query results. It manages the incremental building of complex nested structures including references, IEC 61360 content, value lists, and level types.
The builder maintains a map of data specifications indexed by their database IDs, allowing multiple database rows to contribute to the same specification. This is necessary because the normalized database structure splits embedded data specifications across multiple tables (references, content, value lists, etc.).
Typical usage pattern:
- Create builder with NewEmbeddedDataSpecificationsBuilder()
- Call BuildReferences() to process reference data
- Call BuildContentsIec61360() to process IEC 61360 content
- Call Build() to extract the final slice of specifications
func NewEmbeddedDataSpecificationsBuilder ¶
func NewEmbeddedDataSpecificationsBuilder() *EmbeddedDataSpecificationsBuilder
NewEmbeddedDataSpecificationsBuilder creates a new instance of EmbeddedDataSpecificationsBuilder with an initialized data specifications map ready to process database results.
Returns:
- *EmbeddedDataSpecificationsBuilder: A new builder instance for constructing embedded data specifications from database query results
Example:
builder := NewEmbeddedDataSpecificationsBuilder()
err := builder.BuildReferences(refData, referredRefData)
if err != nil {
// Handle error
}
err = builder.BuildContentsIec61360(iecData)
if err != nil {
// Handle error
}
specs := builder.Build()
func (*EmbeddedDataSpecificationsBuilder) Build ¶
func (edsb *EmbeddedDataSpecificationsBuilder) Build() []types.IEmbeddedDataSpecification
Build finalizes the construction of all embedded data specifications and returns them as a slice. This method should be called after all data specifications and their contents have been processed through BuildReferences() and BuildContentsIec61360().
The method extracts all embedded data specifications from the internal map and returns them as a slice. Each specification contains complete reference hierarchies and IEC 61360 content where applicable.
Returns:
- []types.IEmbeddedDataSpecification: A slice containing all constructed embedded data specifications with their complete reference hierarchies and content
Example:
builder := NewEmbeddedDataSpecificationsBuilder() builder.BuildReferences(refData, referredRefData) builder.BuildContentsIec61360(iecData) specs := builder.Build()
func (*EmbeddedDataSpecificationsBuilder) BuildContentsIec61360 ¶
func (edsb *EmbeddedDataSpecificationsBuilder) BuildContentsIec61360(iecRows json.RawMessage) error
BuildContentsIec61360 processes IEC 61360 data specification content and populates the DataSpecificationContent field of each EmbeddedDataSpecification.
This method handles the complex IEC 61360 data specification format, which includes:
- Multi-language preferred names, short names, and definitions
- Unit references with hierarchical structures
- Data types, value formats, and values
- Optional value lists with reference pairs
- Optional level types for hierarchical concepts
Parameters:
- iecRows: JSON-encoded array of EdsContentIec61360Row objects containing IEC 61360 content data including language strings, references, value lists, and level types
Returns:
- error: An error if unmarshalling fails, data type conversion fails, language string parsing fails, reference building fails, or validation checks fail. Returns nil on success.
The method performs comprehensive processing:
- Unmarshals IEC 61360 content rows
- Creates placeholder entries for each specification
- For each IEC 61360 content: - Converts data type from string to enum - Parses multi-language strings (preferred name, short name, definition) - Builds unit ID references with hierarchy - Processes optional value lists with their references - Parses optional level type information
- Constructs DataSpecificationIec61360 objects
- Attaches optional value lists and level types using setter methods
Validation ensures:
- Exactly one unit ID reference per specification
- Exactly one reference per value list entry
Example:
builder := NewEmbeddedDataSpecificationsBuilder()
builder.BuildReferences(refJSON, referredRefJSON)
err := builder.BuildContentsIec61360(iecJSON)
if err != nil {
log.Printf("Failed to build IEC 61360 content: %v", err)
}
func (*EmbeddedDataSpecificationsBuilder) BuildReferences ¶
func (edsb *EmbeddedDataSpecificationsBuilder) BuildReferences(edsReferenceRows json.RawMessage, edsReferredReferenceRows json.RawMessage) error
BuildReferences processes reference data for embedded data specifications and constructs complete Reference objects with their hierarchical ReferredSemanticID structures.
This method handles the DataSpecification field of EmbeddedDataSpecification objects, which points to the semantic definition of the data specification. It processes both direct references and referred references (nested references), building the complete reference hierarchy.
Parameters:
- edsReferenceRows: JSON-encoded array of EdsReferenceRow objects containing reference and key data from the database
- edsReferredReferenceRows: JSON-encoded array of ReferredReferenceRow objects containing hierarchical referred reference data
Returns:
- error: An error if unmarshalling fails, reference parsing fails, or if an embedded data specification doesn't have exactly one reference. Returns nil on success.
The method performs the following steps:
- Unmarshals the reference row data
- Creates placeholder EmbeddedDataSpecification entries for each unique EDS ID
- Converts EdsReferenceRow objects to ReferenceRow format for processing
- Parses references using ReferenceBuilder for each specification
- Processes referred references to build hierarchical structures
- Finalizes the nested reference structures
Example:
builder := NewEmbeddedDataSpecificationsBuilder()
err := builder.BuildReferences(refJSON, referredRefJSON)
if err != nil {
log.Printf("Failed to build references: %v", err)
}
type ExtensionsBuilder ¶
type ExtensionsBuilder struct {
// contains filtered or unexported fields
}
ExtensionsBuilder constructs Extension objects with their associated references (SemanticID, SupplementalSemanticIds, RefersTo) from flattened database rows. It handles the complexity of building extensions with nested reference structures where references can contain ReferredSemanticIds.
The builder tracks database IDs to avoid duplicate entries and maintains a map of ReferenceBuilders to construct the hierarchical reference trees associated with each extension.
func NewExtensionsBuilder ¶
func NewExtensionsBuilder() *ExtensionsBuilder
NewExtensionsBuilder creates a new ExtensionsBuilder instance with initialized maps for tracking extensions and reference builders.
Returns:
- *ExtensionsBuilder: A pointer to the newly created builder instance
Example:
builder := NewExtensionsBuilder() builder.AddExtension(1, "CustomProperty", "xs:string", "customValue")
func (*ExtensionsBuilder) AddExtension ¶
func (b *ExtensionsBuilder) AddExtension(extensionDbID int64, name string, valueType string, value string, position int) (*ExtensionsBuilder, error)
AddExtension creates a new Extension with the specified properties and adds it to the builder. Extensions provide additional information or custom data that extends the standard AAS metamodel. Duplicate extensions (based on database ID) are automatically skipped with a warning message.
Parameters:
- extensionDbID: The database ID of the extension for tracking and duplicate detection
- name: The name of the extension that identifies its purpose or type
- valueType: The data type of the extension value (e.g., "xs:string", "xs:boolean", "xs:int")
- value: The actual value of the extension as a string
Returns:
- *ExtensionsBuilder: Returns the builder instance for method chaining
- error: Returns an error if the value type cannot be parsed, nil otherwise
The method validates that the valueType is valid according to the XSD data type definitions before creating the extension. If parsing fails, detailed error information is printed to the console.
Example:
builder := NewExtensionsBuilder() builder.AddExtension(1, "CustomProperty", "xs:string", "customValue") builder.AddExtension(2, "IsActive", "xs:boolean", "true")
func (*ExtensionsBuilder) AddRefersTo ¶
func (b *ExtensionsBuilder) AddRefersTo(extensionDbID int64, refersToRows json.RawMessage, refersToReferredRows json.RawMessage) (*ExtensionsBuilder, error)
AddRefersTo adds RefersTo references to an extension. RefersTo references specify other elements that this extension relates to or references, establishing relationships between the extension and other AAS elements.
Parameters:
- extensionDbID: The database ID of the extension to add the RefersTo references to
- refersToRows: JSON-encoded array of ReferenceRow objects representing the RefersTo references
- refersToReferredRows: JSON-encoded array of ReferredReferenceRow objects representing nested ReferredSemanticIds within the RefersTo references
Returns:
- *ExtensionsBuilder: Returns the builder instance for method chaining
- error: Returns an error if the extension doesn't exist or if parsing fails, nil otherwise
This method accepts multiple references (zero or more) as an extension can refer to multiple other elements.
Example:
builder.AddRefersTo(1, refersToJSON, referredReferencesJSON)
func (*ExtensionsBuilder) AddSemanticID ¶
func (b *ExtensionsBuilder) AddSemanticID(extensionDbID int64, semanticIDRows json.RawMessage, semanticIDReferredSemanticIDRows json.RawMessage) (*ExtensionsBuilder, error)
AddSemanticID adds a SemanticID reference to an extension. The SemanticID provides semantic meaning to the extension, linking it to a concept definition. This method expects exactly one reference and will return an error if zero or multiple references are provided.
Parameters:
- extensionDbID: The database ID of the extension to add the SemanticID to
- semanticIdRows: JSON-encoded array of ReferenceRow objects representing the SemanticId
- semanticIdReferredSemanticIdRows: JSON-encoded array of ReferredReferenceRow objects representing nested ReferredSemanticIds within the SemanticId
Returns:
- *ExtensionsBuilder: Returns the builder instance for method chaining
- error: Returns an error if the extension doesn't exist, if parsing fails, or if the number of references is not exactly one
Example:
builder.AddSemanticID(1, semanticIdJSON, referredSemanticIdJSON)
func (*ExtensionsBuilder) AddSupplementalSemanticIDs ¶
func (b *ExtensionsBuilder) AddSupplementalSemanticIDs(extensionDbID int64, supplementalSemanticIDsRows json.RawMessage, supplementalSemanticIDsReferredSemanticIDRows json.RawMessage) (*ExtensionsBuilder, error)
AddSupplementalSemanticIDs adds supplemental semantic IDs to an extension. Supplemental semantic IDs provide additional semantic context beyond the primary SemanticID, allowing multiple semantic interpretations or classifications to be associated with an extension.
Parameters:
- extensionDbID: The database ID of the extension to add the supplemental semantic IDs to
- supplementalSemanticIdsRows: JSON-encoded array of ReferenceRow objects representing the supplemental semantic ID references
- supplementalSemanticIdsReferredSemanticIdRows: JSON-encoded array of ReferredReferenceRow objects representing nested ReferredSemanticIds within the supplemental semantic IDs
Returns:
- *ExtensionsBuilder: Returns the builder instance for method chaining
- error: Returns an error if the extension doesn't exist or if parsing fails, nil otherwise
Unlike AddSemanticID, this method accepts multiple references (zero or more) as supplemental semantic IDs are inherently a collection.
Example:
builder.AddSupplementalSemanticIDs(1, supplementalSemanticIdsJSON, referredSemanticIdsJSON)
func (*ExtensionsBuilder) Build ¶
func (b *ExtensionsBuilder) Build() []types.IExtension
Build finalizes the construction of all extensions and their associated references. This method must be called after all extensions and their references have been added through the Add* methods.
The method performs the following operations:
- Calls BuildNestedStructure() on all ReferenceBuilders to construct the hierarchical ReferredSemanticID trees within each reference
- Collects all extensions from the internal map into a slice for return
Returns:
- []types.IExtension: A slice containing all constructed extensions with their complete reference hierarchies
Example:
builder := NewExtensionsBuilder() builder.AddExtension(1, "CustomProperty", "xs:string", "value") builder.AddSemanticID(1, semanticIdJSON, referredJSON) extensions := builder.Build()
type QualifiersBuilder ¶
type QualifiersBuilder struct {
// contains filtered or unexported fields
}
QualifiersBuilder constructs Qualifier objects with their associated references (SemanticID, ValueID, SupplementalSemanticIds) from flattened database rows. It handles the complexity of building qualifiers with nested reference structures where references can contain ReferredSemanticIds.
The builder tracks database IDs to avoid duplicate entries and maintains a map of ReferenceBuilders to construct the hierarchical reference trees associated with each qualifier.
func NewQualifiersBuilder ¶
func NewQualifiersBuilder() *QualifiersBuilder
NewQualifiersBuilder creates a new QualifiersBuilder instance with initialized maps for tracking qualifiers and reference builders.
Returns:
- *QualifiersBuilder: A pointer to the newly created builder instance
Example:
builder := NewQualifiersBuilder() builder.AddQualifier(1, "ConceptQualifier", "ExpressionSemantic", "xs:string", "example value")
func (*QualifiersBuilder) AddQualifier ¶
func (b *QualifiersBuilder) AddQualifier(qualifierDbID int64, qType string, valueType int64, value string, position int, kind *int64) (*QualifiersBuilder, error)
AddQualifier creates a new Qualifier with the specified properties and adds it to the builder. Qualifiers provide additional information about other AAS elements and can restrict their values or semantics. Duplicate qualifiers (based on database ID) are automatically skipped with a warning message.
Parameters:
- qualifierDbID: The database ID of the qualifier for tracking and duplicate detection
- kind: The kind of qualifier (e.g., "ConceptQualifier", "ValueQualifier", "TemplateQualifier")
- qType: The type that qualifies the qualifier itself (semantic identifier)
- valueType: The data type of the qualifier value (e.g., "xs:string", "xs:boolean", "xs:int")
- value: The actual value of the qualifier as a string
Returns:
- *QualifiersBuilder: Returns the builder instance for method chaining
- error: Returns an error if the qualifier kind or value type cannot be parsed, nil otherwise
The method validates that the kind and valueType are valid according to the AAS metamodel before creating the qualifier. If parsing fails, detailed error information is printed to the console.
Example:
builder := NewQualifiersBuilder() builder.AddQualifier(1, "ConceptQualifier", "ExpressionSemantic", "xs:string", "example value") builder.AddQualifier(2, "ValueQualifier", "ExpressionLogic", "xs:boolean", "true")
func (*QualifiersBuilder) AddSemanticID ¶
func (b *QualifiersBuilder) AddSemanticID(qualifierDbID int64, semanticIDRows json.RawMessage, semanticIDReferredSemanticIDRows json.RawMessage) (*QualifiersBuilder, error)
AddSemanticID adds a SemanticID reference to a qualifier. This method expects exactly one reference and will return an error if zero or multiple references are provided.
Parameters:
- qualifierDbID: The database ID of the qualifier to add the SemanticID to
- semanticIdRows: JSON-encoded array of ReferenceRow objects representing the SemanticId
- semanticIdReferredSemanticIdRows: JSON-encoded array of ReferredReferenceRow objects representing nested ReferredSemanticIds within the SemanticId
Returns:
- *QualifiersBuilder: Returns the builder instance for method chaining
- error: Returns an error if the qualifier doesn't exist, if parsing fails, or if the number of references is not exactly one
The method uses the internal createExactlyOneReference helper to ensure exactly one reference is created from the provided rows. It also processes any nested ReferredSemanticIds to build the complete reference hierarchy.
Example:
builder.AddSemanticID(1, semanticIdJSON, referredSemanticIdJSON)
func (*QualifiersBuilder) AddSupplementalSemanticIDs ¶
func (b *QualifiersBuilder) AddSupplementalSemanticIDs(qualifierDbID int64, supplementalSemanticIDsRows json.RawMessage, supplementalSemanticIDsReferredSemanticIDRows json.RawMessage) (*QualifiersBuilder, error)
AddSupplementalSemanticIDs adds supplemental semantic IDs to a qualifier. Supplemental semantic IDs provide additional semantic context beyond the primary SemanticID, allowing multiple semantic interpretations or classifications to be associated with a qualifier.
Parameters:
- qualifierDbID: The database ID of the qualifier to add the supplemental semantic IDs to
- supplementalSemanticIdsRows: JSON-encoded array of ReferenceRow objects representing the supplemental semantic ID references
- supplementalSemanticIdsReferredSemanticIdRows: JSON-encoded array of ReferredReferenceRow objects representing nested ReferredSemanticIds within the supplemental semantic IDs
Returns:
- *QualifiersBuilder: Returns the builder instance for method chaining
- error: Returns an error if the qualifier doesn't exist or if parsing fails, nil otherwise
Unlike AddSemanticID and AddValueID, this method accepts multiple references (zero or more) as supplemental semantic IDs are inherently a collection. Each reference can have its own nested ReferredSemanticID hierarchy.
Example:
builder.AddSupplementalSemanticIDs(1, supplementalSemanticIdsJSON, referredSemanticIdsJSON)
func (*QualifiersBuilder) AddValueID ¶
func (b *QualifiersBuilder) AddValueID(qualifierDbID int64, valueIDRows json.RawMessage, valueIDReferredSemanticIDRows json.RawMessage) (*QualifiersBuilder, error)
AddValueID adds a ValueID reference to a qualifier. The ValueID references the value of the qualifier in a global, unique way, allowing the qualifier's value to be semantically interpreted across different contexts. This method expects exactly one reference and will return an error if zero or multiple references are provided.
Parameters:
- qualifierDbID: The database ID of the qualifier to add the ValueID to
- valueIdRows: JSON-encoded array of ReferenceRow objects representing the ValueId
- valueIdReferredSemanticIdRows: JSON-encoded array of ReferredReferenceRow objects representing nested ReferredSemanticIds within the ValueId
Returns:
- *QualifiersBuilder: Returns the builder instance for method chaining
- error: Returns an error if the qualifier doesn't exist, if parsing fails, or if the number of references is not exactly one
The method uses the internal createExactlyOneReference helper to ensure exactly one reference is created from the provided rows. It also processes any nested ReferredSemanticIds to build the complete reference hierarchy.
Example:
builder.AddValueID(1, valueIdJSON, referredSemanticIdJSON)
func (*QualifiersBuilder) Build ¶
func (b *QualifiersBuilder) Build() []types.IQualifier
Build finalizes the construction of all qualifiers and their associated references. This method must be called after all qualifiers and their references have been added through the Add* methods. It performs the following operations:
- Calls BuildNestedStructure() on all ReferenceBuilders to construct the hierarchical ReferredSemanticID trees within each reference
- Collects all qualifiers from the internal map into a slice for return
Returns:
- []gen.Qualifier: A slice containing all constructed qualifiers with their complete reference hierarchies
After calling Build(), the builder can be discarded as all data has been extracted and properly structured. The returned qualifiers contain fully constructed references with nested ReferredSemanticIds where applicable.
Typical usage pattern:
// 1. Create the builder builder := NewQualifiersBuilder() // 2. Add qualifiers and their references (typically in a loop over database rows) builder.AddQualifier(1, "ConceptQualifier", "ExpressionSemantic", "xs:string", "example") builder.AddSemanticID(1, semanticIdRows, referredSemanticIdRows) builder.AddValueID(1, valueIdRows, referredValueIdRows) builder.AddSupplementalSemanticIds(1, supplSemanticIdsRows, supplReferredRows) builder.AddQualifier(2, "ValueQualifier", "ExpressionLogic", "xs:boolean", "true") builder.AddValueID(2, valueIdRows2, referredValueIdRows2) // 3. Build and retrieve the final qualifiers qualifiers := builder.Build() // Now 'qualifiers' contains all qualifiers with complete reference hierarchies
type ReferenceBuilder ¶
type ReferenceBuilder struct {
// contains filtered or unexported fields
}
ReferenceBuilder constructs Reference objects with nested ReferredSemanticID structures from flattened database rows. It handles the complexity of building hierarchical reference trees where references can contain other references as ReferredSemanticIds.
The builder tracks database IDs to avoid duplicate entries and maintains relationships between parent and child references in the hierarchy.
func NewReferenceBuilder ¶
func NewReferenceBuilder(referenceType types.ReferenceTypes, dbID int64) (types.IReference, *ReferenceBuilder)
NewReferenceBuilder creates a new ReferenceBuilder instance and initializes a Reference object with the specified type and database ID.
Parameters:
- referenceType: The type of reference (e.g., "ExternalReference", "ModelReference")
- dbID: The database ID of the reference for tracking and hierarchy building
Returns:
- *gen.Reference: A pointer to the newly created Reference object
- *ReferenceBuilder: A pointer to the builder for constructing the reference
Example:
ref, builder := NewReferenceBuilder("ExternalReference", 123)
builder.CreateKey(1, "GlobalReference", "https://example.com/concept")
func (*ReferenceBuilder) BuildNestedStructure ¶
func (rb *ReferenceBuilder) BuildNestedStructure()
BuildNestedStructure constructs the hierarchical tree of ReferredSemanticIds by linking child references to their parent references. This method should be called after all references and keys have been added through CreateReferredSemanticID and CreateReferredSemanticIdKey.
The method iterates through all ReferredSemanticIds and assigns each one to its parent's ReferredSemanticID field, building the complete nested structure. References already attached to the root are skipped.
Typical usage pattern:
// 1. Create the builder
ref, builder := NewReferenceBuilder("ExternalReference", 123)
// 2. Add keys and ReferredSemanticIds (typically in a loop over database rows)
builder.CreateKey(1, "Submodel", "https://example.com/submodel")
builder.CreateReferredSemanticID(456, 123, "ModelReference")
builder.CreateReferredSemanticIdKey(456, 2, "ConceptDescription", "0173-1#01-ABC123#001")
builder.CreateReferredSemanticID(789, 456, "ExternalReference")
builder.CreateReferredSemanticIdKey(789, 3, "GlobalReference", "https://example.com/concept")
// 3. Build the nested structure
builder.BuildNestedStructure()
// Now 'ref' contains the complete nested hierarchy
func (*ReferenceBuilder) CreateKey ¶
func (rb *ReferenceBuilder) CreateKey(keyID int64, keyType types.KeyTypes, keyValue string)
CreateKey adds a new key to the root reference. Keys are the building blocks of a reference and define the path to the referenced element. Duplicate keys (based on database ID) are automatically skipped to prevent duplication when processing multiple database rows.
Parameters:
- key_id: The database ID of the key for duplicate detection
- key_type: The type of key (e.g., "Submodel", "GlobalReference", "ConceptDescription")
- key_value: The value of the key (e.g., a URL or identifier)
Example:
builder.CreateKey(1, "Submodel", "https://example.com/submodel/123") builder.CreateKey(2, "SubmodelElementCollection", "MyCollection")
func (*ReferenceBuilder) CreateReferredSemanticID ¶
func (rb *ReferenceBuilder) CreateReferredSemanticID(referredSemanticIDDbID int64, parentID int64, referenceType types.ReferenceTypes) *ReferenceBuilder
CreateReferredSemanticID creates a new ReferredSemanticID reference within the hierarchy. ReferredSemanticIds can be nested, forming a tree structure where each reference can have its own ReferredSemanticId. This method handles creating new references and tracking their position in the hierarchy.
Parameters:
- referredSemanticIdDbID: The database ID of the ReferredSemanticID reference
- parentID: The database ID of the parent reference in the hierarchy
- referenceType: The type of the ReferredSemanticID reference
Returns:
- *ReferenceBuilder: Returns the builder instance for method chaining
If the parentID matches the root reference's database ID, the ReferredSemanticID is immediately attached to the root reference. Otherwise, it's stored for later attachment during the BuildNestedStructure phase.
Example:
// Create a ReferredSemanticID directly under the root reference builder.CreateReferredSemanticID(456, 123, "ExternalReference") // Create a nested ReferredSemanticID under another ReferredSemanticId builder.CreateReferredSemanticID(789, 456, "ModelReference")
func (*ReferenceBuilder) CreateReferredSemanticIDKey ¶
func (rb *ReferenceBuilder) CreateReferredSemanticIDKey(referredSemanticIDDbID int64, keyID int64, keyType types.KeyTypes, keyValue string) error
CreateReferredSemanticIDKey adds a key to a specific ReferredSemanticID reference in the hierarchy. This method delegates to the appropriate builder for the target reference.
Parameters:
- referredSemanticIdDbID: The database ID of the ReferredSemanticID to add the key to
- key_id: The database ID of the key for duplicate detection
- key_type: The type of key (e.g., "ConceptDescription", "GlobalReference")
- key_value: The value of the key
Returns:
- error: Returns an error if the ReferredSemanticID builder cannot be found, nil otherwise
This method must be called after CreateReferredSemanticID has been called for the corresponding referredSemanticIdDbID, otherwise it will return an error.
Example:
builder.CreateReferredSemanticID(456, 123, "ExternalReference")
err := builder.CreateReferredSemanticIDKey(456, 1, "GlobalReference", "https://example.com")
if err != nil {
// Handle error
}
func (*ReferenceBuilder) SetReferredSemanticID ¶
func (rb *ReferenceBuilder) SetReferredSemanticID(referredSemanticID types.IReference)
SetReferredSemanticID directly assigns a ReferredSemanticID to the root reference. This is used when the referred semantic ID is already constructed and needs to be attached to the reference.
Parameters:
- referredSemanticID: A pointer to the Reference that should be set as the ReferredSemanticId
Note: This method is typically used after the referred semantic ID has been fully constructed with all its keys and nested structure.
type ReferenceMetadata ¶
type ReferenceMetadata struct {
// contains filtered or unexported fields
}
ReferenceMetadata holds metadata about a reference in the hierarchy, including its parent reference database ID and the reference object itself.
type SimpleToken ¶
type SimpleToken struct {
Name string
}
SimpleToken represents a plain, non-array field name such as "id" or "submodel".
func (SimpleToken) GetName ¶
func (sp SimpleToken) GetName() string
GetName returns the name of the simple token.
type SubmodelElementBuilder ¶
type SubmodelElementBuilder struct {
DatabaseID int
SubmodelElement types.ISubmodelElement
}
SubmodelElementBuilder encapsulates the database ID and the constructed SubmodelElement, providing a way to manage and build submodel elements from database rows.
func BuildSubmodelElement ¶
func BuildSubmodelElement(smeRow model.SubmodelElementRow, db *sql.DB) (types.ISubmodelElement, *SubmodelElementBuilder, error)
BuildSubmodelElement constructs a SubmodelElement from the provided database row. It parses the row data, builds the appropriate submodel element type, and sets common attributes like IDShort, Category, and ModelType. It also handles parallel parsing of related data such as semantic IDs, descriptions, and qualifiers. Returns the constructed SubmodelElement and a SubmodelElementBuilder for further management. nolint:revive // This method is already refactored and further changes would not improve readability.
type Token ¶
type Token interface {
// GetName returns the primary name of the token (field name or array name).
GetName() string
}
Token represents one part of a parsed field expression. Tokens correspond to segments split by '.' or array selectors such as "[0]".
func TokenizeField ¶
TokenizeField parses a field reference into a slice of Tokens.
The input must be a field path of the form:
#field.part[0].subpart
TokenizeField performs the following steps:
- Removes everything up to and including the first '#'.
- Splits the remaining expression on '.'.
- Converts each segment into either a SimpleToken (no brackets) or an ArrayToken (contains "[index]"). An empty index ("[]") is interpreted as a wildcard and stored as -1.
Example:
input: "$aasdesc#submodels[2].id"
output: [ SimpleToken{"submodels"}, ArrayToken{"submodels", 2}, SimpleToken{"id"} ]