mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
[DURACOM-191] Fix resource-policy-target.resolver which still used getDataServiceFor decorator
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import {
|
||||
Inject,
|
||||
Injectable,
|
||||
InjectionToken,
|
||||
Injector,
|
||||
} from '@angular/core';
|
||||
import {
|
||||
@@ -9,10 +11,15 @@ import {
|
||||
RouterStateSnapshot,
|
||||
} from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
|
||||
import { getDataServiceFor } from '../../../core/data/base/data-service.decorator';
|
||||
import {
|
||||
APP_DATA_SERVICES_MAP,
|
||||
LazyDataServicesMap,
|
||||
} from '../../../../config/app-config.interface';
|
||||
import { IdentifiableDataService } from '../../../core/data/base/identifiable-data.service';
|
||||
import { RemoteData } from '../../../core/data/remote-data';
|
||||
import { lazyService } from '../../../core/lazy-service';
|
||||
import { DSpaceObject } from '../../../core/shared/dspace-object.model';
|
||||
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
|
||||
import { ResourceType } from '../../../core/shared/resource-type';
|
||||
@@ -23,12 +30,11 @@ import { isEmpty } from '../../empty.util';
|
||||
*/
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ResourcePolicyTargetResolver implements Resolve<RemoteData<DSpaceObject>> {
|
||||
/**
|
||||
* The data service used to make request.
|
||||
*/
|
||||
private dataService: IdentifiableDataService<DSpaceObject>;
|
||||
|
||||
constructor(private parentInjector: Injector, private router: Router) {
|
||||
constructor(
|
||||
private parentInjector: Injector,
|
||||
private router: Router,
|
||||
@Inject(APP_DATA_SERVICES_MAP) private dataServiceMap: InjectionToken<LazyDataServicesMap>) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,13 +52,13 @@ export class ResourcePolicyTargetResolver implements Resolve<RemoteData<DSpaceOb
|
||||
this.router.navigateByUrl('/404', { skipLocationChange: true });
|
||||
}
|
||||
|
||||
const provider = getDataServiceFor(new ResourceType(targetType));
|
||||
this.dataService = Injector.create({
|
||||
providers: [],
|
||||
parent: this.parentInjector,
|
||||
}).get(provider);
|
||||
const resourceType: ResourceType = new ResourceType(targetType);
|
||||
const lazyProvider$: Observable<IdentifiableDataService<DSpaceObject>> = lazyService(this.dataServiceMap[resourceType.value], this.parentInjector);
|
||||
|
||||
return this.dataService.findById(policyTargetId).pipe(
|
||||
return lazyProvider$.pipe(
|
||||
switchMap((dataService: IdentifiableDataService<DSpaceObject>) => {
|
||||
return dataService.findById(policyTargetId);
|
||||
}),
|
||||
getFirstCompletedRemoteData(),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user