Skip to content

Commit b9d3a51

Browse files
committed
Updates after merging with master branch
1 parent b9b7414 commit b9d3a51

File tree

4 files changed

+188
-10
lines changed

4 files changed

+188
-10
lines changed

src/main/java/org/mskcc/oncokb/transcript/config/cache/LoggingCacheErrorHandler.java renamed to src/main/java/org/mskcc/oncokb/curation/config/cache/LoggingCacheErrorHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.mskcc.oncokb.transcript.config.cache;
1+
package org.mskcc.oncokb.curation.config.cache;
22

33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;

src/main/java/org/mskcc/oncokb/curation/repository/GeneRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public interface GeneRepository extends JpaRepository<Gene, Long>, JpaSpecificat
2121
@Cacheable(cacheResolver = "geneCacheResolver")
2222
Optional<Gene> findByHugoSymbol(String hugoSymbol);
2323

24-
@Query("select distinct g from Gene g left join fetch g.geneAliases ga left join fetch g.ensemblGenes eg")
24+
@Query(value = "select distinct g from Gene g left join fetch g.geneAliases ga left join fetch g.ensemblGenes eg", nativeQuery = true)
2525
Page<Gene> findAllWithGeneAliasAndEnsemblGenes(Pageable pageable);
2626

2727
@Query(
Lines changed: 182 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
package org.mskcc.oncokb.curation.web.rest;
22

3+
import java.net.URI;
4+
import java.net.URISyntaxException;
35
import java.util.List;
6+
import java.util.Objects;
7+
import java.util.Optional;
48
import org.mskcc.oncokb.curation.domain.Gene;
9+
import org.mskcc.oncokb.curation.repository.GeneRepository;
10+
import org.mskcc.oncokb.curation.service.GeneQueryService;
511
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;
614
import org.slf4j.Logger;
715
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;
820
import org.springframework.http.ResponseEntity;
921
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;
1026

1127
/**
1228
* REST controller for managing {@link org.mskcc.oncokb.curation.domain.Gene}.
@@ -17,20 +33,182 @@ public class GeneResource {
1733

1834
private final Logger log = LoggerFactory.getLogger(GeneResource.class);
1935

36+
private static final String ENTITY_NAME = "gene";
37+
38+
@Value("${jhipster.clientApp.name}")
39+
private String applicationName;
40+
2041
private final GeneService geneService;
2142

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) {
2348
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+
);
24137
}
25138

26139
/**
27140
* {@code GET /genes} : get all the genes.
28141
*
142+
* @param pageable the pagination information.
143+
* @param criteria the criteria which the requested entities should match.
29144
* @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of genes in body.
30145
*/
31146
@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());
35213
}
36214
}

src/main/resources/config/application-dev.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
logging:
1717
level:
18-
ROOT: DEBUG
19-
tech.jhipster: DEBUG
20-
org.hibernate.SQL: DEBUG
21-
org.mskcc.oncokb.curation: DEBUG
18+
ROOT: INFO
19+
tech.jhipster: INFO
20+
org.hibernate.SQL: INFO
21+
org.mskcc.oncokb.curation: INFO
2222

2323
spring:
2424
devtools:

0 commit comments

Comments
 (0)