fix: generate library online links properly

Closes #340
This commit is contained in:
Jovan Krunić
2022-11-17 15:01:54 +01:00
committed by Rainer Killinger
parent cbb949e397
commit 9854541a0c
4 changed files with 49 additions and 28 deletions

View File

@@ -30,6 +30,9 @@ export class DaiaHoldingComponent implements OnInit {
resourceLink?: string;
ngOnInit(): void {
this.resourceLink = this.daiaDataProvider.getHoldingLink(this.holding);
this.resourceLink = this.daiaDataProvider.getHoldingLink(
this.holding,
this.holding.open,
);
}
}

View File

@@ -39,6 +39,9 @@ describe('DaiaDataProvider', () => {
let daiaDataProvider: DaiaDataProvider;
let configProvider: ConfigProvider;
const proxyUrl = 'https://some-proxy.com?q=';
const getProxifiedUrl = (url: string) =>
`${proxyUrl}${encodeURIComponent(url)}`;
beforeEach(async () => {
configProvider = jasmine.createSpyObj('ConfigProvider', ['getValue']);
TestBed.configureTestingModule({
@@ -68,24 +71,13 @@ describe('DaiaDataProvider', () => {
daiaDataProvider.hebisProxyUrl = proxyUrl;
});
describe('getResourceLink', () => {
it('should return undefined when available not defined', () => {
const holding: DaiaHolding = {
department: {id: '', content: ''},
id: '',
online: false,
signature: '',
};
expect(daiaDataProvider.getHoldingLink(holding)).toEqual(undefined);
});
it('should return the resource link without proxy when service is openaccess', () => {
it('should return link with proxy when open property is undefined', () => {
const available: DaiaService = {
delay: '',
expected: '',
href: 'https://some-url.com',
limitations: [],
service: 'openaccess',
service: 'presentation',
};
const holding: DaiaHolding = {
department: {id: '', content: ''},
@@ -95,10 +87,12 @@ describe('DaiaDataProvider', () => {
available: available,
};
expect(daiaDataProvider.getHoldingLink(holding)).toEqual(available.href);
expect(daiaDataProvider.getHoldingLink(holding, holding.open)).toEqual(
getProxifiedUrl(available.href as string),
);
});
it('should return the resource link with proxy when service is not openaccess', () => {
it('should return the resource link without proxy when the resource is open', () => {
const available: DaiaService = {
delay: '',
expected: '',
@@ -110,12 +104,35 @@ describe('DaiaDataProvider', () => {
department: {id: '', content: ''},
id: '',
online: false,
open: true,
signature: '',
available: available,
};
expect(daiaDataProvider.getHoldingLink(holding)).toEqual(
`${proxyUrl}${encodeURIComponent(available.href as string)}`,
expect(daiaDataProvider.getHoldingLink(holding, holding.open)).toEqual(
available.href as string,
);
});
it('should return the resource link with proxy when the resource is not open', () => {
const available: DaiaService = {
delay: '',
expected: '',
href: 'https://some-url.com',
limitations: [],
service: 'other',
};
const holding: DaiaHolding = {
department: {id: '', content: ''},
id: '',
online: false,
open: false,
signature: '',
available: available,
};
expect(daiaDataProvider.getHoldingLink(holding, holding.open)).toEqual(
getProxifiedUrl(available.href as string),
);
});
});

View File

@@ -172,6 +172,12 @@ export class DaiaDataProvider {
storage,
about,
holdings: chronology?.about,
open:
(Array.isArray(available) &&
available.some(
item => item.service === 'openaccess',
)) ||
undefined,
});
} catch {
// No element available
@@ -191,22 +197,16 @@ export class DaiaDataProvider {
);
}
getHoldingLink(holding: DaiaHolding) {
getHoldingLink(holding: DaiaHolding, open = false) {
if (typeof this.hebisProxyUrl === 'undefined') {
this.logger.error('HeBIS proxy url undefined');
return;
}
const resourceLink = holding.available?.href;
if (
typeof resourceLink === 'undefined' ||
holding.available?.service === 'openaccess'
) {
return resourceLink;
}
return `${this.hebisProxyUrl}${encodeURIComponent(resourceLink)}`;
return open
? resourceLink
: `${this.hebisProxyUrl}${encodeURIComponent(resourceLink as string)}`;
}
holdingHasStatus(available: DaiaService[]): boolean {

View File

@@ -60,6 +60,7 @@ export interface DaiaHolding {
unavailable?: DaiaService;
about?: string;
online: boolean;
open?: boolean;
dueDate?: string;
holdings?: string;
status?: