1
1
package org .mskcc .oncokb .curation .web .rest ;
2
2
3
+ import java .net .URI ;
4
+ import java .net .URISyntaxException ;
3
5
import java .util .List ;
6
+ import java .util .Objects ;
7
+ import java .util .Optional ;
4
8
import org .mskcc .oncokb .curation .domain .Gene ;
9
+ import org .mskcc .oncokb .curation .repository .GeneRepository ;
10
+ import org .mskcc .oncokb .curation .service .GeneQueryService ;
5
11
import org .mskcc .oncokb .curation .service .GeneService ;
12
+ import org .mskcc .oncokb .curation .service .criteria .GeneCriteria ;
13
+ import org .mskcc .oncokb .curation .web .rest .errors .BadRequestAlertException ;
6
14
import org .slf4j .Logger ;
7
15
import org .slf4j .LoggerFactory ;
16
+ import org .springframework .beans .factory .annotation .Value ;
17
+ import org .springframework .data .domain .Page ;
18
+ import org .springframework .data .domain .Pageable ;
19
+ import org .springframework .http .HttpHeaders ;
8
20
import org .springframework .http .ResponseEntity ;
9
21
import org .springframework .web .bind .annotation .*;
22
+ import org .springframework .web .servlet .support .ServletUriComponentsBuilder ;
23
+ import tech .jhipster .web .util .HeaderUtil ;
24
+ import tech .jhipster .web .util .PaginationUtil ;
25
+ import tech .jhipster .web .util .ResponseUtil ;
10
26
11
27
/**
12
28
* REST controller for managing {@link org.mskcc.oncokb.curation.domain.Gene}.
@@ -17,20 +33,182 @@ public class GeneResource {
17
33
18
34
private final Logger log = LoggerFactory .getLogger (GeneResource .class );
19
35
36
+ private static final String ENTITY_NAME = "gene" ;
37
+
38
+ @ Value ("${jhipster.clientApp.name}" )
39
+ private String applicationName ;
40
+
20
41
private final GeneService geneService ;
21
42
22
- public GeneResource (GeneService geneService ) {
43
+ private final GeneRepository geneRepository ;
44
+
45
+ private final GeneQueryService geneQueryService ;
46
+
47
+ public GeneResource (GeneService geneService , GeneRepository geneRepository , GeneQueryService geneQueryService ) {
23
48
this .geneService = geneService ;
49
+ this .geneRepository = geneRepository ;
50
+ this .geneQueryService = geneQueryService ;
51
+ }
52
+
53
+ /**
54
+ * {@code POST /genes} : Create a new gene.
55
+ *
56
+ * @param gene the gene to create.
57
+ * @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new gene, or with status {@code 400 (Bad Request)} if the gene has already an ID.
58
+ * @throws URISyntaxException if the Location URI syntax is incorrect.
59
+ */
60
+ @ PostMapping ("/genes" )
61
+ public ResponseEntity <Gene > createGene (@ RequestBody Gene gene ) throws URISyntaxException {
62
+ log .debug ("REST request to save Gene : {}" , gene );
63
+ if (gene .getId () != null ) {
64
+ throw new BadRequestAlertException ("A new gene cannot already have an ID" , ENTITY_NAME , "idexists" );
65
+ }
66
+ Gene result = geneService .save (gene );
67
+ return ResponseEntity
68
+ .created (new URI ("/api/genes/" + result .getId ()))
69
+ .headers (HeaderUtil .createEntityCreationAlert (applicationName , false , ENTITY_NAME , result .getId ().toString ()))
70
+ .body (result );
71
+ }
72
+
73
+ /**
74
+ * {@code PUT /genes/:id} : Updates an existing gene.
75
+ *
76
+ * @param id the id of the gene to save.
77
+ * @param gene the gene to update.
78
+ * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated gene,
79
+ * or with status {@code 400 (Bad Request)} if the gene is not valid,
80
+ * or with status {@code 500 (Internal Server Error)} if the gene couldn't be updated.
81
+ * @throws URISyntaxException if the Location URI syntax is incorrect.
82
+ */
83
+ @ PutMapping ("/genes/{id}" )
84
+ public ResponseEntity <Gene > updateGene (@ PathVariable (value = "id" , required = false ) final Long id , @ RequestBody Gene gene )
85
+ throws URISyntaxException {
86
+ log .debug ("REST request to update Gene : {}, {}" , id , gene );
87
+ if (gene .getId () == null ) {
88
+ throw new BadRequestAlertException ("Invalid id" , ENTITY_NAME , "idnull" );
89
+ }
90
+ if (!Objects .equals (id , gene .getId ())) {
91
+ throw new BadRequestAlertException ("Invalid ID" , ENTITY_NAME , "idinvalid" );
92
+ }
93
+
94
+ if (!geneRepository .existsById (id )) {
95
+ throw new BadRequestAlertException ("Entity not found" , ENTITY_NAME , "idnotfound" );
96
+ }
97
+
98
+ Gene result = geneService .save (gene );
99
+ return ResponseEntity
100
+ .ok ()
101
+ .headers (HeaderUtil .createEntityUpdateAlert (applicationName , false , ENTITY_NAME , gene .getId ().toString ()))
102
+ .body (result );
103
+ }
104
+
105
+ /**
106
+ * {@code PATCH /genes/:id} : Partial updates given fields of an existing gene, field will ignore if it is null
107
+ *
108
+ * @param id the id of the gene to save.
109
+ * @param gene the gene to update.
110
+ * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated gene,
111
+ * or with status {@code 400 (Bad Request)} if the gene is not valid,
112
+ * or with status {@code 404 (Not Found)} if the gene is not found,
113
+ * or with status {@code 500 (Internal Server Error)} if the gene couldn't be updated.
114
+ * @throws URISyntaxException if the Location URI syntax is incorrect.
115
+ */
116
+ @ PatchMapping (value = "/genes/{id}" , consumes = { "application/json" , "application/merge-patch+json" })
117
+ public ResponseEntity <Gene > partialUpdateGene (@ PathVariable (value = "id" , required = false ) final Long id , @ RequestBody Gene gene )
118
+ throws URISyntaxException {
119
+ log .debug ("REST request to partial update Gene partially : {}, {}" , id , gene );
120
+ if (gene .getId () == null ) {
121
+ throw new BadRequestAlertException ("Invalid id" , ENTITY_NAME , "idnull" );
122
+ }
123
+ if (!Objects .equals (id , gene .getId ())) {
124
+ throw new BadRequestAlertException ("Invalid ID" , ENTITY_NAME , "idinvalid" );
125
+ }
126
+
127
+ if (!geneRepository .existsById (id )) {
128
+ throw new BadRequestAlertException ("Entity not found" , ENTITY_NAME , "idnotfound" );
129
+ }
130
+
131
+ Optional <Gene > result = geneService .partialUpdate (gene );
132
+
133
+ return ResponseUtil .wrapOrNotFound (
134
+ result ,
135
+ HeaderUtil .createEntityUpdateAlert (applicationName , false , ENTITY_NAME , gene .getId ().toString ())
136
+ );
24
137
}
25
138
26
139
/**
27
140
* {@code GET /genes} : get all the genes.
28
141
*
142
+ * @param pageable the pagination information.
143
+ * @param criteria the criteria which the requested entities should match.
29
144
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of genes in body.
30
145
*/
31
146
@ GetMapping ("/genes" )
32
- public List <Gene > getAllGenes () {
33
- log .debug ("REST request to get all Genes" );
34
- return geneService .findAll ();
147
+ public ResponseEntity <List <Gene >> getAllGenes (GeneCriteria criteria , Pageable pageable ) {
148
+ log .debug ("REST request to get Genes by criteria: {}" , criteria );
149
+ Page <Gene > page = Page .empty ();
150
+ if (criteria == null ) {
151
+ page = geneService .findAll (pageable );
152
+ }
153
+ page = geneQueryService .findByCriteria (criteria , pageable );
154
+ HttpHeaders headers = PaginationUtil .generatePaginationHttpHeaders (ServletUriComponentsBuilder .fromCurrentRequest (), page );
155
+ return ResponseEntity .ok ().headers (headers ).body (page .getContent ());
156
+ }
157
+
158
+ /**
159
+ * {@code GET /genes/count} : count all the genes.
160
+ *
161
+ * @param criteria the criteria which the requested entities should match.
162
+ * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the count in body.
163
+ */
164
+ @ GetMapping ("/genes/count" )
165
+ public ResponseEntity <Long > countGenes (GeneCriteria criteria ) {
166
+ log .debug ("REST request to count Genes by criteria: {}" , criteria );
167
+ return ResponseEntity .ok ().body (geneQueryService .countByCriteria (criteria ));
168
+ }
169
+
170
+ /**
171
+ * {@code GET /genes/:id} : get the "id" gene.
172
+ *
173
+ * @param id the id of the gene to retrieve.
174
+ * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the gene, or with status {@code 404 (Not Found)}.
175
+ */
176
+ @ GetMapping ("/genes/{id}" )
177
+ public ResponseEntity <Gene > getGene (@ PathVariable Long id ) {
178
+ log .debug ("REST request to get Gene : {}" , id );
179
+ Optional <Gene > gene = geneService .findOne (id );
180
+ return ResponseUtil .wrapOrNotFound (gene );
181
+ }
182
+
183
+ /**
184
+ * {@code DELETE /genes/:id} : delete the "id" gene.
185
+ *
186
+ * @param id the id of the gene to delete.
187
+ * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}.
188
+ */
189
+ @ DeleteMapping ("/genes/{id}" )
190
+ public ResponseEntity <Void > deleteGene (@ PathVariable Long id ) {
191
+ log .debug ("REST request to delete Gene : {}" , id );
192
+ geneService .delete (id );
193
+ return ResponseEntity
194
+ .noContent ()
195
+ .headers (HeaderUtil .createEntityDeletionAlert (applicationName , false , ENTITY_NAME , id .toString ()))
196
+ .build ();
197
+ }
198
+
199
+ /**
200
+ * {@code SEARCH /_search/genes?query=:query} : search for the gene corresponding
201
+ * to the query.
202
+ *
203
+ * @param query the query of the gene search.
204
+ * @param pageable the pagination information.
205
+ * @return the result of the search.
206
+ */
207
+ @ GetMapping ("/_search/genes" )
208
+ public ResponseEntity <List <Gene >> searchGenes (@ RequestParam String query , Pageable pageable ) {
209
+ log .debug ("REST request to search for a page of Genes for query {}" , query );
210
+ Page <Gene > page = geneQueryService .findBySearchQuery (query , pageable );
211
+ HttpHeaders headers = PaginationUtil .generatePaginationHttpHeaders (ServletUriComponentsBuilder .fromCurrentRequest (), page );
212
+ return ResponseEntity .ok ().headers (headers ).body (page .getContent ());
35
213
}
36
214
}
0 commit comments