Skip to content

Commit 586d3e8

Browse files
Added switch for repo vs index API endpoints. Resolves #1193. (#1196)
* Added switch for repo vs index API endpoints. Resolves #1193. * Minor linting.
1 parent 185d0c3 commit 586d3e8

35 files changed

+208
-126
lines changed

spa/src/app/app.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe("AppComponent:", () => {
102102
useValue: routerMock
103103
}, {
104104
provide: ConfigService,
105-
useValue: jasmine.createSpyObj("ConfigService", ["getPortalURL"])
105+
useValue: jasmine.createSpyObj("ConfigService", ["isV2", "isEnvLocal", "isEnvUxDev", "getPortalUrl"])
106106
}, {
107107
provide: LocalStorageService,
108108
useValue: jasmine.createSpyObj("LocalStorageService", ["get", "set"])

spa/src/app/app.module.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ import { NotFoundComponent } from "./system/not-found/not-found.component";
4545
import { SystemService } from "./system/shared/system.service";
4646
import { SystemService20 } from "./system/shared/system.2.0.service";
4747

48+
// True if current environment is running v2.0 code.
49+
const v2 = environment.version === "2.0";
50+
4851
@NgModule({
4952
bootstrap: [AppComponent],
5053
imports: [
@@ -91,7 +94,7 @@ import { SystemService20 } from "./system/shared/system.2.0.service";
9194
LocalStorageService,
9295
{
9396
provide: "SYSTEM_SERVICE",
94-
useClass: environment.version === "2.0" ? SystemService20 : SystemService
97+
useClass: v2 ? SystemService20 : SystemService
9598
},
9699
// Bootstrap config from API end point, must return function from useFactory method, when function is invoked,
97100
// must return promise to ensure Angular "pauses" until config is resolved from API end point.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Human Cell Atlas
3+
* https://www.humancellatlas.org/
4+
*
5+
* Set of end point paths used by the Browser.
6+
*/
7+
8+
export enum APIEndpoints {
9+
"INDEX_STATUS" = "/health/progress",
10+
"INTEGRATIONS" = "/integrations",
11+
"FILE_MANIFEST_SUMMARY" = "/fetch/manifest/files",
12+
"MATRIX_FORMATS" = "/formats",
13+
"PROJECT_MATRICES" = "/project-assets/project-matrices",
14+
"PROJECT_METADATA" = "/project-assets/project-metadata",
15+
"PROJECTS" = "/projects",
16+
"RELEASES" = "/release-files/releases/2020-mar",
17+
"SUMMARY" = "/summary"
18+
}

spa/src/app/config/config.service.ts

Lines changed: 129 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@ import { Config } from "./config.model";
1414
import { environment } from "../../environments/environment";
1515
import { AppState } from "../_ngrx/app.state";
1616
import { FetchConfigRequestSuccessAction } from "./_ngrx/config.actions";
17+
import { APIEndpoints } from "./api-endpoints.model";
1718

1819
@Injectable()
1920
export class ConfigService {
2021

2122
// Locals
22-
private dataURL: string; // Pulled from config store, saved as local state here on service
23-
private dcpHealthCheckUrl: string;
24-
private matrixURL: string;
25-
private portalURL: string;
26-
private deployment: string;
27-
private projectMetaURL: string;
28-
private store: Store<AppState>;
29-
private version: string;
23+
protected dataURL: string; // Pulled from config store, saved as local state here on service
24+
protected dcpHealthCheckUrl: string;
25+
protected matrixURL: string;
26+
protected portalURL: string;
27+
protected deployment: string;
28+
protected projectMetaURL: string;
29+
protected store: Store<AppState>;
30+
protected version: string;
3031

3132
/**
3233
* @param store {Store<AppState>}
@@ -37,41 +38,55 @@ export class ConfigService {
3738
}
3839

3940
/**
40-
* Build full end point URL, from API URL and specified path.
41-
*
42-
* @param path
41+
* Returns the URL for an entities end point (projects, files, samples).
42+
*
43+
* @param {string} entityName
4344
* @returns {string}
4445
*/
45-
public buildApiUrl(path: string) {
46+
public getEntitiesUrl(entityName: string): string {
4647

47-
const domain = this.getAPIURL();
48-
return `${domain}${path}`;
48+
const pathBase = this.getIndexBasePath();
49+
return `${this.dataURL}${pathBase}/${entityName}`;
4950
}
5051

5152
/**
52-
* Hit API end point to retrieve configuration information for this HCA instance. Must return promise here
53-
* as this method is called during Angular's app initialization and we need to resolve the config details (eg
54-
* data URL) before any components are instantiated. The config details returned from the server are saved on
55-
* this config service as local state (for easy access from calling classes where we don't want to handle
56-
* Observables) as well as in the store.
53+
* Returns the URL for the integrations end point.
5754
*
58-
* Note: if we add a fetch method at a later stage (eg to retrieve updated config), the local data URL value on this
59-
* service must be updated as well as the value in the store.
55+
* @returns {string}
56+
*/
57+
public getFileManifestUrl(): string {
58+
59+
const fileManifestSummaryPath = APIEndpoints.FILE_MANIFEST_SUMMARY;
60+
return `${this.dataURL}${fileManifestSummaryPath}`;
61+
}
62+
63+
/**
64+
* Returns the URL for checking the system status and indexing status of Azul.
65+
*
66+
* @returns {string}
67+
*/
68+
public getIndexStatusUrl(): string {
69+
70+
return `${this.dataURL}${APIEndpoints.INDEX_STATUS}`;
71+
}
72+
73+
/**
74+
* Returns the URL for the integrations end point.
6075
*
61-
* @returns {Promise<Config>}
76+
* @returns {string}
6277
*/
63-
public initConfig(): Promise<Config> {
78+
public getIntegrationsUrl(): string {
6479

65-
this.storeConfig(environment as Config);
66-
return Promise.resolve(environment as Config);
80+
const integrationsPath = APIEndpoints.INTEGRATIONS;
81+
return `${this.dataURL}${integrationsPath}`;
6782
}
6883

6984
/**
7085
* Return the data URL.
7186
*
7287
* @returns {string}
7388
*/
74-
public getDataURL(): string {
89+
public getDataUrl(): string {
7590

7691
return this.dataURL;
7792
}
@@ -81,7 +96,7 @@ export class ConfigService {
8196
*
8297
* @returns {string}
8398
*/
84-
public getDCPHealthCheckURL(): string {
99+
public getDCPHealthCheckUrl(): string {
85100

86101
return this.dcpHealthCheckUrl;
87102
}
@@ -91,17 +106,38 @@ export class ConfigService {
91106
*
92107
* @returns {string}
93108
*/
94-
public getMatrixURL(): string {
109+
public getMatrixUrl(): string {
95110

96111
return this.matrixURL;
97112
}
98113

114+
/**
115+
* Returns the matrix formats URL.
116+
*
117+
* @returns {string}
118+
*/
119+
public getMatrixFormatsUrl(): string {
120+
121+
return `${this.matrixURL}${APIEndpoints.MATRIX_FORMATS}`;
122+
}
123+
124+
/**
125+
* Returns the matrix request URL.
126+
*
127+
* @param {string} requestId
128+
* @returns {string}
129+
*/
130+
public getMatrixRequestUrl(requestId: string): string {
131+
132+
return `${this.matrixURL}/${requestId}`;
133+
}
134+
99135
/**
100136
* Returns the portal URL.
101137
*
102138
* @returns {string}
103139
*/
104-
public getPortalURL(): string {
140+
public getPortalUrl(): string {
105141

106142
return this.portalURL;
107143
}
@@ -111,7 +147,7 @@ export class ConfigService {
111147
*
112148
* @returns {string}
113149
*/
114-
public getProjectMetaURL(): string {
150+
public getProjectMetaUrl(): string {
115151

116152
return this.projectMetaURL;
117153
}
@@ -122,9 +158,9 @@ export class ConfigService {
122158
* @param {string} projectId
123159
* @returns {string}
124160
*/
125-
public getProjectMetaDownloadURL(projectId: string): string {
161+
public getProjectMetaDownloadUrl(projectId: string): string {
126162

127-
return `${this.getProjectMetaURL()}/project-assets/project-metadata/${projectId}.tsv`;
163+
return `${this.getProjectMetaUrl()}${APIEndpoints.PROJECT_METADATA}/${projectId}.tsv`;
128164
}
129165

130166
/**
@@ -133,23 +169,63 @@ export class ConfigService {
133169
* @param {string} fileName
134170
* @returns {string}
135171
*/
136-
public getProjectPreparedMatrixDownloadURL(fileName: string): string {
172+
public getProjectPreparedMatrixDownloadUrl(fileName: string): string {
137173

138-
return `${this.getProjectMetaURL()}/project-assets/project-matrices/${fileName}`;
174+
return `${this.getProjectMetaUrl()}${APIEndpoints.PROJECT_MATRICES}/${fileName}`;
139175
}
140176

141177
/**
142-
* Return the full data API URL for this HCA instance.
178+
* Returns the URL for the project end point.
143179
*
180+
* @param {string} projectId
144181
* @returns {string}
145182
*/
146-
public getAPIURL(): string {
183+
public getProjectUrl(projectId: string): string {
147184

148-
if ( this.dataURL ) {
149-
return this.dataURL;
150-
}
151-
152-
return "";
185+
const pathBase = this.getIndexBasePath();
186+
const projectsPath = APIEndpoints.PROJECTS;
187+
return `${this.dataURL}${pathBase}${projectsPath}/${projectId}`;
188+
}
189+
190+
/**
191+
* Return the full URL for the specified release file URL.
192+
*
193+
* @param {string} releaseFileUrl
194+
* @returns {string}
195+
*/
196+
public getReleaseFileUrl(releaseFileUrl: string): string {
197+
198+
return `${this.getProjectMetaUrl()}${APIEndpoints.RELEASES}/${releaseFileUrl}`;
199+
}
200+
201+
/**
202+
* Returns the URL for the summary end point.
203+
*
204+
* @returns {string}
205+
*/
206+
public getSummaryUrl(): string {
207+
208+
const pathBase = this.getIndexBasePath();
209+
const summaryPath = APIEndpoints.SUMMARY;
210+
return `${this.dataURL}${pathBase}${summaryPath}`;
211+
}
212+
213+
/**
214+
* Hit API end point to retrieve configuration information for this HCA instance. Must return promise here
215+
* as this method is called during Angular's app initialization and we need to resolve the config details (eg
216+
* data URL) before any components are instantiated. The config details returned from the server are saved on
217+
* this config service as local state (for easy access from calling classes where we don't want to handle
218+
* Observables) as well as in the store.
219+
*
220+
* Note: if we add a fetch method at a later stage (eg to retrieve updated config), the local data URL value on this
221+
* service must be updated as well as the value in the store.
222+
*
223+
* @returns {Promise<Config>}
224+
*/
225+
public initConfig(): Promise<Config> {
226+
227+
this.storeConfig(environment as Config);
228+
return Promise.resolve(environment as Config);
153229
}
154230

155231
/**
@@ -182,6 +258,18 @@ export class ConfigService {
182258
return this.version === "2.0";
183259
}
184260

261+
/**
262+
* Returns the "base path" for index/repository API calls.
263+
*/
264+
private getIndexBasePath(): string {
265+
266+
if ( this.isV2() ){
267+
return "/index";
268+
}
269+
270+
return "/repository";
271+
}
272+
185273
/**
186274
* Save the data URL as a local variable ogetAPIURLn this instance, and update the corresponding config value in the store.
187275
*

spa/src/app/files/analysis-protocol-pipeline-linker/analysis-protocol-pipeline-linker.component.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ describe("AnalysisProtocolPipelineLinkerComponent", () => {
1919
let component: AnalysisProtocolPipelineLinkerComponent;
2020
let fixture: ComponentFixture<AnalysisProtocolPipelineLinkerComponent>;
2121

22-
const testConfig = jasmine.createSpyObj("ConfigService", ["getPortalURL"]);
22+
const testConfig = jasmine.createSpyObj("ConfigService", ["getPortalUrl"]);
2323

2424
// Create response for testConfig.getPortalUrl()
25-
testConfig.getPortalURL.and.returnValue("https://test.com");
25+
testConfig.getPortalUrl.and.returnValue("https://test.com");
2626

2727
// Local values
2828
const LOCAL_VALUE_PIPELINE_LINKS_BY_ANALYSIS_PROTOCOL_KEY = {
@@ -83,7 +83,7 @@ describe("AnalysisProtocolPipelineLinkerComponent", () => {
8383

8484
// Confirm link is for data portal optimus
8585
const pipelineLink = component.getPipelineLink(TEST_VALUE_OPTIMUS);
86-
expect(pipelineLink).toEqual(`${testConfig.getPortalURL()}${TEMPLATE_VALUE_DATA_PORTAL_LINK_OPTIMUS}`);
86+
expect(pipelineLink).toEqual(`${testConfig.getPortalUrl()}${TEMPLATE_VALUE_DATA_PORTAL_LINK_OPTIMUS}`);
8787
});
8888

8989
/**
@@ -93,7 +93,7 @@ describe("AnalysisProtocolPipelineLinkerComponent", () => {
9393

9494
// Confirm link is for data portal smartseq2
9595
const pipelineLink = component.getPipelineLink(TEST_VALUE_SMARTSEQ2);
96-
expect(pipelineLink).toEqual(`${testConfig.getPortalURL()}${TEMPLATE_VALUE_DATA_PORTAL_LINK_SMARTSEQ2}`);
96+
expect(pipelineLink).toEqual(`${testConfig.getPortalUrl()}${TEMPLATE_VALUE_DATA_PORTAL_LINK_SMARTSEQ2}`);
9797
});
9898

9999
/**
@@ -283,7 +283,7 @@ describe("AnalysisProtocolPipelineLinkerComponent", () => {
283283
const analysisPortalDEs = getAnalysisProtocolsDisplayed("a");
284284

285285
// Confirm href link
286-
expect(getHrefValue(analysisPortalDEs[0])).toEqual(`${testConfig.getPortalURL()}${TEMPLATE_VALUE_DATA_PORTAL_LINK_OPTIMUS}`);
286+
expect(getHrefValue(analysisPortalDEs[0])).toEqual(`${testConfig.getPortalUrl()}${TEMPLATE_VALUE_DATA_PORTAL_LINK_OPTIMUS}`);
287287
});
288288

289289
/**
@@ -299,7 +299,7 @@ describe("AnalysisProtocolPipelineLinkerComponent", () => {
299299
const analysisPortalDEs = getAnalysisProtocolsDisplayed("a");
300300

301301
// Confirm href link
302-
expect(getHrefValue(analysisPortalDEs[0])).toEqual(`${testConfig.getPortalURL()}${TEMPLATE_VALUE_DATA_PORTAL_LINK_SMARTSEQ2}`);
302+
expect(getHrefValue(analysisPortalDEs[0])).toEqual(`${testConfig.getPortalUrl()}${TEMPLATE_VALUE_DATA_PORTAL_LINK_SMARTSEQ2}`);
303303
});
304304

305305
/**

spa/src/app/files/analysis-protocol-pipeline-linker/analysis-protocol-pipeline-linker.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class AnalysisProtocolPipelineLinkerComponent {
3737
*/
3838
constructor(private configService: ConfigService) {
3939

40-
this.portalURL = this.configService.getPortalURL();
40+
this.portalURL = this.configService.getPortalUrl();
4141
}
4242

4343
/**

spa/src/app/files/data-download-citation/data-download-citation.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class DataDownloadCitationComponent {
2727
*/
2828
public constructor(private configService: ConfigService) {
2929

30-
this.portalURL = this.configService.getPortalURL();
30+
this.portalURL = this.configService.getPortalUrl();
3131
}
3232

3333
}

spa/src/app/files/entity/entity-request.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ export class EntityRequestService {
8787
/**
8888
* Build the entity search results end point URL.
8989
*
90-
* @param {string} entity
90+
* @param {string} entityName
9191
* @returns {string}
9292
*/
93-
public buildEntitySearchResultsUrl(entity: string): string {
93+
public buildEntitySearchResultsUrl(entityName: string): string {
9494

95-
return this.configService.buildApiUrl(`/repository/${entity}`);
95+
return this.configService.getEntitiesUrl(entityName);
9696
}
9797

9898
/**

0 commit comments

Comments
 (0)