diff --git a/src/app/core/data/signposting-data.service.ts b/src/app/core/data/signposting-data.service.ts index 25bac49f17..0ef2b49f0f 100644 --- a/src/app/core/data/signposting-data.service.ts +++ b/src/app/core/data/signposting-data.service.ts @@ -16,8 +16,7 @@ export class SignpostingDataService { constructor(private restService: DspaceRestService, protected halService: HALEndpointService) { } getLinks(uuid: string): Observable { - const url = this.halService.getRootHref().split('/'); - const baseUrl = `${url[0]}//${url[2]}/${url[3]}`; + const baseUrl = this.halService.getRootHref().replace('/api', ''); return this.restService.get(`${baseUrl}/signposting/links/${uuid}`).pipe( catchError((err ) => { @@ -28,9 +27,8 @@ export class SignpostingDataService { ); } - getLinksets(uuid: string): Observable { - const url = this.halService.getRootHref().split('/'); - const baseUrl = `${url[0]}//${url[2]}/${url[3]}`; + getLinksets(uuid: string): Observable { + const baseUrl = this.halService.getRootHref().replace('/api', ''); const requestOptions = { observe: 'response' as any, @@ -46,7 +44,7 @@ export class SignpostingDataService { console.error(err); return observableOf(false); }), - map((res: RawRestResponse) => res) + map((res: RawRestResponse) => res.payload.body) ); } } diff --git a/src/app/core/metadata/metadata.service.ts b/src/app/core/metadata/metadata.service.ts index 6d5ca91b8d..3cc678fb15 100644 --- a/src/app/core/metadata/metadata.service.ts +++ b/src/app/core/metadata/metadata.service.ts @@ -165,7 +165,6 @@ export class MetadataService { this.setCitationPdfUrlTag(); this.setCitationPublisherTag(); this.setSignpostingLinks(); - this.setSignpostingLinksets(); if (this.isDissertation()) { this.setCitationDissertationNameTag(); @@ -211,21 +210,24 @@ export class MetadataService { console.log(link); } - private setSignpostingLinksets() { - if (this.currentObject.value instanceof Item){ - const value = this.signpostginDataService.getLinksets(this.currentObject.getValue().id); - value.subscribe(linksets => { - this.setLinkAttribute(linksets); - }); - } - } + // public setSignpostingLinksets(itemId: string) { + // let linkSet: string; - setLinkAttribute(linksets){ - console.log('ANDREA', linksets); - const linkAttribute = `Link: ${linksets.payload.body}`; - const textNode = document.createTextNode(linkAttribute); - document.head.appendChild(textNode); - } + // const value = this.signpostginDataService.getLinksets(itemId); + + // value.subscribe(linksets => { + // linkSet = linksets.payload.body; + // }); + + // return linkSet; + // } + + // setLinkAttribute(linksets){ + // console.log('ANDREA', linksets); + // const linkAttribute = `Link: ${linksets.payload.body}`; + // const textNode = document.createTextNode(linkAttribute); + // document.head.appendChild(textNode); + // } /** * Add to the diff --git a/src/app/core/services/server-hard-redirect.service.ts b/src/app/core/services/server-hard-redirect.service.ts index 94b9ed6198..a6c0e09aee 100644 --- a/src/app/core/services/server-hard-redirect.service.ts +++ b/src/app/core/services/server-hard-redirect.service.ts @@ -2,6 +2,9 @@ import { Inject, Injectable } from '@angular/core'; import { Request, Response } from 'express'; import { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens'; import { HardRedirectService } from './hard-redirect.service'; +import { SignpostingDataService } from '../data/signposting-data.service'; +import { ActivatedRoute } from '@angular/router'; +import { take } from 'rxjs'; /** * Service for performing hard redirects within the server app module @@ -12,6 +15,8 @@ export class ServerHardRedirectService extends HardRedirectService { constructor( @Inject(REQUEST) protected req: Request, @Inject(RESPONSE) protected res: Response, + private signpostginDataService: SignpostingDataService, + protected route: ActivatedRoute ) { super(); } @@ -46,6 +51,13 @@ export class ServerHardRedirectService extends HardRedirectService { } console.log(`Redirecting from ${this.req.url} to ${url} with ${status}`); + + this.route.params.subscribe(params => { + this.signpostginDataService.getLinksets(params.id).pipe(take(1)).subscribe(linksets => { + this.res.setHeader('Link', linksets); + }); + }); + this.res.redirect(status, url); this.res.end(); // I haven't found a way to correctly stop Angular rendering. diff --git a/src/app/core/services/server-response.service.ts b/src/app/core/services/server-response.service.ts index 02e00446bc..6dd50506e9 100644 --- a/src/app/core/services/server-response.service.ts +++ b/src/app/core/services/server-response.service.ts @@ -35,4 +35,10 @@ export class ServerResponseService { setInternalServerError(message = 'Internal Server Error'): this { return this.setStatus(500, message); } + + setLinksetsHeader(linksets: string){ + if (this.response) { + this.response.setHeader('Link', linksets); + } + } } diff --git a/src/app/item-page/full/full-item-page.component.ts b/src/app/item-page/full/full-item-page.component.ts index 118e436004..44766bac7b 100644 --- a/src/app/item-page/full/full-item-page.component.ts +++ b/src/app/item-page/full/full-item-page.component.ts @@ -16,6 +16,8 @@ import { hasValue } from '../../shared/empty.util'; import { AuthService } from '../../core/auth/auth.service'; import { Location } from '@angular/common'; import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service'; +import { ServerResponseService } from 'src/app/core/services/server-response.service'; +import { SignpostingDataService } from 'src/app/core/data/signposting-data.service'; /** @@ -48,8 +50,10 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit, items: ItemDataService, authService: AuthService, authorizationService: AuthorizationDataService, - private _location: Location) { - super(route, router, items, authService, authorizationService); + private _location: Location, + responseService: ServerResponseService, + signpostginDataService: SignpostingDataService) { + super(route, router, items, authService, authorizationService, responseService, signpostginDataService); } /*** AoT inheritance fix, will hopefully be resolved in the near future **/ diff --git a/src/app/item-page/simple/item-page.component.ts b/src/app/item-page/simple/item-page.component.ts index 6e0db386db..058cbc667a 100644 --- a/src/app/item-page/simple/item-page.component.ts +++ b/src/app/item-page/simple/item-page.component.ts @@ -15,6 +15,8 @@ import { getItemPageRoute } from '../item-page-routing-paths'; import { redirectOn4xx } from '../../core/shared/authorized.operators'; import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service'; import { FeatureID } from '../../core/data/feature-authorization/feature-id'; +import { ServerResponseService } from '../../core/services/server-response.service'; +import { SignpostingDataService } from '../../core/data/signposting-data.service'; /** * This component renders a simple item page. @@ -62,8 +64,15 @@ export class ItemPageComponent implements OnInit { private router: Router, private items: ItemDataService, private authService: AuthService, - private authorizationService: AuthorizationDataService + private authorizationService: AuthorizationDataService, + private responseService: ServerResponseService, + private signpostginDataService: SignpostingDataService ) { + this.route.params.subscribe(params => { + this.signpostginDataService.getLinksets(params.id).subscribe(linksets => { + this.responseService.setLinksetsHeader(linksets); + }); + }); } /**