Commit 04f89a7b authored by Matija Obreza's avatar Matija Obreza

Updates for ES indexing

- ensure all entities are reindexed by using `ORDER BY id`
- disabled FORCE_LAZY_LOADING
parent 8197cdd2
......@@ -38,6 +38,7 @@ import org.genesys.worldclim.WorldClimUtil;
import org.genesys2.server.model.impl.GeoReferencedEntity;
import org.genesys2.server.model.impl.TileClimate;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonView;
@Entity
......@@ -71,6 +72,7 @@ public class AccessionGeo extends BasicModel implements GeoReferencedEntity, Acc
@ManyToOne(cascade = {}, fetch = FetchType.LAZY, optional = true)
@JoinColumn(name = "tileIndex", nullable = true, insertable = false, updatable = false, foreignKey = @javax.persistence.ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
@JsonView({ JsonViews.Protected.class })
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private TileClimate climate;
/**
......
......@@ -283,7 +283,9 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
PathBuilder<R> pathBuilder = new PathBuilder<R>(clazz, entityPath.getMetadata().getName());
JPQLQuery<Long> query = querydsl.createQuery(entityPath)
// select id only
.select(pathBuilder.getNumber("id", Long.class));
.select(pathBuilder.getNumber("id", Long.class))
// and order by id
.orderBy(pathBuilder.getNumber("id", Long.class).asc());
if (filter != null) {
// apply filter
......@@ -404,7 +406,7 @@ public class ElasticsearchServiceImpl implements ElasticsearchService, Initializ
try {
elasticsearchTemplate.bulkIndex(queries);
} catch (org.springframework.data.elasticsearch.ElasticsearchException e) {
LOG.error(e.getMessage());
LOG.error(e.getMessage(), e);
Map<String, String> failedDocs = e.getFailedDocuments();
if (failedDocs != null) {
for (String key : failedDocs.keySet()) {
......
......@@ -53,7 +53,6 @@ import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module.Feature;
......@@ -190,16 +189,17 @@ public class ElasticsearchConfig {
public static class GenesysEntityMapper implements EntityMapper {
private final ObjectMapper mapper;
private ObjectWriter writer;
/**
* Instantiates a new genesys entity mapper.
*/
public GenesysEntityMapper() {
mapper = new ObjectMapper();
Hibernate4Module hib4 = new Hibernate4Module();
hib4.enable(Feature.FORCE_LAZY_LOADING);
mapper.registerModule(hib4);
Hibernate4Module hibernateModule = new Hibernate4Module();
hibernateModule.disable(Feature.FORCE_LAZY_LOADING);
hibernateModule.disable(Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS);
mapper.registerModule(hibernateModule);
// deserialization
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
......
......@@ -62,6 +62,7 @@ import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module.Feature;
/**
* Spring MVC
......@@ -215,7 +216,12 @@ public class WebConfiguration extends WebMvcConfigurerAdapter {
final MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
final ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Hibernate4Module());
Hibernate4Module hibernateModule = new Hibernate4Module();
hibernateModule.disable(Feature.FORCE_LAZY_LOADING);
hibernateModule.disable(Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS);
mapper.registerModule(hibernateModule);
// serialization
mapper.disable(SerializationFeature.EAGER_SERIALIZER_FETCH);
// deserialization
......
......@@ -54,6 +54,7 @@ import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module.Feature;
public final class ApplicationConfig {
......@@ -234,7 +235,12 @@ public final class ApplicationConfig {
final MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
final ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new Hibernate4Module());
Hibernate4Module hibernateModule = new Hibernate4Module();
hibernateModule.disable(Feature.FORCE_LAZY_LOADING);
hibernateModule.disable(Feature.SERIALIZE_IDENTIFIER_FOR_LAZY_NOT_LOADED_OBJECTS);
mapper.registerModule(hibernateModule);
// serialization
mapper.disable(SerializationFeature.EAGER_SERIALIZER_FETCH);
// deserialization
......
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