Skip to content

Commit

Permalink
database interface ok
Browse files Browse the repository at this point in the history
begin of database-detail interface (request the data, no good display for the moment)
  • Loading branch information
acheype committed Apr 11, 2017
1 parent ac6338e commit 94b657e
Show file tree
Hide file tree
Showing 32 changed files with 4,508 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import nc.ird.malariaplantdb.domain.Ethnology;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

Expand All @@ -20,4 +22,8 @@ public interface EthnologyRepository extends JpaRepository<Ethnology,Long> {
// .id =:id")
//Ethnology findOneWithEagerRelationships(@Param("id") Long id);

@Query("select e from Ethnology e join e.plantIngredients pi where e.publication.id = :pubId and pi.id in :piIds")
List<Ethnology> findByPublicationIdAndPlantIngredients(@Param("pubId") Long pubId, @Param("piIds") List<Long>
piIds);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import nc.ird.malariaplantdb.domain.InVivoPharmaco;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

Expand All @@ -22,4 +24,7 @@ public interface InVivoPharmacoRepository extends JpaRepository<InVivoPharmaco,L
// ".plantIngredients where inVivoPharmaco.id =:id")
//InVivoPharmaco findOneWithEagerRelationships(@Param("id") Long id);

@Query("select iv from InVivoPharmaco iv join iv.plantIngredients pi where iv.publication.id = :pubId and pi.id in :piIds")
List<InVivoPharmaco> findByPublicationIdAndPlantIngredients(@Param("pubId") Long pubId, @Param("piIds") List<Long>
piIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import nc.ird.malariaplantdb.domain.PubSpecies;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

Expand All @@ -12,4 +14,8 @@ public interface PubSpeciesRepository extends JpaRepository<PubSpecies,Long> {

List<PubSpecies> findByPublicationId(Long id);

@Query("select ps from PubSpecies ps, PlantIngredient pi join ps.species s join pi.species s2 where ps.publication.id = :pubId and s.id = s2.id and pi.id in :piIds")
List<PubSpecies> findByPublicationIdAndPlantIngredients(@Param("pubId") Long pubId, @Param("piIds") List<Long>
piIds);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package nc.ird.malariaplantdb.repository;

import nc.ird.malariaplantdb.domain.Species;
import org.springframework.data.jpa.repository.*;

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;

/**
* Spring Data JPA repository for the Species entity.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package nc.ird.malariaplantdb.service;

import nc.ird.malariaplantdb.domain.Publication;
import nc.ird.malariaplantdb.domain.util.CitationConverter;
import nc.ird.malariaplantdb.repository.PublicationRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.inject.Inject;

/**
* Service for the Publication entity
*/
@Service
@Transactional
public class PublicationService {

private final Logger log = LoggerFactory.getLogger(PublicationService.class);

@Inject
private PublicationRepository publicationRepository;

/**
* Save a publication entity which the citation has been set
*
* @param publication the publication to save
* @return the saved publication
*/
public Publication save(Publication publication){

CitationConverter converter = new CitationConverter();
publication.setCitation(converter.convert(publication));

return publicationRepository.save(publication);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ public ResponseEntity<List<Ethnology>> getEthnologiesByPublicationId(@PathVariab
return new ResponseEntity<>(ethnologies, HttpStatus.OK);
}

/**
* GET /publications/:pubId/pi/:piIds/ethnologies -> get all the ethnologies with the "id" publication and the
* list of plant ingredient ids
*/
@RequestMapping(value = "/publications/{pubId}/pi/{piIds}/ethnologies",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<Ethnology>> getEthnologiesByPubIdAndPiIds(@PathVariable Long pubId, @PathVariable
List<Long> piIds) {
log.debug("REST request to get the Ethnologies of the Publication : {}, and the PlantIngredient(s) : {}",
pubId, piIds.stream().map(id -> id.toString()).collect(Collectors.joining(",")));
List<Ethnology> ethnologies = ethnologyRepository.findByPublicationIdAndPlantIngredients(pubId, piIds);
return new ResponseEntity<>(ethnologies, HttpStatus.OK);
}

/**
* DELETE /ethnologies/:id -> delete the "id" ethnology.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public ResponseEntity<InVitroPharmaco> getInVitroPharmaco(@PathVariable Long id)
/**
* GET /publications/:id/invitropharmacos -> get all the inVitroPharmacos of the "id" publication.
*/
@RequestMapping(value = "/publications/{id}/invitropharmacos",
@RequestMapping(value = "/publ/{id}/invitropharmacos",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,35 @@ public ResponseEntity<InVivoPharmaco> getInVivoPharmaco(@PathVariable Long id) {
}

/**
* GET /publications/:id/invivopharmacos -> get all the inVivoPharmacos of the "id" publication.
* GET /publications/:id/inVivoPharmacos -> get all the inVivoPharmacos of the "id" publication.
*/
@RequestMapping(value = "/publications/{id}/invivopharmacos",
@RequestMapping(value = "/pub/{id}/inVivoPharmacos",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<InVivoPharmaco>> getInVivoPharmacosByPublicationId(@PathVariable Long id) {
log.debug("REST request to get the inVivoPharmacos of the Publication : {}", id);
List<InVivoPharmaco> invivopharmacos = inVivoPharmacoRepository.findByPublicationId(id);
return new ResponseEntity<>(invivopharmacos, HttpStatus.OK);
log.debug("REST request to get the InVivoPharmacos of the Publication : {}", id);
List<InVivoPharmaco> inVivoPharmacos = inVivoPharmacoRepository.findByPublicationId(id);
return new ResponseEntity<>(inVivoPharmacos, HttpStatus.OK);
}

/**
* GET /publications/:pubId/pi/:piIds/inVivoPharmacos -> get all the inVivoPharmacos with the "id" publication and the
* list of plant ingredient ids
*/
@RequestMapping(value = "/publications/{pubId}/pi/{piIds}/inVivoPharmacos",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<InVivoPharmaco>> getEthnologiesByPubIdAndPiIds(@PathVariable Long pubId, @PathVariable
List<Long> piIds) {
log.debug("REST request to get the InVivoPharmaco of the Publication : {}, and the PlantIngredient(s) : {}",
pubId, piIds.stream().map(id -> id.toString()).collect(Collectors.joining(",")));
List<InVivoPharmaco> inVivoPharmacos = inVivoPharmacoRepository.findByPublicationIdAndPlantIngredients(pubId, piIds);
return new ResponseEntity<>(inVivoPharmacos, HttpStatus.OK);
}


/**
* DELETE /inVivoPharmacos/:id -> delete the "id" inVivoPharmaco.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ public ResponseEntity<List<PubSpecies>> getPubSpeciesByPublicationId(@PathVariab
return new ResponseEntity<>(pubSpecies, HttpStatus.OK);
}

/**
* GET /publications/:pubId/pi/:piIds/ethnologies -> get all the pubSpecies with the "id" publication and the
* list of plant ingredient ids
*/
@RequestMapping(value = "/publications/{pubId}/pi/{piIds}/pubSpecies",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
public ResponseEntity<List<PubSpecies>> getPubSpeciesByPubIdAndPiIds(@PathVariable Long pubId, @PathVariable
List<Long> piIds) {
log.debug("REST request to get the PubSpecies of the Publication : {}, and the PlantIngredient(s) : {}",
pubId, piIds.stream().map(id -> id.toString()).collect(Collectors.joining(",")));
List<PubSpecies> pubSpecies = pubSpeciesRepository.findByPublicationIdAndPlantIngredients(pubId, piIds);
return new ResponseEntity<>(pubSpecies, HttpStatus.OK);
}

/**
* DELETE /pubSpecies/:id -> delete the "id" pubSpecies.
*/
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/nc/ird/malariaplantdb/web/rest/dto/PISummaryDTO.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nc.ird.malariaplantdb.web.rest.dto;

import java.math.BigDecimal;
import java.util.List;

/**
* Plant Ingredient summary used to display the publications list
Expand Down Expand Up @@ -31,6 +32,8 @@ public enum TestType {

public final static String ERYTHROCYT_TXT = "erythrocyt";

private List<Long> plantIngredientsIds;

private boolean isInVivo = false;

private boolean isInVivoPeters = false;
Expand Down Expand Up @@ -71,6 +74,10 @@ public enum TestType {

private boolean isInVitroToxicity = false;

public PISummaryDTO(List<Long> plantIngredientsIds) {
this.plantIngredientsIds = plantIngredientsIds;
}

public void setTestedEntity(TestType testType, String screeningTest, BigDecimal inVivoInhibition, BigDecimal
inVivoEd50, BigDecimal inVitroInhibition, BigDecimal inVitroIC50, BigDecimal inVitroMolIc50){
if (TestType.IN_VIVO.equals(testType))
Expand Down Expand Up @@ -135,6 +142,14 @@ public void setTestedEntity(TestType testType, String screeningTest, BigDecimal
}
}

public List<Long> getPlantIngredientsIds() {
return plantIngredientsIds;
}

public void setPlantIngredientsIds(List<Long> plantIngredientsIds) {
this.plantIngredientsIds = plantIngredientsIds;
}

public boolean isInVivo() {
return isInVivo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import nc.ird.malariaplantdb.domain.*;

import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand All @@ -15,6 +12,8 @@
*/
public class PubSummaryDTO {

private Long id;

private String citation;

private String doi;
Expand All @@ -30,6 +29,7 @@ public class PubSummaryDTO {
private SortedMap<String, PISummaryDTO> plantIngredients = new TreeMap<>();

public PubSummaryDTO(Publication pub) {
id = pub.getId();
citation = pub.getCitation();
doi = pub.getDoi();
pmid = pub.getPmid();
Expand All @@ -43,8 +43,11 @@ public PubSummaryDTO(Publication pub) {
for (InVivoPharmaco inVivoPharmaco : pub.getInVivoPharmacos()){
String plantIngredientStr = buildPlantIngredientsKey(inVivoPharmaco.getPlantIngredients());

if (!plantIngredients.containsKey(plantIngredientStr))
plantIngredients.put(plantIngredientStr, new PISummaryDTO());
if (!plantIngredients.containsKey(plantIngredientStr)) {
List<Long> plantIngredientsIds = inVivoPharmaco.getPlantIngredients().stream().map(pi -> pi.getId())
.collect(Collectors.toList());
plantIngredients.put(plantIngredientStr, new PISummaryDTO(plantIngredientsIds));
}

plantIngredients.get(plantIngredientStr).setTestedEntity(PISummaryDTO.TestType.IN_VIVO,
inVivoPharmaco.getScreeningTest(), inVivoPharmaco.getInhibition(), inVivoPharmaco.getEd50(), null,
Expand All @@ -54,8 +57,11 @@ public PubSummaryDTO(Publication pub) {
for (InVitroPharmaco inVitroPharmaco : pub.getInVitroPharmacos()){
String plantIngredientStr = buildPlantIngredientsKey(inVitroPharmaco.getPlantIngredients());

if (!plantIngredients.containsKey(plantIngredientStr))
plantIngredients.put(plantIngredientStr, new PISummaryDTO());
if (!plantIngredients.containsKey(plantIngredientStr)) {
List<Long> plantIngredientsIds = inVitroPharmaco.getPlantIngredients().stream().map(pi -> pi.getId())
.collect(Collectors.toList());
plantIngredients.put(plantIngredientStr, new PISummaryDTO(plantIngredientsIds));
}

plantIngredients.get(plantIngredientStr).setTestedEntity(PISummaryDTO.TestType.IN_VITRO,
inVitroPharmaco.getScreeningTest(), null, null, inVitroPharmaco.getInhibition(),
Expand All @@ -69,6 +75,14 @@ private String buildPlantIngredientsKey(SortedSet<PlantIngredient> plantIngredie
.collect(Collectors.joining(" / "));
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getCitation() {
return citation;
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/resources/hibernate.cfg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url"/>
<property name="connection.driver_class"/>
<property name="connection.username"/>
<property name="connection.password"/>
<!-- DB schema will be updated if needed -->
<!-- <property name="hbm2ddl.auto">update</property> -->
</session-factory>
</hibernate-configuration>
1 change: 1 addition & 0 deletions src/main/scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ $font-family-base: $font-family-sans-serif !default;
$font-size-base: 15px !default;
$font-size-large: ceil(($font-size-base * 1.25)) !default; // ~18px
$font-size-small: ceil(($font-size-base * 0.85)) !default; // ~12px
$font-size-smaller: ceil(($font-size-base * 0.75)) !default;

$font-size-h1: floor(($font-size-base * 2.6)) !default; // ~36px
$font-size-h2: floor(($font-size-base * 2.15)) !default; // ~30px
Expand Down
Loading

0 comments on commit 94b657e

Please sign in to comment.