Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ehennestad committed Mar 22, 2024
1 parent 5218aa3 commit 7cca552
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 39 deletions.
5 changes: 0 additions & 5 deletions server/internal/createFormSchemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ async function assembleRJSFSchemas () {
console.log('\n')
console.log('Deleting temporary folder.')
console.log('- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -')
fse.remove(SCHEMA_TEMPORARY_DIRECTORY, err => {
if (err) return console.error(err);
console.log('Deleted temporary folder');
});

try {
await fse.remove(SCHEMA_TEMPORARY_DIRECTORY)
console.log('Deleted temporary folder');
Expand Down
6 changes: 2 additions & 4 deletions server/internal/fetchDataFromKg.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ configObject = [
module.exports = fetchDataFromKg;

async function fetchDataFromKg() {
console.log('Fetching openMINDS instances...')
await fetchCoreSchemaInstances(configObject)
console.log('Fetching controlled term instances...')
await fetchControlledTerms()
console.log('Fetching data from KG')
await Promise.all( [fetchCoreSchemaInstances(configObject), fetchControlledTerms()] )
}
51 changes: 22 additions & 29 deletions server/kg-util/fetchCoreSchemaInstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,30 @@ fs.mkdir(INSTANCE_OUTPUT_DIRECTORY, { recursive: true }, (err) => {
let fetchCoreSchemaInstances = async (typeSpecifications) => {
// Create request header with authorization and options
const requestOptions = await getRequestOptions();
const API_BASE_URL = "https://core.kg.ebrains.eu/";
const API_ENDPOINT = "v3/instances";

const fetchPromises = typeSpecifications.map(async (typeSpecification) => {
let spaceName = typeSpecification.space !== undefined ? typeSpecification.space : "common";
const QUERY_PARAMS = ["stage=RELEASED", `space=${spaceName}`, "type=https://openminds.ebrains.eu/core/"];
const TYPE_NAME = typeSpecification.openMindsType;

// Assemble Query URL
let queryUrl = `${API_BASE_URL}${API_ENDPOINT}?${QUERY_PARAMS.join("&")}${TYPE_NAME}`;

try {
// Fetch instances
await fetchInstances(queryUrl, requestOptions, TYPE_NAME, typeSpecification.typeProperties);
} catch (error) {
// Handle error for this specific fetch
console.error(`Error fetching instances for ${TYPE_NAME}:`, error);
}
});

return new Promise((resolve, reject) => {

// Define some api constants
const API_BASE_URL = "https://core.kg.ebrains.eu/";
const API_ENDPOINT = "v3/instances";

typeSpecifications.forEach(async (typeSpecification) => {
let spaceName = "common";
if (typeSpecification.space !== undefined) {
spaceName = typeSpecification.space;
}

const QUERY_PARAMS = ["stage=RELEASED", `space=${spaceName}`, "type=https://openminds.ebrains.eu/core/"];
const TYPE_NAME = typeSpecification.openMindsType;

var completedRequests = 0;

// Assemble Query URL
let queryUrl = `${API_BASE_URL}${API_ENDPOINT}?${QUERY_PARAMS.join("&")}${TYPE_NAME}`;
// Wait for all fetch operations to complete
await Promise.all(fetchPromises);
};

try {
// Fetch instances
const data = await fetchInstances(queryUrl, requestOptions, TYPE_NAME, typeSpecification.typeProperties);
resolve(data);
} catch (error) {
reject(error);
}
});
});
}

// function to get schema instances from kg api
function fetchInstances(apiQueryUrl, requestOptions, typeName, propertyNames) {
Expand Down
2 changes: 1 addition & 1 deletion setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ async function setup() {

var startTime = performance.now()

console.log('Fetching openMINDS instances...')
fetchDataFromKg()
.then( () => {
var endTime = performance.now()
Expand All @@ -29,6 +28,7 @@ async function setup() {
assembleRJSFSchemas()
.then( () => {
console.log('Assembled form schemas from templates and controlled terms.')
console.log('')

// Redo the build in order for the updated terms to be used by the frontend
console.log('Creating a production build for the React App...')
Expand Down

0 comments on commit 7cca552

Please sign in to comment.