Commit 85f78a8c authored by Matija Obreza's avatar Matija Obreza

ES6 skip scanning for @Document entities

parent 75d0cbca
......@@ -21,7 +21,9 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
......@@ -66,7 +68,10 @@ import org.springframework.data.elasticsearch.core.ElasticsearchEntityMapper;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.EntityMapper;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.context.MappingContext;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
......@@ -149,11 +154,18 @@ public class ElasticsearchConfig extends ElasticsearchConfigurationSupport {
return new RestHighLevelClient(RestClient.builder(httpHosts.toArray(new HttpHost[httpHosts.size()])));
}
}
// We don't want to scan for entities
@Override
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {
return new HashSet<>();
}
@Bean
@Override
public EntityMapper entityMapper() {
ElasticsearchEntityMapper entityMapper = new GenesysEntityMapper();
ElasticsearchEntityMapper entityMapper = new GenesysEntityMapper(elasticsearchMappingContext());
entityMapper.setConversions(elasticsearchCustomConversions());
return entityMapper;
}
......@@ -240,15 +252,16 @@ public class ElasticsearchConfig extends ElasticsearchConfigurationSupport {
/**
* The Class GenesysEntityMapper.
*/
public class GenesysEntityMapper extends ElasticsearchEntityMapper {
public static class GenesysEntityMapper extends ElasticsearchEntityMapper {
private final ObjectMapper mapper;
/**
* Instantiates a new genesys entity mapper.
* @param mappingContext
*/
public GenesysEntityMapper() {
super(elasticsearchMappingContext(), new DefaultConversionService());
public GenesysEntityMapper(MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext) {
super(mappingContext, new DefaultConversionService());
mapper = new ObjectMapper();
......
......@@ -16,6 +16,8 @@
package org.genesys.test.config;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.elasticsearch.client.RestHighLevelClient;
......@@ -99,10 +101,16 @@ public class TestElasticsearchConfig extends ElasticsearchConfigurationSupport i
return RestClients.create(ClientConfiguration.localhost()).rest();
}
// We don't want to scan for entities
@Override
protected Set<Class<?>> getInitialEntitySet() throws ClassNotFoundException {
return new HashSet<>();
}
@Bean
@Override
public EntityMapper entityMapper() {
ElasticsearchEntityMapper entityMapper = new ElasticsearchConfig().new GenesysEntityMapper();
ElasticsearchEntityMapper entityMapper = new ElasticsearchConfig.GenesysEntityMapper(elasticsearchMappingContext());
entityMapper.setConversions(elasticsearchCustomConversions());
return entityMapper;
}
......
......@@ -19,6 +19,7 @@ import static com.google.common.collect.Sets.newHashSet;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -31,6 +32,7 @@ import org.genesys.catalog.model.filters.DatasetFilter;
import org.genesys.test.base.AbstractElasticServiceTest;
import org.genesys2.server.model.PublishState;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.impl.Country;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.persistence.AccessionIdRepository;
import org.genesys2.server.persistence.AccessionRepository;
......@@ -46,6 +48,7 @@ import org.genesys2.server.service.worker.AccessionUploader;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.elasticsearch.core.EntityMapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -79,6 +82,8 @@ public class ElasticQueryBuilderTest extends AbstractElasticServiceTest {
private AccessionIdRepository accessionIdRepository;
@Autowired
private ElasticsearchService elasticsearchService;
@Autowired
private EntityMapper entityMapper;
static {
objectMapper = new ObjectMapper();
......@@ -144,6 +149,16 @@ public class ElasticQueryBuilderTest extends AbstractElasticServiceTest {
} while (count != 0);
}
@Test
public void testEntityMapper() throws IOException {
Country c = new Country();
c.setCode2("00");
c.setCode3("000");
c.setName("Foo");
c.setNameL("NameL");
assertThat(entityMapper.mapToString(c), is("{\"code3\":\"000\",\"code2\":\"00\",\"current\":false,\"name\":\"Foo\",\"_class\":\"Country\"}"));
}
@Test
public void testHolderCode() throws SearchException, JsonProcessingException {
......
package org.genesys.test.simpletest;
import java.io.IOException;
import org.genesys2.server.model.impl.Country;
import org.genesys2.spring.config.ElasticsearchConfig;
import org.genesys2.spring.config.ElasticsearchConfig.GenesysEntityMapper;
import org.junit.Test;
public class ElasticSerializerTest {
GenesysEntityMapper mapper = new ElasticsearchConfig().new GenesysEntityMapper();
@Test
public void test1() throws IOException {
Country c = new Country();
c.setCode2("00");
c.setCode3("000");
c.setName("Foo");
c.setNameL("NameL");
System.out.println(mapper.mapToString(c));
}
}
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