Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-2028 (pull request DSpace#2545)
Browse files Browse the repository at this point in the history
Task/dspace cris 2023 02 x/DSC-2028

Approved-by: Giuseppe Digilio
  • Loading branch information
FrancescoMolinaro authored and atarix83 committed Nov 28, 2024
2 parents ddbd43a + 2df6906 commit 29a111a
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/app/collection-page/collection-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { RouterStub } from '../shared/testing/router.stub';
import { environment } from 'src/environments/environment.test';
import { createSuccessfulRemoteDataObject$ } from '../shared/remote-data.utils';
import { Collection } from '../core/shared/collection.model';
import { SearchService } from '../core/shared/search/search.service';
import { By } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { VarDirective } from '../shared/utils/var.directive';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { Bitstream } from '../core/shared/bitstream.model';
import { SearchManager } from '../core/browse/search-manager';

describe('CollectionPageComponent', () => {
let component: CollectionPageComponent;
Expand All @@ -33,7 +33,7 @@ describe('CollectionPageComponent', () => {
let paginationServiceSpy: jasmine.SpyObj<PaginationService>;
let authorizationDataServiceSpy: jasmine.SpyObj<AuthorizationDataService>;
let dsoNameServiceSpy: jasmine.SpyObj<DSONameService>;
let searchServiceSpy: jasmine.SpyObj<SearchService>;
let searchServiceSpy: jasmine.SpyObj<SearchManager>;
let aroute = new ActivatedRouteStub();
let router = new RouterStub();

Expand All @@ -44,7 +44,7 @@ describe('CollectionPageComponent', () => {
paginationServiceSpy = jasmine.createSpyObj('PaginationService', ['getCurrentPagination', 'getCurrentSort', 'clearPagination']);
authorizationDataServiceSpy = jasmine.createSpyObj('AuthorizationDataService', ['isAuthorized']);
collectionDataServiceSpy = jasmine.createSpyObj('CollectionDataService', ['findById', 'getAuthorizedCollection']);
searchServiceSpy = jasmine.createSpyObj('SearchService', ['search']);
searchServiceSpy = jasmine.createSpyObj('SearchManager', ['search']);
dsoNameServiceSpy = jasmine.createSpyObj('DSONameService', ['getName']);

await TestBed.configureTestingModule({
Expand All @@ -58,7 +58,7 @@ describe('CollectionPageComponent', () => {
{ provide: PaginationService, useValue: paginationServiceSpy },
{ provide: AuthorizationDataService, useValue: authorizationDataServiceSpy },
{ provide: DSONameService, useValue: dsoNameServiceSpy },
{ provide: SearchService, useValue: searchServiceSpy },
{ provide: SearchManager, useValue: searchServiceSpy },
{ provide: APP_CONFIG, useValue: environment },
{ provide: PLATFORM_ID, useValue: 'browser' },
]
Expand Down
9 changes: 3 additions & 6 deletions src/app/collection-page/collection-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subject } from 'rxjs';
import { filter, map, mergeMap, startWith, switchMap, take } from 'rxjs/operators';
import { PaginatedSearchOptions } from '../shared/search/models/paginated-search-options.model';
import { SearchService } from '../core/shared/search/search.service';
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
import { CollectionDataService } from '../core/data/collection-data.service';
import { PaginatedList } from '../core/data/paginated-list.model';
import { RemoteData } from '../core/data/remote-data';
import { Bitstream } from '../core/shared/bitstream.model';
Expand All @@ -30,6 +28,7 @@ import { redirectOn4xx } from '../core/shared/authorized.operators';
import { BROWSE_LINKS_TO_FOLLOW } from '../core/browse/browse.service';
import { DSONameService } from '../core/breadcrumbs/dso-name.service';
import { APP_CONFIG, AppConfig } from '../../../src/config/app-config.interface';
import { SearchManager } from '../core/browse/search-manager';

@Component({
selector: 'ds-collection-page',
Expand Down Expand Up @@ -64,8 +63,7 @@ export class CollectionPageComponent implements OnInit {

constructor(
@Inject(PLATFORM_ID) private platformId: Object,
private collectionDataService: CollectionDataService,
private searchService: SearchService,
private searchManager: SearchManager,
private route: ActivatedRoute,
private router: Router,
private authService: AuthService,
Expand Down Expand Up @@ -113,14 +111,13 @@ export class CollectionPageComponent implements OnInit {
getFirstSucceededRemoteData(),
map((rd) => rd.payload.id),
switchMap((id: string) => {
return this.searchService.search<Item>(
return this.searchManager.search<Item>(
new PaginatedSearchOptions({
scope: id,
pagination: currentPagination,
sort: currentSort,
dsoTypes: [DSpaceObjectType.ITEM],
forcedEmbeddedKeys: ['metrics'],
projection: 'preventMetadataSecurity'
}), null, true, true, ...BROWSE_LINKS_TO_FOLLOW)
.pipe(toDSpaceObjectListRD()) as Observable<RemoteData<PaginatedList<Item>>>;
}),
Expand Down
5 changes: 3 additions & 2 deletions src/app/core/browse/search-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class SearchManager {
* @returns {Observable<RemoteData<PaginatedList<Item>>>}
*/
getBrowseItemsFor(filterValue: string, filterAuthority: string, options: BrowseEntrySearchOptions, ...linksToFollow: FollowLinkConfig<any>[]): Observable<RemoteData<PaginatedList<Item>>> {
const browseOptions = Object.assign({}, options, { projection: 'preventMetadataSecurity' });
const browseOptions = Object.assign({}, options, { projection: options.projection ?? 'preventMetadataSecurity' });
return this.browseService.getBrowseItemsFor(filterValue, filterAuthority, browseOptions, ...linksToFollow)
.pipe(this.completeWithExtraData());
}
Expand All @@ -67,7 +67,8 @@ export class SearchManager {
useCachedVersionIfAvailable = true,
reRequestOnStale = true,
...linksToFollow: FollowLinkConfig<T>[]): Observable<RemoteData<SearchObjects<T>>> {
return this.searchService.search(searchOptions, responseMsToLive, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow)
const optionsWithDefaultProjection = Object.assign(new PaginatedSearchOptions({}), searchOptions, { projection: searchOptions.projection ?? 'preventMetadataSecurity' });
return this.searchService.search(optionsWithDefaultProjection, responseMsToLive, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow)
.pipe(this.completeSearchObjectsWithExtraData());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('CrisrefComponent', () => {
let fixture: ComponentFixture<CrisrefComponent>;

const itemService = jasmine.createSpyObj('ItemDataService', {
findById: jasmine.createSpy('findById')
findByIdWithProjections: jasmine.createSpy('findByIdWithProjections')
});
const metadataValue = Object.assign(new MetadataValue(), {
'value': 'test item title',
Expand Down Expand Up @@ -106,7 +106,7 @@ describe('CrisrefComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(CrisrefComponent);
component = fixture.componentInstance;
itemService.findById.and.returnValue(createSuccessfulRemoteDataObject$(testPerson));
itemService.findByIdWithProjections.and.returnValue(createSuccessfulRemoteDataObject$(testPerson));
fixture.detectChanges();
});

Expand Down
1 change: 0 additions & 1 deletion src/app/my-dspace-page/my-dspace-page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
[configurationList]="(configurationList$ | async)"
[context]="context"
[viewModeList]="viewModeList"
[projection]="projection"
[showThumbnails]="false"
[selectable]="(currentConfiguration$ | async) === workflowType"
[selectionConfig]="{ repeatable: true, listId: listId }"
Expand Down
4 changes: 0 additions & 4 deletions src/app/my-dspace-page/my-dspace-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ export class MyDSpacePageComponent implements OnInit {
*/
roleTypeEnum = RoleType;

/**
* Projection to use during the search
*/
projection = 'preventMetadataSecurity';

/**
* List of available view mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { CollectionElementLinkType } from '../object-collection/collection-eleme
import { Component, Input, OnChanges, OnInit, PLATFORM_ID, inject } from '@angular/core';
import { isPlatformServer } from '@angular/common';

import { SearchService } from '../../core/shared/search/search.service';
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
import { DSpaceObject } from '../../core/shared/dspace-object.model';
import { SearchResult } from '../search/models/search-result.model';
Expand All @@ -21,6 +20,7 @@ import { BehaviorSubject, Observable, mergeMap } from 'rxjs';
import { Item } from '../../core/shared/item.model';
import { getItemPageRoute } from '../../item-page/item-page-routing-paths';
import { TopSection } from '../../core/layout/models/section.model';
import { SearchManager } from '../../core/browse/search-manager';

@Component({
template: ''
Expand All @@ -29,7 +29,7 @@ export abstract class AbstractBrowseElementsComponent implements OnInit, OnChang

protected readonly appConfig = inject(APP_CONFIG);
protected readonly platformId = inject(PLATFORM_ID);
protected readonly searchService = inject(SearchService);
protected readonly searchManager = inject(SearchManager);

protected abstract followMetricsLink: boolean; // to be overridden
protected abstract followThumbnailLink: boolean; // to be overridden
Expand All @@ -47,7 +47,7 @@ export abstract class AbstractBrowseElementsComponent implements OnInit, OnChang
/**
* Optional projection to use during the search
*/
@Input() projection = 'preventMetadataSecurity';
@Input() projection;

/**
* Whether to show the badge label or not
Expand Down Expand Up @@ -96,10 +96,12 @@ export abstract class AbstractBrowseElementsComponent implements OnInit, OnChang
this.paginatedSearchOptions = Object.assign(new PaginatedSearchOptions({}), this.paginatedSearchOptions, {
projection: this.projection
});

this.paginatedSearchOptions$ = new BehaviorSubject<PaginatedSearchOptions>(this.paginatedSearchOptions);

this.searchResults$ = this.paginatedSearchOptions$.asObservable().pipe(
mergeMap((paginatedSearchOptions) =>
this.searchService.search(paginatedSearchOptions, null, true, true, ...followLinks),
this.searchManager.search(paginatedSearchOptions, null, true, true, ...followLinks),
),
getAllCompletedRemoteData(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class BrowseMostElementsComponent implements OnInit, OnChanges {
/**
* Optional projection to use during the search
*/
@Input() projection = 'preventMetadataSecurity';
@Input() projection;

/**
* Whether to show the badge label or not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ThemedBrowseMostElementsComponent extends ThemedComponent<BrowseMos

@Input() paginatedSearchOptions: PaginatedSearchOptions;

@Input() projection = 'preventMetadataSecurity';
@Input() projection: string;

@Input() showLabel: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('MetadataLinkViewComponent', () => {
});

itemService = jasmine.createSpyObj('ItemDataService', {
findById: jasmine.createSpy('findById')
findByIdWithProjections: jasmine.createSpy('findByIdWithProjections')
});

beforeEach(waitForAsync(() => {
Expand All @@ -110,7 +110,7 @@ describe('MetadataLinkViewComponent', () => {
describe('Check metadata without authority', () => {
beforeEach(() => {
fixture = TestBed.createComponent(MetadataLinkViewComponent);
itemService.findById.and.returnValue(createSuccessfulRemoteDataObject$(testOrgunit));
itemService.findByIdWithProjections.and.returnValue(createSuccessfulRemoteDataObject$(testOrgunit));
component = fixture.componentInstance;
component.item = testPerson;
component.metadata = testMetadataValueWithoutAuthority;
Expand All @@ -135,7 +135,7 @@ describe('MetadataLinkViewComponent', () => {
describe('when item is found with orcid', () => {
beforeEach(() => {
fixture = TestBed.createComponent(MetadataLinkViewComponent);
itemService.findById.and.returnValue(createSuccessfulRemoteDataObject$(testPerson));
itemService.findByIdWithProjections.and.returnValue(createSuccessfulRemoteDataObject$(testPerson));
component = fixture.componentInstance;
component.item = testPerson;
component.metadata = testMetadataValueWithAuthority;
Expand All @@ -162,7 +162,7 @@ describe('MetadataLinkViewComponent', () => {
describe('when item is found without orcid', () => {
beforeEach(() => {
fixture = TestBed.createComponent(MetadataLinkViewComponent);
itemService.findById.and.returnValue(createSuccessfulRemoteDataObject$(testOrgunit));
itemService.findByIdWithProjections.and.returnValue(createSuccessfulRemoteDataObject$(testOrgunit));
component = fixture.componentInstance;
component.item = testPerson;
component.metadata = testMetadataValueWithAuthority;
Expand All @@ -189,7 +189,7 @@ describe('MetadataLinkViewComponent', () => {
describe('when item is not found', () => {
beforeEach(() => {
fixture = TestBed.createComponent(MetadataLinkViewComponent);
itemService.findById.and.returnValue(createFailedRemoteDataObject$());
itemService.findByIdWithProjections.and.returnValue(createFailedRemoteDataObject$());
component = fixture.componentInstance;
component.item = testPerson;
component.metadata = testMetadataValueWithAuthority;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class MetadataLinkViewComponent implements OnInit {
const linksToFollow = [followLink('thumbnail')];

if (Metadata.hasValidAuthority(metadataValue.authority)) {
return this.itemService.findById(metadataValue.authority, true, false, ...linksToFollow).pipe(
return this.itemService.findByIdWithProjections(metadataValue.authority, ['preventMetadataSecurity'], true, false, ...linksToFollow).pipe(
getFirstCompletedRemoteData(),
map((itemRD: RemoteData<Item>) => this.createMetadataView(itemRD, metadataValue))
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/search/search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class SearchComponent implements OnInit, OnDestroy {
/**
* Optional projection to use during the search
*/
@Input() projection = 'preventMetadataSecurity';
@Input() projection;

/**
* Whether or not the search bar should be visible
Expand Down

0 comments on commit 29a111a

Please sign in to comment.