@@ -12,8 +12,12 @@ import {
1212 Router ,
1313} from '@angular/router' ;
1414import { RestRequestMethod } from '@dspace/config/rest-request-method' ;
15+ import { LinkService } from '@dspace/core/cache/builders/link.service' ;
1516import { NotificationsService } from '@dspace/core/notification-system/notifications.service' ;
1617import { getBitstreamModuleRoute } from '@dspace/core/router/core-routing-paths' ;
18+ import { Bundle } from '@dspace/core/shared/bundle.model' ;
19+ import { followLink } from '@dspace/core/shared/follow-link-config.model' ;
20+ import { Item } from '@dspace/core/shared/item.model' ;
1721import {
1822 hasValue ,
1923 isEmpty ,
@@ -91,12 +95,6 @@ export class ReplaceBitstreamPageComponent implements OnInit {
9195 */
9296 private uploadFilesUrlNoParam : string ;
9397
94- /**
95- * The bundle's self link, resolved from the route-resolved bitstream for cache invalidation.
96- * This is the bundle's own URL (e.g. bundles/{uuid}), not the bitstream-to-bundle link.
97- */
98- private bundleSelfLink : string ;
99-
10098 /**
10199 * The bitstream's remote data observable
102100 * Tracks changes and updates the view
@@ -108,19 +106,21 @@ export class ReplaceBitstreamPageComponent implements OnInit {
108106 */
109107 protected shouldReplaceName = true ;
110108
111- constructor ( private route : ActivatedRoute ,
112- private notificationService : NotificationsService ,
113- private location : Location ,
114- private translateService : TranslateService ,
115- private authService : AuthService ,
116- private requestService : RequestService ,
117- private router : Router ) {
109+ constructor (
110+ private route : ActivatedRoute ,
111+ private notificationService : NotificationsService ,
112+ private location : Location ,
113+ private translateService : TranslateService ,
114+ private authService : AuthService ,
115+ private requestService : RequestService ,
116+ private router : Router ,
117+ private linkService : LinkService ,
118+ ) {
118119 }
119120
120121 ngOnInit ( ) : void {
121122 this . bitstreamRD$ = this . route . data . pipe ( map ( ( data ) => data . bitstream ) ) ;
122123 this . setUploadUrl ( ) ;
123- this . resolveBundleLink ( ) ;
124124 }
125125
126126 back ( ) {
@@ -137,10 +137,11 @@ export class ReplaceBitstreamPageComponent implements OnInit {
137137 * @param bitstream
138138 */
139139 public onCompleteItem ( bitstream : Bitstream ) {
140- this . requestService . setStaleByHrefSubstring ( bitstream . self ) ;
141- this . requestService . setStaleByHrefSubstring ( this . bundleSelfLink ) ;
140+ this . invalidate ( bitstream ) ;
142141 this . notificationService . success ( this . translateService . instant ( this . saveNotificationKey ) ) ;
143- this . router . navigate ( [ getBitstreamModuleRoute ( ) , bitstream . id , 'edit' ] ) ;
142+ this . router . navigate ( [ getBitstreamModuleRoute ( ) , bitstream . id , 'edit' ] , {
143+ replaceUrl : true ,
144+ } ) ;
144145 }
145146
146147 /**
@@ -167,17 +168,25 @@ export class ReplaceBitstreamPageComponent implements OnInit {
167168 }
168169
169170 /**
170- * Resolve the bundle from the route-resolved bitstream to store its self URL.
171- * The bundle's self URL (bundles/{uuid}) is needed for cache invalidation because it is a
172- * substring of the bundle's bitstreams list endpoint (bundles/{uuid}/bitstreams).
171+ * Invalidate the old Bitstream that has been replaced (and thus deleted), as well as our owning Bundle and Item
173172 */
174- private resolveBundleLink ( ) {
175- this . bitstreamRD$ . pipe (
173+ private invalidate ( newBitstream : Bitstream ) {
174+ console . log ( newBitstream ) ; // todo: remove this
175+ // the Bitstream returned after upload is not an instance of Bitstream yet
176+ newBitstream = Object . assign ( new Bitstream ( ) , newBitstream )
177+ this . linkService . resolveLink < Bitstream > ( newBitstream , followLink ( 'bundle' ) ) ;
178+ this . requestService . setStaleByHrefSubstring ( newBitstream . firstMetadata ( 'dspace.bitstream.isReplacementOf' ) ?. authority ) ;
179+
180+ newBitstream . bundle . pipe (
176181 getFirstSucceededRemoteDataPayload ( ) ,
177- switchMap ( ( bitstream : Bitstream ) => bitstream . bundle ) ,
182+ switchMap ( ( bundle : Bundle ) => {
183+ this . requestService . setStaleByHrefSubstring ( bundle . self ) ;
184+ this . linkService . resolveLink < Bundle > ( bundle , followLink ( 'item' ) ) ;
185+ return bundle . item ;
186+ } ) ,
178187 getFirstSucceededRemoteDataPayload ( ) ,
179- ) . subscribe ( ( bundle ) => {
180- this . bundleSelfLink = bundle . _links . self . href ;
188+ ) . subscribe ( ( item : Item ) => {
189+ this . requestService . setStaleByHrefSubstring ( item . self ) ;
181190 } ) ;
182191 }
183192
0 commit comments