diff --git a/src/app/core/cache/models/normalized-version-history.model.ts b/src/app/core/cache/models/normalized-version-history.model.ts new file mode 100644 index 0000000000..336f589736 --- /dev/null +++ b/src/app/core/cache/models/normalized-version-history.model.ts @@ -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 implements TypedObject { + /** + * The identifier of this Version History + */ + @autoserialize + id: number; + + /** + * The list of versions within this history + */ + @deserialize + @relationship(Version, true) + versions: string[]; +} diff --git a/src/app/core/cache/models/normalized-version.model.ts b/src/app/core/cache/models/normalized-version.model.ts new file mode 100644 index 0000000000..b9781cbcb7 --- /dev/null +++ b/src/app/core/cache/models/normalized-version.model.ts @@ -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 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; +} diff --git a/src/app/core/core.module.ts b/src/app/core/core.module.ts index 1621c4081d..ce7769098f 100644 --- a/src/app/core/core.module.ts +++ b/src/app/core/core.module.ts @@ -142,6 +142,10 @@ import { NormalizedExternalSource } from './cache/models/normalized-external-sou import { NormalizedExternalSourceEntry } from './cache/models/normalized-external-source-entry.model'; import { ExternalSourceService } from './data/external-source.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 @@ -257,6 +261,8 @@ const PROVIDERS = [ RelationshipTypeService, ExternalSourceService, LookupRelationService, + VersionDataService, + VersionHistoryDataService, // register AuthInterceptor as HttpInterceptor { provide: HTTP_INTERCEPTORS, @@ -304,7 +310,9 @@ export const normalizedModels = NormalizedRelationshipType, NormalizedItemType, NormalizedExternalSource, - NormalizedExternalSourceEntry + NormalizedExternalSourceEntry, + NormalizedVersion, + NormalizedVersionHistory ]; @NgModule({ diff --git a/src/app/core/data/version-data.service.ts b/src/app/core/data/version-data.service.ts new file mode 100644 index 0000000000..cdc7de69f9 --- /dev/null +++ b/src/app/core/data/version-data.service.ts @@ -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 { + protected linkPath = 'versions'; + + constructor( + protected requestService: RequestService, + protected rdbService: RemoteDataBuildService, + protected dataBuildService: NormalizedObjectBuildService, + protected store: Store, + protected objectCache: ObjectCacheService, + protected halService: HALEndpointService, + protected notificationsService: NotificationsService, + protected http: HttpClient, + protected comparator: DefaultChangeAnalyzer) { + super(); + } + + /** + * Get the endpoint for browsing versions + */ + getBrowseEndpoint(options: FindListOptions = {}, linkPath?: string): Observable { + return this.halService.getEndpoint(this.linkPath); + } +} diff --git a/src/app/core/data/version-history-data.service.ts b/src/app/core/data/version-history-data.service.ts new file mode 100644 index 0000000000..5f1543b664 --- /dev/null +++ b/src/app/core/data/version-history-data.service.ts @@ -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 { + protected linkPath = 'versionhistories'; + + constructor( + protected requestService: RequestService, + protected rdbService: RemoteDataBuildService, + protected dataBuildService: NormalizedObjectBuildService, + protected store: Store, + protected objectCache: ObjectCacheService, + protected halService: HALEndpointService, + protected notificationsService: NotificationsService, + protected http: HttpClient, + protected comparator: DefaultChangeAnalyzer) { + super(); + } + + /** + * Get the endpoint for browsing versions + */ + getBrowseEndpoint(options: FindListOptions = {}, linkPath?: string): Observable { + return this.halService.getEndpoint(this.linkPath); + } +} diff --git a/src/app/core/shared/version-history.model.ts b/src/app/core/shared/version-history.model.ts new file mode 100644 index 0000000000..de31bc9e0e --- /dev/null +++ b/src/app/core/shared/version-history.model.ts @@ -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>>; + + /** + * Method that returns as which type of object this object should be rendered + */ + getRenderTypes(): Array> { + return [this.constructor as GenericConstructor]; + } +} diff --git a/src/app/core/shared/version.model.ts b/src/app/core/shared/version.model.ts new file mode 100644 index 0000000000..521cfa2664 --- /dev/null +++ b/src/app/core/shared/version.model.ts @@ -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>; + + /** + * The item this version represents + */ + @excludeFromEquals + item: Observable>; + + /** + * Method that returns as which type of object this object should be rendered + */ + getRenderTypes(): Array> { + return [this.constructor as GenericConstructor]; + } +}