Skip to content

Commit 87512a2

Browse files
committed
LicensedItems store
1 parent 3901cf6 commit 87512a2

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/* ************************************************************************
2+
3+
osparc - the simcore frontend
4+
5+
https://osparc.io
6+
7+
Copyright:
8+
2025 IT'IS Foundation, https://itis.swiss
9+
10+
License:
11+
MIT: https://opensource.org/licenses/MIT
12+
13+
Authors:
14+
* Odei Maiz (odeimaiz)
15+
16+
************************************************************************ */
17+
18+
qx.Class.define("osparc.store.LicensedItems", {
19+
extend: qx.core.Object,
20+
type: "singleton",
21+
22+
construct: function() {
23+
this.base(arguments);
24+
25+
this.__modelsCache = {};
26+
},
27+
28+
statics: {
29+
VIP_MODELS: {
30+
HUMAN_BODY: "https://itis.swiss/PD_DirectDownload/getDownloadableItems/HumanWholeBody",
31+
HUMAN_BODY_REGION: "https://itis.swiss/PD_DirectDownload/getDownloadableItems/HumanBodyRegion",
32+
ANIMAL_BODY: "https://itis.swiss/PD_DirectDownload/getDownloadableItems/AnimalWholeBody",
33+
PHANTOM: "https://speag.swiss/PD_DirectDownload/getDownloadableItems/ComputationalPhantom",
34+
},
35+
36+
curateAnatomicalModels: function(anatomicalModelsRaw) {
37+
const anatomicalModels = [];
38+
const models = anatomicalModelsRaw["availableDownloads"];
39+
models.forEach(model => {
40+
const curatedModel = {};
41+
Object.keys(model).forEach(key => {
42+
if (key === "Features") {
43+
let featuresRaw = model["Features"];
44+
featuresRaw = featuresRaw.substring(1, featuresRaw.length-1); // remove brackets
45+
featuresRaw = featuresRaw.split(","); // split the string by commas
46+
const features = {};
47+
featuresRaw.forEach(pair => { // each pair is "key: value"
48+
const keyValue = pair.split(":");
49+
features[keyValue[0].trim()] = keyValue[1].trim()
50+
});
51+
curatedModel["Features"] = features;
52+
} else {
53+
curatedModel[key] = model[key];
54+
}
55+
});
56+
anatomicalModels.push(curatedModel);
57+
});
58+
return anatomicalModels;
59+
},
60+
},
61+
62+
members: {
63+
__modelsCache: null,
64+
65+
__fetchVipModels: async function(vipSubset) {
66+
if (!(vipSubset in this.VIP_MODELS)) {
67+
return [];
68+
}
69+
70+
if (vipSubset in this.__modelsCache) {
71+
return this.__modelsCache[vipSubset];
72+
}
73+
74+
return await fetch(this.VIP_MODELS[vipSubset], {
75+
method:"POST"
76+
})
77+
.then(resp => resp.json())
78+
.then(anatomicalModelsRaw => {
79+
const allAnatomicalModels = this.self().curateAnatomicalModels(anatomicalModelsRaw);
80+
const anatomicalModels = [];
81+
allAnatomicalModels.forEach(model => {
82+
const anatomicalModel = {};
83+
anatomicalModel["modelId"] = model["ID"];
84+
anatomicalModel["thumbnail"] = model["Thumbnail"];
85+
anatomicalModel["name"] = model["Features"]["name"] + " " + model["Features"]["version"];
86+
anatomicalModel["description"] = model["Description"];
87+
anatomicalModel["features"] = model["Features"];
88+
anatomicalModel["date"] = new Date(model["Features"]["date"]);
89+
anatomicalModel["DOI"] = model["DOI"];
90+
anatomicalModels.push(anatomicalModel);
91+
});
92+
this.__modelsCache[vipSubset] = anatomicalModels;
93+
return anatomicalModels;
94+
});
95+
},
96+
97+
fetchVipModels: async function(vipSubset) {
98+
const vipModels = this.self().VIP_MODELS;
99+
if (vipSubset && vipSubset in vipModels) {
100+
return await this.__fetchVipModels(vipSubset);
101+
}
102+
const promises = [];
103+
Object.keys(vipModels).forEach(sbs => promises.push(this.__fetchVipModels(sbs)));
104+
return await Promise.all(promises)
105+
.then(values => {
106+
const allVipModels = [];
107+
values.forEach(value => allVipModels.push(...value));
108+
return allVipModels;
109+
});
110+
},
111+
}
112+
});

0 commit comments

Comments
 (0)