Skip to content
Snippets Groups Projects
Commit f48bad67 authored by Martin Weise's avatar Martin Weise
Browse files

updated interfaces

Former-commit-id: 5b723126
parent 66d5e936
No related branches found
No related tags found
1 merge request!42Fixed the query service tests
......@@ -5,7 +5,7 @@ import at.tuwien.api.database.table.TableCsvDto;
import at.tuwien.api.database.table.TableInsertDto;
import at.tuwien.entities.database.table.Table;
import at.tuwien.exception.*;
import at.tuwien.service.impl.MariaDataService;
import at.tuwien.service.DataService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
......@@ -24,10 +24,10 @@ import java.sql.Timestamp;
@RequestMapping("/api/database/{id}/table/{tableId}/data")
public class DataEndpoint {
private final MariaDataService dataService;
private final DataService dataService;
@Autowired
public DataEndpoint(MariaDataService dataService) {
public DataEndpoint(DataService dataService) {
this.dataService = dataService;
}
......
......@@ -4,6 +4,8 @@ import at.tuwien.api.database.table.*;
import at.tuwien.entities.database.table.Table;
import at.tuwien.exception.*;
import at.tuwien.mapper.TableMapper;
import at.tuwien.service.MessageQueueService;
import at.tuwien.service.TableService;
import at.tuwien.service.impl.RabbitMqService;
import at.tuwien.service.impl.TableServiceImpl;
import io.swagger.annotations.ApiOperation;
......@@ -26,12 +28,12 @@ import java.util.stream.Collectors;
@RequestMapping("/api/database/{id}")
public class TableEndpoint {
private final TableServiceImpl tableService;
private final RabbitMqService amqpService;
private final TableService tableService;
private final MessageQueueService amqpService;
private final TableMapper tableMapper;
@Autowired
public TableEndpoint(TableServiceImpl tableService, RabbitMqService amqpService, TableMapper tableMapper) {
public TableEndpoint(TableService tableService, MessageQueueService amqpService, TableMapper tableMapper) {
this.tableService = tableService;
this.amqpService = amqpService;
this.tableMapper = tableMapper;
......
......@@ -5,14 +5,22 @@ import at.tuwien.api.database.table.TableCsvDto;
import at.tuwien.api.database.table.TableInsertDto;
import at.tuwien.entities.database.table.Table;
import at.tuwien.exception.*;
import com.opencsv.exceptions.CsvException;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.sql.Timestamp;
public interface DataService {
/**
* Find a table by database-table id pair
*
* @param databaseId The database-table id pair.
* @param tableId The database-table id pair.
* @return The table.
* @throws TableNotFoundException The table was not found.
* @throws DatabaseNotFoundException The database was not found.
*/
Table findById(Long databaseId, Long tableId) throws TableNotFoundException, DatabaseNotFoundException;
/**
* Insert data from a file into a table of a database
*
......
......@@ -52,6 +52,7 @@ public class MariaDataService extends JdbcConnector implements DataService {
this.databaseRepository = databaseRepository;
}
@Override
@Transactional
public Table findById(Long databaseId, Long tableId) throws TableNotFoundException, DatabaseNotFoundException {
final Optional<Table> table = tableRepository.findByDatabaseAndId(findDatabase(databaseId), tableId);
......
......@@ -7,6 +7,7 @@ import at.tuwien.exception.AmqpException;
import at.tuwien.exception.ImageNotSupportedException;
import at.tuwien.exception.TableMalformedException;
import at.tuwien.repository.jpa.TableRepository;
import at.tuwien.service.DataService;
import at.tuwien.service.MessageQueueService;
import at.tuwien.service.impl.MariaDataService;
import com.fasterxml.jackson.core.JsonParseException;
......@@ -34,12 +35,12 @@ public class RabbitMqService implements MessageQueueService {
private static final String AMQP_EXCHANGE = "fda";
private final Channel channel;
private final MariaDataService dataService;
private final DataService dataService;
private final ObjectMapper objectMapper;
private final TableRepository tableRepository;
@Autowired
public RabbitMqService(Channel channel, MariaDataService dataService, ObjectMapper objectMapper,
public RabbitMqService(Channel channel, DataService dataService, ObjectMapper objectMapper,
TableRepository tableRepository) {
this.channel = channel;
this.dataService = dataService;
......@@ -99,14 +100,14 @@ public class RabbitMqService implements MessageQueueService {
public void createUserConsumer(Table table) throws IOException {
channel.basicConsume(table.getTopic(), true, (consumerTag, response) -> {
try {
dataService.insertCsv(table, objectMapper.readValue(response.getBody(), TableCsvDto.class));
dataService.insert(table, objectMapper.readValue(response.getBody(), TableCsvDto.class));
} catch (JsonParseException | MismatchedInputException e) {
log.warn("Could not parse AMQP payload {}", e.getMessage());
/* ignore */
} catch (ConnectException e) {
log.warn("Could not redirect AMQP payload {}", e.getMessage());
/* ignore */
} catch (SQLException | ImageNotSupportedException | DataAccessException | TableMalformedException e) {
} catch (ImageNotSupportedException | DataAccessException | TableMalformedException e) {
log.warn("Could not insert AMQP payload {}", e.getMessage());
/* ignore */
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment