mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
committed by
Rainer Killinger
parent
cbb949e397
commit
9854541a0c
@@ -30,6 +30,9 @@ export class DaiaHoldingComponent implements OnInit {
|
|||||||
resourceLink?: string;
|
resourceLink?: string;
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.resourceLink = this.daiaDataProvider.getHoldingLink(this.holding);
|
this.resourceLink = this.daiaDataProvider.getHoldingLink(
|
||||||
|
this.holding,
|
||||||
|
this.holding.open,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ describe('DaiaDataProvider', () => {
|
|||||||
let daiaDataProvider: DaiaDataProvider;
|
let daiaDataProvider: DaiaDataProvider;
|
||||||
let configProvider: ConfigProvider;
|
let configProvider: ConfigProvider;
|
||||||
const proxyUrl = 'https://some-proxy.com?q=';
|
const proxyUrl = 'https://some-proxy.com?q=';
|
||||||
|
const getProxifiedUrl = (url: string) =>
|
||||||
|
`${proxyUrl}${encodeURIComponent(url)}`;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
configProvider = jasmine.createSpyObj('ConfigProvider', ['getValue']);
|
configProvider = jasmine.createSpyObj('ConfigProvider', ['getValue']);
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
@@ -68,24 +71,13 @@ describe('DaiaDataProvider', () => {
|
|||||||
daiaDataProvider.hebisProxyUrl = proxyUrl;
|
daiaDataProvider.hebisProxyUrl = proxyUrl;
|
||||||
});
|
});
|
||||||
describe('getResourceLink', () => {
|
describe('getResourceLink', () => {
|
||||||
it('should return undefined when available not defined', () => {
|
it('should return link with proxy when open property is undefined', () => {
|
||||||
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', () => {
|
|
||||||
const available: DaiaService = {
|
const available: DaiaService = {
|
||||||
delay: '',
|
delay: '',
|
||||||
expected: '',
|
expected: '',
|
||||||
href: 'https://some-url.com',
|
href: 'https://some-url.com',
|
||||||
limitations: [],
|
limitations: [],
|
||||||
service: 'openaccess',
|
service: 'presentation',
|
||||||
};
|
};
|
||||||
const holding: DaiaHolding = {
|
const holding: DaiaHolding = {
|
||||||
department: {id: '', content: ''},
|
department: {id: '', content: ''},
|
||||||
@@ -95,10 +87,12 @@ describe('DaiaDataProvider', () => {
|
|||||||
available: available,
|
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 = {
|
const available: DaiaService = {
|
||||||
delay: '',
|
delay: '',
|
||||||
expected: '',
|
expected: '',
|
||||||
@@ -110,12 +104,35 @@ describe('DaiaDataProvider', () => {
|
|||||||
department: {id: '', content: ''},
|
department: {id: '', content: ''},
|
||||||
id: '',
|
id: '',
|
||||||
online: false,
|
online: false,
|
||||||
|
open: true,
|
||||||
signature: '',
|
signature: '',
|
||||||
available: available,
|
available: available,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(daiaDataProvider.getHoldingLink(holding)).toEqual(
|
expect(daiaDataProvider.getHoldingLink(holding, holding.open)).toEqual(
|
||||||
`${proxyUrl}${encodeURIComponent(available.href as string)}`,
|
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),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -172,6 +172,12 @@ export class DaiaDataProvider {
|
|||||||
storage,
|
storage,
|
||||||
about,
|
about,
|
||||||
holdings: chronology?.about,
|
holdings: chronology?.about,
|
||||||
|
open:
|
||||||
|
(Array.isArray(available) &&
|
||||||
|
available.some(
|
||||||
|
item => item.service === 'openaccess',
|
||||||
|
)) ||
|
||||||
|
undefined,
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
// No element available
|
// No element available
|
||||||
@@ -191,22 +197,16 @@ export class DaiaDataProvider {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getHoldingLink(holding: DaiaHolding) {
|
getHoldingLink(holding: DaiaHolding, open = false) {
|
||||||
if (typeof this.hebisProxyUrl === 'undefined') {
|
if (typeof this.hebisProxyUrl === 'undefined') {
|
||||||
this.logger.error('HeBIS proxy url undefined');
|
this.logger.error('HeBIS proxy url undefined');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const resourceLink = holding.available?.href;
|
const resourceLink = holding.available?.href;
|
||||||
|
return open
|
||||||
if (
|
? resourceLink
|
||||||
typeof resourceLink === 'undefined' ||
|
: `${this.hebisProxyUrl}${encodeURIComponent(resourceLink as string)}`;
|
||||||
holding.available?.service === 'openaccess'
|
|
||||||
) {
|
|
||||||
return resourceLink;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `${this.hebisProxyUrl}${encodeURIComponent(resourceLink)}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
holdingHasStatus(available: DaiaService[]): boolean {
|
holdingHasStatus(available: DaiaService[]): boolean {
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ export interface DaiaHolding {
|
|||||||
unavailable?: DaiaService;
|
unavailable?: DaiaService;
|
||||||
about?: string;
|
about?: string;
|
||||||
online: boolean;
|
online: boolean;
|
||||||
|
open?: boolean;
|
||||||
dueDate?: string;
|
dueDate?: string;
|
||||||
holdings?: string;
|
holdings?: string;
|
||||||
status?:
|
status?:
|
||||||
|
|||||||
Reference in New Issue
Block a user