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

updated interfaces

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