Skip to content

Commit 2b1f541

Browse files
authored
Merge pull request #44 from haniffalab/feat/resources
Feat/resources
2 parents ae34bf3 + 51a0170 commit 2b1f541

14 files changed

Lines changed: 141 additions & 59 deletions

File tree

src/api/collection/content-types/collection/schema.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
},
2828
"name": {
2929
"type": "string",
30-
"unique": true
30+
"unique": true,
31+
"required": true
3132
},
3233
"uid": {
3334
"type": "uid",
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
module.exports = {
22
async beforeCreate(event) {
3-
event.params.data.uid = await strapi.service('plugin::content-manager.uid')
3+
const { data } = event.params;
4+
5+
const uid = await strapi.service('plugin::content-manager.uid')
46
.generateUIDField({
57
contentTypeUID: 'api::dataset.dataset',
68
field: 'uid',
7-
data: event.params.data
9+
data: event.params.data.name
810
});
11+
12+
event.params.data.uid = uid;
13+
event.params.data.dataset_id = data.study?.connect?.[0] || null + ':' + uid;
914
},
1015
async beforeUpdate(event) {
1116
const { data, where } = event.params;
1217

1318
const isPublishAction = 'publishedAt' in data;
1419

1520
if (!isPublishAction){
16-
const entry = await strapi.entityService.findOne('api::dataset.dataset', where.id);
17-
21+
const entry = await strapi.entityService.findOne('api::dataset.dataset', where.id,
22+
{populate: {study: {fields: ['id']}}}
23+
);
24+
1825
if ('name' in data && data.name !== entry.name){
1926
event.params.data.uid = await strapi.service('plugin::content-manager.uid')
2027
.generateUIDField({
2128
contentTypeUID: 'api::dataset.dataset',
2229
field: 'uid',
23-
data: data
30+
data: data.name
2431
});
2532
}
33+
34+
event.params.data.dataset_id = (data.study?.connect?.[0] || entry.study?.id || null) + ':' + (event.params.data.uid || entry.uid);
2635
}
2736
},
2837
};

src/api/dataset/content-types/dataset/schema.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"name": {
2424
"type": "string",
2525
"required": true,
26-
"unique": true
26+
"unique": false
2727
},
2828
"description": {
2929
"type": "text"
@@ -59,7 +59,7 @@
5959
},
6060
"uid": {
6161
"type": "uid",
62-
"targetField": "name",
62+
"targetField": "dataset_id",
6363
"required": true
6464
},
6565
"metadata": {
@@ -120,6 +120,15 @@
120120
"ontology": "hsapdv"
121121
},
122122
"customField": "plugin::ebi-ols.ontology-term"
123+
},
124+
"resources": {
125+
"type": "component",
126+
"repeatable": true,
127+
"component": "data.resource"
128+
},
129+
"dataset_id": {
130+
"type": "string",
131+
"unique": true
123132
}
124133
}
125134
}

src/api/dataset/controllers/dataset.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ module.exports = createCoreController('api::dataset.dataset', ({ strapi }) => ({
4141
fields: ['name', 'slug'],
4242
},
4343
data: {
44-
fields: ['format', 'file_type']
44+
fields: ['type']
4545
},
46+
resources: {
47+
fields: ['name', 'description', 'type', 'category', 'is_primary_data']
48+
}
4649
}
4750
};
4851
return await super.find(ctx);
@@ -60,6 +63,7 @@ module.exports = createCoreController('api::dataset.dataset', ({ strapi }) => ({
6063
fields: ['name', 'slug'],
6164
},
6265
data: true,
66+
resources: true,
6367
}
6468
};
6569
const dataset = await super.findOne(ctx);

src/api/dataset/services/dataset.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ module.exports = createCoreService('api::dataset.dataset', ({strapi}) => ({
1010
async findByUid(ctx){
1111
const ctUid = 'api::dataset.dataset';
1212
const attrs = strapi.contentTypes[ctUid].__schema__.attributes;
13-
const uidTarget =attrs['uid'].targetField;
14-
const { [uidTarget]: uidTargetValue } = ctx.params;
15-
13+
const { dataset_id, name, study_id } = ctx.params;
14+
15+
let where;
16+
if (dataset_id){
17+
where = { dataset_id: dataset_id };
18+
}
19+
else {
20+
const studyEntry = await strapi.service('api::study.study').findByUid({params: {study_id: study_id}});
21+
where = { study: studyEntry?.id || null, name: name };
22+
}
23+
1624
const populateParams = strapi.config.functions.getPopulateParams(attrs);
17-
25+
1826
let entity = await strapi.db.query(ctUid).findOne({
19-
where: { [uidTarget]: uidTargetValue },
27+
where: where,
2028
populate: populateParams
2129
});
2230

src/api/study/content-types/study/lifecycles.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module.exports = {
1313
event.params.data.password = data.password?.length ?
1414
bcrypt.hashSync(data.password, 10) :
1515
null;
16+
17+
event.state = data.datasets;
1618
},
1719
async beforeUpdate(event) {
1820
const { data, where } = event.params;
@@ -37,5 +39,29 @@ module.exports = {
3739
null;
3840
}
3941
}
42+
43+
event.state = data.datasets;
44+
},
45+
// Update datasets' dataset_id when connecting/disconnecting to/from study
46+
async afterCreate(event) {
47+
const datasets = event.state;
48+
for (const idx in datasets) {
49+
await strapi.entityService.update('api::dataset.dataset', datasets[idx], {
50+
data: { study: event.result.id }
51+
});
52+
}
4053
},
54+
async afterUpdate(event) {
55+
const { disconnect, connect } = event.state;
56+
for (const idx in disconnect) {
57+
await strapi.entityService.update('api::dataset.dataset', disconnect[idx].id, {
58+
data: { study: null }
59+
});
60+
}
61+
for (const idx in connect) {
62+
await strapi.entityService.update('api::dataset.dataset', connect[idx].id, {
63+
data: { study: event.result.id }
64+
});
65+
}
66+
}
4167
};

src/api/study/content-types/study/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@
9898
"type": "customField",
9999
"customField": "plugin::custom-fields.customPassword",
100100
"private": true
101+
},
102+
"resources": {
103+
"type": "component",
104+
"repeatable": true,
105+
"component": "data.resource"
101106
}
102107
}
103108
}

src/api/study/controllers/study.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
4343
populate: {
4444
cover_image: true,
4545
publications: {
46-
fields: ['title', 'doi', 'url', 'abstract'],
46+
fields: ['title', 'doi', 'url', 'abstract', 'date', 'is_published', 'is_preprint'],
4747
populate: {
4848
journal: {
4949
fields: ['name'],
@@ -73,6 +73,9 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
7373
fields: ['name', 'description', 'tissues', 'organisms', 'assays', 'diseases', 'celltypes', 'human_developmental_stages', 'count'],
7474
populate: ['media'],
7575
},
76+
resources: {
77+
fields: ['name', 'description', 'type', 'category' ]
78+
}
7679
},
7780
};
7881
return await super.find(ctx);
@@ -96,7 +99,7 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
9699
populate: {
97100
cover_image: true,
98101
publications: {
99-
fields: ['title', 'doi', 'url', 'abstract'],
102+
fields: ['title', 'doi', 'url', 'abstract', 'date', 'is_published', 'is_preprint'],
100103
populate: {
101104
journal: {
102105
fields: ['name'],
@@ -124,8 +127,9 @@ module.exports = createCoreController('api::study.study', ({ strapi }) => ({
124127
},
125128
datasets: {
126129
fields: ['name', 'description', 'tissues', 'organisms', 'assays', 'diseases', 'celltypes', 'human_developmental_stages', 'count'],
127-
populate: ['media'],
130+
populate: ['media', 'data', 'resources'],
128131
},
132+
resources: true
129133
},
130134
};
131135

src/api/team/content-types/team/schema.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
"configurable": false
2222
},
2323
"name": {
24-
"type": "string"
24+
"type": "string",
25+
"unique": true,
26+
"required": true
2527
},
2628
"logo": {
2729
"type": "media",

src/components/data/file.json

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,19 @@
66
},
77
"options": {},
88
"attributes": {
9-
"file_type": {
10-
"type": "enumeration",
11-
"enum": [
12-
"h5ad",
13-
"h5",
14-
"h5mu",
15-
"zarr",
16-
"tif",
17-
"zip",
18-
"h5seurat",
19-
"rds",
20-
"csv",
21-
"txt",
22-
"xlsx",
23-
"json",
24-
"link",
25-
"other"
26-
]
27-
},
289
"url": {
2910
"type": "string"
3011
},
31-
"format": {
12+
"metadata": {
13+
"type": "json"
14+
},
15+
"type": {
3216
"type": "enumeration",
3317
"enum": [
34-
"AnnData",
35-
"Seurat",
36-
"MuData",
37-
"SpatialData",
38-
"Raw OME-TIFF",
39-
"Label OME-TIFF",
40-
"OME-TIFF",
41-
"CellRanger",
42-
"SpaceRanger",
43-
"WebAtlas config",
44-
"metadata",
45-
"other"
18+
"AnnData-Zarr",
19+
"VitessceConfig"
4620
],
4721
"required": true
48-
},
49-
"metadata": {
50-
"type": "json"
5122
}
5223
}
5324
}

0 commit comments

Comments
 (0)