import { Injectable } from '@angular/core' ; import { Observable , of } from 'rxjs' ; import { catchError , map } from 'rxjs/operators' ; import { EndpointErrorHandler , EndpointErrorHandling , HsEndpoint , isErrorHandlerFunction , } from '../../../common/endpoints/endpoint.interface' ; import { HsCommonEndpointsService } from '../../../common/endpoints/endpoints.service' ; import { HsCompositionsMapService } from '../compositions-map.service' ; import { HsCompositionsMickaService } from './compositions-micka.service' ; import { HsCompositionsParserService } from '../compositions-parser.service' ; import { HsCompositionsStatusManagerService } from './compositions-status-manager.service' ; import { HsLanguageService } from '../../language/language.service' ; import { HsToastService } from '../../layout/toast/toast.service' ; import { HsUtilsService } from '../../utils/utils.service' ; @ Injectable ( { providedIn : 'root' , } ) export class HsCompositionsStatusManagerMickaJointService { constructor ( public HsCompositionsStatusManagerService , public HsCompositionsMickaService , public HsCompositionsMapService , public HsCompositionsParserService , public HsUtilsService , public HsToastService , public HsLanguageService , public HsCommonEndpointsService ) { } public description param ds param params param bbox loadList ( ds , params , extentFeatureCreated , bbox ) { const Observable = this . HsCompositionsMickaService . loadList ( ds , params , extentFeatureCreated , bbox ) . pipe ( map ( ( response ) => { this . HsCompositionsStatusManagerService . loadList ( ds , params , bbox ) ; } ) , catchError ( ( e ) => { if ( isErrorHandlerFunction ( ds . onError ?. compositionLoad ) ) { ( < EndpointErrorHandler > ds . onError ?. compositionLoad ) . handle ( ds , e ) ; return of ( e ) ; } switch ( ds . onError ?. compositionLoad ) { case EndpointErrorHandling . ignore : break ; case EndpointErrorHandling . toast : default : this . HsToastService . createToastPopupMessage ( this . HsLanguageService . getTranslation ( 'COMPOSITIONS.errorWhileRequestingCompositions' ) , ds . title + ': ' + this . HsLanguageService . getTranslationIgnoreNonExisting ( 'ERRORMESSAGES' , e . status ? e . status . toString ( ) : e . message , { url : ds . url } ) , { disableLocalization : true , serviceCalledFrom : 'HsCompositionsStatusManagerMickaJointService' , } ) ; } return of ( e ) ; } ) ) ; return Observable ; } async getInfo ( composition ) { const compLinks = composition . link || composition . links ; if ( compLinks === undefined ) { return ; } const compUrls = this . getCompositionUrls ( compLinks ) ; let info = { } ; let url = '' ; Array . isArray ( compUrls ) ? ( url = compUrls [ 0 ] ) : ( url = compUrls ) ; try { info = await this . HsCompositionsParserService . loadInfo ( url ) ; info . metadata = { record_url : composition . endpoint . url . replace ( 'csw' , 'record/basic/' ) + composition . id , } ; return info ; } catch ( e ) { this . HsToastService . createToastPopupMessage ( this . HsLanguageService . getTranslation ( 'COMPOSITIONS.errorWhileLoadingCompositionMetadata' ) , this . HsLanguageService . getTranslationIgnoreNonExisting ( 'ERRORMESSAGES' , e . status ? e . status . toString ( ) : e . message , { url : url } ) , { disableLocalization : true , serviceCalledFrom : 'HsCompositionsStatusManagerMickaJointService' , } ) ; } } delete ( endpoint , composition ) { this . HsCompositionsStatusManagerService . delete ( endpoint , composition ) ; } getCompositionUrls ( compData ) { if ( typeof compData == 'string' ) { return compData ; } if ( typeof compData == 'object' && compData . url !== undefined ) { return compData . url ; } return compData . map ( ( link ) => typeof link == 'object' && link . url !== undefined ? link . url : link ) ; } }