diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 3705a57ea..000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "java", - "name": "Launch Current File", - "request": "launch", - "mainClass": "${file}", - "env": { - "SPRING_PROFILES_ACTIVE": "dev,cdx-importer" - } - } - ] -} diff --git a/src/main/java/org/mskcc/oncokb/transcript/config/cache/LoggingCacheErrorHandler.java b/src/main/java/org/mskcc/oncokb/curation/config/cache/LoggingCacheErrorHandler.java similarity index 97% rename from src/main/java/org/mskcc/oncokb/transcript/config/cache/LoggingCacheErrorHandler.java rename to src/main/java/org/mskcc/oncokb/curation/config/cache/LoggingCacheErrorHandler.java index 25a2944d3..9b16542e7 100644 --- a/src/main/java/org/mskcc/oncokb/transcript/config/cache/LoggingCacheErrorHandler.java +++ b/src/main/java/org/mskcc/oncokb/curation/config/cache/LoggingCacheErrorHandler.java @@ -1,4 +1,4 @@ -package org.mskcc.oncokb.transcript.config.cache; +package org.mskcc.oncokb.curation.config.cache; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/mskcc/oncokb/curation/repository/GeneRepository.java b/src/main/java/org/mskcc/oncokb/curation/repository/GeneRepository.java index ef8cc8d48..1b6f8c82e 100644 --- a/src/main/java/org/mskcc/oncokb/curation/repository/GeneRepository.java +++ b/src/main/java/org/mskcc/oncokb/curation/repository/GeneRepository.java @@ -21,7 +21,7 @@ public interface GeneRepository extends JpaRepository, JpaSpecificat @Cacheable(cacheResolver = "geneCacheResolver") Optional findByHugoSymbol(String hugoSymbol); - @Query("select distinct g from Gene g left join fetch g.geneAliases ga left join fetch g.ensemblGenes eg") + @Query(value = "select distinct g from Gene g left join fetch g.geneAliases ga left join fetch g.ensemblGenes eg", nativeQuery = true) Page findAllWithGeneAliasAndEnsemblGenes(Pageable pageable); @Query( diff --git a/src/main/java/org/mskcc/oncokb/curation/web/rest/GeneResource.java b/src/main/java/org/mskcc/oncokb/curation/web/rest/GeneResource.java index 874e7398c..2741739eb 100644 --- a/src/main/java/org/mskcc/oncokb/curation/web/rest/GeneResource.java +++ b/src/main/java/org/mskcc/oncokb/curation/web/rest/GeneResource.java @@ -1,12 +1,28 @@ package org.mskcc.oncokb.curation.web.rest; +import java.net.URI; +import java.net.URISyntaxException; import java.util.List; +import java.util.Objects; +import java.util.Optional; import org.mskcc.oncokb.curation.domain.Gene; +import org.mskcc.oncokb.curation.repository.GeneRepository; +import org.mskcc.oncokb.curation.service.GeneQueryService; import org.mskcc.oncokb.curation.service.GeneService; +import org.mskcc.oncokb.curation.service.criteria.GeneCriteria; +import org.mskcc.oncokb.curation.web.rest.errors.BadRequestAlertException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; +import tech.jhipster.web.util.HeaderUtil; +import tech.jhipster.web.util.PaginationUtil; +import tech.jhipster.web.util.ResponseUtil; /** * REST controller for managing {@link org.mskcc.oncokb.curation.domain.Gene}. @@ -17,20 +33,182 @@ public class GeneResource { private final Logger log = LoggerFactory.getLogger(GeneResource.class); + private static final String ENTITY_NAME = "gene"; + + @Value("${jhipster.clientApp.name}") + private String applicationName; + private final GeneService geneService; - public GeneResource(GeneService geneService) { + private final GeneRepository geneRepository; + + private final GeneQueryService geneQueryService; + + public GeneResource(GeneService geneService, GeneRepository geneRepository, GeneQueryService geneQueryService) { this.geneService = geneService; + this.geneRepository = geneRepository; + this.geneQueryService = geneQueryService; + } + + /** + * {@code POST /genes} : Create a new gene. + * + * @param gene the gene to create. + * @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. + * @throws URISyntaxException if the Location URI syntax is incorrect. + */ + @PostMapping("/genes") + public ResponseEntity createGene(@RequestBody Gene gene) throws URISyntaxException { + log.debug("REST request to save Gene : {}", gene); + if (gene.getId() != null) { + throw new BadRequestAlertException("A new gene cannot already have an ID", ENTITY_NAME, "idexists"); + } + Gene result = geneService.save(gene); + return ResponseEntity + .created(new URI("/api/genes/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(applicationName, false, ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * {@code PUT /genes/:id} : Updates an existing gene. + * + * @param id the id of the gene to save. + * @param gene the gene to update. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated gene, + * or with status {@code 400 (Bad Request)} if the gene is not valid, + * or with status {@code 500 (Internal Server Error)} if the gene couldn't be updated. + * @throws URISyntaxException if the Location URI syntax is incorrect. + */ + @PutMapping("/genes/{id}") + public ResponseEntity updateGene(@PathVariable(value = "id", required = false) final Long id, @RequestBody Gene gene) + throws URISyntaxException { + log.debug("REST request to update Gene : {}, {}", id, gene); + if (gene.getId() == null) { + throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); + } + if (!Objects.equals(id, gene.getId())) { + throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid"); + } + + if (!geneRepository.existsById(id)) { + throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound"); + } + + Gene result = geneService.save(gene); + return ResponseEntity + .ok() + .headers(HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, gene.getId().toString())) + .body(result); + } + + /** + * {@code PATCH /genes/:id} : Partial updates given fields of an existing gene, field will ignore if it is null + * + * @param id the id of the gene to save. + * @param gene the gene to update. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated gene, + * or with status {@code 400 (Bad Request)} if the gene is not valid, + * or with status {@code 404 (Not Found)} if the gene is not found, + * or with status {@code 500 (Internal Server Error)} if the gene couldn't be updated. + * @throws URISyntaxException if the Location URI syntax is incorrect. + */ + @PatchMapping(value = "/genes/{id}", consumes = { "application/json", "application/merge-patch+json" }) + public ResponseEntity partialUpdateGene(@PathVariable(value = "id", required = false) final Long id, @RequestBody Gene gene) + throws URISyntaxException { + log.debug("REST request to partial update Gene partially : {}, {}", id, gene); + if (gene.getId() == null) { + throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); + } + if (!Objects.equals(id, gene.getId())) { + throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid"); + } + + if (!geneRepository.existsById(id)) { + throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound"); + } + + Optional result = geneService.partialUpdate(gene); + + return ResponseUtil.wrapOrNotFound( + result, + HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, gene.getId().toString()) + ); } /** * {@code GET /genes} : get all the genes. * + * @param pageable the pagination information. + * @param criteria the criteria which the requested entities should match. * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of genes in body. */ @GetMapping("/genes") - public List getAllGenes() { - log.debug("REST request to get all Genes"); - return geneService.findAll(); + public ResponseEntity> getAllGenes(GeneCriteria criteria, Pageable pageable) { + log.debug("REST request to get Genes by criteria: {}", criteria); + Page page = Page.empty(); + if (criteria == null) { + page = geneService.findAll(pageable); + } + page = geneQueryService.findByCriteria(criteria, pageable); + HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page); + return ResponseEntity.ok().headers(headers).body(page.getContent()); + } + + /** + * {@code GET /genes/count} : count all the genes. + * + * @param criteria the criteria which the requested entities should match. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the count in body. + */ + @GetMapping("/genes/count") + public ResponseEntity countGenes(GeneCriteria criteria) { + log.debug("REST request to count Genes by criteria: {}", criteria); + return ResponseEntity.ok().body(geneQueryService.countByCriteria(criteria)); + } + + /** + * {@code GET /genes/:id} : get the "id" gene. + * + * @param id the id of the gene to retrieve. + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the gene, or with status {@code 404 (Not Found)}. + */ + @GetMapping("/genes/{id}") + public ResponseEntity getGene(@PathVariable Long id) { + log.debug("REST request to get Gene : {}", id); + Optional gene = geneService.findOne(id); + return ResponseUtil.wrapOrNotFound(gene); + } + + /** + * {@code DELETE /genes/:id} : delete the "id" gene. + * + * @param id the id of the gene to delete. + * @return the {@link ResponseEntity} with status {@code 204 (NO_CONTENT)}. + */ + @DeleteMapping("/genes/{id}") + public ResponseEntity deleteGene(@PathVariable Long id) { + log.debug("REST request to delete Gene : {}", id); + geneService.delete(id); + return ResponseEntity + .noContent() + .headers(HeaderUtil.createEntityDeletionAlert(applicationName, false, ENTITY_NAME, id.toString())) + .build(); + } + + /** + * {@code SEARCH /_search/genes?query=:query} : search for the gene corresponding + * to the query. + * + * @param query the query of the gene search. + * @param pageable the pagination information. + * @return the result of the search. + */ + @GetMapping("/_search/genes") + public ResponseEntity> searchGenes(@RequestParam String query, Pageable pageable) { + log.debug("REST request to search for a page of Genes for query {}", query); + Page page = geneQueryService.findBySearchQuery(query, pageable); + HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(ServletUriComponentsBuilder.fromCurrentRequest(), page); + return ResponseEntity.ok().headers(headers).body(page.getContent()); } } diff --git a/src/main/resources/config/application-dev.yml b/src/main/resources/config/application-dev.yml index 5f83ff593..375fcac4c 100644 --- a/src/main/resources/config/application-dev.yml +++ b/src/main/resources/config/application-dev.yml @@ -15,10 +15,10 @@ logging: level: - ROOT: DEBUG - tech.jhipster: DEBUG - org.hibernate.SQL: DEBUG - org.mskcc.oncokb.curation: DEBUG + ROOT: INFO + tech.jhipster: INFO + org.hibernate.SQL: INFO + org.mskcc.oncokb.curation: INFO spring: devtools: