Skip to content
Snippets Groups Projects
Commit d1770eb9 authored by Cornelia Michlits's avatar Cornelia Michlits
Browse files

Merge branch '84-search-service' into dev

# Conflicts:
#	fda-database-service/services/src/main/java/at/tuwien/service/DatabaseService.java
#	fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/Database.java
#	fda-metadata-db/entities/src/main/java/at/tuwien/entities/database/table/Table.java
#	fda-table-service/rest-service/src/main/resources/application-docker.yml
#	fda-table-service/rest-service/src/main/resources/application.yml
#	fda-table-service/services/src/main/java/at/tuwien/service/TableService.java


Former-commit-id: 0f9801f0
parents 113a39e1 d6a34b41
Branches
Tags
1 merge request!42Fixed the query service tests
Showing
with 134 additions and 6 deletions
...@@ -230,6 +230,7 @@ services: ...@@ -230,6 +230,7 @@ services:
container_name: fda-search-service container_name: fda-search-service
hostname: fda-search-service hostname: fda-search-service
image: elasticsearch:7.13.4 image: elasticsearch:7.13.4
command: ["elasticsearch", "-Elogger.level=WARN"]
networks: networks:
- fda-public - fda-public
environment: environment:
...@@ -239,6 +240,8 @@ services: ...@@ -239,6 +240,8 @@ services:
ports: ports:
- 9200:9200 - 9200:9200
- 9600:9600 - 9600:9600
logging:
driver: json-file
fda-ui: fda-ui:
restart: on-failure restart: on-failure
...@@ -269,4 +272,4 @@ services: ...@@ -269,4 +272,4 @@ services:
API_IMAGE: http://fda-container-service:9091 API_IMAGE: http://fda-container-service:9091
API_DATABASE: http://fda-database-service:9092 API_DATABASE: http://fda-database-service:9092
API_TABLES: http://fda-table-service:9094 API_TABLES: http://fda-table-service:9094
API_ANALYSE: http://fda-analyse-service:5000 API_ANALYSE: http://fda-analyse-service:5000
\ No newline at end of file
package at.tuwien.config;
import at.tuwien.entities.database.Database;
import com.google.common.collect.ImmutableMap;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.stereotype.Component;
import java.util.HashMap;
@Component
@Log4j2
public class IndexInitializer {
private final ElasticsearchOperations elasticsearchOperations;
public IndexInitializer(ElasticsearchOperations elasticsearchOperations) {
this.elasticsearchOperations = elasticsearchOperations;
}
@EventListener(ApplicationReadyEvent.class)
public void initIndex() {
log.debug("creating index");
IndexCoordinates indexCoordinates = IndexCoordinates.of("databaseindex");
if (!elasticsearchOperations.indexOps(indexCoordinates).exists()) {
elasticsearchOperations.indexOps(indexCoordinates).create();
elasticsearchOperations.indexOps(indexCoordinates).createMapping(Database.class);
}
}
}
...@@ -5,5 +5,5 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository ...@@ -5,5 +5,5 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository(value = "ElasticDatabaseRepository") @Repository(value = "ElasticDatabaseRepository")
public interface DatabaseRepository extends ElasticsearchRepository<Database, Long> { public interface DatabaseidxRepository extends ElasticsearchRepository<Database, Long> {
} }
...@@ -11,6 +11,7 @@ import at.tuwien.mapper.DatabaseMapper; ...@@ -11,6 +11,7 @@ import at.tuwien.mapper.DatabaseMapper;
import at.tuwien.mapper.ImageMapper; import at.tuwien.mapper.ImageMapper;
import at.tuwien.repository.jpa.ContainerRepository; import at.tuwien.repository.jpa.ContainerRepository;
import at.tuwien.repository.jpa.DatabaseRepository; import at.tuwien.repository.jpa.DatabaseRepository;
import at.tuwien.repository.elastic.DatabaseidxRepository;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -31,18 +32,21 @@ public class DatabaseService extends JdbcConnector { ...@@ -31,18 +32,21 @@ public class DatabaseService extends JdbcConnector {
private final ContainerRepository containerRepository; private final ContainerRepository containerRepository;
private final DatabaseRepository databaseRepository; private final DatabaseRepository databaseRepository;
private final DatabaseidxRepository databaseidxRepository;
private final DatabaseMapper databaseMapper; private final DatabaseMapper databaseMapper;
private final AmqpService amqpService; private final AmqpService amqpService;
private final AmqpMapper amqpMapper; private final AmqpMapper amqpMapper;
@Autowired @Autowired
public DatabaseService(ContainerRepository containerRepository, DatabaseRepository databaseRepository, public DatabaseService(ContainerRepository containerRepository, DatabaseRepository databaseRepository,
ImageMapper imageMapper, DatabaseMapper databaseMapper, DatabaseidxRepository databaseidxRepository, ImageMapper imageMapper,
DatabaseMapper databaseMapper,
AmqpService amqpService, AmqpMapper amqpMapper) { AmqpService amqpService, AmqpMapper amqpMapper) {
super(imageMapper, databaseMapper); super(imageMapper, databaseMapper);
this.containerRepository = containerRepository; this.containerRepository = containerRepository;
this.databaseRepository = databaseRepository; this.databaseRepository = databaseRepository;
this.databaseMapper = databaseMapper; this.databaseMapper = databaseMapper;
this.databaseidxRepository = databaseidxRepository;
this.amqpService = amqpService; this.amqpService = amqpService;
this.amqpMapper = amqpMapper; this.amqpMapper = amqpMapper;
} }
...@@ -125,6 +129,8 @@ public class DatabaseService extends JdbcConnector { ...@@ -125,6 +129,8 @@ public class DatabaseService extends JdbcConnector {
final Database out = databaseRepository.save(database); final Database out = databaseRepository.save(database);
log.info("Created database {}", out.getId()); log.info("Created database {}", out.getId());
log.debug("created database {}", out); log.debug("created database {}", out);
// save in database_index - elastic search
databaseidxRepository.save(database);
return out; return out;
} }
...@@ -148,6 +154,8 @@ public class DatabaseService extends JdbcConnector { ...@@ -148,6 +154,8 @@ public class DatabaseService extends JdbcConnector {
final Database out = databaseRepository.save(database); final Database out = databaseRepository.save(database);
log.info("Updated database {}", out.getId()); log.info("Updated database {}", out.getId());
log.debug("updated database {}", out); log.debug("updated database {}", out);
// save in database_index - elastic search
databaseidxRepository.save(database);
return out; return out;
} }
......
...@@ -21,8 +21,8 @@ import java.util.List; ...@@ -21,8 +21,8 @@ import java.util.List;
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Document(indexName = "databaseindex", createIndex = false)
@Where(clause = "deleted is null") @Where(clause = "deleted is null")
@Document(indexName = "databaseindex")
@ToString(onlyExplicitlyIncluded = true) @ToString(onlyExplicitlyIncluded = true)
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
......
...@@ -6,6 +6,9 @@ import lombok.*; ...@@ -6,6 +6,9 @@ import lombok.*;
import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*; import javax.persistence.*;
...@@ -17,6 +20,7 @@ import java.util.List; ...@@ -17,6 +20,7 @@ import java.util.List;
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Document(indexName = "tblindex", createIndex = false)
@IdClass(TableKey.class) @IdClass(TableKey.class)
@ToString(onlyExplicitlyIncluded = true) @ToString(onlyExplicitlyIncluded = true)
@EntityListeners(AuditingEntityListener.class) @EntityListeners(AuditingEntityListener.class)
...@@ -67,6 +71,7 @@ public class Table { ...@@ -67,6 +71,7 @@ public class Table {
@ToString.Include @ToString.Include
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "table") @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "table")
@Field(type = FieldType.Nested)
private List<TableColumn> columns; private List<TableColumn> columns;
@Column(nullable = false, updatable = false) @Column(nullable = false, updatable = false)
......
...@@ -31,6 +31,7 @@ eureka: ...@@ -31,6 +31,7 @@ eureka:
fda: fda:
mapping.path: /root mapping.path: /root
table.path: /root table.path: /root
elastic.endpoint: fda-search-service:9200
zenodo: zenodo:
endpoint: https://sandbox.zenodo.org/ endpoint: https://sandbox.zenodo.org/
api_key: "${ZENODO_API_KEY}" api_key: "${ZENODO_API_KEY}"
\ No newline at end of file
...@@ -32,6 +32,7 @@ eureka: ...@@ -32,6 +32,7 @@ eureka:
fda: fda:
mapping.path: rest-service/src/main/resources mapping.path: rest-service/src/main/resources
table.path: rest-service/src/main/java/at/tuwien/userdb table.path: rest-service/src/main/java/at/tuwien/userdb
elastic.endpoint: fda-search-service:9200
zenodo: zenodo:
endpoint: https://sandbox.zenodo.org/ endpoint: https://sandbox.zenodo.org/
api_key: "${ZENODO_API_KEY}" api_key: "${ZENODO_API_KEY}"
\ No newline at end of file
package at.tuwien.config;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import java.util.Properties;
@Configuration
public class ElasticsearchConfig {
@Value("${fda.elastic.endpoint}")
private String elasticEndpoint;
@Bean
public RestHighLevelClient client() {
ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo(elasticEndpoint)
.build();
return RestClients.create(clientConfiguration).rest();
}
@Bean
public ElasticsearchOperations elasticsearchTemplate() {
return new ElasticsearchRestTemplate(client());
}
}
\ No newline at end of file
package at.tuwien.config;
import at.tuwien.entities.database.Database;
import com.google.common.collect.ImmutableMap;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.stereotype.Component;
import java.util.HashMap;
@Component
@Log4j2
public class IndexInitializer {
private final ElasticsearchOperations elasticsearchOperations;
public IndexInitializer(ElasticsearchOperations elasticsearchOperations) {
this.elasticsearchOperations = elasticsearchOperations;
}
@EventListener(ApplicationReadyEvent.class)
public void initIndex() {
log.debug("creating index");
IndexCoordinates indexCoordinates = IndexCoordinates.of("tblindex");
if (!elasticsearchOperations.indexOps(indexCoordinates).exists()) {
elasticsearchOperations.indexOps(indexCoordinates).create();
elasticsearchOperations.indexOps(indexCoordinates).createMapping(Database.class);
}
}
}
package at.tuwien.repository.elastic;
import at.tuwien.entities.database.Database;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;
@Repository(value = "ElasticDatabaseRepository")
public interface DatabaseidxRepository extends ElasticsearchRepository<Database, Long> {
}
package at.tuwien.repository.elastic; package at.tuwien.repository.elastic;
import at.tuwien.entities.database.Database; import at.tuwien.entities.database.table.Table;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository(value = "ElasticDatabaseService") @Repository(value = "ElasticDatabaseService")
public interface DatabaseRepository extends ElasticsearchRepository<Database, Long> { public interface TableidxRepository extends ElasticsearchRepository<Table, Long> {
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment