Skip to content

Commit

Permalink
Fixing code smells and codacy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-peter committed Jan 6, 2022
1 parent 2c0b041 commit 6898605
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public SqlTimeSeriesMappingSource(

@Override
public Map<UUID, UUID> getMapping() {
return executeQuery(queryFull, (ps) -> {}).stream()
return executeQuery(queryFull, ps -> {}).stream()
.collect(Collectors.toMap(MappingEntry::getParticipant, MappingEntry::getTimeSeries));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ public class SqlTimeSeriesSource<V extends Value> extends SqlDataSource<TimeBase
implements TimeSeriesSource<V> {
private static final String WHERE = " WHERE ";

private final UUID timeSeriesUuid;
private final Class<V> valueClass;
private final TimeBasedSimpleValueFactory<V> valueFactory;

/**
* Queries that are available within this source. Motivation to have them as field value is to
* avoid creating a new string each time, bc they're always the same.
*/
private final String queryFull;

private final String queryTimeInterval;
private final String queryTime;

/**
* Factory method to build a source from given meta information
*
Expand Down Expand Up @@ -64,19 +77,6 @@ private static <T extends Value> SqlTimeSeriesSource<T> create(
connector, schemaName, tableName, timeSeriesUuid, valClass, valueFactory);
}

private final UUID timeSeriesUuid;
private final Class<V> valueClass;
private final TimeBasedSimpleValueFactory<V> valueFactory;

/**
* Queries that are available within this source. Motivation to have them as field value is to
* avoid creating a new string each time, bc they're always the same.
*/
private final String queryFull;

private final String queryTimeInterval;
private final String queryTime;

/**
* Initializes a new SqlTimeSeriesSource
*
Expand Down Expand Up @@ -109,7 +109,7 @@ public SqlTimeSeriesSource(

@Override
public IndividualTimeSeries<V> getTimeSeries() {
List<TimeBasedValue<V>> timeBasedValues = executeQuery(queryFull, (ps) -> {});
List<TimeBasedValue<V>> timeBasedValues = executeQuery(queryFull, ps -> {});
return new IndividualTimeSeries<>(timeSeriesUuid, new HashSet<>(timeBasedValues));
}

Expand All @@ -118,7 +118,7 @@ public IndividualTimeSeries<V> getTimeSeries(ClosedInterval<ZonedDateTime> timeI
List<TimeBasedValue<V>> timeBasedValues =
executeQuery(
queryTimeInterval,
(ps) -> {
ps -> {
ps.setTimestamp(1, Timestamp.from(timeInterval.getLower().toInstant()));
ps.setTimestamp(2, Timestamp.from(timeInterval.getUpper().toInstant()));
});
Expand All @@ -128,7 +128,7 @@ public IndividualTimeSeries<V> getTimeSeries(ClosedInterval<ZonedDateTime> timeI
@Override
public Optional<V> getValue(ZonedDateTime time) {
List<TimeBasedValue<V>> timeBasedValues =
executeQuery(queryTime, (ps) -> ps.setTimestamp(1, Timestamp.from(time.toInstant())));
executeQuery(queryTime, ps -> ps.setTimestamp(1, Timestamp.from(time.toInstant())));
if (timeBasedValues.isEmpty()) return Optional.empty();
if (timeBasedValues.size() > 1)
log.warn("Retrieved more than one result value, using the first");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class SqlTimeSeriesMappingSourceIT extends Specification {
"its_pq_3fbfaa97-cff4-46d4-95ba-a95665e87c26.sql",
"its_pqh_46be1e57-e4ed-4ef7-95f1-b2b321cb2047.sql",
"time_series_mapping.sql")
for(String file: importFiles) {
for (String file: importFiles) {
Container.ExecResult res = postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/" + file)
assert res.stderr.isEmpty()
assert res.stderr.empty
}

def connector = new SqlConnector(postgreSQLContainer.jdbcUrl, postgreSQLContainer.username, postgreSQLContainer.password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class SqlTimeSeriesSourceIT extends Specification {
"its_pq_3fbfaa97-cff4-46d4-95ba-a95665e87c26.sql",
"its_pqh_46be1e57-e4ed-4ef7-95f1-b2b321cb2047.sql",
"time_series_mapping.sql")
for(String file: importFiles) {
for (String file: importFiles) {
Container.ExecResult res = postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/" + file)
assert res.stderr.isEmpty()
assert res.stderr.empty
}

connector = new SqlConnector(postgreSQLContainer.jdbcUrl, postgreSQLContainer.username, postgreSQLContainer.password)
Expand Down Expand Up @@ -133,7 +133,7 @@ class SqlTimeSeriesSourceIT extends Specification {

def "A SqlTimeSeriesSource can read all value data"() {
when:
def actualTimeSeries = pSource.getTimeSeries()
def actualTimeSeries = pSource.timeSeries

then:
actualTimeSeries.uuid == timeSeriesUuid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SqlWeatherSourceIconIT extends Specification implements WeatherSourceTestH
postgreSQLContainer.copyFileToContainer(sqlImportFile, "/home/weather.sql")
// Execute import script
Container.ExecResult res = postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/weather.sql")
assert res.stderr.isEmpty()
assert res.stderr.empty

def connector = new SqlConnector(postgreSQLContainer.jdbcUrl, postgreSQLContainer.username, postgreSQLContainer.password)
def weatherFactory = new IconTimeBasedWeatherValueFactory(TimeUtil.withDefaults)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SqlWeatherSourcePsdmIT extends Specification implements WeatherSourceTestH
postgreSQLContainer.copyFileToContainer(sqlImportFile, "/home/weather.sql")
// Execute import script
Container.ExecResult res = postgreSQLContainer.execInContainer("psql", "-Utest", "-f/home/weather.sql")
assert res.stderr.isEmpty()
assert res.stderr.empty

def connector = new SqlConnector(postgreSQLContainer.jdbcUrl, postgreSQLContainer.username, postgreSQLContainer.password)
def weatherFactory = new PsdmTimeBasedWeatherValueFactory(TimeUtil.withDefaults)
Expand Down

0 comments on commit 6898605

Please sign in to comment.