Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
edlu77 committed Jan 30, 2024
1 parent c0415a4 commit 333fe8c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Injectable, ProviderToken } from '@angular/core';
import {
ApiEndpointDataSourceService, CCFDatabaseDataSourceService, DataSourceLike, InjectorDelegateDataSourceService, MixedCCfDatabaseDatasourceService
ApiEndpointDataSourceService, CCFDatabaseDataSourceService, DataSourceLike,
HybridCCfDatabaseDatasourceService,
InjectorDelegateDataSourceService
} from 'ccf-shared';

import { environment } from '../../../../environments/environment';
Expand All @@ -23,7 +25,7 @@ export class DelegateDataSourceService extends InjectorDelegateDataSourceService

if (useRemoteApi && !!remoteApiEndpoint) {
if (dataSources && dataSources.length > 0) {
return MixedCCfDatabaseDatasourceService;
return HybridCCfDatabaseDatasourceService;
} else {
return ApiEndpointDataSourceService;
}
Expand Down
4 changes: 2 additions & 2 deletions projects/ccf-eui/src/app/core/store/data/data.state.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TestBed } from '@angular/core/testing';
import { NgxsDataPluginModule } from '@angular-ru/ngxs';
import { TestBed } from '@angular/core/testing';
import { NgxsModule } from '@ngxs/store';
import { CCFDatabaseDataSourceService, DataSourceService, GlobalConfigState, DEFAULT_FILTER } from 'ccf-shared';
import { CCFDatabaseDataSourceService, DEFAULT_FILTER, DataSourceService, GlobalConfigState } from 'ccf-shared';

import { DataState } from './data.state';

Expand Down
8 changes: 4 additions & 4 deletions projects/ccf-eui/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export const environment = {
dbOptions: {
ccfOwlUrl: 'https://apps.humanatlas.io/hra-api/v1/ccf.owl.n3store.json',
ccfContextUrl: 'https://hubmapconsortium.github.io/ccf-ontology/ccf-context.jsonld',
dataSources: [
'https://hubmapconsortium.github.io/hra-registrations/federated/rui_locations.jsonld',
'https://apps.humanatlas.io/hra-api/v1/gtex/rui_locations.jsonld'
],
// dataSources: [
// 'https://hubmapconsortium.github.io/hra-registrations/federated/rui_locations.jsonld',
// 'https://apps.humanatlas.io/hra-api/v1/gtex/rui_locations.jsonld'
// ],
hubmapDataService: 'search-api',
hubmapDataUrl: 'https://search.api.hubmapconsortium.org/v3/entities/search',
hubmapToken: localStorage.getItem('HUBMAP_TOKEN') ?? '',
Expand Down
8 changes: 4 additions & 4 deletions projects/ccf-eui/src/environments/environment.staging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export const environment = {
dbOptions: {
ccfOwlUrl: 'https://apps.humanatlas.io/hra-api--staging/v1/ccf.owl.n3store.json',
ccfContextUrl: 'https://hubmapconsortium.github.io/ccf-ontology/ccf-context.jsonld',
dataSources: [
'https://hubmapconsortium.github.io/hra-registrations/federated/rui_locations.jsonld',
'https://apps.humanatlas.io/hra-api/v1/gtex/rui_locations.jsonld'
],
// dataSources: [
// 'https://hubmapconsortium.github.io/hra-registrations/federated/rui_locations.jsonld',
// 'https://apps.humanatlas.io/hra-api/v1/gtex/rui_locations.jsonld'
// ],
hubmapDataService: 'search-api',
hubmapDataUrl: 'https://search.api.hubmapconsortium.org/v3/entities/search',
hubmapToken: localStorage.getItem('HUBMAP_TOKEN') ?? '',
Expand Down
8 changes: 4 additions & 4 deletions projects/ccf-eui/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export const environment = {
dbOptions: {
ccfOwlUrl: 'assets/ccf.owl.n3store.json',
ccfContextUrl: 'https://hubmapconsortium.github.io/ccf-ontology/ccf-context.jsonld',
dataSources: [
'https://hubmapconsortium.github.io/hra-registrations/federated/rui_locations.jsonld',
'https://apps.humanatlas.io/hra-api/v1/gtex/rui_locations.jsonld'
],
// dataSources: [
// 'https://hubmapconsortium.github.io/hra-registrations/federated/rui_locations.jsonld',
// 'https://apps.humanatlas.io/hra-api/v1/gtex/rui_locations.jsonld'
// ],
hubmapDataService: 'search-api',
hubmapDataUrl: 'https://search.api.hubmapconsortium.org/v3/entities/search',
hubmapToken: localStorage.getItem('HUBMAP_TOKEN') ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ import { GlobalConfigState } from '../../config/global-config.state';
import { DataSource } from './data-source';


export interface ApiEndpointDataSourceOptions {
interface ApiEndpointDataSourceOptions {
remoteApiEndpoint: string;
hubmapToken?: string;
}

// Not exported from ts-cacheable!?
type IObservableCacheConfig = NonNullable<Parameters<typeof Cacheable>[0]>;

export type RequestMethod<P, T> = (params: P) => Observable<T>;
export type DataReviver<T, U> = (data: T) => U;
type RequestMethod<P, T> = (params: P) => Observable<T>;
type DataReviver<T, U> = (data: T) => U;

export interface DefaultParams {
interface DefaultParams {
token?: string;
}

export interface FilterParams {
interface FilterParams {
age?: MinMax;
ageRange?: string;
bmi?: MinMax;
Expand Down Expand Up @@ -62,7 +62,7 @@ function cast<T>(): (data: unknown) => T {
return data => data as T;
}

export function rangeToMinMax(
function rangeToMinMax(
range: [number, number] | undefined,
low: number, high: number
): MinMax | undefined {
Expand All @@ -72,7 +72,7 @@ export function rangeToMinMax(
} : undefined;
}

export function filterToParams(filter?: Filter): FilterParams {
function filterToParams(filter?: Filter): FilterParams {
return {
age: rangeToMinMax(filter?.ageRange, 1, 110),
bmi: rangeToMinMax(filter?.bmiRange, 13, 83),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { filter, map, shareReplay, switchMap } from 'rxjs/operators';
import { GlobalConfigState } from '../../config/global-config.state';
import { ApiEndpointDataSourceService } from './api-endpoint.service';
import { DataSource, DataSourceDataType, DataSourceLike, DataSourceMethod, DelegateDataSource, ForwardingDataSource } from './data-source';
import { isEqual } from 'lodash';

/** Default values for filters. */
export const DEFAULT_FILTER: Filter = {
Expand Down Expand Up @@ -91,8 +90,6 @@ export abstract class WorkerCCFDatabaseDataSourceService extends CCFDatabaseData
}

const REMOTE_METHODS: (keyof DataSource)[] = [
'getProviderNames',
'getDatasetTechnologyNames',
'getOntologyTreeModel',
'getCellTypeTreeModel',
'getBiomarkerTreeModel',
Expand All @@ -113,7 +110,7 @@ const FILTER_METHODS_ARG_1: (keyof DataSource)[] = [
@Injectable({
providedIn: 'root'
})
export class MixedCCfDatabaseDatasourceService extends ForwardingDataSource {
export class HybridCCfDatabaseDatasourceService extends ForwardingDataSource {
constructor(
private readonly remote: ApiEndpointDataSourceService,
private readonly local: CCFDatabaseDataSourceService,
Expand All @@ -126,21 +123,17 @@ export class MixedCCfDatabaseDatasourceService extends ForwardingDataSource {
): Observable<DataSourceDataType<K>> {
type AnyFunction = (...rest: unknown[]) => ObservableInput<unknown>;
type Res = Observable<DataSourceDataType<K>>;
const source = this.isRemoteCall(method, args) ? this.remote : this.local;
const source = this.isRemoteCall(method) ? this.remote : this.local;
return (source[method] as AnyFunction)(...args) as Res;
}

private isRemoteCall(method: keyof DataSource, args: unknown[]): boolean {
private isRemoteCall(method: keyof DataSource): boolean {
return (
REMOTE_METHODS.includes(method) ||
(FILTER_METHODS_ARG_0.includes(method) && this.isDefaultFilter(args[0] as Filter)) ||
(FILTER_METHODS_ARG_1.includes(method) && this.isDefaultFilter(args[1] as Filter))
(FILTER_METHODS_ARG_0.includes(method)) ||
(FILTER_METHODS_ARG_1.includes(method))
);
}

private isDefaultFilter(value?: Filter): boolean {
return isEqual(value, DEFAULT_FILTER);
}
}


0 comments on commit 333fe8c

Please sign in to comment.