Skip to content

Commit a207afa

Browse files
committed
Force user to provide time stamp pattern to ensure harmonized parsing
1 parent 4e4c447 commit a207afa

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class CouchbaseWeatherSource implements WeatherSource {
4747
private final CouchbaseConnector connector;
4848
private final IdCoordinateSource coordinateSource;
4949
private final String coordinateIdColumnName;
50+
private final String timeStampPattern;
5051

5152
/**
5253
* Instantiate a weather source utilising a connection to a couchbase instance obtained via the
@@ -58,13 +59,20 @@ public class CouchbaseWeatherSource implements WeatherSource {
5859
* @param coordinateSource Source to obtain actual coordinates from
5960
* @param weatherFactory Factory to transfer field to value mapping into actual java object
6061
* instances
62+
* @param timeStampPattern Pattern of time stamps to parse
6163
*/
6264
public CouchbaseWeatherSource(
6365
CouchbaseConnector connector,
6466
IdCoordinateSource coordinateSource,
65-
TimeBasedWeatherValueFactory weatherFactory) {
67+
TimeBasedWeatherValueFactory weatherFactory,
68+
String timeStampPattern) {
6669
this(
67-
connector, coordinateSource, DEFAULT_KEY_PREFIX, DEFAULT_NAMING_CONVENTION, weatherFactory);
70+
connector,
71+
coordinateSource,
72+
DEFAULT_KEY_PREFIX,
73+
DEFAULT_TIMESTAMP_PATTERN,
74+
DEFAULT_NAMING_CONVENTION,
75+
weatherFactory);
6876
}
6977

7078
/**
@@ -77,15 +85,22 @@ public CouchbaseWeatherSource(
7785
* @param weatherFactory Factory to transfer field to value mapping into actual java object
7886
* instances
7987
* @deprecated Use {@link CouchbaseWeatherSource#CouchbaseWeatherSource(CouchbaseConnector,
80-
* IdCoordinateSource, String, NamingConvention, TimeBasedWeatherValueFactory)} instead
88+
* IdCoordinateSource, String, String, NamingConvention, TimeBasedWeatherValueFactory)}
89+
* instead
8190
*/
8291
@Deprecated
8392
public CouchbaseWeatherSource(
8493
CouchbaseConnector connector,
8594
IdCoordinateSource coordinateSource,
8695
String keyPrefix,
8796
TimeBasedWeatherValueFactory weatherFactory) {
88-
this(connector, coordinateSource, keyPrefix, DEFAULT_NAMING_CONVENTION, weatherFactory);
97+
this(
98+
connector,
99+
coordinateSource,
100+
keyPrefix,
101+
DEFAULT_TIMESTAMP_PATTERN,
102+
DEFAULT_NAMING_CONVENTION,
103+
weatherFactory);
89104
}
90105

91106
/**
@@ -95,6 +110,7 @@ public CouchbaseWeatherSource(
95110
* @param connector Connector, that establishes the connection to the couchbase instance
96111
* @param coordinateSource Source to obtain actual coordinates from
97112
* @param keyPrefix Prefix of entries, that belong to weather
113+
* @param timeStampPattern Pattern of time stamps to parse
98114
* @param namingConvention the (case) convention, how columns are named
99115
* @param weatherFactory Factory to transfer field to value mapping into actual java object
100116
* instances
@@ -103,12 +119,14 @@ public CouchbaseWeatherSource(
103119
CouchbaseConnector connector,
104120
IdCoordinateSource coordinateSource,
105121
String keyPrefix,
122+
String timeStampPattern,
106123
NamingConvention namingConvention,
107124
TimeBasedWeatherValueFactory weatherFactory) {
108125
this.connector = connector;
109126
this.coordinateSource = coordinateSource;
110127
this.keyPrefix = keyPrefix;
111128
this.weatherFactory = weatherFactory;
129+
this.timeStampPattern = timeStampPattern;
112130
this.namingConvention = namingConvention;
113131
this.coordinateIdColumnName = weatherFactory.getCoordinateIdFieldString(namingConvention);
114132
}
@@ -188,7 +206,7 @@ public Optional<TimeBasedValue<WeatherValue>> getWeather(ZonedDateTime date, Poi
188206
public String generateWeatherKey(ZonedDateTime time, Integer coordinateId) {
189207
String key = keyPrefix + "::";
190208
key += coordinateId + "::";
191-
key += time.format(DateTimeFormatter.ofPattern(DEFAULT_TIMESTAMP_PATTERN));
209+
key += time.format(DateTimeFormatter.ofPattern(timeStampPattern));
192210
return key;
193211
}
194212

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ class CouchbaseWeatherSourceCosmoIT extends Specification implements WeatherSour
6363
"--dataset", "file:///home/weather.json")
6464

6565
def connector = new CouchbaseConnector(couchbaseContainer.connectionString, bucketDefinition.name, couchbaseContainer.username, couchbaseContainer.password)
66-
def weatherFactory = new CosmoTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd'T'HH:mm:ssxxx"))
67-
source = new CouchbaseWeatherSource(connector, CosmoWeatherTestData.coordinateSource, weatherFactory)
66+
def dtfPattern = "yyyy-MM-dd'T'HH:mm:ssxxx"
67+
def weatherFactory = new CosmoTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, dtfPattern))
68+
source = new CouchbaseWeatherSource(connector, CosmoWeatherTestData.coordinateSource, weatherFactory, dtfPattern)
6869
}
6970

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

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ class CouchbaseWeatherSourceIconIT extends Specification implements WeatherSourc
6161
"--dataset", "file:///home/weather.json")
6262

6363
def connector = new CouchbaseConnector(couchbaseContainer.connectionString, bucketDefinition.name, couchbaseContainer.username, couchbaseContainer.password)
64-
def weatherFactory = new IconTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, "yyyy-MM-dd'T'HH:mm:ssxxx"))
65-
source = new CouchbaseWeatherSource(connector, IconWeatherTestData.coordinateSource, weatherFactory)
64+
def dtfPattern = "yyyy-MM-dd'T'HH:mm:ssxxx"
65+
def weatherFactory = new IconTimeBasedWeatherValueFactory(new TimeUtil(ZoneId.of("UTC"), Locale.GERMANY, dtfPattern))
66+
source = new CouchbaseWeatherSource(connector, IconWeatherTestData.coordinateSource, weatherFactory, dtfPattern)
6667
}
6768

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

0 commit comments

Comments
 (0)