@@ -164,16 +164,21 @@ func (s *AssetAdministrationShellDatabase) appendAASHistoryTx(ctx context.Contex
164164 return history .AppendVersionTx (ctx , tx , history .TableAAS , aas .ID (), changeType , snapshot , deleted )
165165}
166166
167- func appendAASUpdatedHistoryByIdentifierTx (ctx context.Context , tx * sql.Tx , aasIdentifier string ) error {
168- return history .AppendVersionTx (
169- ctx ,
170- tx ,
171- history .TableAAS ,
172- aasIdentifier ,
173- history .ChangeUpdated ,
174- map [string ]any {"id" : aasIdentifier },
175- false ,
176- )
167+ func (s * AssetAdministrationShellDatabase ) appendAASUpdatedHistoryByIdentifierTx (ctx context.Context , tx * sql.Tx , aasIdentifier string ) error {
168+ aasDBID , err := persistenceutils .GetAssetAdministrationShellDatabaseID (tx , aasIdentifier )
169+ if err != nil {
170+ if errors .Is (err , sql .ErrNoRows ) {
171+ return common .NewErrNotFound ("AASREPO-HISTORYUPDATED-AASNOTFOUND Asset Administration Shell with ID '" + aasIdentifier + "' not found" )
172+ }
173+ return common .NewInternalServerError ("AASREPO-HISTORYUPDATED-GETAASDBID " + err .Error ())
174+ }
175+
176+ aas , err := s .getAssetAdministrationShellMapByDBIDFromDB (ctx , tx , int64 (aasDBID ))
177+ if err != nil {
178+ return err
179+ }
180+
181+ return s .appendAASHistoryTx (ctx , tx , aas , history .ChangeUpdated , false )
177182}
178183
179184// GetSignedAssetAdministrationShell returns a compact JWS for the requested AAS.
@@ -513,7 +518,7 @@ func (s *AssetAdministrationShellDatabase) createSubmodelReferenceInAssetAdminis
513518 return common .NewErrDenied ("AASREPO-NEWSMREFINAAS-ABACDENIED written AAS is not accessible under ABAC constraints" )
514519 }
515520 }
516- return appendAASUpdatedHistoryByIdentifierTx (ctx , tx , aasIdentifier )
521+ return s . appendAASUpdatedHistoryByIdentifierTx (ctx , tx , aasIdentifier )
517522}
518523
519524func (s * AssetAdministrationShellDatabase ) getNextSubmodelReferencePositionInTransaction (tx * sql.Tx , aasDBID int64 ) (int , error ) {
@@ -1081,7 +1086,7 @@ func (s *AssetAdministrationShellDatabase) PutAssetInformationByAASIDInTransacti
10811086 if err := s .ensureAASVisibleAfterAssetInformationUpdate (ctx , tx , aasIdentifier , shouldEnforce ); err != nil {
10821087 return err
10831088 }
1084- return appendAASUpdatedHistoryByIdentifierTx (ctx , tx , aasIdentifier )
1089+ return s . appendAASUpdatedHistoryByIdentifierTx (ctx , tx , aasIdentifier )
10851090}
10861091
10871092type currentAssetInformationState struct {
@@ -1322,7 +1327,7 @@ func (s *AssetAdministrationShellDatabase) PutThumbnailByAASID(ctx context.Conte
13221327 if uploadErr := thumbnailHandler .uploadThumbnailByAASIDInTransaction (tx , aasIdentifier , fileName , file ); uploadErr != nil {
13231328 return uploadErr
13241329 }
1325- if err := appendAASUpdatedHistoryByIdentifierTx (ctx , tx , aasIdentifier ); err != nil {
1330+ if err := s . appendAASUpdatedHistoryByIdentifierTx (ctx , tx , aasIdentifier ); err != nil {
13261331 return err
13271332 }
13281333
@@ -1367,7 +1372,7 @@ func (s *AssetAdministrationShellDatabase) DeleteThumbnailByAASID(ctx context.Co
13671372 if deleteErr := thumbnailHandler .deleteThumbnailByAASIDInTransaction (tx , aasIdentifier ); deleteErr != nil {
13681373 return deleteErr
13691374 }
1370- if err := appendAASUpdatedHistoryByIdentifierTx (ctx , tx , aasIdentifier ); err != nil {
1375+ if err := s . appendAASUpdatedHistoryByIdentifierTx (ctx , tx , aasIdentifier ); err != nil {
13711376 return err
13721377 }
13731378
@@ -1625,7 +1630,7 @@ func (s *AssetAdministrationShellDatabase) deleteSubmodelReferenceInAssetAdminis
16251630 if err := s .deleteSubmodelReferenceInAssetAdministrationShellInTransaction (tx , aasIdentifier , submodelIdentifier ); err != nil {
16261631 return err
16271632 }
1628- return appendAASUpdatedHistoryByIdentifierTx (ctx , tx , aasIdentifier )
1633+ return s . appendAASUpdatedHistoryByIdentifierTx (ctx , tx , aasIdentifier )
16291634}
16301635
16311636// deleteSubmodelReferenceInAssetAdministrationShellInTransaction removes a submodel reference within an existing transaction.
@@ -1684,6 +1689,10 @@ type coreAssetAdministrationShellRow struct {
16841689// nolint:revive // cyclomatic complexity of 32
16851690// getAssetAdministrationShellMapByDBID loads an AAS and maps it to a typed model.
16861691func (s * AssetAdministrationShellDatabase ) getAssetAdministrationShellMapByDBID (ctx context.Context , aasDBID int64 ) (types.IAssetAdministrationShell , error ) {
1692+ return s .getAssetAdministrationShellMapByDBIDFromDB (ctx , s .db , aasDBID )
1693+ }
1694+
1695+ func (s * AssetAdministrationShellDatabase ) getAssetAdministrationShellMapByDBIDFromDB (ctx context.Context , db descriptors.DBQueryer , aasDBID int64 ) (types.IAssetAdministrationShell , error ) {
16871696 dialect := goqu .Dialect ("postgres" )
16881697 querySQL , queryArgs , buildErr := buildGetAssetAdministrationShellMapByDBIDQuery (& dialect , aasDBID )
16891698 if buildErr != nil {
@@ -1692,7 +1701,7 @@ func (s *AssetAdministrationShellDatabase) getAssetAdministrationShellMapByDBID(
16921701
16931702 var row coreAssetAdministrationShellRow
16941703
1695- if queryErr := s . db .QueryRow ( querySQL , queryArgs ... ).Scan (
1704+ if queryErr := db .QueryRowContext ( ctx , querySQL , queryArgs ... ).Scan (
16961705 & row .aasID ,
16971706 & row .idShort ,
16981707 & row .category ,
@@ -1714,12 +1723,12 @@ func (s *AssetAdministrationShellDatabase) getAssetAdministrationShellMapByDBID(
17141723 return nil , common .NewInternalServerError ("AASREPO-MAPAAS-EXECSQL " + queryErr .Error ())
17151724 }
17161725
1717- specificAssetIDs , specificErr := s .readSpecificAssetIDsByAssetInformationID (ctx , aasDBID )
1726+ specificAssetIDs , specificErr := s .readSpecificAssetIDsByAssetInformationIDFromDB (ctx , db , aasDBID )
17181727 if specificErr != nil {
17191728 return nil , common .NewInternalServerError ("AASREPO-MAPAAS-READSPECIFICASSETIDS " + specificErr .Error ())
17201729 }
17211730
1722- submodelsByAASID , submodelErr := s .readSubmodelReferencePayloadsByAASDBIDs (ctx , []int64 {aasDBID })
1731+ submodelsByAASID , submodelErr := s .readSubmodelReferencePayloadsByAASDBIDsFromDB (ctx , db , []int64 {aasDBID })
17231732 if submodelErr != nil {
17241733 return nil , submodelErr
17251734 }
@@ -1809,6 +1818,10 @@ func (s *AssetAdministrationShellDatabase) getAssetAdministrationShellMapsByDBID
18091818}
18101819
18111820func (s * AssetAdministrationShellDatabase ) readSubmodelReferencePayloadsByAASDBIDs (ctx context.Context , aasDBIDs []int64 ) (map [int64 ][]types.IReference , error ) {
1821+ return s .readSubmodelReferencePayloadsByAASDBIDsFromDB (ctx , s .db , aasDBIDs )
1822+ }
1823+
1824+ func (s * AssetAdministrationShellDatabase ) readSubmodelReferencePayloadsByAASDBIDsFromDB (ctx context.Context , db descriptors.DBQueryer , aasDBIDs []int64 ) (map [int64 ][]types.IReference , error ) {
18121825 out := make (map [int64 ][]types.IReference , len (aasDBIDs ))
18131826 if len (aasDBIDs ) == 0 {
18141827 return out , nil
@@ -1820,7 +1833,7 @@ func (s *AssetAdministrationShellDatabase) readSubmodelReferencePayloadsByAASDBI
18201833 return nil , common .NewInternalServerError ("AASREPO-READSMREFBATCH-BUILDSQL " + submodelBuildErr .Error ())
18211834 }
18221835
1823- rows , submodelQueryErr := s . db .QueryContext (ctx , submodelSQL , submodelArgs ... )
1836+ rows , submodelQueryErr := db .QueryContext (ctx , submodelSQL , submodelArgs ... )
18241837 if submodelQueryErr != nil {
18251838 return nil , common .NewInternalServerError ("AASREPO-READSMREFBATCH-EXECSQL " + submodelQueryErr .Error ())
18261839 }
@@ -2137,15 +2150,14 @@ func parseSpecificAssetIDSemanticIDPayload(payload []byte) (types.IReference, bo
21372150 return parsedReference , true , nil
21382151}
21392152
2140- // readSpecificAssetIDsByAssetInformationID reads and enriches specificAssetIds for an assetInformation record.
2141- func (s * AssetAdministrationShellDatabase ) readSpecificAssetIDsByAssetInformationID (ctx context.Context , assetInformationID int64 ) ([]types.ISpecificAssetID , error ) {
2153+ func (s * AssetAdministrationShellDatabase ) readSpecificAssetIDsByAssetInformationIDFromDB (ctx context.Context , db descriptors.DBQueryer , assetInformationID int64 ) ([]types.ISpecificAssetID , error ) {
21422154 dialect := goqu .Dialect ("postgres" )
21432155 querySQL , queryArgs , buildErr := buildReadSpecificAssetIDsByAssetInformationIDQuery (& dialect , assetInformationID )
21442156 if buildErr != nil {
21452157 return nil , common .NewInternalServerError ("AASREPO-READSPECIFIC-BUILDSQL " + buildErr .Error ())
21462158 }
21472159
2148- rows , queryErr := s . db .QueryContext (ctx , querySQL , queryArgs ... )
2160+ rows , queryErr := db .QueryContext (ctx , querySQL , queryArgs ... )
21492161 if queryErr != nil {
21502162 return nil , common .NewInternalServerError ("AASREPO-READSPECIFIC-EXECSQL " + queryErr .Error ())
21512163 }
@@ -2178,12 +2190,12 @@ func (s *AssetAdministrationShellDatabase) readSpecificAssetIDsByAssetInformatio
21782190 return []types.ISpecificAssetID {}, nil
21792191 }
21802192
2181- externalSubjectByID , extErr := descriptors .ReadSpecificAssetExternalSubjectReferencesBySpecificAssetIDs (ctx , s . db , ids )
2193+ externalSubjectByID , extErr := descriptors .ReadSpecificAssetExternalSubjectReferencesBySpecificAssetIDs (ctx , db , ids )
21822194 if extErr != nil {
21832195 return nil , extErr
21842196 }
21852197
2186- supplementalByID , suppErr := descriptors .ReadSpecificAssetSupplementalSemanticReferencesBySpecificAssetIDs (ctx , s . db , ids )
2198+ supplementalByID , suppErr := descriptors .ReadSpecificAssetSupplementalSemanticReferencesBySpecificAssetIDs (ctx , db , ids )
21872199 if suppErr != nil {
21882200 return nil , suppErr
21892201 }
0 commit comments