mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Merge remote-tracking branch 'origin/main' into upgrade_angular10
# Conflicts: # src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.spec.ts # src/app/+admin/admin-access-control/epeople-registry/epeople-registry.component.ts # src/app/+admin/admin-access-control/epeople-registry/eperson-form/eperson-form.component.spec.ts # src/app/+admin/admin-access-control/group-registry/group-form/group-form.component.spec.ts # src/app/+admin/admin-access-control/group-registry/group-form/members-list/members-list.component.spec.ts # src/app/+admin/admin-access-control/group-registry/group-form/subgroup-list/subgroups-list.component.spec.ts # src/app/+admin/admin-access-control/group-registry/groups-registry.component.ts # src/app/+admin/admin-import-metadata-page/metadata-import-page.component.ts # src/app/+admin/admin-registries/metadata-registry/metadata-registry.component.ts # src/app/+admin/admin-registries/metadata-schema/metadata-schema.component.ts # src/app/+admin/admin-search-page/admin-search-results/admin-search-result-grid-element/item-search-result/item-admin-search-result-grid-element.component.spec.ts # src/app/+admin/admin-search-page/admin-search-results/admin-search-result-list-element/item-search-result/item-admin-search-result-list-element.component.spec.ts # src/app/+bitstream-page/bitstream-page.resolver.ts # src/app/+bitstream-page/edit-bitstream-page/edit-bitstream-page.component.spec.ts # src/app/+bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts # src/app/+collection-page/collection-item-mapper/collection-item-mapper.component.ts # src/app/+collection-page/collection-page.component.ts # src/app/+collection-page/edit-collection-page/collection-roles/collection-roles.component.ts # src/app/+collection-page/edit-item-template-page/item-template-page.resolver.spec.ts # src/app/+collection-page/edit-item-template-page/item-template-page.resolver.ts # src/app/+item-page/edit-item-page/item-authorizations/item-authorizations.component.ts # src/app/+item-page/edit-item-page/item-bitstreams/item-bitstreams.component.spec.ts # src/app/+item-page/edit-item-page/item-bitstreams/item-bitstreams.component.ts # src/app/+item-page/edit-item-page/item-collection-mapper/item-collection-mapper.component.ts # src/app/+item-page/edit-item-page/item-private/item-private.component.ts # src/app/+item-page/edit-item-page/item-public/item-public.component.ts # src/app/+item-page/edit-item-page/item-reinstate/item-reinstate.component.ts # src/app/+item-page/edit-item-page/item-relationships/edit-relationship-list/edit-relationship-list.component.ts # src/app/+item-page/edit-item-page/item-relationships/item-relationships.component.ts # src/app/+item-page/edit-item-page/item-withdraw/item-withdraw.component.ts # src/app/+item-page/simple/item-types/shared/item-relationships-utils.ts # src/app/+my-dspace-page/collection-selector/collection-selector.component.spec.ts # src/app/+search-page/search-tracker.component.ts # src/app/app-routing.module.ts # src/app/community-list-page/community-list-service.ts # src/app/community-list-page/community-list.reducer.spec.ts # src/app/core/auth/auth-response-parsing.service.spec.ts # src/app/core/auth/auth.interceptor.spec.ts # src/app/core/browse/browse.service.spec.ts # src/app/core/browse/browse.service.ts # src/app/core/cache/builders/link.service.spec.ts # src/app/core/cache/builders/remote-data-build.service.ts # src/app/core/cache/object-cache.service.spec.ts # src/app/core/cache/response.models.ts # src/app/core/data/base-response-parsing.service.ts # src/app/core/data/bitstream-data.service.ts # src/app/core/data/bitstream-format-data.service.ts # src/app/core/data/bundle-data.service.spec.ts # src/app/core/data/bundle-data.service.ts # src/app/core/data/change-analyzer.ts # src/app/core/data/collection-data.service.spec.ts # src/app/core/data/collection-data.service.ts # src/app/core/data/comcol-data.service.spec.ts # src/app/core/data/comcol-data.service.ts # src/app/core/data/data.service.ts # src/app/core/data/entity-type-data.service.ts # src/app/core/data/entity-type.service.ts # src/app/core/data/feature-authorization/authorization-data.service.ts # src/app/core/data/feature-authorization/feature-data.service.ts # src/app/core/data/item-template-data.service.ts # src/app/core/data/license-data.service.ts # src/app/core/data/metadata-field-data.service.ts # src/app/core/data/processes/process-data.service.ts # src/app/core/data/processes/script-data.service.ts # src/app/core/data/relationship.service.spec.ts # src/app/core/data/relationship.service.ts # src/app/core/data/remote-data.ts # src/app/core/data/request.actions.ts # src/app/core/data/request.effects.ts # src/app/core/data/request.reducer.spec.ts # src/app/core/data/request.reducer.ts # src/app/core/data/request.service.spec.ts # src/app/core/data/request.service.ts # src/app/core/dspace-rest/dspace-rest.service.spec.ts # src/app/core/eperson/eperson-data.service.spec.ts # src/app/core/eperson/eperson-data.service.ts # src/app/core/eperson/group-data.service.spec.ts # src/app/core/eperson/group-data.service.ts # src/app/core/forward-client-ip/forward-client-ip.interceptor.spec.ts # src/app/core/index/index.reducer.ts # src/app/core/json-patch/json-patch-operations.service.spec.ts # src/app/core/json-patch/json-patch-operations.service.ts # src/app/core/locale/locale.interceptor.spec.ts # src/app/core/registry/registry.service.ts # src/app/core/resource-policy/resource-policy.service.ts # src/app/core/shared/operators.ts # src/app/core/shared/search/search.service.ts # src/app/core/submission/submission-object-data.service.ts # src/app/core/submission/submission-rest.service.ts # src/app/core/submission/vocabularies/vocabulary-entries-response-parsing.service.spec.ts # src/app/core/submission/vocabularies/vocabulary.service.spec.ts # src/app/core/submission/vocabularies/vocabulary.service.ts # src/app/core/submission/workflowitem-data.service.ts # src/app/core/tasks/tasks.service.ts # src/app/curation-form/curation-form.component.ts # src/app/process-page/process-page.resolver.ts # src/app/shared/collection-dropdown/collection-dropdown.component.spec.ts # src/app/shared/collection-dropdown/collection-dropdown.component.ts # src/app/shared/comcol-forms/create-comcol-page/create-comcol-page.component.spec.ts # src/app/shared/comcol-forms/create-comcol-page/create-comcol-page.component.ts # src/app/shared/comcol-forms/edit-comcol-page/comcol-metadata/comcol-metadata.component.spec.ts # src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.spec.ts # src/app/shared/comcol-forms/edit-comcol-page/comcol-role/comcol-role.component.ts # src/app/shared/dso-selector/dso-selector/dso-selector.component.ts # src/app/shared/dso-selector/modal-wrappers/export-metadata-selector/export-metadata-selector.component.ts # src/app/shared/form/builder/ds-dynamic-form-ui/relation-lookup-modal/relationship.effects.ts # src/app/shared/form/builder/form-builder.service.ts # src/app/shared/item/item-versions/item-versions.component.ts # src/app/shared/mocks/remote-data-build.service.mock.ts # src/app/shared/mydspace-actions/workspaceitem/workspaceitem-actions.component.ts # src/app/shared/object-detail/my-dspace-result-detail-element/item-detail-preview/item-detail-preview.component.spec.ts # src/app/shared/object-select/collection-select/collection-select.component.spec.ts # src/app/shared/object-select/item-select/item-select.component.spec.ts # src/app/shared/pagination-drag-and-drop/abstract-paginated-drag-and-drop-list.component.spec.ts # src/app/shared/pagination-drag-and-drop/abstract-paginated-drag-and-drop-list.component.ts # src/app/shared/resource-policies/form/eperson-group-list/eperson-group-list.component.ts # src/app/shared/search/search-query-response.model.ts # src/app/statistics/statistics.module.ts # src/app/submission/import-external/import-external-searchbar/submission-import-external-searchbar.component.spec.ts # src/app/submission/sections/form/section-form.component.ts # src/app/submission/sections/upload/section-upload.component.spec.ts # src/app/submission/sections/upload/section-upload.component.ts # src/app/submission/submission.service.spec.ts # src/app/submission/submission.service.ts
This commit is contained in:
154
src/app/core/cache/object-cache.service.ts
vendored
154
src/app/core/cache/object-cache.service.ts
vendored
@@ -1,14 +1,17 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { createSelector, MemoizedSelector, select, Store } from '@ngrx/store';
|
||||
import { applyPatch, Operation } from 'fast-json-patch';
|
||||
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
|
||||
import { combineLatest as observableCombineLatest, Observable, of as observableOf } from 'rxjs';
|
||||
|
||||
import { distinctUntilChanged, filter, map, mergeMap, take, } from 'rxjs/operators';
|
||||
import { hasNoValue, isNotEmpty } from '../../shared/empty.util';
|
||||
import { distinctUntilChanged, filter, map, mergeMap, switchMap, take } from 'rxjs/operators';
|
||||
import { hasValue, isNotEmpty, isEmpty } from '../../shared/empty.util';
|
||||
import { CoreState } from '../core.reducers';
|
||||
import { coreSelector } from '../core.selectors';
|
||||
import { RestRequestMethod } from '../data/rest-request-method';
|
||||
import { selfLinkFromUuidSelector } from '../index/index.selectors';
|
||||
import {
|
||||
selfLinkFromAlternativeLinkSelector,
|
||||
selfLinkFromUuidSelector
|
||||
} from '../index/index.selectors';
|
||||
import { GenericConstructor } from '../shared/generic-constructor';
|
||||
import { getClassForType } from './builders/build-decorators';
|
||||
import { LinkService } from './builders/link.service';
|
||||
@@ -21,6 +24,9 @@ import {
|
||||
|
||||
import { CacheableObject, ObjectCacheEntry, ObjectCacheState } from './object-cache.reducer';
|
||||
import { AddToSSBAction } from './server-sync-buffer.actions';
|
||||
import { RemoveFromIndexBySubstringAction } from '../index/index.actions';
|
||||
import { IndexName } from '../index/index.reducer';
|
||||
import { HALLink } from '../shared/hal-link.model';
|
||||
|
||||
/**
|
||||
* The base selector function to select the object cache in the store
|
||||
@@ -60,10 +66,12 @@ export class ObjectCacheService {
|
||||
* The number of milliseconds it should be cached for
|
||||
* @param requestUUID
|
||||
* The UUID of the request that resulted in this object
|
||||
* @param alternativeLink
|
||||
* An optional alternative link to this object
|
||||
*/
|
||||
add(object: CacheableObject, msToLive: number, requestUUID: string): void {
|
||||
add(object: CacheableObject, msToLive: number, requestUUID: string, alternativeLink?: string): void {
|
||||
object = this.linkService.removeResolvedLinks(object); // Ensure the object we're storing has no resolved links
|
||||
this.store.dispatch(new AddToObjectCacheAction(object, new Date().getTime(), msToLive, requestUUID));
|
||||
this.store.dispatch(new AddToObjectCacheAction(object, new Date().getTime(), msToLive, requestUUID, alternativeLink));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,9 +81,33 @@ export class ObjectCacheService {
|
||||
* The unique href of the object to be removed
|
||||
*/
|
||||
remove(href: string): void {
|
||||
this.removeRelatedLinksFromIndex(href);
|
||||
this.store.dispatch(new RemoveFromObjectCacheAction(href));
|
||||
}
|
||||
|
||||
private removeRelatedLinksFromIndex(href: string) {
|
||||
const cacheEntry$ = this.getByHref(href);
|
||||
const altLinks$ = cacheEntry$.pipe(map((entry: ObjectCacheEntry) => entry.alternativeLinks), take(1));
|
||||
const childLinks$ = cacheEntry$.pipe(map((entry: ObjectCacheEntry) => {
|
||||
return Object
|
||||
.entries(entry.data._links)
|
||||
.filter(([key, value]: [string, HALLink]) => key !== 'self')
|
||||
.map(([key, value]: [string, HALLink]) => value.href);
|
||||
}),
|
||||
take(1)
|
||||
);
|
||||
this.removeLinksFromAlternativeLinkIndex(altLinks$);
|
||||
this.removeLinksFromAlternativeLinkIndex(childLinks$);
|
||||
|
||||
}
|
||||
|
||||
private removeLinksFromAlternativeLinkIndex(links$: Observable<string[]>) {
|
||||
links$.subscribe((links: string[]) => links.forEach((link: string) => {
|
||||
this.store.dispatch(new RemoveFromIndexBySubstringAction(IndexName.ALTERNATIVE_OBJECT_LINK, link));
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an observable of the object with the specified UUID
|
||||
*
|
||||
@@ -88,7 +120,7 @@ export class ObjectCacheService {
|
||||
Observable<T> {
|
||||
return this.store.pipe(
|
||||
select(selfLinkFromUuidSelector(uuid)),
|
||||
mergeMap((selfLink: string) => this.getObjectBySelfLink<T>(selfLink)
|
||||
mergeMap((selfLink: string) => this.getObjectByHref<T>(selfLink)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -96,13 +128,13 @@ export class ObjectCacheService {
|
||||
/**
|
||||
* Get an observable of the object with the specified selfLink
|
||||
*
|
||||
* @param selfLink
|
||||
* The selfLink of the object to get
|
||||
* @param href
|
||||
* The href of the object to get
|
||||
* @return Observable<T>
|
||||
* An observable of the requested object
|
||||
*/
|
||||
getObjectBySelfLink<T extends CacheableObject>(selfLink: string): Observable<T> {
|
||||
return this.getBySelfLink(selfLink).pipe(
|
||||
getObjectByHref<T extends CacheableObject>(href: string): Observable<T> {
|
||||
return this.getByHref(href).pipe(
|
||||
map((entry: ObjectCacheEntry) => {
|
||||
if (isNotEmpty(entry.patches)) {
|
||||
const flatPatch: Operation[] = [].concat(...entry.patches.map((patch) => patch.operations));
|
||||
@@ -126,16 +158,31 @@ export class ObjectCacheService {
|
||||
/**
|
||||
* Get an observable of the object cache entry with the specified selfLink
|
||||
*
|
||||
* @param selfLink
|
||||
* The selfLink of the object to get
|
||||
* @param href
|
||||
* The href of the object to get
|
||||
* @return Observable<ObjectCacheEntry>
|
||||
* An observable of the requested object cache entry
|
||||
*/
|
||||
getBySelfLink(selfLink: string): Observable<ObjectCacheEntry> {
|
||||
getByHref(href: string): Observable<ObjectCacheEntry> {
|
||||
return observableCombineLatest([
|
||||
this.getByAlternativeLink(href),
|
||||
this.getBySelfLink(href),
|
||||
]).pipe(
|
||||
map((results: ObjectCacheEntry[]) => results.find((entry: ObjectCacheEntry) => hasValue(entry))),
|
||||
filter((entry: ObjectCacheEntry) => hasValue(entry))
|
||||
);
|
||||
}
|
||||
|
||||
private getBySelfLink(selfLink: string): Observable<ObjectCacheEntry> {
|
||||
return this.store.pipe(
|
||||
select(entryFromSelfLinkSelector(selfLink)),
|
||||
filter((entry) => this.isValid(entry)),
|
||||
distinctUntilChanged()
|
||||
select(entryFromSelfLinkSelector(selfLink))
|
||||
);
|
||||
}
|
||||
|
||||
private getByAlternativeLink(alternativeLink: string): Observable<ObjectCacheEntry> {
|
||||
return this.store.pipe(
|
||||
select(selfLinkFromAlternativeLinkSelector(alternativeLink)),
|
||||
switchMap((selfLink) => this.getBySelfLink(selfLink)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -148,7 +195,7 @@ export class ObjectCacheService {
|
||||
* An observable of the request's uuid
|
||||
*/
|
||||
getRequestUUIDBySelfLink(selfLink: string): Observable<string> {
|
||||
return this.getBySelfLink(selfLink).pipe(
|
||||
return this.getByHref(selfLink).pipe(
|
||||
map((entry: ObjectCacheEntry) => entry.requestUUID),
|
||||
distinctUntilChanged());
|
||||
}
|
||||
@@ -188,9 +235,13 @@ export class ObjectCacheService {
|
||||
* @return Observable<Array<T>>
|
||||
*/
|
||||
getList<T extends CacheableObject>(selfLinks: string[]): Observable<T[]> {
|
||||
return observableCombineLatest(
|
||||
selfLinks.map((selfLink: string) => this.getObjectBySelfLink<T>(selfLink))
|
||||
);
|
||||
if (isEmpty(selfLinks)) {
|
||||
return observableOf([]);
|
||||
} else {
|
||||
return observableCombineLatest(
|
||||
selfLinks.map((selfLink: string) => this.getObjectByHref<T>(selfLink))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -209,64 +260,49 @@ export class ObjectCacheService {
|
||||
this.store.pipe(
|
||||
select(selfLinkFromUuidSelector(uuid)),
|
||||
take(1)
|
||||
).subscribe((selfLink: string) => result = this.hasBySelfLink(selfLink));
|
||||
).subscribe((selfLink: string) => result = this.hasByHref(selfLink));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the object with the specified self link is cached
|
||||
* Check whether the object with the specified self link is cached. Note that it doesn't check
|
||||
* whether the response this object came in on is still valid. Just whether it exists.
|
||||
*
|
||||
* @param selfLink
|
||||
* The self link of the object to check
|
||||
* @param href
|
||||
* The href of the object to check
|
||||
* @param requestUUID
|
||||
* Optional. If the object exists, check whether it links back to this requestUUID
|
||||
* @return boolean
|
||||
* true if the object with the specified self link is cached,
|
||||
* true if the object with the specified href is cached,
|
||||
* false otherwise
|
||||
*/
|
||||
hasBySelfLink(selfLink: string): boolean {
|
||||
hasByHref(href: string, requestUUID?: string): boolean {
|
||||
let result = false;
|
||||
|
||||
this.store.pipe(select(entryFromSelfLinkSelector(selfLink)),
|
||||
take(1)
|
||||
).subscribe((entry: ObjectCacheEntry) => result = this.isValid(entry));
|
||||
|
||||
this.getByHref(href).subscribe((entry: ObjectCacheEntry) => {
|
||||
if (isNotEmpty(requestUUID)) {
|
||||
result = entry.requestUUID === requestUUID;
|
||||
} else {
|
||||
result = true;
|
||||
}
|
||||
}).unsubscribe();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an observable that emits a new value whenever the availability of the cached object changes.
|
||||
* The value it emits is a boolean stating if the object exists in cache or not.
|
||||
* @param selfLink The self link of the object to observe
|
||||
* @param href The self link of the object to observe
|
||||
*/
|
||||
hasBySelfLinkObservable(selfLink: string): Observable<boolean> {
|
||||
return this.store.pipe(
|
||||
select(entryFromSelfLinkSelector(selfLink)),
|
||||
map((entry: ObjectCacheEntry) => this.isValid(entry))
|
||||
hasByHref$(href: string): Observable<boolean> {
|
||||
return observableCombineLatest(
|
||||
this.getBySelfLink(href),
|
||||
this.getByAlternativeLink(href)
|
||||
).pipe(
|
||||
map((entries: ObjectCacheEntry[]) => entries.some((entry) => hasValue(entry)))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether an ObjectCacheEntry should still be cached
|
||||
*
|
||||
* @param entry
|
||||
* the entry to check
|
||||
* @return boolean
|
||||
* false if the entry is null, undefined, or its time to
|
||||
* live has been exceeded, true otherwise
|
||||
*/
|
||||
private isValid(entry: ObjectCacheEntry): boolean {
|
||||
if (hasNoValue(entry)) {
|
||||
return false;
|
||||
} else {
|
||||
const timeOutdated = entry.timeAdded + entry.msToLive;
|
||||
const isOutDated = new Date().getTime() > timeOutdated;
|
||||
if (isOutDated) {
|
||||
this.store.dispatch(new RemoveFromObjectCacheAction(entry.data._links.self.href));
|
||||
}
|
||||
return !isOutDated;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add operations to the existing list of operations for an ObjectCacheEntry
|
||||
* Makes sure the ServerSyncBuffer for this ObjectCacheEntry is updated
|
||||
|
Reference in New Issue
Block a user