@@ -2279,15 +2279,17 @@ public void exportData(Function<Entity, Void> handler) throws RegistryStorageExc
2279
2279
2280
2280
// Export all branches
2281
2281
/////////////////////////////////
2282
- // TODO add the list of versions to the BranchEntity when exporting
2283
2282
handles .withHandle (handle -> {
2284
2283
Stream <BranchEntity > stream = handle .createQuery (sqlStatements .exportBranches ())
2285
2284
.setFetchSize (50 )
2286
2285
.map (BranchEntityMapper .instance )
2287
2286
.stream ();
2288
2287
// Process and then close the stream.
2289
2288
try (stream ) {
2290
- stream .forEach (handler ::apply );
2289
+ stream .forEach (branch -> {
2290
+ branch .versions = getBranchVersionNumbersRaw (handle , branch .toGA (), branch .toBranchId ());
2291
+ handler .apply (branch );
2292
+ });
2291
2293
}
2292
2294
return null ;
2293
2295
});
@@ -3426,6 +3428,15 @@ public BranchMetaDataDto getBranchMetaData(GA ga, BranchId branchId) {
3426
3428
});
3427
3429
}
3428
3430
3431
+ protected List <String > getBranchVersionNumbersRaw (Handle handle , GA ga , BranchId branchId ) {
3432
+ return handle .createQuery (sqlStatements .selectBranchVersionNumbers ())
3433
+ .bind (0 , ga .getRawGroupId ())
3434
+ .bind (1 , ga .getRawArtifactId ())
3435
+ .bind (2 , branchId .getRawBranchId ())
3436
+ .map (StringMapper .instance )
3437
+ .list ();
3438
+ }
3439
+
3429
3440
@ Override
3430
3441
public VersionSearchResultsDto getBranchVersions (GA ga , BranchId branchId , int offset , int limit ) {
3431
3442
return handles .withHandleNoException (handle -> {
@@ -3755,24 +3766,35 @@ public void deleteBranch(GA ga, BranchId branchId) {
3755
3766
@ Override
3756
3767
@ Transactional
3757
3768
public void importBranch (BranchEntity entity ) {
3758
- // var gav = entity.toGAV();
3759
- // var branchId = entity.toBranchId();
3760
- // handles.withHandleNoException(handle -> {
3761
- // try {
3762
- // handle.createUpdate(sqlStatements.importBranch())
3763
- // .bind(0, gav.getRawGroupId())
3764
- // .bind(1, gav.getRawArtifactId())
3765
- // .bind(2, branchId.getRawBranchId())
3766
- // .bind(3, entity.branchOrder)
3767
- // .bind(4, gav.getRawVersionId())
3768
- // .execute();
3769
- // } catch (Exception ex) {
3770
- // if (sqlStatements.isForeignKeyViolation(ex)) {
3771
- // throw new VersionNotFoundException(gav, ex);
3772
- // }
3773
- // throw ex;
3774
- // }
3775
- // });
3769
+ var ga = entity .toGA ();
3770
+ var branchId = entity .toBranchId ();
3771
+ handles .withHandleNoException (handle -> {
3772
+ try {
3773
+ handle .createUpdate (sqlStatements .insertBranch ())
3774
+ .bind (0 , ga .getRawGroupId ())
3775
+ .bind (1 , ga .getRawArtifactId ())
3776
+ .bind (2 , branchId .getRawBranchId ())
3777
+ .bind (3 , entity .description )
3778
+ .bind (4 , entity .userDefined )
3779
+ .bind (5 , entity .owner )
3780
+ .bind (6 , entity .createdOn )
3781
+ .bind (7 , entity .modifiedBy )
3782
+ .bind (8 , entity .modifiedOn )
3783
+ .execute ();
3784
+ } catch (Exception ex ) {
3785
+ if (sqlStatements .isForeignKeyViolation (ex )) {
3786
+ throw new ArtifactNotFoundException (ga .getRawGroupIdWithDefaultString (), ga .getRawArtifactId ());
3787
+ }
3788
+ throw ex ;
3789
+ }
3790
+
3791
+ // Append each of the versions onto the branch
3792
+ if (entity .versions != null ) {
3793
+ entity .versions .forEach (version -> {
3794
+ appendVersionToBranchRaw (handle , ga , branchId , new VersionId (version ));
3795
+ });
3796
+ }
3797
+ });
3776
3798
}
3777
3799
3778
3800
@ Override
0 commit comments