mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
remove normalized models part 1
This commit is contained in:
30
src/app/core/cache/builders/build-decorators.ts
vendored
30
src/app/core/cache/builders/build-decorators.ts
vendored
@@ -30,6 +30,21 @@ export function mapsTo(value: GenericConstructor<TypedObject>) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorator function to map a normalized class to it's not-normalized counter part class
|
||||
* It will also maps a type to the matching class
|
||||
* @param value The not-normalized class to map to
|
||||
*/
|
||||
// export function resourceType(target: any, key: string) {
|
||||
// typeMap.set(target.key.value, target.constructor);
|
||||
// }
|
||||
|
||||
export function resourceType(value: ResourceType) {
|
||||
return function decorator(objectConstructor: GenericConstructor<TypedObject>) {
|
||||
typeMap.set(value.value, objectConstructor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a type to the matching class
|
||||
* @param value The resourse type
|
||||
@@ -180,3 +195,18 @@ export const getLinkDefinition = <T extends HALResource>(source: GenericConstruc
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const inheritLinkAnnotations = (parent: any): any => {
|
||||
return (child: any) => {
|
||||
const parentMap: Map<string, LinkDefinition<any>> = linkMap.get(parent) || new Map();
|
||||
const childMap: Map<string, LinkDefinition<any>> = linkMap.get(child) || new Map();
|
||||
|
||||
parentMap.forEach((value, key) => {
|
||||
if (!childMap.has(key)) {
|
||||
childMap.set(key, value);
|
||||
}
|
||||
});
|
||||
|
||||
linkMap.set(child, childMap);
|
||||
}
|
||||
};
|
||||
|
14
src/app/core/cache/builders/link.service.ts
vendored
14
src/app/core/cache/builders/link.service.ts
vendored
@@ -1,5 +1,5 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { hasNoValue, isNotEmpty } from '../../../shared/empty.util';
|
||||
import { hasNoValue, hasValue, isNotEmpty } from '../../../shared/empty.util';
|
||||
import { FollowLinkConfig } from '../../../shared/utils/follow-link-config.model';
|
||||
import { GenericConstructor } from '../../shared/generic-constructor';
|
||||
import { HALResource } from '../../shared/hal-resource.model';
|
||||
@@ -40,10 +40,14 @@ export class LinkService {
|
||||
|
||||
const href = model._links[matchingLinkDef.linkName].href;
|
||||
|
||||
if (matchingLinkDef.isList) {
|
||||
model[linkToFollow.name] = service.findAllByHref(href, linkToFollow.findListOptions, ...linkToFollow.linksToFollow);
|
||||
} else {
|
||||
model[linkToFollow.name] = service.findByHref(href, ...linkToFollow.linksToFollow);
|
||||
try {
|
||||
if (matchingLinkDef.isList) {
|
||||
model[linkToFollow.name] = service.findAllByHref(href, linkToFollow.findListOptions, ...linkToFollow.linksToFollow);
|
||||
} else {
|
||||
model[linkToFollow.name] = service.findByHref(href, ...linkToFollow.linksToFollow);
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(`Something went wrong when using @dataService(${matchingLinkDef.resourceType.value}) ${hasValue(service) ? '' : '(undefined) '}to resolve link ${linkToFollow.name} from ${href}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ export class RemoteDataBuildService {
|
||||
* Creates a single {@link RemoteData} object based on the response of a request to the REST server, with a list of
|
||||
* {@link FollowLinkConfig} that indicate which embedded info should be added to the object
|
||||
* @param href$ Observable href of object we want to retrieve
|
||||
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which embedded info should be added
|
||||
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which HALLinks should be automatically resolved
|
||||
*/
|
||||
buildSingle<T extends CacheableObject>(href$: string | Observable<string>, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<RemoteData<T>> {
|
||||
if (typeof href$ === 'string') {
|
||||
@@ -126,7 +126,7 @@ export class RemoteDataBuildService {
|
||||
* Creates a list of {@link RemoteData} objects based on the response of a request to the REST server, with a list of
|
||||
* {@link FollowLinkConfig} that indicate which embedded info should be added to the objects
|
||||
* @param href$ Observable href of objects we want to retrieve
|
||||
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which embedded info should be added
|
||||
* @param linksToFollow List of {@link FollowLinkConfig} that indicate which HALLinks should be automatically resolved
|
||||
*/
|
||||
buildList<T extends CacheableObject>(href$: string | Observable<string>, ...linksToFollow: Array<FollowLinkConfig<T>>): Observable<RemoteData<PaginatedList<T>>> {
|
||||
if (typeof href$ === 'string') {
|
||||
@@ -229,8 +229,13 @@ export class RemoteDataBuildService {
|
||||
}
|
||||
}
|
||||
});
|
||||
let domainModel;
|
||||
const domainModelConstructor = getMapsTo(normalized.constructor);
|
||||
const domainModel = Object.assign(new domainModelConstructor(), normalized, halLinks);
|
||||
if(hasValue(domainModelConstructor) && domainModelConstructor !== normalized.constructor) {
|
||||
domainModel = Object.assign(new domainModelConstructor(), normalized, halLinks);
|
||||
} else {
|
||||
domainModel = normalized;
|
||||
}
|
||||
|
||||
this.linkService.resolveLinks(domainModel, ...linksToFollow);
|
||||
|
||||
|
@@ -1,30 +0,0 @@
|
||||
import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize';
|
||||
import { ItemType } from '../../../shared/item-relationships/item-type.model';
|
||||
import { mapsTo } from '../../builders/build-decorators';
|
||||
import { NormalizedObject } from '../normalized-object.model';
|
||||
import { IDToUUIDSerializer } from '../../id-to-uuid-serializer';
|
||||
|
||||
/**
|
||||
* Normalized model class for a DSpace ItemType
|
||||
*/
|
||||
@mapsTo(ItemType)
|
||||
@inheritSerialization(NormalizedObject)
|
||||
export class NormalizedItemType extends NormalizedObject<ItemType> {
|
||||
/**
|
||||
* The label that describes the ResourceType of the Item
|
||||
*/
|
||||
@autoserialize
|
||||
label: string;
|
||||
|
||||
/**
|
||||
* The identifier of this ItemType
|
||||
*/
|
||||
@autoserialize
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* The universally unique identifier of this ItemType
|
||||
*/
|
||||
@autoserializeAs(new IDToUUIDSerializer(ItemType.type.value), 'id')
|
||||
uuid: string;
|
||||
}
|
@@ -1,77 +0,0 @@
|
||||
import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize';
|
||||
import { RelationshipType } from '../../../shared/item-relationships/relationship-type.model';
|
||||
import { ResourceType } from '../../../shared/resource-type';
|
||||
import { mapsTo, relationship } from '../../builders/build-decorators';
|
||||
import { NormalizedDSpaceObject } from '../normalized-dspace-object.model';
|
||||
import { NormalizedObject } from '../normalized-object.model';
|
||||
import { IDToUUIDSerializer } from '../../id-to-uuid-serializer';
|
||||
import { ItemType } from '../../../shared/item-relationships/item-type.model';
|
||||
|
||||
/**
|
||||
* Normalized model class for a DSpace RelationshipType
|
||||
*/
|
||||
@mapsTo(RelationshipType)
|
||||
@inheritSerialization(NormalizedDSpaceObject)
|
||||
export class NormalizedRelationshipType extends NormalizedObject<RelationshipType> {
|
||||
/**
|
||||
* The identifier of this RelationshipType
|
||||
*/
|
||||
@autoserialize
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* The label that describes the Relation to the left of this RelationshipType
|
||||
*/
|
||||
@autoserialize
|
||||
leftwardType: string;
|
||||
|
||||
/**
|
||||
* The maximum amount of Relationships allowed to the left of this RelationshipType
|
||||
*/
|
||||
@autoserialize
|
||||
leftMaxCardinality: number;
|
||||
|
||||
/**
|
||||
* The minimum amount of Relationships allowed to the left of this RelationshipType
|
||||
*/
|
||||
@autoserialize
|
||||
leftMinCardinality: number;
|
||||
|
||||
/**
|
||||
* The label that describes the Relation to the right of this RelationshipType
|
||||
*/
|
||||
@autoserialize
|
||||
rightwardType: string;
|
||||
|
||||
/**
|
||||
* The maximum amount of Relationships allowed to the right of this RelationshipType
|
||||
*/
|
||||
@autoserialize
|
||||
rightMaxCardinality: number;
|
||||
|
||||
/**
|
||||
* The minimum amount of Relationships allowed to the right of this RelationshipType
|
||||
*/
|
||||
@autoserialize
|
||||
rightMinCardinality: number;
|
||||
|
||||
/**
|
||||
* The type of Item found to the left of this RelationshipType
|
||||
*/
|
||||
@autoserialize
|
||||
@relationship(ItemType, false)
|
||||
leftType: string;
|
||||
|
||||
/**
|
||||
* The type of Item found to the right of this RelationshipType
|
||||
*/
|
||||
@autoserialize
|
||||
@relationship(ItemType, false)
|
||||
rightType: string;
|
||||
|
||||
/**
|
||||
* The universally unique identifier of this RelationshipType
|
||||
*/
|
||||
@autoserializeAs(new IDToUUIDSerializer(RelationshipType.type.value), 'id')
|
||||
uuid: string;
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
import { autoserialize, deserialize, deserializeAs, inheritSerialization } from 'cerialize';
|
||||
import { Relationship } from '../../../shared/item-relationships/relationship.model';
|
||||
import { mapsTo, relationship } from '../../builders/build-decorators';
|
||||
import { NormalizedObject } from '../normalized-object.model';
|
||||
import { IDToUUIDSerializer } from '../../id-to-uuid-serializer';
|
||||
import { RelationshipType } from '../../../shared/item-relationships/relationship-type.model';
|
||||
import { Item } from '../../../shared/item.model';
|
||||
|
||||
/**
|
||||
* Normalized model class for a DSpace Relationship
|
||||
*/
|
||||
@mapsTo(Relationship)
|
||||
@inheritSerialization(NormalizedObject)
|
||||
export class NormalizedRelationship extends NormalizedObject<Relationship> {
|
||||
|
||||
/**
|
||||
* The identifier of this Relationship
|
||||
*/
|
||||
@deserialize
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* The item to the left of this relationship
|
||||
*/
|
||||
@deserialize
|
||||
@relationship(Item, false, false)
|
||||
leftItem: string;
|
||||
|
||||
/**
|
||||
* The item to the right of this relationship
|
||||
*/
|
||||
@deserialize
|
||||
@relationship(Item, false, false)
|
||||
rightItem: string;
|
||||
|
||||
/**
|
||||
* The place of the Item to the left side of this Relationship
|
||||
*/
|
||||
@autoserialize
|
||||
leftPlace: number;
|
||||
|
||||
/**
|
||||
* The place of the Item to the right side of this Relationship
|
||||
*/
|
||||
@autoserialize
|
||||
rightPlace: number;
|
||||
|
||||
/**
|
||||
* The name variant of the Item to the left side of this Relationship
|
||||
*/
|
||||
@autoserialize
|
||||
leftwardValue: string;
|
||||
|
||||
/**
|
||||
* The name variant of the Item to the right side of this Relationship
|
||||
*/
|
||||
@autoserialize
|
||||
rightwardValue: string;
|
||||
|
||||
/**
|
||||
* The type of Relationship
|
||||
*/
|
||||
@deserialize
|
||||
@relationship(RelationshipType, false, false)
|
||||
relationshipType: string;
|
||||
|
||||
/**
|
||||
* The universally unique identifier of this Relationship
|
||||
*/
|
||||
@deserializeAs(new IDToUUIDSerializer(Relationship.type.value), 'id')
|
||||
uuid: string;
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize';
|
||||
import { BitstreamFormat } from '../../shared/bitstream-format.model';
|
||||
|
||||
import { mapsTo } from '../builders/build-decorators';
|
||||
import { IDToUUIDSerializer } from '../id-to-uuid-serializer';
|
||||
import { NormalizedObject } from './normalized-object.model';
|
||||
import { BitstreamFormatSupportLevel } from '../../shared/bitstream-format-support-level';
|
||||
|
||||
/**
|
||||
* Normalized model class for a Bitstream Format
|
||||
*/
|
||||
@mapsTo(BitstreamFormat)
|
||||
@inheritSerialization(NormalizedObject)
|
||||
export class NormalizedBitstreamFormat extends NormalizedObject<BitstreamFormat> {
|
||||
/**
|
||||
* Short description of this Bitstream Format
|
||||
*/
|
||||
@autoserialize
|
||||
shortDescription: string;
|
||||
|
||||
/**
|
||||
* Description of this Bitstream Format
|
||||
*/
|
||||
@autoserialize
|
||||
description: string;
|
||||
|
||||
/**
|
||||
* String representing the MIME type of this Bitstream Format
|
||||
*/
|
||||
@autoserialize
|
||||
mimetype: string;
|
||||
|
||||
/**
|
||||
* The level of support the system offers for this Bitstream Format
|
||||
*/
|
||||
@autoserialize
|
||||
supportLevel: BitstreamFormatSupportLevel;
|
||||
|
||||
/**
|
||||
* True if the Bitstream Format is used to store system information, rather than the content of items in the system
|
||||
*/
|
||||
@autoserialize
|
||||
internal: boolean;
|
||||
|
||||
/**
|
||||
* String representing this Bitstream Format's file extension
|
||||
*/
|
||||
@autoserialize
|
||||
extensions: string[];
|
||||
|
||||
/**
|
||||
* Identifier for this Bitstream Format
|
||||
* Note that this ID is unique for bitstream formats,
|
||||
* but might not be unique across different object types
|
||||
*/
|
||||
@autoserialize
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* Universally unique identifier for this Bitstream Format
|
||||
* Consist of a prefix and the id field to ensure the identifier is unique across all object types
|
||||
*/
|
||||
@autoserializeAs(new IDToUUIDSerializer('bitstream-format'), 'id')
|
||||
uuid: string;
|
||||
}
|
@@ -1,61 +0,0 @@
|
||||
import { autoserialize, inheritSerialization } from 'cerialize';
|
||||
|
||||
import { NormalizedDSpaceObject } from './normalized-dspace-object.model';
|
||||
import { Bitstream } from '../../shared/bitstream.model';
|
||||
import { mapsTo, relationship } from '../builders/build-decorators';
|
||||
import { Item } from '../../shared/item.model';
|
||||
import { BitstreamFormat } from '../../shared/bitstream-format.model';
|
||||
|
||||
/**
|
||||
* Normalized model class for a DSpace Bitstream
|
||||
*/
|
||||
@mapsTo(Bitstream)
|
||||
@inheritSerialization(NormalizedDSpaceObject)
|
||||
export class NormalizedBitstream extends NormalizedDSpaceObject<Bitstream> {
|
||||
/**
|
||||
* The size of this bitstream in bytes
|
||||
*/
|
||||
@autoserialize
|
||||
sizeBytes: number;
|
||||
|
||||
/**
|
||||
* The relative path to this Bitstream's file
|
||||
*/
|
||||
@autoserialize
|
||||
@relationship(Bitstream, false, false)
|
||||
content: string;
|
||||
|
||||
/**
|
||||
* The format of this Bitstream
|
||||
*/
|
||||
@autoserialize
|
||||
@relationship(BitstreamFormat, false, false)
|
||||
format: string;
|
||||
|
||||
/**
|
||||
* The description of this Bitstream
|
||||
*/
|
||||
@autoserialize
|
||||
description: string;
|
||||
|
||||
/**
|
||||
* An array of Bundles that are direct parents of this Bitstream
|
||||
*/
|
||||
@autoserialize
|
||||
@relationship(Item, true, false)
|
||||
parents: string[];
|
||||
|
||||
/**
|
||||
* The Bundle that owns this Bitstream
|
||||
*/
|
||||
@autoserialize
|
||||
@relationship(Item, false, false)
|
||||
owner: string;
|
||||
|
||||
/**
|
||||
* The name of the Bundle this Bitstream is part of
|
||||
*/
|
||||
@autoserialize
|
||||
bundleName: string;
|
||||
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
import { autoserialize, inheritSerialization } from 'cerialize';
|
||||
import { Bitstream } from '../../shared/bitstream.model';
|
||||
import { Bundle } from '../../shared/bundle.model';
|
||||
import { mapsTo, relationship } from '../builders/build-decorators';
|
||||
|
||||
import { NormalizedDSpaceObject } from './normalized-dspace-object.model';
|
||||
|
||||
/**
|
||||
* Normalized model class for a DSpace Bundle
|
||||
*/
|
||||
@mapsTo(Bundle)
|
||||
@inheritSerialization(NormalizedDSpaceObject)
|
||||
export class NormalizedBundle extends NormalizedDSpaceObject<Bundle> {
|
||||
|
||||
/**
|
||||
* The bundle's name
|
||||
*/
|
||||
@autoserialize
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The primary bitstream of this Bundle
|
||||
*/
|
||||
@autoserialize
|
||||
@relationship(Bitstream, false, false)
|
||||
primaryBitstream: string;
|
||||
|
||||
/**
|
||||
* List of Bitstreams that are part of this Bundle
|
||||
*/
|
||||
@autoserialize
|
||||
@relationship(Bitstream, true, false)
|
||||
bitstreams: string[];
|
||||
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
import { autoserialize, deserialize, inheritSerialization } from 'cerialize';
|
||||
import { Bitstream } from '../../shared/bitstream.model';
|
||||
import { Collection } from '../../shared/collection.model';
|
||||
import { Item } from '../../shared/item.model';
|
||||
import { ResourcePolicy } from '../../shared/resource-policy.model';
|
||||
import { mapsTo, relationship } from '../builders/build-decorators';
|
||||
|
||||
import { NormalizedDSpaceObject } from './normalized-dspace-object.model';
|
||||
|
||||
/**
|
||||
* Normalized model class for a DSpace Collection
|
||||
*/
|
||||
@mapsTo(Collection)
|
||||
@inheritSerialization(NormalizedDSpaceObject)
|
||||
export class NormalizedCollection extends NormalizedDSpaceObject<Collection> {
|
||||
|
||||
/**
|
||||
* A string representing the unique handle of this Collection
|
||||
*/
|
||||
@autoserialize
|
||||
handle: string;
|
||||
|
||||
/**
|
||||
* The Bitstream that represents the license of this Collection
|
||||
*/
|
||||
@autoserialize
|
||||
license: string;
|
||||
|
||||
/**
|
||||
* The Bitstream that represents the default Access Conditions of this Collection
|
||||
*/
|
||||
@autoserialize
|
||||
@relationship(ResourcePolicy, false, false)
|
||||
defaultAccessConditions: string;
|
||||
|
||||
/**
|
||||
* The Bitstream that represents the logo of this Collection
|
||||
*/
|
||||
@deserialize
|
||||
@relationship(Bitstream, false, false)
|
||||
logo: string;
|
||||
|
||||
/**
|
||||
* List of Items that are part of (not necessarily owned by) this Collection
|
||||
*/
|
||||
@deserialize
|
||||
@relationship(Item, true, false)
|
||||
items: string[];
|
||||
|
||||
}
|
@@ -1,56 +0,0 @@
|
||||
import { autoserialize, deserialize, inheritSerialization } from 'cerialize';
|
||||
|
||||
import { NormalizedDSpaceObject } from './normalized-dspace-object.model';
|
||||
import { Community } from '../../shared/community.model';
|
||||
import { mapsTo, relationship } from '../builders/build-decorators';
|
||||
import { ResourceType } from '../../shared/resource-type';
|
||||
import { NormalizedBitstream } from './normalized-bitstream.model';
|
||||
import { NormalizedCollection } from './normalized-collection.model';
|
||||
import { Bitstream } from '../../shared/bitstream.model';
|
||||
import { Collection } from '../../shared/collection.model';
|
||||
|
||||
/**
|
||||
* Normalized model class for a DSpace Community
|
||||
*/
|
||||
@mapsTo(Community)
|
||||
@inheritSerialization(NormalizedDSpaceObject)
|
||||
export class NormalizedCommunity extends NormalizedDSpaceObject<Community> {
|
||||
/**
|
||||
* A string representing the unique handle of this Community
|
||||
*/
|
||||
@autoserialize
|
||||
handle: string;
|
||||
|
||||
/**
|
||||
* The Bitstream that represents the logo of this Community
|
||||
*/
|
||||
@deserialize
|
||||
@relationship(Bitstream, false, false)
|
||||
logo: string;
|
||||
|
||||
/**
|
||||
* An array of Communities that are direct parents of this Community
|
||||
*/
|
||||
@deserialize
|
||||
@relationship(Community, true, false)
|
||||
parents: string[];
|
||||
|
||||
/**
|
||||
* The Community that owns this Community
|
||||
*/
|
||||
@deserialize
|
||||
@relationship(Community, false, false)
|
||||
owner: string;
|
||||
|
||||
/**
|
||||
* List of Collections that are owned by this Community
|
||||
*/
|
||||
@deserialize
|
||||
@relationship(Collection, true, false)
|
||||
collections: string[];
|
||||
|
||||
@deserialize
|
||||
@relationship(Community, true, false)
|
||||
subcommunities: string[];
|
||||
|
||||
}
|
@@ -2,14 +2,13 @@ import { autoserializeAs, deserializeAs, autoserialize } from 'cerialize';
|
||||
import { DSpaceObject } from '../../shared/dspace-object.model';
|
||||
import { HALLink } from '../../shared/hal-link.model';
|
||||
import { MetadataMap, MetadataMapSerializer } from '../../shared/metadata.models';
|
||||
import { mapsTo } from '../builders/build-decorators';
|
||||
import { ResourceType } from '../../shared/resource-type';
|
||||
import { NormalizedObject } from './normalized-object.model';
|
||||
import { TypedObject } from '../object-cache.reducer';
|
||||
|
||||
/**
|
||||
* An model class for a DSpaceObject.
|
||||
*/
|
||||
@mapsTo(DSpaceObject)
|
||||
export class NormalizedDSpaceObject<T extends DSpaceObject> extends NormalizedObject<T> implements TypedObject {
|
||||
|
||||
/**
|
||||
@@ -37,10 +36,10 @@ export class NormalizedDSpaceObject<T extends DSpaceObject> extends NormalizedOb
|
||||
uuid: string;
|
||||
|
||||
/**
|
||||
* A string representing the kind of DSpaceObject, e.g. community, item, …
|
||||
* The type of the object
|
||||
*/
|
||||
@autoserialize
|
||||
type: string;
|
||||
type: ResourceType;
|
||||
|
||||
/**
|
||||
* All metadata of this DSpaceObject
|
||||
|
@@ -1,42 +0,0 @@
|
||||
import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize';
|
||||
import { NormalizedObject } from './normalized-object.model';
|
||||
import { ExternalSourceEntry } from '../../shared/external-source-entry.model';
|
||||
import { mapsTo } from '../builders/build-decorators';
|
||||
import { MetadataMap, MetadataMapSerializer } from '../../shared/metadata.models';
|
||||
|
||||
/**
|
||||
* Normalized model class for an external source entry
|
||||
*/
|
||||
@mapsTo(ExternalSourceEntry)
|
||||
@inheritSerialization(NormalizedObject)
|
||||
export class NormalizedExternalSourceEntry extends NormalizedObject<ExternalSourceEntry> {
|
||||
/**
|
||||
* Unique identifier
|
||||
*/
|
||||
@autoserialize
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* The value to display
|
||||
*/
|
||||
@autoserialize
|
||||
display: string;
|
||||
|
||||
/**
|
||||
* The value to store the entry with
|
||||
*/
|
||||
@autoserialize
|
||||
value: string;
|
||||
|
||||
/**
|
||||
* The ID of the external source this entry originates from
|
||||
*/
|
||||
@autoserialize
|
||||
externalSource: string;
|
||||
|
||||
/**
|
||||
* Metadata of the entry
|
||||
*/
|
||||
@autoserializeAs(MetadataMapSerializer)
|
||||
metadata: MetadataMap;
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
import { autoserialize, inheritSerialization } from 'cerialize';
|
||||
import { NormalizedObject } from './normalized-object.model';
|
||||
import { ExternalSource } from '../../shared/external-source.model';
|
||||
import { mapsTo } from '../builders/build-decorators';
|
||||
|
||||
/**
|
||||
* Normalized model class for an external source
|
||||
*/
|
||||
@mapsTo(ExternalSource)
|
||||
@inheritSerialization(NormalizedObject)
|
||||
export class NormalizedExternalSource extends NormalizedObject<ExternalSource> {
|
||||
/**
|
||||
* Unique identifier
|
||||
*/
|
||||
@autoserialize
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* The name of this external source
|
||||
*/
|
||||
@autoserialize
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* Is the source hierarchical?
|
||||
*/
|
||||
@autoserialize
|
||||
hierarchical: boolean;
|
||||
}
|
@@ -1,65 +0,0 @@
|
||||
import { inheritSerialization, deserialize, autoserialize, autoserializeAs } from 'cerialize';
|
||||
|
||||
import { NormalizedDSpaceObject } from './normalized-dspace-object.model';
|
||||
import { Item } from '../../shared/item.model';
|
||||
import { mapsTo, relationship } from '../builders/build-decorators';
|
||||
import { Collection } from '../../shared/collection.model';
|
||||
import { Relationship } from '../../shared/item-relationships/relationship.model';
|
||||
import { Bundle } from '../../shared/bundle.model';
|
||||
|
||||
/**
|
||||
* Normalized model class for a DSpace Item
|
||||
*/
|
||||
@mapsTo(Item)
|
||||
@inheritSerialization(NormalizedDSpaceObject)
|
||||
export class NormalizedItem extends NormalizedDSpaceObject<Item> {
|
||||
|
||||
/**
|
||||
* A string representing the unique handle of this Item
|
||||
*/
|
||||
@autoserialize
|
||||
handle: string;
|
||||
|
||||
/**
|
||||
* The Date of the last modification of this Item
|
||||
*/
|
||||
@deserialize
|
||||
lastModified: Date;
|
||||
|
||||
/**
|
||||
* A boolean representing if this Item is currently archived or not
|
||||
*/
|
||||
@autoserializeAs(Boolean, 'inArchive')
|
||||
isArchived: boolean;
|
||||
|
||||
/**
|
||||
* A boolean representing if this Item is currently discoverable or not
|
||||
*/
|
||||
@autoserializeAs(Boolean, 'discoverable')
|
||||
isDiscoverable: boolean;
|
||||
|
||||
/**
|
||||
* A boolean representing if this Item is currently withdrawn or not
|
||||
*/
|
||||
@autoserializeAs(Boolean, 'withdrawn')
|
||||
isWithdrawn: boolean;
|
||||
|
||||
/**
|
||||
* The Collection that owns this Item
|
||||
*/
|
||||
@deserialize
|
||||
@relationship(Collection, false, false)
|
||||
owningCollection: string;
|
||||
|
||||
/**
|
||||
* List of Bitstreams that are owned by this Item
|
||||
*/
|
||||
@deserialize
|
||||
@relationship(Bundle, true, false)
|
||||
bundles: string[];
|
||||
|
||||
@deserialize
|
||||
@relationship(Relationship, true, false)
|
||||
relationships: string[];
|
||||
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
import { autoserialize, inheritSerialization } from 'cerialize';
|
||||
import { mapsTo } from '../builders/build-decorators';
|
||||
import { NormalizedDSpaceObject } from './normalized-dspace-object.model';
|
||||
import { License } from '../../shared/license.model';
|
||||
|
||||
/**
|
||||
* Normalized model class for a Collection License
|
||||
*/
|
||||
@mapsTo(License)
|
||||
@inheritSerialization(NormalizedDSpaceObject)
|
||||
export class NormalizedLicense extends NormalizedDSpaceObject<License> {
|
||||
|
||||
/**
|
||||
* A boolean representing if this License is custom or not
|
||||
*/
|
||||
@autoserialize
|
||||
custom: boolean;
|
||||
|
||||
/**
|
||||
* The text of the license
|
||||
*/
|
||||
@autoserialize
|
||||
text: string;
|
||||
}
|
@@ -22,5 +22,5 @@ export abstract class NormalizedObject<T extends TypedObject> implements Cacheab
|
||||
* A string representing the kind of object
|
||||
*/
|
||||
@deserialize
|
||||
type: string;
|
||||
type: ResourceType;
|
||||
}
|
||||
|
@@ -1,48 +0,0 @@
|
||||
import { autoserialize, autoserializeAs, inheritSerialization } from 'cerialize';
|
||||
import { ResourcePolicy } from '../../shared/resource-policy.model';
|
||||
|
||||
import { mapsTo } from '../builders/build-decorators';
|
||||
import { NormalizedObject } from './normalized-object.model';
|
||||
import { IDToUUIDSerializer } from '../id-to-uuid-serializer';
|
||||
import { ActionType } from './action-type.model';
|
||||
|
||||
/**
|
||||
* Normalized model class for a Resource Policy
|
||||
*/
|
||||
@mapsTo(ResourcePolicy)
|
||||
@inheritSerialization(NormalizedObject)
|
||||
export class NormalizedResourcePolicy extends NormalizedObject<ResourcePolicy> {
|
||||
/**
|
||||
* The action that is allowed by this Resource Policy
|
||||
*/
|
||||
@autoserialize
|
||||
action: ActionType;
|
||||
|
||||
/**
|
||||
* The name for this Resource Policy
|
||||
*/
|
||||
@autoserialize
|
||||
name: string;
|
||||
|
||||
/**
|
||||
* The uuid of the Group this Resource Policy applies to
|
||||
*/
|
||||
@autoserialize
|
||||
groupUUID: string;
|
||||
|
||||
/**
|
||||
* Identifier for this Resource Policy
|
||||
* Note that this ID is unique for resource policies,
|
||||
* but might not be unique across different object types
|
||||
*/
|
||||
@autoserialize
|
||||
id: string;
|
||||
|
||||
/**
|
||||
* The universally unique identifier for this Resource Policy
|
||||
* Consist of a prefix and the id field to ensure the identifier is unique across all object types
|
||||
*/
|
||||
@autoserializeAs(new IDToUUIDSerializer('resource-policy'), 'id')
|
||||
uuid: string;
|
||||
|
||||
}
|
@@ -1,13 +0,0 @@
|
||||
import { inheritSerialization } from 'cerialize';
|
||||
import { NormalizedDSpaceObject } from './normalized-dspace-object.model';
|
||||
import { mapsTo } from '../builders/build-decorators';
|
||||
import { Site } from '../../shared/site.model';
|
||||
|
||||
/**
|
||||
* Normalized model class for a Site object
|
||||
*/
|
||||
@mapsTo(Site)
|
||||
@inheritSerialization(NormalizedDSpaceObject)
|
||||
export class NormalizedSite extends NormalizedDSpaceObject<Site> {
|
||||
|
||||
}
|
8
src/app/core/cache/object-cache.reducer.ts
vendored
8
src/app/core/cache/object-cache.reducer.ts
vendored
@@ -1,5 +1,7 @@
|
||||
import { autoserialize, deserialize } from 'cerialize';
|
||||
import { HALLink } from '../shared/hal-link.model';
|
||||
import { HALResource } from '../shared/hal-resource.model';
|
||||
import { excludeFromEquals } from '../utilities/equals.decorators';
|
||||
import {
|
||||
ObjectCacheAction,
|
||||
ObjectCacheActionTypes,
|
||||
@@ -36,6 +38,7 @@ export interface Patch {
|
||||
|
||||
export abstract class TypedObject {
|
||||
static type: ResourceType;
|
||||
type: ResourceType;
|
||||
}
|
||||
|
||||
/* tslint:disable:max-classes-per-file */
|
||||
@@ -47,7 +50,6 @@ export abstract class TypedObject {
|
||||
export class CacheableObject extends TypedObject implements HALResource {
|
||||
uuid?: string;
|
||||
handle?: string;
|
||||
self: string;
|
||||
|
||||
_links: {
|
||||
self: HALLink;
|
||||
@@ -135,9 +137,9 @@ export function objectCacheReducer(state = initialState, action: ObjectCacheActi
|
||||
* the new state, with the object added, or overwritten.
|
||||
*/
|
||||
function addToObjectCache(state: ObjectCacheState, action: AddToObjectCacheAction): ObjectCacheState {
|
||||
const existing = state[action.payload.objectToCache.self];
|
||||
const existing = state[action.payload.objectToCache._links.self.href];
|
||||
return Object.assign({}, state, {
|
||||
[action.payload.objectToCache.self]: {
|
||||
[action.payload.objectToCache._links.self.href]: {
|
||||
data: action.payload.objectToCache,
|
||||
timeAdded: action.payload.timeAdded,
|
||||
msToLive: action.payload.msToLive,
|
||||
|
@@ -6,7 +6,6 @@ import { first } from 'rxjs/operators';
|
||||
import { CoreState } from '../core.reducers';
|
||||
import { RestRequestMethod } from '../data/rest-request-method';
|
||||
import { Item } from '../shared/item.model';
|
||||
import { NormalizedItem } from './models/normalized-item.model';
|
||||
import {
|
||||
AddPatchObjectCacheAction,
|
||||
AddToObjectCacheAction,
|
||||
@@ -95,7 +94,7 @@ describe('ObjectCacheService', () => {
|
||||
service.getObjectBySelfLink(selfLink).pipe(first()).subscribe((o) => {
|
||||
expect(o.self).toBe(selfLink);
|
||||
// this only works if testObj is an instance of TestClass
|
||||
expect(o instanceof NormalizedItem).toBeTruthy();
|
||||
expect(o instanceof Item).toBeTruthy();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
5
src/app/core/cache/object-cache.service.ts
vendored
5
src/app/core/cache/object-cache.service.ts
vendored
@@ -116,6 +116,9 @@ export class ObjectCacheService {
|
||||
),
|
||||
map((entry: ObjectCacheEntry) => {
|
||||
const type: GenericConstructor<NormalizedObject<T>> = getMapsToType((entry.data as any).type);
|
||||
if (typeof type !== 'function') {
|
||||
throw new Error(`${type} is not a valid constructor for ${JSON.stringify(entry.data)}`);
|
||||
}
|
||||
return Object.assign(new type(), entry.data) as NormalizedObject<T>
|
||||
})
|
||||
);
|
||||
@@ -259,7 +262,7 @@ export class ObjectCacheService {
|
||||
const timeOutdated = entry.timeAdded + entry.msToLive;
|
||||
const isOutDated = new Date().getTime() > timeOutdated;
|
||||
if (isOutDated) {
|
||||
this.store.dispatch(new RemoveFromObjectCacheAction(entry.data.self));
|
||||
this.store.dispatch(new RemoveFromObjectCacheAction(entry.data._links.self.href));
|
||||
}
|
||||
return !isOutDated;
|
||||
}
|
||||
|
4
src/app/core/cache/response.models.ts
vendored
4
src/app/core/cache/response.models.ts
vendored
@@ -1,4 +1,5 @@
|
||||
import { SearchQueryResponse } from '../../shared/search/search-query-response.model';
|
||||
import { AuthStatus } from '../auth/models/auth-status.model';
|
||||
import { RequestError } from '../data/request.models';
|
||||
import { PageInfo } from '../shared/page-info.model';
|
||||
import { ConfigObject } from '../config/models/config.model';
|
||||
@@ -11,7 +12,6 @@ import { RegistryBitstreamformatsResponse } from '../registry/registry-bitstream
|
||||
import { PaginatedList } from '../data/paginated-list';
|
||||
import { SubmissionObject } from '../submission/models/submission-object.model';
|
||||
import { DSpaceObject } from '../shared/dspace-object.model';
|
||||
import { NormalizedAuthStatus } from '../auth/models/normalized-auth-status.model';
|
||||
import { MetadataSchema } from '../metadata/metadata-schema.model';
|
||||
import { MetadataField } from '../metadata/metadata-field.model';
|
||||
import { ContentSource } from '../shared/content-source.model';
|
||||
@@ -203,7 +203,7 @@ export class AuthStatusResponse extends RestResponse {
|
||||
public toCache = false;
|
||||
|
||||
constructor(
|
||||
public response: NormalizedAuthStatus,
|
||||
public response: AuthStatus,
|
||||
public statusCode: number,
|
||||
public statusText: string,
|
||||
) {
|
||||
|
@@ -18,7 +18,7 @@ import { RequestService } from '../data/request.service';
|
||||
import { PutRequest } from '../data/request.models';
|
||||
import { ObjectCacheService } from './object-cache.service';
|
||||
import { ApplyPatchObjectCacheAction } from './object-cache.actions';
|
||||
import { DSpaceRESTv2Serializer } from '../dspace-rest-v2/dspace-rest-v2.serializer';
|
||||
import { NormalizedObjectSerializer } from '../dspace-rest-v2/normalized-object.serializer';
|
||||
import { GenericConstructor } from '../shared/generic-constructor';
|
||||
import { hasValue, isNotEmpty, isNotUndefined } from '../../shared/empty.util';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
@@ -100,7 +100,7 @@ export class ServerSyncBufferEffects {
|
||||
|
||||
return patchObject.pipe(
|
||||
map((object) => {
|
||||
const serializedObject = new DSpaceRESTv2Serializer(object.constructor as GenericConstructor<{}>).serialize(object);
|
||||
const serializedObject = new NormalizedObjectSerializer(object.constructor as GenericConstructor<{}>).serialize(object);
|
||||
|
||||
this.requestService.configure(new PutRequest(this.requestService.generateRequestId(), href, serializedObject));
|
||||
|
||||
|
Reference in New Issue
Block a user