Skip to content
Snippets Groups Projects
Unverified Commit f317ef0b authored by xgui3783's avatar xgui3783 Committed by GitHub
Browse files

Merge pull request #1455 from FZJ-INM1-BDA/feat_spatialXformEndpoint

maint: allow spatial transform to be configured at runtime
parents ebe34ab4 64bf4ee9
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,8 @@ data:
REDIS_ADDR: "cache-redis-service"
V2_7_PLUGIN_URLS: "https://siibra-jugex.apps.tc.humanbrainproject.eu/viewer_plugin/manifest.json;https://ngpy.apps.hbp.eu/viewer_plugin/manifest.json"
LOGGER_DIR: "/sxplr-log"
OVERWRITE_API_ENDPOINT: https://siibra-api-prod.apps.tc.humanbrainproject.eu/v3_0
OVERWRITE_SPATIAL_ENDPOINT: 'https://siibra-spatial-backend.apps.tc.humanbrainproject.eu'
kind: ConfigMap
metadata:
......
......@@ -7,7 +7,6 @@ data:
# n.b. echo -n "foobar" | base64
# or else the new line will also be encoded, and you will
# wonder why your application does not work
OVERWRITE_API_ENDPOINT: Zm9vYmFy
HBP_CLIENTID_V2: Zm9vYmFy
HBP_CLIENTSECRET_V2: Zm9vYmFy
SXPLR_EBRAINS_IAM_SA_CLIENT_ID: Zm9vYmFy
......
......@@ -8,6 +8,8 @@ HOSTNAME = os.getenv("HOSTNAME", "http://localhost:3000")
OVERWRITE_API_ENDPOINT = os.getenv("OVERWRITE_API_ENDPOINT")
OVERWRITE_SPATIAL_ENDPOINT = os.getenv("OVERWRITE_SPATIAL_ENDPOINT")
LOCAL_CDN = os.getenv("LOCAL_CDN")
HBP_CLIENTID_V2 = os.getenv("HBP_CLIENTID_V2", "no hbp id")
......
......@@ -19,3 +19,5 @@ SCOPES = [
DATA_ERROR_ATTR = "data-error"
OVERWRITE_SAPI_ENDPOINT_ATTR = "x-sapi-base-url"
OVERWRITE_SPATIAL_BACKEND_ATTR = "x-spatial-backend-url"
......@@ -2,8 +2,8 @@ from fastapi import APIRouter, Request
from pathlib import Path
from fastapi.responses import Response
from typing import Dict
from .const import ERROR_KEY, DATA_ERROR_ATTR, OVERWRITE_SAPI_ENDPOINT_ATTR, COOKIE_KWARGS
from .config import PATH_TO_PUBLIC, OVERWRITE_API_ENDPOINT
from .const import ERROR_KEY, DATA_ERROR_ATTR, OVERWRITE_SAPI_ENDPOINT_ATTR, COOKIE_KWARGS, OVERWRITE_SPATIAL_BACKEND_ATTR
from .config import PATH_TO_PUBLIC, OVERWRITE_API_ENDPOINT, OVERWRITE_SPATIAL_ENDPOINT
path_to_index = Path(PATH_TO_PUBLIC) / "index.html"
index_html: str = None
......@@ -32,6 +32,8 @@ async def get_index_html(request: Request):
if OVERWRITE_API_ENDPOINT:
attributes_to_append[OVERWRITE_SAPI_ENDPOINT_ATTR] = OVERWRITE_API_ENDPOINT
if OVERWRITE_SPATIAL_ENDPOINT:
attributes_to_append[OVERWRITE_SPATIAL_BACKEND_ATTR] = OVERWRITE_SPATIAL_ENDPOINT
attr_string = " ".join([f"{key}={_monkey_sanitize(value)}" for key, value in attributes_to_append.items()])
......
......@@ -150,7 +150,8 @@ If you do not accept the Terms & Conditions you are not permitted to access or u
AUXMESH_DESC: `Some templates contain auxiliary meshes, which compliment the appearance of the template in the perspective view.`,
OVERWRITE_SAPI_ENDPOINT_ATTR: `x-sapi-base-url`,
DATA_ERROR_ATTR: `data-error`
OVERWRITE_SPATIAL_BACKEND_ATTR: `x-spatial-backend-url`,
DATA_ERROR_ATTR: `data-error`,
}
exports.QUICKTOUR_DESC ={
......
......@@ -9,6 +9,7 @@
| `V2_7_STAGING_PLUGIN_URLS` | semi colon separated urls to be returned when user queries plugins | `''`
| `BUILD_TEXT` | overlay text at bottom right of the viewer. set to `''` to hide. | |
| `OVERWRITE_API_ENDPOINT` | overwrite build time siibra-api endpoint |
| `OVERWRITE_SPATIAL_ENDPOINT` | overwrite build time spatial transform endpoint | |
| `PATH_TO_PUBLIC` | path to built frontend | `../dist/aot` |
......
......@@ -18,3 +18,4 @@
- Removed dependency on connectivity-component
- Removed reference to JSC OKD instance, as the instance is no longer available
- Updated google-site-verification
- Allow inter space transform to be configured at runtime
import { InterSpaceCoordXformSvc, VALID_TEMPLATE_SPACE_NAMES } from './interSpaceCoordXform.service'
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'
import { TestBed, fakeAsync, tick } from '@angular/core/testing'
import { GET_ATTR_TOKEN } from 'src/util/constants'
describe('InterSpaceCoordXformSvc.service.spec.ts', () => {
describe('InterSpaceCoordXformSvc', () => {
let attr: string = null
const defaultUrl = 'https://hbp-spatial-backend.apps.hbp.eu/v1/transform-points'
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule
],
providers: [
InterSpaceCoordXformSvc
InterSpaceCoordXformSvc,
{
provide: GET_ATTR_TOKEN,
useFactory: () => {
return () => attr
}
}
]
})
})
......@@ -39,7 +48,7 @@ describe('InterSpaceCoordXformSvc.service.spec.ts', () => {
).subscribe((_ev) => {
})
const req = httpTestingController.expectOne(service['url'])
const req = httpTestingController.expectOne(defaultUrl)
expect(req.request.method).toEqual('POST')
expect(
JSON.parse(req.request.body)
......@@ -67,7 +76,7 @@ describe('InterSpaceCoordXformSvc.service.spec.ts', () => {
expect(status).toEqual('completed')
expect(result).toEqual([1e6, 2e6, 3e6])
})
const req = httpTestingController.expectOne(service['url'])
const req = httpTestingController.expectOne(defaultUrl)
req.flush({
'target_points':[
[1, 2, 3]
......@@ -87,7 +96,7 @@ describe('InterSpaceCoordXformSvc.service.spec.ts', () => {
expect(status).toEqual('error')
done()
})
const req = httpTestingController.expectOne(service['url'])
const req = httpTestingController.expectOne(defaultUrl)
req.flush('intercepted', { status: 500, statusText: 'internal server error' })
})
......@@ -105,10 +114,36 @@ describe('InterSpaceCoordXformSvc.service.spec.ts', () => {
expect(status).toEqual('error')
expect(statusText).toEqual(`Timeout after 3s`)
})
const req = httpTestingController.expectOne(service['url'])
const req = httpTestingController.expectOne(defaultUrl)
tick(4000)
expect(req.cancelled).toBe(true)
}))
describe("if injected override endpoint", () => {
beforeEach(() => {
attr = "http://foo-bar/"
})
afterEach(() => {
attr = null
})
it("trasnforms argument properly", () => {
const service = TestBed.inject(InterSpaceCoordXformSvc)
const httpTestingController = TestBed.inject(HttpTestingController)
// subscriptions are necessary for http fetch to occur
service.transform(
VALID_TEMPLATE_SPACE_NAMES.MNI152,
VALID_TEMPLATE_SPACE_NAMES.BIG_BRAIN,
[1,2,3]
).subscribe((_ev) => {
})
const req = httpTestingController.expectOne("http://foo-bar/v1/transform-points")
expect(req.request.method).toEqual('POST')
req.flush({})
})
})
})
})
})
import { Injectable } from "@angular/core";
import { Inject, Injectable } from "@angular/core";
import { HttpClient, HttpHeaders, HttpErrorResponse } from "@angular/common/http";
import { catchError, timeout, map } from "rxjs/operators";
import { of, Observable } from "rxjs";
import { environment } from 'src/environments/environment'
import { IDS } from "src/atlasComponents/sapi/constants"
import { GET_ATTR_TOKEN, GetAttr } from "src/util/constants";
import { CONST } from "common/constants"
type ITemplateCoordXformResp = {
status: 'pending' | 'error' | 'completed' | 'cached'
......@@ -49,9 +51,11 @@ export class InterSpaceCoordXformSvc {
}
}
constructor(private httpClient: HttpClient) {}
constructor(private httpClient: HttpClient, @Inject(GET_ATTR_TOKEN) getAttr: GetAttr) {
this.url = (getAttr(CONST.OVERWRITE_SPATIAL_BACKEND_ATTR) || environment.SPATIAL_TRANSFORM_BACKEND).replace(/\/$/, '') + '/v1/transform-points'
}
private url = `${environment.SPATIAL_TRANSFORM_BACKEND.replace(/\/$/, '')}/v1/transform-points`
private url: string
// jasmine marble cannot test promise properly
// see https://github.com/ngrx/platform/issues/498#issuecomment-337465179
......
......@@ -53,6 +53,7 @@ import { CONST } from "common/constants"
import { ViewerCommonEffects } from './viewerModule';
import { environment } from './environments/environment';
import { SAPI } from './atlasComponents/sapi';
import { GET_ATTR_TOKEN, GetAttr } from './util/constants';
@NgModule({
imports: [
......@@ -187,12 +188,20 @@ import { SAPI } from './atlasComponents/sapi';
multi: true,
deps: [ AuthService, Store ]
},
{
provide: GET_ATTR_TOKEN,
useFactory: (document: Document) => {
return (attr: string) => {
const rootEl = document.querySelector("atlas-viewer")
return rootEl?.getAttribute(attr)
}
},
deps: [ DOCUMENT ]
},
{
provide: APP_INITIALIZER,
useFactory: (sapi: SAPI, document: Document) => {
const rootEl = document.querySelector("atlas-viewer")
const overwriteSapiUrl = rootEl?.getAttribute(CONST.OVERWRITE_SAPI_ENDPOINT_ATTR)
useFactory: (sapi: SAPI, getAttr: GetAttr) => {
const overwriteSapiUrl = getAttr(CONST.OVERWRITE_SAPI_ENDPOINT_ATTR)
const { SIIBRA_API_ENDPOINTS } = environment
const endpoints = (overwriteSapiUrl && [ overwriteSapiUrl ]) || SIIBRA_API_ENDPOINTS.split(',')
......@@ -207,7 +216,7 @@ import { SAPI } from './atlasComponents/sapi';
}
},
multi: true,
deps: [ SAPI, DOCUMENT ]
deps: [ SAPI, GET_ATTR_TOKEN ]
}
],
bootstrap: [
......
......@@ -3,7 +3,7 @@ import { provideMockActions } from "@ngrx/effects/testing"
import { Action } from "@ngrx/store"
import { MockStore, provideMockStore } from "@ngrx/store/testing"
import { hot } from "jasmine-marbles"
import { NEVER, ReplaySubject, of, throwError } from "rxjs"
import { EMPTY, NEVER, ReplaySubject, of, throwError } from "rxjs"
import { SAPI, SAPIModule } from "src/atlasComponents/sapi"
import { SxplrRegion, SxplrAtlas, SxplrParcellation, SxplrTemplate } from "src/atlasComponents/sapi/sxplrTypes"
import { IDS } from "src/atlasComponents/sapi/constants"
......@@ -15,6 +15,7 @@ import { BrowserAnimationsModule } from "@angular/platform-browser/animations"
import { translateV3Entities } from "src/atlasComponents/sapi/translateV3"
import { PathReturn } from "src/atlasComponents/sapi/typeV3"
import { MatDialog } from 'src/sharedModules/angularMaterial.exports'
import { InterSpaceCoordXformSvc } from "src/atlasComponents/sapi/core/space/interSpaceCoordXform.service"
describe("> effects.ts", () => {
describe("> Effect", () => {
......@@ -104,6 +105,14 @@ describe("> effects.ts", () => {
}
}
},
{
provide: InterSpaceCoordXformSvc,
useValue: {
transform() {
return EMPTY
}
}
}
]
})
})
......
......@@ -101,3 +101,7 @@ export const parcBanList: string[] = [
"minds/core/parcellationatlas/v1.0.0/887da8eb4c36d944ef626ed5293db3ef",
"minds/core/parcellationatlas/v1.0.0/f2b1ac621421708c1bef422bb5058456",
]
export const GET_ATTR_TOKEN = new InjectionToken("GET_ATTR_TOKEN")
export type GetAttr = (attr: string) => string|null
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment