got rid of TNormalized everywhere

This commit is contained in:
lotte
2019-01-29 16:03:50 +01:00
parent 58b45801b7
commit 0050f58bf0
50 changed files with 223 additions and 191 deletions

View File

@@ -42,7 +42,7 @@ import { RequestEntry } from './request.reducer';
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
import { ChangeAnalyzer } from './change-analyzer';
export abstract class DataService<TNormalized extends NormalizedObject, TDomain extends CacheableObject> {
export abstract class DataService<T extends CacheableObject> {
protected abstract requestService: RequestService;
protected abstract rdbService: RemoteDataBuildService;
protected abstract dataBuildService: NormalizedObjectBuildService;
@@ -52,7 +52,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
protected abstract objectCache: ObjectCacheService;
protected abstract notificationsService: NotificationsService;
protected abstract http: HttpClient;
protected abstract comparator: ChangeAnalyzer<TNormalized>;
protected abstract comparator: ChangeAnalyzer<T>;
public abstract getBrowseEndpoint(options: FindAllOptions, linkPath?: string): Observable<string>
@@ -81,7 +81,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
}
}
findAll(options: FindAllOptions = {}): Observable<RemoteData<PaginatedList<TDomain>>> {
findAll(options: FindAllOptions = {}): Observable<RemoteData<PaginatedList<T>>> {
const hrefObs = this.getFindAllHref(options);
hrefObs.pipe(
@@ -92,7 +92,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
this.requestService.configure(request);
});
return this.rdbService.buildList<TNormalized, TDomain>(hrefObs) as Observable<RemoteData<PaginatedList<TDomain>>>;
return this.rdbService.buildList<T>(hrefObs) as Observable<RemoteData<PaginatedList<T>>>;
}
/**
@@ -104,7 +104,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
return `${endpoint}/${resourceID}`;
}
findById(id: string): Observable<RemoteData<TDomain>> {
findById(id: string): Observable<RemoteData<T>> {
const hrefObs = this.halService.getEndpoint(this.linkPath).pipe(
map((endpoint: string) => this.getIDHref(endpoint, id)));
@@ -115,12 +115,12 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
this.requestService.configure(request);
});
return this.rdbService.buildSingle<TNormalized, TDomain>(hrefObs);
return this.rdbService.buildSingle<T>(hrefObs);
}
findByHref(href: string): Observable<RemoteData<TDomain>> {
findByHref(href: string): Observable<RemoteData<T>> {
this.requestService.configure(new GetRequest(this.requestService.generateRequestId(), href));
return this.rdbService.buildSingle<TNormalized, TDomain>(href);
return this.rdbService.buildSingle<T>(href);
}
/**
@@ -137,11 +137,10 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
* The patch is derived from the differences between the given object and its version in the object cache
* @param {DSpaceObject} object The given object
*/
update(object: TDomain): Observable<RemoteData<TDomain>> {
update(object: T): Observable<RemoteData<T>> {
const oldVersion$ = this.objectCache.getBySelfLink(object.self);
return oldVersion$.pipe(take(1), mergeMap((oldVersion: TNormalized) => {
const newVersion = this.dataBuildService.normalize<TDomain, TNormalized>(object);
const operations = this.comparator.diff(oldVersion, newVersion);
return oldVersion$.pipe(take(1), mergeMap((oldVersion: T) => {
const operations = this.comparator.diff(oldVersion, object);
if (isNotEmpty(operations)) {
this.objectCache.addPatch(object.self, operations);
}
@@ -160,7 +159,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
* @param {string} parentUUID
* The UUID of the parent to create the new object under
*/
create(dso: TDomain, parentUUID: string): Observable<RemoteData<TDomain>> {
create(dso: T, parentUUID: string): Observable<RemoteData<T>> {
const requestId = this.requestService.generateRequestId();
const endpoint$ = this.halService.getEndpoint(this.linkPath).pipe(
isNotEmptyOperator(),
@@ -168,7 +167,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
map((endpoint: string) => parentUUID ? `${endpoint}?parentCommunity=${parentUUID}` : endpoint)
);
const normalizedObject: TNormalized = this.dataBuildService.normalize<TDomain, TNormalized>(dso);
const normalizedObject: NormalizedObject<T> = this.dataBuildService.normalize<T>(dso);
const serializedDso = new DSpaceRESTv2Serializer(NormalizedObjectFactory.getConstructor(dso.type)).serialize(normalizedObject);
const request$ = endpoint$.pipe(
@@ -209,7 +208,7 @@ export abstract class DataService<TNormalized extends NormalizedObject, TDomain
* @param dso The DSpace Object to be removed
* Return an observable that emits true when the deletion was successful, false when it failed
*/
delete(dso: TDomain): Observable<boolean> {
delete(dso: T): Observable<boolean> {
const requestId = this.requestService.generateRequestId();
const hrefObs = this.halService.getEndpoint(this.linkPath).pipe(