@@ -28,41 +28,40 @@ module InstanceLoader
2828 def self . count_instances_by_class ( submission_id , class_id )
2929 ## TODO: pass directly an LinkedData::Models::OntologySubmission instance in the arguments instead of submission_id
3030 s = LinkedData ::Models ::OntologySubmission . find ( submission_id ) . first
31- self . instances_by_class_where_query ( s , class_id ) . count
31+ instances_by_class_where_query ( s , class_id : class_id ) . count
3232 end
3333
34- def self . get_instances_by_class ( submission_id , class_id , page_no = 1 , size = 50 )
34+ def self . get_instances_by_class ( submission_id , class_id , page_no : nil , size : nil )
3535 ## TODO: pass directly an LinkedData::Models::OntologySubmission instance in the arguments instead of submission_id
3636 s = LinkedData ::Models ::OntologySubmission . find ( submission_id ) . first
3737
38- inst = self . instances_by_class_where_query ( s , class_id ) . page ( page_no , size ) . all
38+ inst = instances_by_class_where_query ( s , class_id : class_id , page_no : page_no , size : size ) . all
3939
4040 # TODO test if "include=all" parameter is passed in the request
41- load_unmapped s , inst unless if inst . empty? # For getting all the properties # For getting all the properties
42-
41+ # For getting all the properties # For getting all the properties
42+ load_unmapped s , inst unless inst . nil? || inst . empty?
43+ inst
4344 end
4445
45- def self . get_instances_by_ontology ( submission_id , page_no = 1 , size = 50 )
46+ def self . get_instances_by_ontology ( submission_id , page_no : nil , size : nil )
4647 ## TODO: pass directly an LinkedData::Models::OntologySubmission instance in the arguments instead of submission_id
4748 s = LinkedData ::Models ::OntologySubmission . find ( submission_id ) . first
48- inst = s . nil? ? [ ] : self . instances_by_class_where_query ( s ) . page ( page_no , size ) . all
49+ inst = s . nil? ? [ ] : instances_by_class_where_query ( s , page_no : page_no , size : size ) . all
4950
5051 ## TODO test if "include=all" parameter is passed in the request
51- load_unmapped s , inst unless inst . empty? # For getting all the properties
52- end
52+ load_unmapped s , inst unless inst . nil? || inst . empty? # For getting all the properties
53+ inst
5354 end
5455
55- private
56-
57- def self . instances_by_class_where_query ( submission , class_id = nil )
58-
59- where_condition = class_id . nil? ? nil :{ types : RDF ::URI . new ( class_id . to_s ) }
60- LinkedData ::Models ::Instance . where ( where_condition ) . in ( submission ) . include ( :types )
61-
56+ def self . instances_by_class_where_query ( submission , class_id : nil , page_no : nil , size : nil )
57+ where_condition = class_id . nil? ? nil : { types : RDF ::URI . new ( class_id . to_s ) }
58+ query = LinkedData ::Models ::Instance . where ( where_condition ) . in ( submission ) . include ( :types , :label , :prefLabel )
59+ query . page ( page_no , size ) unless page_no . nil?
60+ query
6261 end
6362
6463 def self . load_unmapped ( submission , models )
65- LinkedData ::Models ::Instance . where . in ( submission ) . models ( models ) . include ( :unmapped ) . all
64+ LinkedData ::Models ::Instance . where . in ( submission ) . models ( models ) . include ( :unmapped ) . all
6665 end
6766
6867
0 commit comments