68729: Version and VersionHistory model, normalized and data-service classes

This commit is contained in:
Kristof De Langhe
2020-02-18 16:05:38 +01:00
parent a04eb28815
commit d4ff4aab36
7 changed files with 268 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
import { autoserialize, deserialize, inheritSerialization } from 'cerialize';
import { NormalizedObject } from './normalized-object.model';
import { TypedObject } from '../object-cache.reducer';
import { mapsTo, relationship } from '../builders/build-decorators';
import { VersionHistory } from '../../shared/version-history.model';
import { Version } from '../../shared/version.model';
/**
* Normalized model class for a DSpace Version History
*/
@mapsTo(VersionHistory)
@inheritSerialization(NormalizedObject)
export class NormalizedVersionHistory extends NormalizedObject<VersionHistory> implements TypedObject {
/**
* The identifier of this Version History
*/
@autoserialize
id: number;
/**
* The list of versions within this history
*/
@deserialize
@relationship(Version, true)
versions: string[];
}

View File

@@ -0,0 +1,52 @@
import { autoserialize, deserialize, inheritSerialization } from 'cerialize';
import { Version } from '../../shared/version.model';
import { mapsTo, relationship } from '../builders/build-decorators';
import { TypedObject } from '../object-cache.reducer';
import { NormalizedObject } from './normalized-object.model';
import { Item } from '../../shared/item.model';
import { VersionHistory } from '../../shared/version-history.model';
/**
* Normalized model class for a DSpace Version
*/
@mapsTo(Version)
@inheritSerialization(NormalizedObject)
export class NormalizedVersion extends NormalizedObject<Version> implements TypedObject {
/**
* The identifier of this Version
*/
@autoserialize
id: number;
/**
* The version number of the version's history this version represents
*/
@autoserialize
version: number;
/**
* The summary for the changes made in this version
*/
@autoserialize
summary: string;
/**
* The Date this version was created
*/
@deserialize
created: Date;
/**
* The full version history this version is apart of
*/
@deserialize
@relationship(VersionHistory, false)
versionhistory: string;
/**
* The item this version represents
*/
@deserialize
@relationship(Item, false)
item: string;
}

View File

@@ -142,6 +142,10 @@ import { NormalizedExternalSource } from './cache/models/normalized-external-sou
import { NormalizedExternalSourceEntry } from './cache/models/normalized-external-source-entry.model'; import { NormalizedExternalSourceEntry } from './cache/models/normalized-external-source-entry.model';
import { ExternalSourceService } from './data/external-source.service'; import { ExternalSourceService } from './data/external-source.service';
import { LookupRelationService } from './data/lookup-relation.service'; import { LookupRelationService } from './data/lookup-relation.service';
import { VersionDataService } from './data/version-data.service';
import { NormalizedVersion } from './cache/models/normalized-version.model';
import { NormalizedVersionHistory } from './cache/models/normalized-version-history.model';
import { VersionHistoryDataService } from './data/version-history-data.service';
/** /**
* When not in production, endpoint responses can be mocked for testing purposes * When not in production, endpoint responses can be mocked for testing purposes
@@ -257,6 +261,8 @@ const PROVIDERS = [
RelationshipTypeService, RelationshipTypeService,
ExternalSourceService, ExternalSourceService,
LookupRelationService, LookupRelationService,
VersionDataService,
VersionHistoryDataService,
// register AuthInterceptor as HttpInterceptor // register AuthInterceptor as HttpInterceptor
{ {
provide: HTTP_INTERCEPTORS, provide: HTTP_INTERCEPTORS,
@@ -304,7 +310,9 @@ export const normalizedModels =
NormalizedRelationshipType, NormalizedRelationshipType,
NormalizedItemType, NormalizedItemType,
NormalizedExternalSource, NormalizedExternalSource,
NormalizedExternalSourceEntry NormalizedExternalSourceEntry,
NormalizedVersion,
NormalizedVersionHistory
]; ];
@NgModule({ @NgModule({

View File

@@ -0,0 +1,40 @@
import { Injectable } from '@angular/core';
import { DataService } from './data.service';
import { Version } from '../shared/version.model';
import { RequestService } from './request.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
import { Store } from '@ngrx/store';
import { CoreState } from '../core.reducers';
import { ObjectCacheService } from '../cache/object-cache.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { HttpClient } from '@angular/common/http';
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
import { FindListOptions } from './request.models';
import { Observable } from 'rxjs/internal/Observable';
@Injectable()
export class VersionDataService extends DataService<Version> {
protected linkPath = 'versions';
constructor(
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected dataBuildService: NormalizedObjectBuildService,
protected store: Store<CoreState>,
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService,
protected notificationsService: NotificationsService,
protected http: HttpClient,
protected comparator: DefaultChangeAnalyzer<Version>) {
super();
}
/**
* Get the endpoint for browsing versions
*/
getBrowseEndpoint(options: FindListOptions = {}, linkPath?: string): Observable<string> {
return this.halService.getEndpoint(this.linkPath);
}
}

View File

@@ -0,0 +1,40 @@
import { DataService } from './data.service';
import { VersionHistory } from '../shared/version-history.model';
import { Injectable } from '@angular/core';
import { RequestService } from './request.service';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { NormalizedObjectBuildService } from '../cache/builders/normalized-object-build.service';
import { Store } from '@ngrx/store';
import { CoreState } from '../core.reducers';
import { ObjectCacheService } from '../cache/object-cache.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { NotificationsService } from '../../shared/notifications/notifications.service';
import { HttpClient } from '@angular/common/http';
import { DefaultChangeAnalyzer } from './default-change-analyzer.service';
import { FindListOptions } from './request.models';
import { Observable } from 'rxjs/internal/Observable';
@Injectable()
export class VersionHistoryDataService extends DataService<VersionHistory> {
protected linkPath = 'versionhistories';
constructor(
protected requestService: RequestService,
protected rdbService: RemoteDataBuildService,
protected dataBuildService: NormalizedObjectBuildService,
protected store: Store<CoreState>,
protected objectCache: ObjectCacheService,
protected halService: HALEndpointService,
protected notificationsService: NotificationsService,
protected http: HttpClient,
protected comparator: DefaultChangeAnalyzer<VersionHistory>) {
super();
}
/**
* Get the endpoint for browsing versions
*/
getBrowseEndpoint(options: FindListOptions = {}, linkPath?: string): Observable<string> {
return this.halService.getEndpoint(this.linkPath);
}
}

View File

@@ -0,0 +1,40 @@
import { ListableObject } from '../../shared/object-collection/shared/listable-object.model';
import { CacheableObject } from '../cache/object-cache.reducer';
import { ResourceType } from './resource-type';
import { excludeFromEquals } from '../utilities/equals.decorators';
import { Observable } from 'rxjs/internal/Observable';
import { RemoteData } from '../data/remote-data';
import { GenericConstructor } from './generic-constructor';
import { PaginatedList } from '../data/paginated-list';
import { Version } from './version.model';
/**
* Class representing a DSpace Version History
*/
export class VersionHistory extends ListableObject implements CacheableObject {
static type = new ResourceType('versionhistory');
/**
* Link to itself
*/
@excludeFromEquals
self: string;
/**
* The identifier of this Version History
*/
id: number;
/**
* The list of versions within this history
*/
@excludeFromEquals
versions: Observable<RemoteData<PaginatedList<Version>>>;
/**
* Method that returns as which type of object this object should be rendered
*/
getRenderTypes(): Array<string | GenericConstructor<ListableObject>> {
return [this.constructor as GenericConstructor<ListableObject>];
}
}

View File

@@ -0,0 +1,61 @@
import { ResourceType } from './resource-type';
import { ListableObject } from '../../shared/object-collection/shared/listable-object.model';
import { CacheableObject } from '../cache/object-cache.reducer';
import { excludeFromEquals } from '../utilities/equals.decorators';
import { GenericConstructor } from './generic-constructor';
import { Item } from './item.model';
import { RemoteData } from '../data/remote-data';
import { Observable } from 'rxjs/internal/Observable';
import { VersionHistory } from './version-history.model';
/**
* Class representing a DSpace Version
*/
export class Version extends ListableObject implements CacheableObject {
static type = new ResourceType('version');
/**
* Link to itself
*/
@excludeFromEquals
self: string;
/**
* The identifier of this Version
*/
id: number;
/**
* The version number of the version's history this version represents
*/
version: number;
/**
* The summary for the changes made in this version
*/
summary: string;
/**
* The Date this version was created
*/
created: Date;
/**
* The full version history this version is apart of
*/
@excludeFromEquals
versionhistory: Observable<RemoteData<VersionHistory>>;
/**
* The item this version represents
*/
@excludeFromEquals
item: Observable<RemoteData<Item>>;
/**
* Method that returns as which type of object this object should be rendered
*/
getRenderTypes(): Array<string | GenericConstructor<ListableObject>> {
return [this.constructor as GenericConstructor<ListableObject>];
}
}