Skip to content

Commit

Permalink
feat(zio-http)!: additional zio http support (DEV-1705) (#497)
Browse files Browse the repository at this point in the history
* feat(zio-http): fix zioApiUrl getter

* refactor(zio-http): refactor zio-http support

* fix test

* add more functionality to the test-framework app and add an e2e test

* remove problematic test due to CORS....
  • Loading branch information
mdelez committed Feb 15, 2023
1 parent c4b286b commit b03c005
Show file tree
Hide file tree
Showing 20 changed files with 322 additions and 90 deletions.
2 changes: 1 addition & 1 deletion src/api/admin/groups/groups-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ApiResponseData } from "../../../models/api-response-data";

describe("GroupsEndpoint", () => {

const config = new KnoraApiConfig("http", "localhost", 3333, 5555, undefined, undefined, true);
const config = new KnoraApiConfig("http", "localhost", 3333, undefined, undefined, true);
const knoraApiConnection = new KnoraApiConnection(config);

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/admin/lists/lists-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { ApiResponseData } from "../../../models/api-response-data";

describe("ListsEndpoint", () => {

const config = new KnoraApiConfig("http", "localhost", 3333, 5555, undefined, undefined, true);
const config = new KnoraApiConfig("http", "localhost", 3333, undefined, undefined, true);
const knoraApiConnection = new KnoraApiConnection(config);

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/admin/permissions/permissions-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ApiResponseData } from "../../../models/api-response-data";

describe("PermissionsEndpoint", () => {

const config = new KnoraApiConfig("http", "localhost", 3333, 5555, undefined, undefined, true);
const config = new KnoraApiConfig("http", "localhost", 3333, undefined, undefined, true);
const knoraApiConnection = new KnoraApiConnection(config);

beforeEach(() => {
Expand Down
24 changes: 12 additions & 12 deletions src/api/admin/projects/projects-endpoint-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class ProjectsEndpointAdmin extends Endpoint {
/**
* Returns a list of all projects.
*/
getProjects(zioRequest: boolean = false): Observable<ApiResponseData<ProjectsResponse> | ApiResponseError> {
getProjects(): Observable<ApiResponseData<ProjectsResponse> | ApiResponseError> {

return this.httpGet("", undefined, zioRequest).pipe(
return this.httpGet("", undefined).pipe(
map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, ProjectsResponse, this.jsonConvert)),
catchError(error => this.handleError(error))
);
Expand All @@ -38,9 +38,9 @@ export class ProjectsEndpointAdmin extends Endpoint {
*
* @param project The project to be created.
*/
createProject(project: Project, zioRequest: boolean = false): Observable<ApiResponseData<ProjectResponse> | ApiResponseError> {
createProject(project: Project): Observable<ApiResponseData<ProjectResponse> | ApiResponseError> {

return this.httpPost("", this.jsonConvert.serializeObject(project), undefined, undefined, zioRequest).pipe(
return this.httpPost("", this.jsonConvert.serializeObject(project), undefined, undefined).pipe(
map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, ProjectResponse, this.jsonConvert)),
catchError(error => this.handleError(error))
);
Expand Down Expand Up @@ -108,9 +108,9 @@ export class ProjectsEndpointAdmin extends Endpoint {
* @param property The name of the property by which the project is identified.
* @param value The value of the property by which the project is identified.
*/
getProject(property: "iri" | "shortname" | "shortcode", value: string, zioRequest: boolean = false): Observable<ApiResponseData<ProjectResponse> | ApiResponseError> {
getProject(property: "iri" | "shortname" | "shortcode", value: string): Observable<ApiResponseData<ProjectResponse> | ApiResponseError> {

return this.httpGet("/" + encodeURIComponent(property) + "/" + encodeURIComponent(value), undefined, zioRequest).pipe(
return this.httpGet("/" + encodeURIComponent(property) + "/" + encodeURIComponent(value), undefined).pipe(
map(ajaxResponse => ApiResponseData.fromAjaxResponse(ajaxResponse, ProjectResponse, this.jsonConvert)),
catchError(error => this.handleError(error))
);
Expand All @@ -122,9 +122,9 @@ export class ProjectsEndpointAdmin extends Endpoint {
*
* @param iri The IRI of the project.
*/
getProjectByIri(iri: string, zioRequest: boolean = false): Observable<ApiResponseData<ProjectResponse> | ApiResponseError> {
getProjectByIri(iri: string): Observable<ApiResponseData<ProjectResponse> | ApiResponseError> {

return this.getProject("iri", iri, zioRequest);
return this.getProject("iri", iri);

}

Expand All @@ -133,9 +133,9 @@ export class ProjectsEndpointAdmin extends Endpoint {
*
* @param shortname The shortname of the project.
*/
getProjectByShortname(shortname: string, zioRequest: boolean = false): Observable<ApiResponseData<ProjectResponse> | ApiResponseError> {
getProjectByShortname(shortname: string): Observable<ApiResponseData<ProjectResponse> | ApiResponseError> {

return this.getProject("shortname", shortname, zioRequest);
return this.getProject("shortname", shortname);

}

Expand All @@ -144,9 +144,9 @@ export class ProjectsEndpointAdmin extends Endpoint {
*
* @param shortcode The shortcode of the project.
*/
getProjectByShortcode(shortcode: string, zioRequest: boolean = false): Observable<ApiResponseData<ProjectResponse> | ApiResponseError> {
getProjectByShortcode(shortcode: string): Observable<ApiResponseData<ProjectResponse> | ApiResponseError> {

return this.getProject("shortcode", shortcode , zioRequest);
return this.getProject("shortcode", shortcode);

}

Expand Down
2 changes: 1 addition & 1 deletion src/api/admin/projects/projects-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { ApiResponseData } from "../../../models/api-response-data";

describe("ProjectsEndpoint", () => {

const config = new KnoraApiConfig("http", "localhost", 3333, 5555, undefined, undefined, true);
const config = new KnoraApiConfig("http", "localhost", 3333, undefined, undefined, true);
const knoraApiConnection = new KnoraApiConnection(config);

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/admin/users/users-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ApiResponseError } from "../../../models/api-response-error";

describe("UsersEndpoint", () => {

const config = new KnoraApiConfig("http", "localhost", 3333, 5555, undefined, undefined, true);
const config = new KnoraApiConfig("http", "localhost", 3333, undefined, undefined, true);
const knoraApiConnection = new KnoraApiConnection(config);

beforeEach(() => {
Expand Down
31 changes: 12 additions & 19 deletions src/api/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ export class Endpoint {
*
* @param path the relative URL for the request
* @param headerOpts additional headers, if any.
* @param zioRequest optional boolean to specify whether or not to use the zio http port
*/
protected httpGet(path?: string, headerOpts?: IHeaderOptions, zioRequest: boolean = false): Observable<AjaxResponse> {

protected httpGet(path?: string, headerOpts?: IHeaderOptions): Observable<AjaxResponse> {
if (path === undefined) path = "";

return ajax(this.setAjaxRequest(path, "GET", zioRequest, undefined, this.constructHeader(undefined, headerOpts)))
return ajax(this.setAjaxRequest(path, "GET", undefined, this.constructHeader(undefined, headerOpts)))
.pipe(
retryOnError(this.delay, this.maxRetries, this.retryOnErrorStatus, this.knoraApiConfig.logErrors)
);
Expand All @@ -85,13 +83,12 @@ export class Endpoint {
* @param body the body of the request, if any.
* @param contentType content content type of body, if any.
* @param headerOpts additional headers, if any.
* @param zioRequest optional boolean to specify whether or not to use the zio http port, defaults to false
*/
protected httpPost(path?: string, body?: any, contentType: "json" | "sparql" = "json", headerOpts?: IHeaderOptions, zioRequest: boolean = false): Observable<AjaxResponse> {
protected httpPost(path?: string, body?: any, contentType: "json" | "sparql" = "json", headerOpts?: IHeaderOptions): Observable<AjaxResponse> {

if (path === undefined) path = "";

return ajax(this.setAjaxRequest(path, "POST", zioRequest, body, this.constructHeader(contentType, headerOpts)))
return ajax(this.setAjaxRequest(path, "POST", body, this.constructHeader(contentType, headerOpts)))
.pipe(
retryOnError(this.delay, this.maxRetries, this.retryOnErrorStatus, this.knoraApiConfig.logErrors)
);
Expand All @@ -105,13 +102,12 @@ export class Endpoint {
* @param body the body of the request
* @param contentType content content type of body, if any.
* @param headerOpts additional headers, if any.
* @param zioRequest optional boolean to specify whether or not to use the zio http port, defaults to false
*/
protected httpPut(path?: string, body?: any, contentType: "json" = "json", headerOpts?: IHeaderOptions, zioRequest: boolean = false): Observable<AjaxResponse> {
protected httpPut(path?: string, body?: any, contentType: "json" = "json", headerOpts?: IHeaderOptions): Observable<AjaxResponse> {

if (path === undefined) path = "";

return ajax(this.setAjaxRequest(path, "PUT", zioRequest, body, this.constructHeader(contentType, headerOpts)))
return ajax(this.setAjaxRequest(path, "PUT", body, this.constructHeader(contentType, headerOpts)))
.pipe(
retryOnError(this.delay, this.maxRetries, this.retryOnErrorStatus, this.knoraApiConfig.logErrors)
);
Expand All @@ -125,13 +121,12 @@ export class Endpoint {
* @param body the body of the request
* @param contentType content content type of body, if any.
* @param headerOpts additional headers, if any.
* @param zioRequest optional boolean to specify whether or not to use the zio http port, defaults to false
*/
protected httpPatch(path?: string, body?: any, contentType: "json" = "json", headerOpts?: IHeaderOptions, zioRequest: boolean = false): Observable<AjaxResponse> {
protected httpPatch(path?: string, body?: any, contentType: "json" = "json", headerOpts?: IHeaderOptions): Observable<AjaxResponse> {

if (path === undefined) path = "";

return ajax(this.setAjaxRequest(path, "PATCH", zioRequest, body, this.constructHeader(contentType, headerOpts)))
return ajax(this.setAjaxRequest(path, "PATCH", body, this.constructHeader(contentType, headerOpts)))
.pipe(
retryOnError(this.delay, this.maxRetries, this.retryOnErrorStatus, this.knoraApiConfig.logErrors)
);
Expand All @@ -143,13 +138,12 @@ export class Endpoint {
*
* @param path the relative URL for the request.
* @param headerOpts additional headers, if any.
* @param zioRequest optional boolean to specify whether or not to use the zio http port, defaults to false
*/
protected httpDelete(path?: string, headerOpts?: IHeaderOptions, zioRequest: boolean = false): Observable<AjaxResponse> {
protected httpDelete(path?: string, headerOpts?: IHeaderOptions): Observable<AjaxResponse> {

if (path === undefined) path = "";

return ajax(this.setAjaxRequest(path, "DELETE", zioRequest, undefined, this.constructHeader(undefined, headerOpts)))
return ajax(this.setAjaxRequest(path, "DELETE", undefined, this.constructHeader(undefined, headerOpts)))
.pipe(
retryOnError(this.delay, this.maxRetries, this.retryOnErrorStatus, this.knoraApiConfig.logErrors)
);
Expand Down Expand Up @@ -233,14 +227,13 @@ export class Endpoint {
* Sets ajax request
* @param path string
* @param method 'GET', 'POST', 'PUT', 'PATCH' or 'DELETE'
* @param zioRequest boolean
* @param [body] any
* @param [headers] IHeaderOptions
* @returns AjaxRequest object
*/
private setAjaxRequest(path: string, method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", zioRequest: boolean, body?: any, headers?: IHeaderOptions): AjaxRequest {
private setAjaxRequest(path: string, method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", body?: any, headers?: IHeaderOptions): AjaxRequest {

let apiUrl = zioRequest ? this.knoraApiConfig.zioApiUrl : this.knoraApiConfig.apiUrl;
let apiUrl = this.knoraApiConfig.zioEndpointsList.includes(this.path) ? this.knoraApiConfig.zioApiUrl : this.knoraApiConfig.apiUrl;

let ajaxRequest: AjaxRequest = {
url: apiUrl + this.path + path,
Expand Down
2 changes: 1 addition & 1 deletion src/api/system/health/health-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HealthResponse } from "../../../models/system/health-response";

describe("HealthEndpoint", () => {

const config = new KnoraApiConfig("http", "localhost", 3333, 5555, undefined, undefined, true);
const config = new KnoraApiConfig("http", "localhost", 3333, undefined, undefined, true);
const knoraApiConnection = new KnoraApiConnection(config);

const getServerFromResponseHeader = (resHeader: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/v2/list/lists-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ListNodeV2 } from "../../../models/v2/lists/list-node-v2";

describe("ListsEndpoint", () => {

const config = new KnoraApiConfig("http", "0.0.0.0", 3333, 5555, undefined, undefined, true);
const config = new KnoraApiConfig("http", "0.0.0.0", 3333, undefined, undefined, true);
const knoraApiConnection = new KnoraApiConnection(config);

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/v2/ontology/ontologies-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { StringLiteralV2 } from "../../../models/v2/string-literal-v2";

describe("OntologiesEndpoint", () => {

const config = new KnoraApiConfig("http", "0.0.0.0", 3333, 5555, undefined, undefined, true);
const config = new KnoraApiConfig("http", "0.0.0.0", 3333, undefined, undefined, true);
const knoraApiConnection = new KnoraApiConnection(config);

beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/v2/resource/resources-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { CreateUriValue } from "../../../models/v2/resources/values/create/creat

describe("ResourcesEndpoint", () => {

const config = new KnoraApiConfig("http", "0.0.0.0", 3333, 5555, undefined, "", true);
const config = new KnoraApiConfig("http", "0.0.0.0", 3333, undefined, "", true);
let knoraApiConnection: KnoraApiConnection;

let getResourceClassDefinitionFromCacheSpy: jasmine.Spy;
Expand Down
2 changes: 1 addition & 1 deletion src/api/v2/search/search-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { SearchEndpointV2 } from "./search-endpoint-v2";

describe("SearchEndpoint", () => {

const config = new KnoraApiConfig("http", "0.0.0.0", 3333, 5555, undefined, "", true);
const config = new KnoraApiConfig("http", "0.0.0.0", 3333, undefined, "", true);
let knoraApiConnection: KnoraApiConnection;

let getResourceClassSpy: jasmine.Spy;
Expand Down
2 changes: 1 addition & 1 deletion src/api/v2/values/values-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import { UpdateValue } from "../../../models/v2/resources/values/update/update-v
import { UpdateValuePermissions } from "../../../models/v2/resources/values/update/update-value-permissions";
import { WriteValueResponse } from "../../../models/v2/resources/values/write-value-response";

const config = new KnoraApiConfig("http", "0.0.0.0", 3333, 5555, undefined, undefined, true);
const config = new KnoraApiConfig("http", "0.0.0.0", 3333, undefined, undefined, true);
let knoraApiConnection: KnoraApiConnection;

let getResourceClassDefinitionFromCacheSpy: jasmine.Spy;
Expand Down
2 changes: 1 addition & 1 deletion src/cache/ListNodeV2Cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ListNodeV2 } from "../models/v2/lists/list-node-v2";

describe("ListNodeV2Cache", () => {

const config = new KnoraApiConfig("http", "0.0.0.0", 3333, 5555, "", "", true);
const config = new KnoraApiConfig("http", "0.0.0.0", 3333, "", "", true);
let knoraApiConnection: KnoraApiConnection;

let getNodeSpy: jasmine.Spy;
Expand Down
4 changes: 2 additions & 2 deletions src/cache/ontology-cache/OntologyCache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("OntologyCache", () => {

describe("successful HTTP request", () => {

const config = new KnoraApiConfig("http", "0.0.0.0", 3333, 5555, "", "", true);
const config = new KnoraApiConfig("http", "0.0.0.0", 3333, "", "", true);
let knoraApiConnection: KnoraApiConnection;

let getOntoSpy: jasmine.Spy;
Expand Down Expand Up @@ -273,7 +273,7 @@ describe("OntologyCache", () => {

describe("unsuccessful HTTP request", () => {

const config = new KnoraApiConfig("http", "0.0.0.0", 3333, 5555, "", "", true);
const config = new KnoraApiConfig("http", "0.0.0.0", 3333, "", "", true);
let knoraApiConnection: KnoraApiConnection;

let getOntoSpy: jasmine.Spy;
Expand Down
Loading

0 comments on commit b03c005

Please sign in to comment.