@@ -3,13 +3,12 @@ import { ScriptDataService } from '../../../../core/data/processes/script-data.s
33import { ContentSource } from '../../../../core/shared/content-source.model' ;
44import { ProcessDataService } from '../../../../core/data/processes/process-data.service' ;
55import {
6- getAllCompletedRemoteData ,
76 getAllSucceededRemoteDataPayload ,
87 getFirstCompletedRemoteData ,
98 getFirstSucceededRemoteDataPayload
109} from '../../../../core/shared/operators' ;
1110import { filter , map , switchMap , tap } from 'rxjs/operators' ;
12- import { hasValue , hasValueOperator } from '../../../../shared/empty.util' ;
11+ import { hasValue } from '../../../../shared/empty.util' ;
1312import { ProcessStatus } from '../../../../process-page/processes/process-status.model' ;
1413import { BehaviorSubject , Observable , Subscription } from 'rxjs' ;
1514import { RequestService } from '../../../../core/data/request.service' ;
@@ -95,36 +94,25 @@ export class CollectionSourceControlsComponent implements OnDestroy {
9594 } ) ,
9695 // filter out responses that aren't successful since the pinging of the process only needs to happen when the invocation was successful.
9796 filter ( ( rd ) => rd . hasSucceeded && hasValue ( rd . payload ) ) ,
98- switchMap ( ( rd ) => this . processDataService . findById ( rd . payload . processId , false ) ) ,
99- getAllCompletedRemoteData ( ) ,
100- filter ( ( rd ) => ! rd . isStale && ( rd . hasSucceeded || rd . hasFailed ) ) ,
101- map ( ( rd ) => rd . payload ) ,
102- hasValueOperator ( ) ,
97+ switchMap ( ( rd ) => this . processDataService . autoRefreshUntilCompletion ( rd . payload . processId ) ) ,
98+ map ( ( rd ) => rd . payload )
10399 ) . subscribe ( ( process : Process ) => {
104- if ( process . processStatus . toString ( ) !== ProcessStatus [ ProcessStatus . COMPLETED ] . toString ( ) &&
105- process . processStatus . toString ( ) !== ProcessStatus [ ProcessStatus . FAILED ] . toString ( ) ) {
106- // Ping the current process state every 5s
107- setTimeout ( ( ) => {
108- this . requestService . setStaleByHrefSubstring ( process . _links . self . href ) ;
109- } , 5000 ) ;
110- }
111- if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . FAILED ] . toString ( ) ) {
112- this . notificationsService . error ( this . translateService . get ( 'collection.source.controls.test.failed' ) ) ;
113- this . testConfigRunning$ . next ( false ) ;
114- }
115- if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . COMPLETED ] . toString ( ) ) {
116- this . bitstreamService . findByHref ( process . _links . output . href ) . pipe ( getFirstSucceededRemoteDataPayload ( ) ) . subscribe ( ( bitstream ) => {
117- this . httpClient . get ( bitstream . _links . content . href , { responseType : 'text' } ) . subscribe ( ( data : any ) => {
118- const output = data . replaceAll ( new RegExp ( '.*\\@(.*)' , 'g' ) , '$1' )
119- . replaceAll ( 'The script has started' , '' )
120- . replaceAll ( 'The script has completed' , '' ) ;
121- this . notificationsService . info ( this . translateService . get ( 'collection.source.controls.test.completed' ) , output ) ;
122- } ) ;
100+ if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . FAILED ] . toString ( ) ) {
101+ this . notificationsService . error ( this . translateService . get ( 'collection.source.controls.test.failed' ) ) ;
102+ this . testConfigRunning$ . next ( false ) ;
103+ }
104+ if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . COMPLETED ] . toString ( ) ) {
105+ this . bitstreamService . findByHref ( process . _links . output . href ) . pipe ( getFirstSucceededRemoteDataPayload ( ) ) . subscribe ( ( bitstream ) => {
106+ this . httpClient . get ( bitstream . _links . content . href , { responseType : 'text' } ) . subscribe ( ( data : any ) => {
107+ const output = data . replaceAll ( new RegExp ( '.*\\@(.*)' , 'g' ) , '$1' )
108+ . replaceAll ( 'The script has started' , '' )
109+ . replaceAll ( 'The script has completed' , '' ) ;
110+ this . notificationsService . info ( this . translateService . get ( 'collection.source.controls.test.completed' ) , output ) ;
123111 } ) ;
124- this . testConfigRunning$ . next ( false ) ;
125- }
112+ } ) ;
113+ this . testConfigRunning$ . next ( false ) ;
126114 }
127- ) ) ;
115+ } ) ) ;
128116 }
129117
130118 /**
@@ -147,31 +135,19 @@ export class CollectionSourceControlsComponent implements OnDestroy {
147135 }
148136 } ) ,
149137 filter ( ( rd ) => rd . hasSucceeded && hasValue ( rd . payload ) ) ,
150- switchMap ( ( rd ) => this . processDataService . findById ( rd . payload . processId , false ) ) ,
151- getAllCompletedRemoteData ( ) ,
152- filter ( ( rd ) => ! rd . isStale && ( rd . hasSucceeded || rd . hasFailed ) ) ,
153- map ( ( rd ) => rd . payload ) ,
154- hasValueOperator ( ) ,
138+ switchMap ( ( rd ) => this . processDataService . autoRefreshUntilCompletion ( rd . payload . processId ) ) ,
139+ map ( ( rd ) => rd . payload )
155140 ) . subscribe ( ( process ) => {
156- if ( process . processStatus . toString ( ) !== ProcessStatus [ ProcessStatus . COMPLETED ] . toString ( ) &&
157- process . processStatus . toString ( ) !== ProcessStatus [ ProcessStatus . FAILED ] . toString ( ) ) {
158- // Ping the current process state every 5s
159- setTimeout ( ( ) => {
160- this . requestService . setStaleByHrefSubstring ( process . _links . self . href ) ;
161- this . requestService . setStaleByHrefSubstring ( this . collection . _links . self . href ) ;
162- } , 5000 ) ;
163- }
164- if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . FAILED ] . toString ( ) ) {
165- this . notificationsService . error ( this . translateService . get ( 'collection.source.controls.import.failed' ) ) ;
166- this . importRunning$ . next ( false ) ;
167- }
168- if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . COMPLETED ] . toString ( ) ) {
169- this . notificationsService . success ( this . translateService . get ( 'collection.source.controls.import.completed' ) ) ;
170- this . requestService . setStaleByHrefSubstring ( this . collection . _links . self . href ) ;
171- this . importRunning$ . next ( false ) ;
172- }
141+ if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . FAILED ] . toString ( ) ) {
142+ this . notificationsService . error ( this . translateService . get ( 'collection.source.controls.import.failed' ) ) ;
143+ this . importRunning$ . next ( false ) ;
144+ }
145+ if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . COMPLETED ] . toString ( ) ) {
146+ this . notificationsService . success ( this . translateService . get ( 'collection.source.controls.import.completed' ) ) ;
147+ this . requestService . setStaleByHrefSubstring ( this . collection . _links . self . href ) ;
148+ this . importRunning$ . next ( false ) ;
173149 }
174- ) ) ;
150+ } ) ) ;
175151 }
176152
177153 /**
@@ -194,31 +170,19 @@ export class CollectionSourceControlsComponent implements OnDestroy {
194170 }
195171 } ) ,
196172 filter ( ( rd ) => rd . hasSucceeded && hasValue ( rd . payload ) ) ,
197- switchMap ( ( rd ) => this . processDataService . findById ( rd . payload . processId , false ) ) ,
198- getAllCompletedRemoteData ( ) ,
199- filter ( ( rd ) => ! rd . isStale && ( rd . hasSucceeded || rd . hasFailed ) ) ,
200- map ( ( rd ) => rd . payload ) ,
201- hasValueOperator ( ) ,
173+ switchMap ( ( rd ) => this . processDataService . autoRefreshUntilCompletion ( rd . payload . processId ) ) ,
174+ map ( ( rd ) => rd . payload )
202175 ) . subscribe ( ( process ) => {
203- if ( process . processStatus . toString ( ) !== ProcessStatus [ ProcessStatus . COMPLETED ] . toString ( ) &&
204- process . processStatus . toString ( ) !== ProcessStatus [ ProcessStatus . FAILED ] . toString ( ) ) {
205- // Ping the current process state every 5s
206- setTimeout ( ( ) => {
207- this . requestService . setStaleByHrefSubstring ( process . _links . self . href ) ;
208- this . requestService . setStaleByHrefSubstring ( this . collection . _links . self . href ) ;
209- } , 5000 ) ;
210- }
211- if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . FAILED ] . toString ( ) ) {
212- this . notificationsService . error ( this . translateService . get ( 'collection.source.controls.reset.failed' ) ) ;
213- this . reImportRunning$ . next ( false ) ;
214- }
215- if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . COMPLETED ] . toString ( ) ) {
216- this . notificationsService . success ( this . translateService . get ( 'collection.source.controls.reset.completed' ) ) ;
217- this . requestService . setStaleByHrefSubstring ( this . collection . _links . self . href ) ;
218- this . reImportRunning$ . next ( false ) ;
219- }
176+ if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . FAILED ] . toString ( ) ) {
177+ this . notificationsService . error ( this . translateService . get ( 'collection.source.controls.reset.failed' ) ) ;
178+ this . reImportRunning$ . next ( false ) ;
179+ }
180+ if ( process . processStatus . toString ( ) === ProcessStatus [ ProcessStatus . COMPLETED ] . toString ( ) ) {
181+ this . notificationsService . success ( this . translateService . get ( 'collection.source.controls.reset.completed' ) ) ;
182+ this . requestService . setStaleByHrefSubstring ( this . collection . _links . self . href ) ;
183+ this . reImportRunning$ . next ( false ) ;
220184 }
221- ) ) ;
185+ } ) ) ;
222186 }
223187
224188 ngOnDestroy ( ) : void {
0 commit comments