Skip to content

Commit

Permalink
- Add the search functionnality on the database (to fix : nested obje…
Browse files Browse the repository at this point in the history
…cts are not indexed)

- Add the How to participate menu and two explicative web pages
  • Loading branch information
acheype committed Feb 27, 2018
1 parent bb6e6df commit af9309a
Show file tree
Hide file tree
Showing 39 changed files with 735 additions and 78 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/main/java/nc/ird/malariaplantdb/domain/Ethnology.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Type;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -41,30 +43,36 @@ public class Ethnology implements Serializable, Comparable<Ethnology> {

@NotNull
@ManyToOne(fetch = FetchType.EAGER)
// @Field(type = FieldType.Nested)
private Remedy remedy;

@NotNull
@Lob
@Type(type = "org.hibernate.type.StringClobType")
@Column(name = "ethno_relevancy", nullable = false)
@Field(type = FieldType.String)
private String ethnoRelevancy;

@NotNull
@Size(max = 255)
@Column(name = "treatment_type", length = 255, nullable = false)
@Field(type = FieldType.String)
private String treatmentType;

@Lob
@Type(type = "org.hibernate.type.StringClobType")
@Column(name = "traditional_recipe_details")
@Field(type = FieldType.String)
private String traditionalRecipeDetails;

@Size(max = 255)
@Column(name = "preparation_mode", length = 255)
@Field(type = FieldType.String)
private String preparationMode;

@Size(max = 255)
@Column(name = "administration_route", length = 255)
@Field(type = FieldType.String)
private String administrationRoute;

public Long getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Type;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.*;
import javax.validation.constraints.*;
Expand Down Expand Up @@ -42,6 +44,7 @@ public class InVitroPharmaco implements Serializable, Comparable<InVitroPharmaco

@NotNull
@ManyToOne(fetch = FetchType.EAGER)
@Field(type = FieldType.Nested)
private Remedy remedy;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Type;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.*;
import javax.validation.constraints.*;
Expand Down Expand Up @@ -42,6 +44,7 @@ public class InVivoPharmaco implements Serializable, Comparable<InVivoPharmaco>

@NotNull
@ManyToOne(fetch = FetchType.EAGER)
@Field(type = FieldType.Nested)
private Remedy remedy;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -40,6 +42,7 @@ public class PlantIngredient implements Serializable, Comparable<PlantIngredient

@NotNull
@ManyToOne
@Field(type = FieldType.Nested)
private Species species;

@NotNull
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/nc/ird/malariaplantdb/domain/PubSpecies.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -40,6 +42,7 @@ public class PubSpecies implements Serializable, Comparable<PubSpecies> {

@NotNull
@ManyToOne
@Field(type = FieldType.Nested)
private Species species = new Species();

@NotNull
Expand Down
35 changes: 30 additions & 5 deletions src/main/java/nc/ird/malariaplantdb/domain/Publication.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package nc.ird.malariaplantdb.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import org.hibernate.annotations.*;
import org.hibernate.annotations.Cache;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.*;
import javax.persistence.Entity;
Expand Down Expand Up @@ -52,6 +53,7 @@ public class Publication implements Serializable {
@BatchSize(size = 100)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@SortNatural
@Field(type = FieldType.Nested)
private SortedSet<Author> authors = new TreeSet<>();

@NotNull
Expand All @@ -63,70 +65,87 @@ public class Publication implements Serializable {
@NotNull
@Size(max = 255)
@Column(name = "title", length = 255, nullable = false)
@Field(type = FieldType.String)
private String title;

@Size(max = 255)
@Column(name = "journal", length = 255)
@Field(type = FieldType.String)
private String journal;

@Size(max = 255)
@Column(name = "pages", length = 255)
@Field(type = FieldType.String)
private String pages;

@Size(max = 255)
@Column(name = "volume", length = 255)
@Field(type = FieldType.String)
private String volume;

@Size(max = 255)
@Column(name = "nb_of_volumes", length = 255)
@Field(type = FieldType.String)
private String nbOfVolumes;

@Size(max = 255)
@Column(name = "number", length = 255)
@Field(type = FieldType.String)
private String number;

@Size(max = 255)
@Column(name = "book_title", length = 255)
@Field(type = FieldType.String)
private String bookTitle;

@Size(max = 255)
@Column(name = "publisher", length = 255)
@Field(type = FieldType.String)
private String publisher;

@Size(max = 255)
@Column(name = "edition", length = 255)
@Field(type = FieldType.String)
private String edition;

@Size(max = 255)
@Column(name = "conference_name", length = 255)
@Field(type = FieldType.String)
private String conferenceName;

@Size(max = 255)
@Column(name = "conference_place", length = 255)
@Field(type = FieldType.String)
private String conferencePlace;

@Size(max = 255)
@Column(name = "university", length = 255)
@Field(type = FieldType.String)
private String university;

@Size(max = 255)
@Column(name = "institution", length = 255)
@Field(type = FieldType.String)
private String institution;

@Size(max = 255)
@Column(name = "doi", length = 255)
@Field(type = FieldType.String)
private String doi;

@Size(max = 255)
@Column(name = "pmid", length = 255)
@Field(type = FieldType.String)
private String pmid;

@Size(max = 255)
@Column(name = "isbn", length = 255)
@Field(type = FieldType.String)
private String isbn;

@Size(max = 255)
@Column(name = "url", length = 255)
@Field(type = FieldType.String)
private String url;

@ManyToMany(fetch = FetchType.EAGER)
Expand All @@ -136,40 +155,46 @@ public class Publication implements Serializable {
joinColumns = @JoinColumn(name = "publications_id", referencedColumnName = "ID"),
inverseJoinColumns = @JoinColumn(name = "compilers_id", referencedColumnName = "ID"))
@SortNatural
// @Field(type = FieldType.Nested)
private SortedSet<Compiler> compilers = new TreeSet<>();

@Lob
@Type(type = "org.hibernate.type.StringClobType")
@Column(name = "compilers_notes")
@Field(type = FieldType.String)
private String compilersNotes;

@Lob
@Type(type = "org.hibernate.type.StringClobType")
@Column(name = "citation")
private String citation;

@JsonIgnore
//@JsonIgnore
@OneToMany(mappedBy = "publication")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@SortNatural
// @Field(type = FieldType.Nested)
private SortedSet<PubSpecies> pubSpecies = new TreeSet<>();

@JsonIgnore
//@JsonIgnore
@OneToMany(mappedBy = "publication")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@SortNatural
@Field(type = FieldType.Nested)
private SortedSet<Ethnology> ethnologies = new TreeSet<>();

@JsonIgnore
//@JsonIgnore
@OneToMany(mappedBy = "publication")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@SortNatural
// @Field(type = FieldType.Nested)
private SortedSet<InVivoPharmaco> inVivoPharmacos = new TreeSet<>();

@JsonIgnore
//@JsonIgnore
@OneToMany(mappedBy = "publication")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@SortNatural
// @Field(type = FieldType.Nested)
private SortedSet<InVitroPharmaco> inVitroPharmacos = new TreeSet<>();

public Long getId() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/nc/ird/malariaplantdb/domain/Remedy.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.SortNatural;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -43,6 +45,7 @@ public class Remedy implements Serializable, Comparable<Remedy> {
@BatchSize(size = 100)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@SortNatural
@Field(type = FieldType.Nested)
private SortedSet<PlantIngredient> plantIngredients = new TreeSet<>();

public Long getId() {
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/nc/ird/malariaplantdb/service/IndexerService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package nc.ird.malariaplantdb.service;

import nc.ird.malariaplantdb.domain.*;
import nc.ird.malariaplantdb.domain.Compiler;
import nc.ird.malariaplantdb.repository.CompilerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.IndexQuery;
Expand All @@ -10,38 +13,47 @@

@Service
public class IndexerService {

private static final Class[] CLASSES_TO_INDEX = {Author.class, Compiler.class, Ethnology.class,
InVivoPharmaco.class, InVitroPharmaco.class, PlantIngredient.class, Publication.class, PubSpecies.class,
Remedy.class, Species.class, User.class};

@Autowired
CompilerRepository compilerRepository;

private static final String INDEX_NAME = "compiler";
public static final double INDEX_COMMIT_SIZE = 100;

// https://stackoverflow.com/questions/37312415/batch-indexing-spring-data-jpa-entries-to-elastic-through-spring-data-elasticsea

@Autowired
ElasticsearchTemplate elasticsearchTemplate;

public long bulkIndex() throws Exception {
int counter = 0;
try {
if (!elasticsearchTemplate.indexExists(INDEX_NAME)) {

} else {
elasticsearchTemplate.deleteIndex(INDEX_NAME);
if (elasticsearchTemplate.indexExists("compiler")) {
elasticsearchTemplate.deleteIndex("compiler");
}
elasticsearchTemplate.createIndex(INDEX_NAME);

elasticsearchTemplate.createIndex("compiler");

List<Compiler> compilers = compilerRepository.findAll();
List<IndexQuery> queries = new ArrayList<IndexQuery>();

// for (Car car : cars) {
for (Compiler compiler : compilers) {
IndexQuery indexQuery = new IndexQuery();
// indexQuery.setId(car.getId().toString());
// indexQuery.setSource(gson.toJson(car));
indexQuery.setIndexName(INDEX_NAME);
indexQuery.setIndexName("compiler");
queries.add(indexQuery);
if (counter % INDEX_COMMIT_SIZE == 0) {
elasticsearchTemplate.bulkIndex(queries);
queries.clear();
System.out.println("bulkIndex counter : " + counter);
}
counter++;
// }
}
if (queries.size() > 0) {
elasticsearchTemplate.bulkIndex(queries);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ResponseEntity<List<Author>> getAllAuthors(Pageable pageable)
Page<Author> page = authorRepository.findAll(pageable);
// eagerly load the association
page.getContent().stream().forEach(author -> author.getPublication().getTitle());
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/authors");
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/authors");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public ResponseEntity<Compiler> updateCompiler(@Valid @RequestBody Compiler comp
public ResponseEntity<List<Compiler>> getAllCompilers(Pageable pageable)
throws URISyntaxException {
Page<Compiler> page = compilerRepository.findAll(pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/compilers");
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/compilers");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public ResponseEntity<Ethnology> updateEthnology(@Valid @RequestBody Ethnology e
public ResponseEntity<List<Ethnology>> getAllEthnologies(Pageable pageable)
throws URISyntaxException {
Page<Ethnology> page = ethnologyRepository.findAll(pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/ethnologies");
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/ethnologies");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}

Expand Down
Loading

0 comments on commit af9309a

Please sign in to comment.