Skip to content

Commit fa6baba

Browse files
committed
Using time stamp pattern from factory to build Couchbase queries
1 parent 1ee3483 commit fa6baba

File tree

3 files changed

+9
-35
lines changed

3 files changed

+9
-35
lines changed

src/main/java/edu/ie3/datamodel/io/source/couchbase/CouchbaseWeatherSource.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public class CouchbaseWeatherSource implements WeatherSource {
3636
private static final Logger logger = LogManager.getLogger(CouchbaseWeatherSource.class);
3737

3838
private static final NamingConvention DEFAULT_NAMING_CONVENTION = NamingConvention.FLAT;
39-
private static final String DEFAULT_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ssxxx";
4039
/** The start of the document key, comparable to a table name in relational databases */
4140
private static final String DEFAULT_KEY_PREFIX = "weather";
4241

@@ -58,20 +57,13 @@ public class CouchbaseWeatherSource implements WeatherSource {
5857
* @param coordinateSource Source to obtain actual coordinates from
5958
* @param weatherFactory Factory to transfer field to value mapping into actual java object
6059
* instances
61-
* @param timeStampPattern Pattern of time stamps to parse
6260
*/
6361
public CouchbaseWeatherSource(
6462
CouchbaseConnector connector,
6563
IdCoordinateSource coordinateSource,
66-
TimeBasedWeatherValueFactory weatherFactory,
67-
String timeStampPattern) {
64+
TimeBasedWeatherValueFactory weatherFactory) {
6865
this(
69-
connector,
70-
coordinateSource,
71-
DEFAULT_KEY_PREFIX,
72-
DEFAULT_TIMESTAMP_PATTERN,
73-
DEFAULT_NAMING_CONVENTION,
74-
weatherFactory);
66+
connector, coordinateSource, DEFAULT_KEY_PREFIX, DEFAULT_NAMING_CONVENTION, weatherFactory);
7567
}
7668

7769
/**
@@ -84,22 +76,15 @@ public CouchbaseWeatherSource(
8476
* @param weatherFactory Factory to transfer field to value mapping into actual java object
8577
* instances
8678
* @deprecated Use {@link CouchbaseWeatherSource#CouchbaseWeatherSource(CouchbaseConnector,
87-
* IdCoordinateSource, String, String, NamingConvention, TimeBasedWeatherValueFactory)}
88-
* instead
79+
* IdCoordinateSource, String, NamingConvention, TimeBasedWeatherValueFactory)} instead
8980
*/
9081
@Deprecated
9182
public CouchbaseWeatherSource(
9283
CouchbaseConnector connector,
9384
IdCoordinateSource coordinateSource,
9485
String keyPrefix,
9586
TimeBasedWeatherValueFactory weatherFactory) {
96-
this(
97-
connector,
98-
coordinateSource,
99-
keyPrefix,
100-
DEFAULT_TIMESTAMP_PATTERN,
101-
DEFAULT_NAMING_CONVENTION,
102-
weatherFactory);
87+
this(connector, coordinateSource, keyPrefix, DEFAULT_NAMING_CONVENTION, weatherFactory);
10388
}
10489

10590
/**
@@ -109,7 +94,6 @@ public CouchbaseWeatherSource(
10994
* @param connector Connector, that establishes the connection to the couchbase instance
11095
* @param coordinateSource Source to obtain actual coordinates from
11196
* @param keyPrefix Prefix of entries, that belong to weather
112-
* @param timeStampPattern Pattern of time stamps to parse
11397
* @param namingConvention the (case) convention, how columns are named
11498
* @param weatherFactory Factory to transfer field to value mapping into actual java object
11599
* instances
@@ -118,14 +102,13 @@ public CouchbaseWeatherSource(
118102
CouchbaseConnector connector,
119103
IdCoordinateSource coordinateSource,
120104
String keyPrefix,
121-
String timeStampPattern,
122105
NamingConvention namingConvention,
123106
TimeBasedWeatherValueFactory weatherFactory) {
124107
this.connector = connector;
125108
this.coordinateSource = coordinateSource;
126109
this.keyPrefix = keyPrefix;
127110
this.weatherFactory = weatherFactory;
128-
this.timeStampPattern = timeStampPattern;
111+
this.timeStampPattern = weatherFactory.getTimeStampPattern();
129112
this.coordinateIdColumnName = weatherFactory.getCoordinateIdFieldString(namingConvention);
130113
}
131114

src/test/groovy/edu/ie3/datamodel/io/source/couchbase/CouchbaseWeatherSourceCosmoIT.groovy

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue
1313
import edu.ie3.datamodel.models.value.WeatherValue
1414
import edu.ie3.test.common.CosmoWeatherTestData
1515
import edu.ie3.test.helper.WeatherSourceTestHelper
16-
import edu.ie3.util.TimeUtil
1716
import edu.ie3.util.interval.ClosedInterval
1817
import org.locationtech.jts.geom.Point
1918
import org.testcontainers.couchbase.BucketDefinition
@@ -23,8 +22,6 @@ import org.testcontainers.utility.MountableFile
2322
import spock.lang.Shared
2423
import spock.lang.Specification
2524

26-
import java.time.ZoneId
27-
2825
@Testcontainers
2926
class CouchbaseWeatherSourceCosmoIT extends Specification implements WeatherSourceTestHelper {
3027

@@ -63,9 +60,8 @@ class CouchbaseWeatherSourceCosmoIT extends Specification implements WeatherSour
6360
"--dataset", "file:///home/weather.json")
6461

6562
def connector = new CouchbaseConnector(couchbaseContainer.connectionString, bucketDefinition.name, couchbaseContainer.username, couchbaseContainer.password)
66-
def dtfPattern = "yyyy-MM-dd'T'HH:mm:ssxxx"
67-
def weatherFactory = new CosmoTimeBasedWeatherValueFactory(dtfPattern)
68-
source = new CouchbaseWeatherSource(connector, CosmoWeatherTestData.coordinateSource, weatherFactory, dtfPattern)
63+
def weatherFactory = new CosmoTimeBasedWeatherValueFactory("yyyy-MM-dd'T'HH:mm:ssxxx")
64+
source = new CouchbaseWeatherSource(connector, CosmoWeatherTestData.coordinateSource, weatherFactory)
6965
}
7066

7167
def "The test container can establish a valid connection"() {
@@ -111,7 +107,6 @@ class CouchbaseWeatherSourceCosmoIT extends Specification implements WeatherSour
111107
}
112108

113109

114-
115110
def "A CouchbaseWeatherSource can read all weather data in a given time interval"() {
116111
given:
117112
def timeInterval = new ClosedInterval(CosmoWeatherTestData.TIME_15H, CosmoWeatherTestData.TIME_17H)

src/test/groovy/edu/ie3/datamodel/io/source/couchbase/CouchbaseWeatherSourceIconIT.groovy

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries
1212
import edu.ie3.datamodel.models.timeseries.individual.TimeBasedValue
1313
import edu.ie3.test.common.IconWeatherTestData
1414
import edu.ie3.test.helper.WeatherSourceTestHelper
15-
import edu.ie3.util.TimeUtil
1615
import edu.ie3.util.interval.ClosedInterval
1716
import org.testcontainers.couchbase.BucketDefinition
1817
import org.testcontainers.couchbase.CouchbaseContainer
@@ -21,8 +20,6 @@ import org.testcontainers.utility.MountableFile
2120
import spock.lang.Shared
2221
import spock.lang.Specification
2322

24-
import java.time.ZoneId
25-
2623
@Testcontainers
2724
class CouchbaseWeatherSourceIconIT extends Specification implements WeatherSourceTestHelper {
2825

@@ -61,9 +58,8 @@ class CouchbaseWeatherSourceIconIT extends Specification implements WeatherSourc
6158
"--dataset", "file:///home/weather.json")
6259

6360
def connector = new CouchbaseConnector(couchbaseContainer.connectionString, bucketDefinition.name, couchbaseContainer.username, couchbaseContainer.password)
64-
def dtfPattern = "yyyy-MM-dd'T'HH:mm:ssxxx"
65-
def weatherFactory = new IconTimeBasedWeatherValueFactory(dtfPattern)
66-
source = new CouchbaseWeatherSource(connector, IconWeatherTestData.coordinateSource, weatherFactory, dtfPattern)
61+
def weatherFactory = new IconTimeBasedWeatherValueFactory("yyyy-MM-dd'T'HH:mm:ssxxx")
62+
source = new CouchbaseWeatherSource(connector, IconWeatherTestData.coordinateSource, weatherFactory)
6763
}
6864

6965
def "The test container can establish a valid connection"() {

0 commit comments

Comments
 (0)