Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions interlex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -345,49 +345,6 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/{group}/query/transitive/{property}/{start}?depth:
get:
summary: Retrieve hierarchy results
operationId: get_hierarchy_results
tags:
- API
parameters:
- name: group
in: path
required: true
description: base group
schema:
type: string
- name: property
in: path
required: true
description: property
schema:
type: string
- name: start
in: path
required: true
description: start
schema:
type: string
responses:
200:
description: A paged array of results
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/Hierarchies'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/{group}/addTerm:
post:
summary: Used to add a new term
Expand Down
4 changes: 2 additions & 2 deletions nginx/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ server {

# Proxy for Elasticsearch API requests
location /api/elasticsearch {
proxy_pass https://scicrunch.org/api/1/elastic/Interlex_pr/_search;
proxy_set_header Host scicrunch.org;
proxy_pass https://api.scicrunch.io/elastic/v1/Interlex_pr/_search;
proxy_set_header Host api.scicrunch.io;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Expand Down
16 changes: 9 additions & 7 deletions src/api/endpoints/apiActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ export const createPostRequest = <T = any, D = any>(endpoint: string, headers :

export const createGetRequest = <T = any, P = any>(endpoint: string, contentType?: string) => {
return (params?: P, options?: SecondParameter<typeof customInstance>, signal?: AbortSignal) => {
const absUrl = endpoint.startsWith('http')
? endpoint
: new URL(endpoint.startsWith('/') ? endpoint : `/${endpoint}`, window.location.origin).toString();

const config: AxiosRequestConfig = {
url: endpoint,
url: absUrl,
method: "GET",
params,
signal,
withCredentials: true
}
};

if (contentType) {
config.headers = {
...config.headers,
"Content-Type": contentType,
}
Accept: contentType,
};
}

return customInstance<T>(config, options).then(response => {
return response;
});
return customInstance<T>(config, options).then(response => response);
}
}
68 changes: 52 additions & 16 deletions src/api/endpoints/apiService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createPostRequest, createGetRequest } from "./apiActions";
import { API_CONFIG } from "../../config";
import termParser from "../../parsers/termParser";
import { jsonldToTriplesAndEdges, PART_OF_IRI } from './hiearchies-parser'
import { jsonldToTriplesAndEdges, PART_OF_IRI } from '../../parsers/hierarchies-parser'
import { buildPredicateGroupsForFocus } from "../../parsers/predicateParser";

export interface LoginRequest {
username: string
Expand Down Expand Up @@ -302,7 +303,7 @@ export const getVariant = (group: string, term: string) => {
return createGetRequest<any, any>(`/${group}/variant/${term}`, "application/json")();
};

export const getTermHierarchies = async ({
export const getTermPredicates = async ({
groupname,
termId,
objToSub = true,
Expand All @@ -311,20 +312,55 @@ export const getTermHierarchies = async ({
termId: string;
objToSub?: boolean;
}) => {
const base = `/${groupname}/query/transitive/${encodeURIComponent(termId)}/ilx.partOf:`;
const url1 = `${base}?obj-to-sub=${objToSub}`;
const url2 = `${base}.jsonld?obj-to-sub=${objToSub}`;
const url = new URL(
`/${groupname}/query/transitive/${encodeURIComponent(termId)}/ilx.partOf:?obj-to-sub=true`,
window.location.origin
).toString();

const resp = await fetch(url, {
headers: { Accept: "application/ld+json" },
credentials: "include",
});
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
const ct = resp.headers.get("content-type") || "";
if (!/application\/(ld\+json|json)/i.test(ct)) {
throw new Error(`Server did not return JSON-LD (content-type: ${ct || "n/a"})`);
}
const jsonld = await resp.json();

try {
const res1 = await createGetRequest<any, any>(url1, 'application/ld+json')();
return jsonldToTriplesAndEdges(res1);
} catch {
try {
const res2 = await createGetRequest<any, any>(url2, 'application/ld+json')();
return jsonldToTriplesAndEdges(res2);
} catch (e2: any) {
console.error('getTermHierarchies failed', e2);
return { error: true, message: e2?.message || String(e2) };
}
// Build gold-standard predicate groups for the focus owl:Class
const predicates = buildPredicateGroupsForFocus(jsonld, termId);
return predicates;
};

export const getTermHierarchies = async ({
groupname,
termId,
objToSub = false,
}: {
groupname: string;
termId: string;
objToSub?: boolean;
}) => {
const url = new URL(
`/${groupname}/query/transitive/${encodeURIComponent(termId)}/ilx.partOf:?obj-to-sub=${objToSub}`,
window.location.origin
).toString();

const resp = await fetch(url, {
headers: { Accept: "application/ld+json" },
credentials: "include",
});
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
const ct = resp.headers.get("content-type") || "";
if (!/application\/(ld\+json|json)/i.test(ct)) {
throw new Error(`Server did not return JSON-LD (content-type: ${ct || "n/a"})`);
}
const jsonld = await resp.json();

// Only what Hierarchy needs
const parsed = jsonldToTriplesAndEdges(jsonld);
const triples = Array.isArray(parsed) ? parsed : (parsed?.triples || parsed?.edges || []);

return { triples };
};
85 changes: 0 additions & 85 deletions src/api/endpoints/hiearchies-parser.ts

This file was deleted.

16 changes: 0 additions & 16 deletions src/api/endpoints/swaggerMockMissingEndpoints.msw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,6 @@ export const getGetOrganizationsCuriesResponseMock = () => ((() => {
}];
})())

export const getGetHierarchyResultsResponseMock = (): Hierarchies => (Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ([])))

export const getAddTermResponseMock = () => ((() => {
return {
Expand Down Expand Up @@ -4294,20 +4293,6 @@ export const getGetOrganizationsCuriesMockHandler = (overrideResponse?: Curies)
})
}

export const getGetHierarchyResultsMockHandler = (overrideResponse?: Hierarchies) => {
return http.get('*/:group/query/transitive/:property/:start?depth', async () => {
await delay(1000);
return new HttpResponse(JSON.stringify(overrideResponse !== undefined ? overrideResponse : getGetHierarchyResultsResponseMock()),
{
status: 200,
headers: {
'Content-Type': 'application/json',
}
}
)
})
}

export const getAddTermMockHandler = (overrideResponse?: Error) => {
return http.post('*/:group/addTerm', async () => {
await delay(1000);
Expand Down Expand Up @@ -4531,7 +4516,6 @@ export const getSwaggerMockMissingEndpointsMock = () => [
getGetOrganizationsTermsMockHandler(),
getGetOrganizationsOntologiesMockHandler(),
getGetOrganizationsCuriesMockHandler(),
getGetHierarchyResultsMockHandler(),
getAddTermMockHandler(),
getBulkEditTermsMockHandler(),
getGetMatchTermsMockHandler(),
Expand Down
14 changes: 0 additions & 14 deletions src/api/endpoints/swaggerMockMissingEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,19 +192,6 @@ export const getOrganizationsCuries = (
options);
}

/**
* @summary Retrieve hierarchy results
*/
export const getHierarchyResults = (
group: string,
property: string,
start: string,
options?: SecondParameter<typeof customInstance>,) => {
return customInstance<Hierarchies>(
{url: `/${group}/query/transitive/${property}/${start}?depth`, method: 'GET'
},
options);
}

/**
* @summary Used to add a new term
Expand Down Expand Up @@ -430,7 +417,6 @@ export type GetOrganizationsResult = NonNullable<Awaited<ReturnType<typeof getOr
export type GetOrganizationsTermsResult = NonNullable<Awaited<ReturnType<typeof getOrganizationsTerms>>>
export type GetOrganizationsOntologiesResult = NonNullable<Awaited<ReturnType<typeof getOrganizationsOntologies>>>
export type GetOrganizationsCuriesResult = NonNullable<Awaited<ReturnType<typeof getOrganizationsCuries>>>
export type GetHierarchyResultsResult = NonNullable<Awaited<ReturnType<typeof getHierarchyResults>>>
export type AddTermResult = NonNullable<Awaited<ReturnType<typeof addTerm>>>
export type BulkEditTermsResult = NonNullable<Awaited<ReturnType<typeof bulkEditTerms>>>
export type GetMatchTermsResult = NonNullable<Awaited<ReturnType<typeof getMatchTerms>>>
Expand Down
Loading