Skip to content

Commit

Permalink
Merge pull request DSpace#2875 from alexandrevryghem/created-metadata…
Browse files Browse the repository at this point in the history
…-service-for-metadata-operations_contribute-main

Moved MetadataValue methods to separate service
  • Loading branch information
tdonohue authored May 8, 2024
2 parents b406e71 + 36e5617 commit ceca3bf
Show file tree
Hide file tree
Showing 22 changed files with 1,148 additions and 1,171 deletions.
6 changes: 3 additions & 3 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { BreadcrumbsService } from './breadcrumbs/breadcrumbs.service';
import { authReducer } from './core/auth/auth.reducer';
import { AuthService } from './core/auth/auth.service';
import { LocaleService } from './core/locale/locale.service';
import { MetadataService } from './core/metadata/metadata.service';
import { HeadTagService } from './core/metadata/head-tag.service';
import { RouteService } from './core/services/route.service';
import {
NativeWindowRef,
Expand All @@ -42,7 +42,7 @@ import { MenuService } from './shared/menu/menu.service';
import { MockActivatedRoute } from './shared/mocks/active-router.mock';
import { AngularticsProviderMock } from './shared/mocks/angulartics-provider.service.mock';
import { AuthServiceMock } from './shared/mocks/auth.service.mock';
import { MetadataServiceMock } from './shared/mocks/metadata-service.mock';
import { HeadTagServiceMock } from './shared/mocks/head-tag-service.mock';
import { RouterMock } from './shared/mocks/router.mock';
import { getMockThemeService } from './shared/mocks/theme-service.mock';
import { TranslateLoaderMock } from './shared/mocks/translate-loader.mock';
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('App component', () => {
],
providers: [
{ provide: NativeWindowService, useValue: new NativeWindowRef() },
{ provide: MetadataService, useValue: new MetadataServiceMock() },
{ provide: HeadTagService, useValue: new HeadTagServiceMock() },
{ provide: Angulartics2DSpace, useValue: new AngularticsProviderMock() },
{ provide: AuthService, useValue: new AuthServiceMock() },
{ provide: Router, useValue: new RouterMock() },
Expand Down
37 changes: 23 additions & 14 deletions src/app/core/data/relationship-data.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { TestBed } from '@angular/core/testing';
import { Store } from '@ngrx/store';
import { provideMockStore } from '@ngrx/store/testing';
import { of as observableOf } from 'rxjs';

import { PAGINATED_RELATIONS_TO_ITEMS_OPERATOR } from '../../item-page/simple/item-types/shared/item-relationships-utils';
import { getMockRemoteDataBuildServiceHrefMap } from '../../shared/mocks/remote-data-build.service.mock';
import { getMockRequestService } from '../../shared/mocks/request.service.mock';
import {
Expand All @@ -11,7 +15,9 @@ import { HALEndpointServiceStub } from '../../shared/testing/hal-endpoint-servic
import { ObjectCacheServiceStub } from '../../shared/testing/object-cache-service.stub';
import { createPaginatedList } from '../../shared/testing/utils.test';
import { followLink } from '../../shared/utils/follow-link-config.model';
import { RemoteDataBuildService } from '../cache/builders/remote-data-build.service';
import { ObjectCacheService } from '../cache/object-cache.service';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { Item } from '../shared/item.model';
import { Relationship } from '../shared/item-relationships/relationship.model';
import { RelationshipType } from '../shared/item-relationships/relationship-type.model';
Expand All @@ -20,6 +26,7 @@ import { MetadataRepresentationType } from '../shared/metadata-representation/me
import { PageInfo } from '../shared/page-info.model';
import { testSearchDataImplementation } from './base/search-data.spec';
import { FindListOptions } from './find-list-options.model';
import { ItemDataService } from './item-data.service';
import { buildPaginatedList } from './paginated-list.model';
import { RelationshipDataService } from './relationship-data.service';
import { DeleteRequest } from './request.models';
Expand Down Expand Up @@ -123,18 +130,6 @@ describe('RelationshipDataService', () => {
findByHref: createSuccessfulRemoteDataObject$(relatedItems[0]),
});

function initTestService() {
return new RelationshipDataService(
requestService,
rdbService,
halService,
objectCache as ObjectCacheService,
itemService,
null,
jasmine.createSpy('paginatedRelationsToItems').and.returnValue((v) => v),
);
}

const getRequestEntry$ = (successful: boolean) => {
return observableOf({
response: { isSuccessful: successful, payload: relationships } as any,
Expand All @@ -143,11 +138,25 @@ describe('RelationshipDataService', () => {

beforeEach(() => {
requestService = getMockRequestService(getRequestEntry$(true));
service = initTestService();

TestBed.configureTestingModule({
providers: [
{ provide: RequestService, useValue: requestService },
{ provide: RemoteDataBuildService, useValue: rdbService },
{ provide: HALEndpointService, useValue: halService },
{ provide: ObjectCacheService, useValue: objectCache },
{ provide: ItemDataService, useValue: itemService },
{ provide: RequestService, useValue: requestService },
{ provide: PAGINATED_RELATIONS_TO_ITEMS_OPERATOR, useValue: jasmine.createSpy('paginatedRelationsToItems').and.returnValue((v) => v) },
{ provide: Store, useValue: provideMockStore() },
RelationshipDataService,
],
});
service = TestBed.inject(RelationshipDataService);
});

describe('composition', () => {
const initService = () => new RelationshipDataService(null, null, null, null, null, null, null);
const initService = () => new RelationshipDataService(null, null, null, null, null, null, null, null);

testSearchDataImplementation(initService);
});
Expand Down
6 changes: 4 additions & 2 deletions src/app/core/data/relationship-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { RemoteDataBuildService } from '../cache/builders/remote-data-build.serv
import { RequestParam } from '../cache/models/request-param.model';
import { ObjectCacheService } from '../cache/object-cache.service';
import { HttpOptions } from '../dspace-rest/dspace-rest.service';
import { MetadataService } from '../metadata/metadata.service';
import { DSpaceObject } from '../shared/dspace-object.model';
import { HALEndpointService } from '../shared/hal-endpoint.service';
import { Item } from '../shared/item.model';
Expand Down Expand Up @@ -128,6 +129,7 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
protected rdbService: RemoteDataBuildService,
protected halService: HALEndpointService,
protected objectCache: ObjectCacheService,
protected metadataService: MetadataService,
protected itemService: ItemDataService,
protected appStore: Store<AppState>,
@Inject(PAGINATED_RELATIONS_TO_ITEMS_OPERATOR) private paginatedRelationsToItems: (thisId: string) => (source: Observable<RemoteData<PaginatedList<Relationship>>>) => Observable<RemoteData<PaginatedList<Item>>>,
Expand Down Expand Up @@ -602,8 +604,8 @@ export class RelationshipDataService extends IdentifiableDataService<Relationshi
* @param itemType The type of item this metadata value represents (will only be used when no related item can be found, as a fallback)
*/
resolveMetadataRepresentation(metadatum: MetadataValue, parentItem: DSpaceObject, itemType: string): Observable<MetadataRepresentation> {
if (metadatum.isVirtual) {
return this.findById(metadatum.virtualValue, true, false, followLink('leftItem'), followLink('rightItem')).pipe(
if (this.metadataService.isVirtual(metadatum)) {
return this.findById(this.metadataService.virtualValue(metadatum), true, false, followLink('leftItem'), followLink('rightItem')).pipe(
getFirstSucceededRemoteData(),
switchMap((relRD: RemoteData<Relationship>) =>
observableCombineLatest(relRD.payload.leftItem, relRD.payload.rightItem).pipe(
Expand Down
Loading

0 comments on commit ceca3bf

Please sign in to comment.