Commit 08b13ca4 authored by Matija Obreza's avatar Matija Obreza

Fix: ensure current GRIN species is loaded in search

parent 2723cf79
......@@ -97,12 +97,14 @@ public class Taxonomy2 extends GlobalVersionedAuditedModel {
@JoinColumn(name = "grinTaxonomySpecies")
@JsonProperty(access = Access.READ_ONLY)
@Field(type = FieldType.Object)
@JsonIgnoreProperties({ "currentTaxonomySpecies", "taxonomyGenus" })
private TaxonomySpecies grinTaxonomySpecies;
@ManyToOne(cascade = {}, fetch = FetchType.EAGER, optional = true)
@JoinColumn(name = "currentTaxonomySpecies")
@JsonProperty(access = Access.READ_ONLY)
@Field(type = FieldType.Object)
@JsonIgnoreProperties({ "currentTaxonomySpecies", "taxonomyGenus" })
private TaxonomySpecies currentTaxonomySpecies;
@ManyToOne(cascade = {}, fetch = FetchType.EAGER, optional = true)
......
......@@ -32,6 +32,7 @@ import javax.persistence.Table;
import org.apache.commons.lang3.StringUtils;
import org.genesys.blocks.model.Copyable;
import org.genesys.custom.elasticsearch.IgnoreField;
import org.genesys.taxonomy.gringlobal.model.IGrinSpecies;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
......@@ -80,8 +81,7 @@ public class TaxonomySpecies extends CooperatorOwnedModel implements IGrinSpecie
@ManyToOne(fetch = FetchType.LAZY, cascade = {})
@JoinColumn(name = "current_taxonomy_species_id")
@JsonIdentityInfo(scope = TaxonomySpecies.class, generator = ObjectIdGenerators.PropertyGenerator.class, property = "id")
@JsonIdentityReference(alwaysAsId = true)
@Field(index = false, type = FieldType.Long)
@IgnoreField
@JsonIgnoreProperties({ "currentTaxonomySpecies", "taxonomyGenus" })
private TaxonomySpecies currentTaxonomySpecies;
......
......@@ -35,6 +35,7 @@ import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.filter.TaxonomyExtraFilter;
import org.genesys2.server.service.filter.TaxonomyFilter;
import org.genesys2.server.service.filter.TaxonomySpeciesFilter;
import org.hibernate.Hibernate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -259,6 +260,8 @@ public class TaxonomyServiceImpl implements TaxonomyService {
}
}
Page<TaxonomySpecies> res = grinSpeciesRepository.findAll(predicate, page);
// Ensure current species is loaded
res.getContent().forEach(grinSpecies -> Hibernate.initialize(grinSpecies.getCurrentTaxonomySpecies()));
return new PageImpl<>(res.getContent(), page, res.getTotalElements());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment