From b260838e0ce392481fa3554f27871d51e75d8ee9 Mon Sep 17 00:00:00 2001 From: manalejandro Date: Thu, 12 Jul 2018 21:02:30 +0200 Subject: [PATCH] annotations and elasticsearch --- pom.xml | 2 +- .../com/manalejandro/arjion/ESConfig.java | 64 +++++++++++++++++++ .../arjion/ServletInitializer.java | 12 ++++ .../arjion/controllers/MainController.java | 8 +++ .../arjion/forms/DocumentoForm.java | 5 ++ .../manalejandro/arjion/model/Documento.java | 12 ++++ .../arjion/repositories/MainRepository.java | 11 ++++ .../arjion/services/MainService.java | 8 +++ .../arjion/services/MainServiceImpl.java | 5 ++ .../manalejandro/arjion/vo/DocumentoVO.java | 5 ++ src/main/resources/application.properties | 9 +++ src/main/resources/elasticsearch/mapping.json | 0 .../resources/elasticsearch/settings.json | 0 13 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/manalejandro/arjion/ESConfig.java create mode 100644 src/main/java/com/manalejandro/arjion/ServletInitializer.java create mode 100644 src/main/java/com/manalejandro/arjion/controllers/MainController.java create mode 100644 src/main/java/com/manalejandro/arjion/forms/DocumentoForm.java create mode 100644 src/main/java/com/manalejandro/arjion/model/Documento.java create mode 100644 src/main/java/com/manalejandro/arjion/repositories/MainRepository.java create mode 100644 src/main/java/com/manalejandro/arjion/services/MainService.java create mode 100644 src/main/java/com/manalejandro/arjion/services/MainServiceImpl.java create mode 100644 src/main/java/com/manalejandro/arjion/vo/DocumentoVO.java create mode 100644 src/main/resources/elasticsearch/mapping.json create mode 100644 src/main/resources/elasticsearch/settings.json diff --git a/pom.xml b/pom.xml index 39e516d..8228cf1 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ war arjion - Demo project for Spring Boot + Demo project of Apache Tika for Spring Boot org.springframework.boot diff --git a/src/main/java/com/manalejandro/arjion/ESConfig.java b/src/main/java/com/manalejandro/arjion/ESConfig.java new file mode 100644 index 0000000..3684273 --- /dev/null +++ b/src/main/java/com/manalejandro/arjion/ESConfig.java @@ -0,0 +1,64 @@ +package com.manalejandro.arjion; + +import java.net.InetAddress; +import org.elasticsearch.client.Client; +import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.TransportAddress; +import org.elasticsearch.transport.client.PreBuiltTransportClient; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.elasticsearch.core.ElasticsearchOperations; +import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; +import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; + +@Configuration +@EnableElasticsearchRepositories(basePackages = "com.manalejandro.arjion.repositories") +public class ESConfig { + + @Value("${elasticsearch.host}") + private String EsHost; + + @Value("${elasticsearch.port}") + private int EsPort; + + @Value("${elasticsearch.clustername}") + private String EsClusterName; + + @Value("${elasticsearch.nodename}") + private String EsNodeName; + + @Value("${arjion.indexName}") + private String indexName; + + @Value("${arjion.documentType}") + private String documentType; + + private TransportClient client; + + @Bean + public Client client() throws Exception { + + Settings esSettings = Settings.builder().put("cluster.name", EsClusterName).put("node.name", EsNodeName) + .build(); + + client = new PreBuiltTransportClient(esSettings); + return client.addTransportAddress(new TransportAddress(InetAddress.getByName(EsHost), EsPort)); + } + + @Bean + public ElasticsearchOperations elasticsearchTemplate() throws Exception { + return new ElasticsearchTemplate(client()); + } + + @Bean + public String indexName() { + return indexName; + } + + @Bean + public String documentType() { + return documentType; + } +} diff --git a/src/main/java/com/manalejandro/arjion/ServletInitializer.java b/src/main/java/com/manalejandro/arjion/ServletInitializer.java new file mode 100644 index 0000000..17d336f --- /dev/null +++ b/src/main/java/com/manalejandro/arjion/ServletInitializer.java @@ -0,0 +1,12 @@ +package com.manalejandro.arjion; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +public class ServletInitializer extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(ArjionApplication.class); + } +} diff --git a/src/main/java/com/manalejandro/arjion/controllers/MainController.java b/src/main/java/com/manalejandro/arjion/controllers/MainController.java new file mode 100644 index 0000000..b4da584 --- /dev/null +++ b/src/main/java/com/manalejandro/arjion/controllers/MainController.java @@ -0,0 +1,8 @@ +package com.manalejandro.arjion.controllers; + +import org.springframework.stereotype.Controller; + +@Controller +public class MainController { + +} diff --git a/src/main/java/com/manalejandro/arjion/forms/DocumentoForm.java b/src/main/java/com/manalejandro/arjion/forms/DocumentoForm.java new file mode 100644 index 0000000..6ffe4a3 --- /dev/null +++ b/src/main/java/com/manalejandro/arjion/forms/DocumentoForm.java @@ -0,0 +1,5 @@ +package com.manalejandro.arjion.forms; + +public class DocumentoForm { + +} diff --git a/src/main/java/com/manalejandro/arjion/model/Documento.java b/src/main/java/com/manalejandro/arjion/model/Documento.java new file mode 100644 index 0000000..9029b8e --- /dev/null +++ b/src/main/java/com/manalejandro/arjion/model/Documento.java @@ -0,0 +1,12 @@ +package com.manalejandro.arjion.model; + +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Mapping; +import org.springframework.data.elasticsearch.annotations.Setting; + +@Document(indexName = "#{@indexName}", type = "#{@documentType}") +@Setting(settingPath = "/elasticsearch/settings.json") +@Mapping(mappingPath = "/elasticsearch/mapping.json") +public class Documento { + +} diff --git a/src/main/java/com/manalejandro/arjion/repositories/MainRepository.java b/src/main/java/com/manalejandro/arjion/repositories/MainRepository.java new file mode 100644 index 0000000..8071e87 --- /dev/null +++ b/src/main/java/com/manalejandro/arjion/repositories/MainRepository.java @@ -0,0 +1,11 @@ +package com.manalejandro.arjion.repositories; + +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; +import org.springframework.stereotype.Repository; + +import com.manalejandro.arjion.model.Documento; + +@Repository +public interface MainRepository extends ElasticsearchRepository { + +} diff --git a/src/main/java/com/manalejandro/arjion/services/MainService.java b/src/main/java/com/manalejandro/arjion/services/MainService.java new file mode 100644 index 0000000..ce8570e --- /dev/null +++ b/src/main/java/com/manalejandro/arjion/services/MainService.java @@ -0,0 +1,8 @@ +package com.manalejandro.arjion.services; + +import org.springframework.stereotype.Service; + +@Service +public interface MainService { + +} diff --git a/src/main/java/com/manalejandro/arjion/services/MainServiceImpl.java b/src/main/java/com/manalejandro/arjion/services/MainServiceImpl.java new file mode 100644 index 0000000..48b97b0 --- /dev/null +++ b/src/main/java/com/manalejandro/arjion/services/MainServiceImpl.java @@ -0,0 +1,5 @@ +package com.manalejandro.arjion.services; + +public class MainServiceImpl implements MainService { + +} diff --git a/src/main/java/com/manalejandro/arjion/vo/DocumentoVO.java b/src/main/java/com/manalejandro/arjion/vo/DocumentoVO.java new file mode 100644 index 0000000..6e20522 --- /dev/null +++ b/src/main/java/com/manalejandro/arjion/vo/DocumentoVO.java @@ -0,0 +1,5 @@ +package com.manalejandro.arjion.vo; + +public class DocumentoVO { + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e69de29..dd98db8 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -0,0 +1,9 @@ +server.servlet.context-path=/arjion +server.port=8080 +elasticsearch.clustername=development +elasticsearch.host=localhost +elasticsearch.port=9300 +elasticsearch.nodename=arjion +arjion.indexName=documentos +arjion.documentType=documento +spring.main.allow-bean-definition-overriding=true \ No newline at end of file diff --git a/src/main/resources/elasticsearch/mapping.json b/src/main/resources/elasticsearch/mapping.json new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/elasticsearch/settings.json b/src/main/resources/elasticsearch/settings.json new file mode 100644 index 0000000..e69de29