forked from bioversity/Crop-Ontology
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ontologymodel.js
64 lines (58 loc) · 1.97 KB
/
ontologymodel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var ontologymodel = (function() {
var categories = [
"010-089 General Germplasm Ontology",
"090-099 Taxonomic Ontology",
"100-299 Plant Anatomy & Development Ontology",
"300-499 Phenotype and Trait Ontology",
"500-699 Structural and Functional Genomic Ontology",
"700-799 Location and Environmental Ontology",
"800-899 General Science Ontology",
"900-999 Other (Sub-domain or Site-Specific) Ontology"
];
function catsSelectHtml() {
var options = "<select name='category'>";
for(var i=0; i<categories.length; i++) {
options += "<option value='"+categories[i]+"'>"+categories[i]+"</option>";
}
options += "</select>";
return options;
}
function create(currUser, ontologyId, ontologyName, ontologySummary, category) {
// create the ontology
var ontoEntity = googlestore.entity("ontology", ontologyId, {
created_at: new java.util.Date(),
user_key: currUser.getKey(),
ontology_id: ontologyId,
ontology_name: ontologyName,
ontology_summary: ontologySummary,
category: category
});
googlestore.put(ontoEntity);
memcache.clearAll();
}
function getById(ontologyId) {
// check if this ontoId already exists
try {
var ontoKey = googlestore.createKey("ontology", ontologyId);
var ontoEntity = googlestore.get(ontoKey);
return ontoEntity;
} catch (e) {
// if we get here, ontology doesn't exist
return false;
}
}
function owns(currUser, ontoEntity) {
if(ontoEntity.getProperty("user_key").equals(currUser.getKey())) {
return true;
} else {
return false;
}
}
return {
catsSelectHtml: catsSelectHtml,
create: create,
getById: getById,
owns: owns
};
})();
exports = ontologymodel;