diff --git a/.gitignore b/.gitignore index fb1dd713..abe7e1eb 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,4 @@ Package.resolved #xcode xcuserdata/ +/temp/ diff --git a/service-data/src/main/java/com/mowesta/data/ftp/FtpFolderSync.java b/service-data/src/main/java/com/mowesta/data/ftp/FtpFolderSync.java index 34684669..ff7609cc 100644 --- a/service-data/src/main/java/com/mowesta/data/ftp/FtpFolderSync.java +++ b/service-data/src/main/java/com/mowesta/data/ftp/FtpFolderSync.java @@ -1,16 +1,16 @@ package com.mowesta.data.ftp; +import com.mowesta.data.ftp.FileStatus.Action; +import org.apache.commons.net.ftp.FTPClient; +import org.apache.commons.net.ftp.FTPFile; +import org.apache.commons.net.ftp.FTPReply; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; - -import org.apache.commons.net.ftp.FTPClient; -import org.apache.commons.net.ftp.FTPFile; -import org.apache.commons.net.ftp.FTPReply; - -import com.mowesta.data.ftp.FileStatus.Action; +import java.util.function.Predicate; /** * A utility class that synchronizes a folder of an ftp server with a local @@ -19,28 +19,34 @@ import com.mowesta.data.ftp.FileStatus.Action; * * @author Marcus */ -public class FtpFolderSync { +public class FtpFolderSync { /** * The local directory to write to. */ - protected File localPath; + protected final File localPath; /** * The name of the server (i.e. the DNS name without URL scheme). */ - protected String serverName; + protected final String serverName; /** * The path on the server. */ - protected String serverPath; + protected final String serverPath; + + /** + * A filter to choose weather a file should get synchronized + */ + protected final Predicate fileFilter; /** * Sets a file status listener. */ protected FileStatusListener statusListener; + /** * A flag that indicates whether the synchronizer * should cancel its execution. @@ -55,9 +61,22 @@ public class FtpFolderSync { * @param serverPath The server path. */ public FtpFolderSync(File localPath, String serverName, String serverPath) { + this(localPath, serverName, serverPath, a -> true); + } + + /** + * Creates a new synchronizer. + * + * @param localPath The local path to write to and delete from. + * @param serverName The server name. + * @param serverPath The server path. + * @param fileFilter A filter to choose weather a file should get synchronized + */ + public FtpFolderSync(File localPath, String serverName, String serverPath, Predicate fileFilter) { this.localPath = localPath; this.serverName = serverName; this.serverPath = serverPath; + this.fileFilter = fileFilter; } /** @@ -94,13 +113,12 @@ public class FtpFolderSync { File[] localFiles = localPath.listFiles(); boolean[] keepFiles = new boolean[localFiles.length]; List filesToDownload = new ArrayList<>(); - i: for (int i = 0; i < remoteFiles.length; i++) { - FTPFile remoteFile = remoteFiles[i]; + i: for (FTPFile remoteFile : remoteFiles) { for (int j = 0; j < localFiles.length; j++) { File localFile = localFiles[j]; if (remoteFile.getName().equals(localFile.getName()) && remoteFile.getSize() == localFile.length()) { - keepFiles[i] = true; - FileStatus status = new FileStatus(Action.MAINTAINED, localFiles[i]); + keepFiles[j] = true; + FileStatus status = new FileStatus(Action.MAINTAINED, localFile); result.add(status); synchronized (this) { fireStatusChange(status); @@ -113,7 +131,7 @@ public class FtpFolderSync { } // delete files that are not available remotely for (int i = 0; i < localFiles.length; i++) { - if (!keepFiles[i]) { + if (!keepFiles[i] && fileFilter.test(localFiles[i])) { deleteFile(localFiles[i]); FileStatus status = new FileStatus(Action.DELETED, localFiles[i]); result.add(status); @@ -126,12 +144,14 @@ public class FtpFolderSync { // download files that are not available locally for (FTPFile file: filesToDownload) { File destination = new File(localPath, file.getName()); - downloadFile(client, file, destination); - FileStatus status = new FileStatus(Action.DOWNLOADED, destination); - result.add(status); - synchronized (this) { - fireStatusChange(status); - if (canceled) return result; + if (fileFilter.test(destination)) { + downloadFile(client, file, destination); + FileStatus status = new FileStatus(Action.DOWNLOADED, destination); + result.add(status); + synchronized (this) { + fireStatusChange(status); + if (canceled) return result; + } } } } finally { diff --git a/service-data/src/main/java/com/mowesta/data/grib2/Grib2File.java b/service-data/src/main/java/com/mowesta/data/grib2/Grib2File.java index 5743af14..f1d80707 100644 --- a/service-data/src/main/java/com/mowesta/data/grib2/Grib2File.java +++ b/service-data/src/main/java/com/mowesta/data/grib2/Grib2File.java @@ -1,24 +1,19 @@ package com.mowesta.data.grib2; -import java.io.IOException; -import java.io.InputStream; import com.mowesta.data.grib2.code.CodeTables; import com.mowesta.data.grib2.io.DataStream; import com.mowesta.data.grib2.io.LimitedStream; -import com.mowesta.data.grib2.section.BitmapSection; -import com.mowesta.data.grib2.section.EndSection; -import com.mowesta.data.grib2.section.GridSection; -import com.mowesta.data.grib2.section.IdentificationSection; -import com.mowesta.data.grib2.section.LocalSection; -import com.mowesta.data.grib2.section.ProductSection; -import com.mowesta.data.grib2.section.RepresentationSection; +import com.mowesta.data.grib2.section.*; + +import java.io.IOException; +import java.io.InputStream; /** * The basic abstraction to load data from grib2 files. * * @author Marcus */ -public class Grib2File extends Grib2Object { +public class Grib2File extends Grib2Object implements AutoCloseable { /** * The 4 byte magic number at the beginning of the file. @@ -285,6 +280,7 @@ public class Grib2File extends Grib2Object { * * @throws IOException Thrown by the stream. */ + @Override public void close() throws IOException { data.close(); } diff --git a/service-data/src/main/java/com/mowesta/data/grib2/io/CsvReader.java b/service-data/src/main/java/com/mowesta/data/grib2/io/CsvReader.java index 80052a6f..8db61fc4 100644 --- a/service-data/src/main/java/com/mowesta/data/grib2/io/CsvReader.java +++ b/service-data/src/main/java/com/mowesta/data/grib2/io/CsvReader.java @@ -12,7 +12,7 @@ import java.util.List; * * @author Marcus */ -public class CsvReader { +public class CsvReader implements AutoCloseable { /** * The buffered reader that we use to read lines. @@ -172,5 +172,15 @@ public class CsvReader { } - -} \ No newline at end of file + @Override + public void close() { + if (reader != null) { + try { + reader.close(); + } + catch (IOException e) { + throw new RuntimeException(e); + } + } + } +} diff --git a/service-ejb/src/main/java/com/mowesta/service/entity/AbstractLocationEntity.java b/service-ejb/src/main/java/com/mowesta/service/entity/AbstractLocationEntity.java index aa3e3d98..d2826829 100644 --- a/service-ejb/src/main/java/com/mowesta/service/entity/AbstractLocationEntity.java +++ b/service-ejb/src/main/java/com/mowesta/service/entity/AbstractLocationEntity.java @@ -1,6 +1,7 @@ package com.mowesta.service.entity; import org.hibernate.search.annotations.Field; +import org.hibernate.search.annotations.Indexed; import org.hibernate.search.annotations.IndexedEmbedded; import javax.persistence.*; @@ -16,8 +17,9 @@ import java.util.List; * @author Marcus */ @Entity +@Indexed @SuppressWarnings("serial") -public abstract class AbstractLocationEntity extends AbstractEntity { +public abstract class AbstractLocationEntity extends AbstractPositionEntity { /** * The id used for synchronization. This is the original id @@ -26,14 +28,6 @@ public abstract class AbstractLocationEntity extends AbstractEntity { */ private long externalId; - /** - * The longitude and latitude of the center of the location. - */ - @Embedded - @NotNull - @IndexedEmbedded - private EmbeddedCoordinate coordinate; - /** * The names of the location. */ @@ -88,24 +82,6 @@ public abstract class AbstractLocationEntity extends AbstractEntity { public void setExternalId(long externalId) { this.externalId = externalId; } - - /** - * Returns the coordiante. - * - * @return The coordiante. - */ - public EmbeddedCoordinate getCoordinate() { - return coordinate; - } - - /** - * Sets the coordiante. - * - * @param coordiante The coordiante to set. - */ - public void setCoordinate(EmbeddedCoordinate coordiante) { - this.coordinate = coordiante; - } /** * Returns the names. @@ -236,5 +212,4 @@ public abstract class AbstractLocationEntity extends AbstractEntity { if (result.size() == 1) return result.get(0); throw new RuntimeException("Found duplicate external id for location of type " + type.getClass().getName() + "."); } - } diff --git a/service-ejb/src/main/java/com/mowesta/service/entity/AbstractPositionEntity.java b/service-ejb/src/main/java/com/mowesta/service/entity/AbstractPositionEntity.java new file mode 100644 index 00000000..b5fe79c2 --- /dev/null +++ b/service-ejb/src/main/java/com/mowesta/service/entity/AbstractPositionEntity.java @@ -0,0 +1,112 @@ +package com.mowesta.service.entity; + +import org.apache.lucene.search.Sort; +import org.hibernate.search.annotations.Indexed; +import org.hibernate.search.annotations.IndexedEmbedded; +import org.hibernate.search.annotations.Spatial; +import org.hibernate.search.annotations.SpatialMode; +import org.hibernate.search.jpa.FullTextEntityManager; +import org.hibernate.search.jpa.FullTextQuery; +import org.hibernate.search.jpa.Search; +import org.hibernate.search.query.dsl.QueryBuilder; +import org.hibernate.search.query.dsl.Unit; + +import javax.persistence.Embedded; +import javax.persistence.Entity; +import javax.persistence.EntityManager; +import javax.validation.constraints.NotNull; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +@Entity +@Indexed +public abstract class AbstractPositionEntity extends AbstractEntity { + private static final long serialVersionUID = -7905096177276397385L; + /** + * The longitude and latitude of the center of the location. + */ + @Embedded + @NotNull + @IndexedEmbedded + @Spatial(spatialMode = SpatialMode.HASH) + private EmbeddedCoordinate coordinate; + + /** + * Returns the coordiante. + * + * @return The coordiante. + */ + public EmbeddedCoordinate getCoordinate() { + return coordinate; + } + + /** + * Sets the coordiante. + * + * @param coordiante The coordiante to set. + */ + public void setCoordinate(EmbeddedCoordinate coordiante) { + this.coordinate = coordiante; + } + + + public static E findEntityNearPosition(EntityManager em, Class entityClass, AbstractPositionEntity position) { + final List entitiesNearPosition = findEntitiesNearPosition(em, entityClass, position, true); + if (entitiesNearPosition.size() == 0) { + return null; + } + return entitiesNearPosition.get(0); + } + + public static List findEntitiesNearPosition(EntityManager em, Class entityClass, AbstractPositionEntity position) { + return findEntitiesNearPosition(em, entityClass, position, false); + } + + private static List findEntitiesNearPosition(EntityManager em, Class entityClass, AbstractPositionEntity position, boolean single) { + if (AbstractEntity.getCount(em, entityClass, false) == 0) { + return Collections.emptyList(); + } + FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(em); + QueryBuilder builder = fullTextEntityManager.getSearchFactory() + .buildQueryBuilder() + .forEntity(entityClass) + .get(); + + FullTextQuery hibQuery; + double radius = 1d; + do { + org.apache.lucene.search.Query luceneQuery = builder + .spatial() + .onField("coordinate") + .within(radius, Unit.KM) + .ofLatitude(position.getCoordinate().getLatitude()) + .andLongitude(position.getCoordinate().getLongitude()) + .createQuery(); + + Sort distanceSort = builder + .sort() + .byDistance() + .onField("coordinate") + .fromLatitude(position.getCoordinate().getLatitude()) + .andLongitude(position.getCoordinate().getLongitude()) + .createSort(); + hibQuery = fullTextEntityManager + .createFullTextQuery(luceneQuery, entityClass) + .setSort(distanceSort); + if (single) { + hibQuery.setMaxResults(1); + } + radius *= 2; + } + while (hibQuery.getResultSize() <= 0); + + @SuppressWarnings("unchecked") final List resultList = hibQuery.getResultList(); + if (single) { + return resultList; + } + + final EmbeddedCoordinate nearestCoordinate = resultList.get(0).getCoordinate(); + return resultList.stream().filter(e -> nearestCoordinate.equals(e.getCoordinate())).collect(Collectors.toList()); + } +} diff --git a/service-ejb/src/main/java/com/mowesta/service/entity/CountryEntity.java b/service-ejb/src/main/java/com/mowesta/service/entity/CountryEntity.java index 4d3d7f16..b81d4167 100644 --- a/service-ejb/src/main/java/com/mowesta/service/entity/CountryEntity.java +++ b/service-ejb/src/main/java/com/mowesta/service/entity/CountryEntity.java @@ -1,14 +1,10 @@ package com.mowesta.service.entity; -import java.util.Set; - -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Index; -import javax.persistence.OneToMany; -import javax.persistence.Table; - import org.hibernate.search.annotations.ContainedIn; +import org.hibernate.search.annotations.Indexed; + +import javax.persistence.*; +import java.util.Set; /** * An entity that represents countries. @@ -17,6 +13,7 @@ import org.hibernate.search.annotations.ContainedIn; */ @Entity @Table(name = "country", indexes = { @Index(columnList = "externalId", unique = true), @Index(columnList="deleted,modificationTime", unique = false) }) +@Indexed public class CountryEntity extends AbstractLocationEntity { /** diff --git a/service-ejb/src/main/java/com/mowesta/service/entity/CurrentWeatherEntity.java b/service-ejb/src/main/java/com/mowesta/service/entity/CurrentWeatherEntity.java index 46187f38..6dde1f2f 100644 --- a/service-ejb/src/main/java/com/mowesta/service/entity/CurrentWeatherEntity.java +++ b/service-ejb/src/main/java/com/mowesta/service/entity/CurrentWeatherEntity.java @@ -1,20 +1,54 @@ package com.mowesta.service.entity; -import javax.persistence.Entity; -import javax.persistence.NamedQueries; -import javax.persistence.Table; +import org.hibernate.search.annotations.Indexed; + +import javax.persistence.*; @Entity @Table(name = "currentWeather" ) @NamedQueries({ + @NamedQuery(name = "deleteAllCurrentWeatherEntities", query = "delete from CurrentWeatherEntity c") }) -public class CurrentWeatherEntity extends AbstractEntity { +@Indexed +public class CurrentWeatherEntity extends AbstractPositionEntity { /** * The serialization id. */ private static final long serialVersionUID = 5443960038620074108L; + @Column + private long measurementDate; + @Column + private float temperature; + + + public void setMeasurementDate(long measurementDate) { + this.measurementDate = measurementDate; + } + + public long getMeasurementDate() { + return measurementDate; + } + + public void setTemperature(float temperature) { + this.temperature = temperature; + } + + public float getTemperature() { + return temperature; + } + + /** + * Actually deletes all CurrentWeatherEntities + * + * @param em The entity manager. + * @return The total number of deleted entities. + */ + public static int deleteAllEntries(EntityManager em) { + Query q = em.createNamedQuery("deleteAllCurrentWeatherEntities"); + return q.executeUpdate(); + } } diff --git a/service-ejb/src/main/java/com/mowesta/service/entity/EmbeddedCoordinate.java b/service-ejb/src/main/java/com/mowesta/service/entity/EmbeddedCoordinate.java index e884f736..324fc638 100644 --- a/service-ejb/src/main/java/com/mowesta/service/entity/EmbeddedCoordinate.java +++ b/service-ejb/src/main/java/com/mowesta/service/entity/EmbeddedCoordinate.java @@ -1,35 +1,38 @@ package com.mowesta.service.entity; -import javax.persistence.Embeddable; - import org.hibernate.search.annotations.Latitude; import org.hibernate.search.annotations.Longitude; import org.hibernate.search.annotations.Spatial; +import org.hibernate.search.annotations.SpatialMode; +import org.hibernate.search.spatial.Coordinates; + +import javax.persistence.Embeddable; +import java.util.Objects; +import java.util.StringJoiner; /** * An embeddable coordinate. - * + * * @author Marcus */ @Embeddable -@Spatial -public class EmbeddedCoordinate { - +@Spatial(spatialMode = SpatialMode.HASH) +public class EmbeddedCoordinate implements Coordinates { + /** * The latitude. */ - @Latitude + @Latitude private double latitude; /** * The longitude. */ - @Longitude + @Longitude private double longitude; - + /** - * Creates a new coordinate with longitude and - * latitude set to 0. + * Creates a new coordinate with longitude and latitude set to 0. */ public EmbeddedCoordinate() { super(); @@ -37,11 +40,11 @@ public class EmbeddedCoordinate { /** * Creates a new coordinate with the latitude and longitude. - * + * + * @param latitude The latitude. * @param longitude The longitude. - * @param latitude The latitude. */ - public EmbeddedCoordinate(double longitude, double latitude) { + public EmbeddedCoordinate(double latitude, double longitude) { this.longitude = longitude; this.latitude = latitude; } @@ -52,10 +55,11 @@ public class EmbeddedCoordinate { * * @return The latitude. */ - public double getLatitude() { + @Override + public Double getLatitude() { return latitude; } - + /** * Sets the latitude. * @@ -64,16 +68,17 @@ public class EmbeddedCoordinate { public void setLatitude(double latitude) { this.latitude = latitude; } - + /** * Returns the longitude. * * @return The longitude. */ - public double getLongitude() { + @Override + public Double getLongitude() { return longitude; } - + /** * Sets the longitude. * @@ -83,6 +88,25 @@ public class EmbeddedCoordinate { this.longitude = longitude; } + @Override + public String toString() { + return new StringJoiner(", ", "[", "]") + .add("latitude=" + latitude) + .add("longitude=" + longitude) + .toString(); + } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + EmbeddedCoordinate that = (EmbeddedCoordinate) o; + return Double.compare(that.latitude, latitude) == 0 && + Double.compare(that.longitude, longitude) == 0; + } + @Override + public int hashCode() { + return Objects.hash(latitude, longitude); + } } diff --git a/service-ejb/src/main/java/com/mowesta/service/entity/PredictionSystemType.java b/service-ejb/src/main/java/com/mowesta/service/entity/PredictionSystemType.java new file mode 100644 index 00000000..42afb191 --- /dev/null +++ b/service-ejb/src/main/java/com/mowesta/service/entity/PredictionSystemType.java @@ -0,0 +1,23 @@ +package com.mowesta.service.entity; + +public enum PredictionSystemType { + ICON(0), + ICON_EU(1), + COSMO_D2(2), + UNKNOWN(-1); + + private final int dwdIndex; + + PredictionSystemType(int dwdIndex) { + this.dwdIndex = dwdIndex; + } + + public static PredictionSystemType getByDwdIndex(int dwdIndex) { + for (PredictionSystemType predictionSystemType : values()) { + if (predictionSystemType.dwdIndex == dwdIndex) { + return predictionSystemType; + } + } + throw new IllegalArgumentException("Es konnte kein PredictionSystemType zum dwdIndex=" + dwdIndex + " gefunden werden!"); + } +} diff --git a/service-ejb/src/main/java/com/mowesta/service/entity/SoilType.java b/service-ejb/src/main/java/com/mowesta/service/entity/SoilType.java new file mode 100644 index 00000000..aa7d7d83 --- /dev/null +++ b/service-ejb/src/main/java/com/mowesta/service/entity/SoilType.java @@ -0,0 +1,19 @@ +package com.mowesta.service.entity; + +public enum SoilType { + ICE(1), ROCK(2), SAND(3), SANDYLOAM(4), LOAM(5), CLAYLOAM(6), CLAY(7), PEAT(8), SEA_WATER(9); + private final int dwdIndex; + + SoilType(int dwdIndex) { + this.dwdIndex = dwdIndex; + } + + public static SoilType getByDwdIndex(int dwdIndex) { + for (SoilType soilType : values()) { + if (soilType.dwdIndex == dwdIndex) { + return soilType; + } + } + throw new IllegalArgumentException("Es konnte kein SoilType zum dwdIndex=" + dwdIndex + " gefunden werden!"); + } +} diff --git a/service-ejb/src/main/java/com/mowesta/service/entity/WeatherForecastEntity.java b/service-ejb/src/main/java/com/mowesta/service/entity/WeatherForecastEntity.java index e3dc4479..b71331cd 100644 --- a/service-ejb/src/main/java/com/mowesta/service/entity/WeatherForecastEntity.java +++ b/service-ejb/src/main/java/com/mowesta/service/entity/WeatherForecastEntity.java @@ -1,20 +1,295 @@ package com.mowesta.service.entity; -import javax.persistence.Entity; -import javax.persistence.NamedQueries; -import javax.persistence.Table; +import org.hibernate.search.annotations.Indexed; + +import javax.persistence.*; +import java.util.StringJoiner; @Entity -@Table(name = "weatherForecast" +@Table(name = "weatherForecast", + indexes = { + @Index(columnList = "deleted,predictionStartTimestamp,longitude") + } ) @NamedQueries({ + @NamedQuery(name = "deleteAllMarkedForecastEntitites", query = "delete from WeatherForecastEntity f where f.deleted=true"), + @NamedQuery(name = "markAllForecastEntitiesAsDeleted", query = "update WeatherForecastEntity f set f.deleted=true"), + @NamedQuery(name = "deleteAllForecastEntitiesAtTime", query = "delete from WeatherForecastEntity f where f.deleted=true and f.predictionStartTimestamp=:time AND abs(cast(f.coordinate.longitude as int)/9)=:chunk") }) -public class WeatherForecastEntity extends AbstractEntity { +@Indexed +public class WeatherForecastEntity extends AbstractPositionEntity { /** * The serialization id. */ private static final long serialVersionUID = -8827543222342384548L; + /** + * The start time of the prediction as timestamp. + */ + @Column + private long predictionStartTimestamp; + /** + * The duration time of the prediction as seconds. + */ + @Column + private long predictionDuration; + + /** + * The System of the prediction (ICON, ICON-EU or COSMO-D2). + */ + @Column + private PredictionSystemType predictionSystemType; + + /** + * The average temperature at 2 meter height. The DWD uses t_2m as abbreviation. + */ + @Column + private double airTemperature2m; + + /** + * The minimal air temperature at 2 meter height. The DWD uses tmin_2m as abbreviation. + */ + @Column + private double airTemperatureMin2m; + + /** + * The maximal air temperature at 2 meter height. The DWD uses tmax_2m as abbreviation. + */ + @Column + private double airTemperatureMax2m; + + /** + * The specific humidity at 2 meter height. The DWD uses qv_s as abbreviation. + */ + @Column + private double humidity2mSpecific; + + /** + * The relative humidity at 2 meter height. The DWD uses relhum_2m as abbreviation. + */ + @Column + private double humidity2mRelative; + + /** + * The pressure at 2 meter height. The DWD uses ps as abbreviation. + */ + @Column + private double pressure; + + /** + * The current snow depth at this location. The DWD uses h_snow as abbreviation. + */ + @Column + private double snowDepth; + + /** + * The current weather interpretation type at this location. The DWD uses ww as abbreviation. + */ + @Column + private WeatherInterpretationType weatherInterpretationType; + + /** + * The current wind direction at this location. The DWD just provides vertical and horizontal vectors (u,v). This values are calculated by our Importer. + */ + @Column + private WindDirectionType windDirection; + + /** + * The current wind velocity at this location. The DWD just provides vertical and horizontal vectors (u,v). This values are calculated by our Importer. + */ + @Column + private double windVelocity; + + /** + * The wind in u direction. The DWD uses u as abbreviation. + */ + @Column + private double uWind10m; + + /** + * The wind in v direction. The DWD uses v as abbreviation. + */ + @Column + private double vWind10m; + + public long getPredictionStartTimestamp() { + return predictionStartTimestamp; + } + + public void setPredictionStartTimestamp(long predictionStartTimestamp) { + this.predictionStartTimestamp = predictionStartTimestamp; + } + + public long getPredictionDuration() { + return predictionDuration; + } + + public void setPredictionDuration(long predictionDuration) { + this.predictionDuration = predictionDuration; + } + + public PredictionSystemType getPredictionSystemType() { + return predictionSystemType; + } + + public void setPredictionSystemType(PredictionSystemType predictionSystemType) { + this.predictionSystemType = predictionSystemType; + } + + public double getAirTemperature2m() { + return airTemperature2m; + } + + public void setAirTemperature2m(double airTemperature2m) { + this.airTemperature2m = airTemperature2m; + } + + public double getAirTemperatureMin2m() { + return airTemperatureMin2m; + } + + public void setAirTemperatureMin2m(double airTemperatureMin2m) { + this.airTemperatureMin2m = airTemperatureMin2m; + } + + public double getAirTemperatureMax2m() { + return airTemperatureMax2m; + } + + public void setAirTemperatureMax2m(double airTemperatureMax2m) { + this.airTemperatureMax2m = airTemperatureMax2m; + } + + public double getHumidity2mSpecific() { + return humidity2mSpecific; + } + + public void setHumidity2mSpecific(double humidity2mSpecific) { + this.humidity2mSpecific = humidity2mSpecific; + } + + public double getHumidity2mRelative() { + return humidity2mRelative; + } + + public void setHumidity2mRelative(double humidity2mRelative) { + this.humidity2mRelative = humidity2mRelative; + } + + public double getPressure() { + return pressure; + } + + public void setPressure(double pressure) { + this.pressure = pressure; + } + + public double getSnowDepth() { + return snowDepth; + } + + public void setSnowDepth(double snowDepth) { + this.snowDepth = snowDepth; + } + + public WeatherInterpretationType getWeatherInterpretationType() { + return weatherInterpretationType; + } + + public void setWeatherInterpretationType(WeatherInterpretationType weatherInterpretationType) { + this.weatherInterpretationType = weatherInterpretationType; + } + + public WindDirectionType getWindDirection() { + return windDirection; + } + + public void setWindDirection(WindDirectionType windDirection) { + this.windDirection = windDirection; + } + + public double getWindVelocity() { + return windVelocity; + } + + public void setWindVelocity(double windVelocity) { + this.windVelocity = windVelocity; + } + + public double getuWind10m() { + return uWind10m; + } + + public void setuWind10m(double uWind10m) { + this.uWind10m = uWind10m; + } + + public double getvWind10m() { + return vWind10m; + } + + public void setvWind10m(double vWind10m) { + this.vWind10m = vWind10m; + } + + @Override + public String toString() { + return new StringJoiner(", ", WeatherForecastEntity.class.getSimpleName() + "[", "]") + .add("predictionStartTimestamp=" + predictionStartTimestamp) + .add("predictionDuration=" + predictionDuration) + .add("predictionSystemType=" + predictionSystemType) + .add("coordinate=" + getCoordinate()) + .add("airTemperature2m=" + airTemperature2m) + .add("airTemperatureMin2m=" + airTemperatureMin2m) + .add("airTemperatureMax2m=" + airTemperatureMax2m) + .add("humidity2mSpecific=" + humidity2mSpecific) + .add("humidity2mRelative=" + humidity2mRelative) + .add("pressure=" + pressure) + .add("snowDepth=" + snowDepth) + .add("weatherInterpretationType=" + weatherInterpretationType) + .add("windDirection=" + windDirection) + .add("windVelocity=" + windVelocity) + .add("uWind10m=" + uWind10m) + .add("vWind10m=" + vWind10m) + .toString(); + } + + /** + * Marks all WeatherForecastEntities as deleted + * + * @param em The entity manager. + * @return The total number of marked entities. + */ + public static int markAllForecastsAsDeleted(EntityManager em) { + Query q = em.createNamedQuery("markAllForecastEntitiesAsDeleted"); + return q.executeUpdate(); + } + + /** + * Actually deletes all WeatherForecastEntities that were marked as deleted and have the given timed + * + * @param em The entity manager. + * @param chunk the chunk of each entity (=abs((int) longitude)) that should get deleted + * @param time the time of each entity that should get deleted + * @return The total number of deleted entities. + */ + public static int deleteAllMarkedForecastsAtTime(EntityManager em, int chunk, long time) { + Query q = em.createNamedQuery("deleteAllForecastEntitiesAtTime"); + q.setParameter("chunk", chunk); + q.setParameter("time", time); + return q.executeUpdate(); + } + + /** + * Actually deletes all WeatherForecastEntities that were marked as deleted + * + * @param em The entity manager. + * @return The total number of deleted entities. + */ + public static int deleteAllMarkedForecasts(EntityManager em) { + Query q = em.createNamedQuery("deleteAllMarkedForecastEntitites"); + return q.executeUpdate(); + } } diff --git a/service-ejb/src/main/java/com/mowesta/service/entity/WeatherInterpretationType.java b/service-ejb/src/main/java/com/mowesta/service/entity/WeatherInterpretationType.java new file mode 100644 index 00000000..fbbb1b0c --- /dev/null +++ b/service-ejb/src/main/java/com/mowesta/service/entity/WeatherInterpretationType.java @@ -0,0 +1,48 @@ +package com.mowesta.service.entity; + +public enum WeatherInterpretationType { + UNKNOWN(-1), + CLEAR_SKY(0), + MAINLY_CLEAR(1), + PARTLY_CLOUDY(2), + CLOUDY(3), + + FOG(45), + FOG_DEPOSITING_RIME(48), + SLIGHT_DRIZZLE(51), + MODERATE_DRIZZLE(53), + HEAVY_DRIZZLE(55), + DRIZZLE_FREEZING_SLIGHT(56), + DRIZZLE_FREEZING_MODERATE_HEAVY(57), + SLIGHT_RAIN_NOT_FREEZING(61), + MODERATE_RAIN_NOT_FREEZING(63), + HEAVY_RAIN_NOT_FREEZING(65), + RAIN_FREEZING_SLIGHT(66), + RAIN_FREEZING_MODERATE_HEAVY(67), + SLIGHT_FALL_OF_SNOWFLAKES(71), + MODERATE_FALL_OF_SNOWFLAKES(73), + HEAVY_FALL_OF_SNOWFLAKES(75), + SNOW_GRAINS(77), + RAIN_SHOWER_SLIGHT(80), + RAIN_SHOWER_MODERATE_HEAVY(81), + RAIN_SHOWER_VIOLENT(82), + SNOW_SHOWER_SLIGHT(85), + SNOW_SHOWER_MODERATE_HEAVY(86), + THUNDERSTORM_SLIGHT_MODERATE(95), + THUNDERSTORM_HAIL_HEAVY(96); + + private final int dwdIndex; + + WeatherInterpretationType(int dwdIndex) { + this.dwdIndex = dwdIndex; + } + + public static WeatherInterpretationType getByDwdIndex(int dwdIndex) { + for (WeatherInterpretationType weatherInterpretationType : values()) { + if (weatherInterpretationType.dwdIndex == dwdIndex) { + return weatherInterpretationType; + } + } + throw new IllegalArgumentException("Es konnte kein WeatherInterpretationType zum dwdIndex=" + dwdIndex + " gefunden werden!"); + } +} diff --git a/service-ejb/src/main/java/com/mowesta/service/entity/WindDirectionType.java b/service-ejb/src/main/java/com/mowesta/service/entity/WindDirectionType.java new file mode 100644 index 00000000..3191313e --- /dev/null +++ b/service-ejb/src/main/java/com/mowesta/service/entity/WindDirectionType.java @@ -0,0 +1,28 @@ +package com.mowesta.service.entity; + +public enum WindDirectionType { + NORTH(0), + NORTH_EAST(1), + EAST(2), + EAST_SOUTH(3), + SOUTH(4), + SOUTH_WEST(5), + WEST(6), + WEST_NORTH(7), + UNKNOWN(-1); + + private final int dwdIndex; + + WindDirectionType(int dwdIndex) { + this.dwdIndex = dwdIndex; + } + + public static WindDirectionType getByDwdIndex(int dwdIndex) { + for (WindDirectionType windDirectionType : values()) { + if (windDirectionType.dwdIndex == dwdIndex) { + return windDirectionType; + } + } + throw new IllegalArgumentException("Es konnte kein WindDirectionType zum dwdIndex=" + dwdIndex + " gefunden werden!"); + } +} diff --git a/service-ejb/src/main/java/com/mowesta/service/session/CurrentWeatherSyncSessionBean.java b/service-ejb/src/main/java/com/mowesta/service/session/CurrentWeatherSyncSessionBean.java new file mode 100644 index 00000000..f0393a1b --- /dev/null +++ b/service-ejb/src/main/java/com/mowesta/service/session/CurrentWeatherSyncSessionBean.java @@ -0,0 +1,168 @@ +package com.mowesta.service.session; + +import com.mowesta.data.grib2.io.CsvReader; +import com.mowesta.service.entity.CurrentWeatherEntity; +import com.mowesta.service.entity.EmbeddedCoordinate; + +import javax.annotation.Resource; +import javax.annotation.security.PermitAll; +import javax.ejb.SessionContext; +import javax.ejb.Singleton; +import javax.ejb.TransactionAttribute; +import javax.ejb.TransactionAttributeType; +import java.io.*; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Enumeration; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; +import java.util.logging.Level; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +@Singleton +public class CurrentWeatherSyncSessionBean extends AbstractSessionBean { + protected static final String STATION_LIST_FILENAME = "zehn_now_tu_Beschreibung_Stationen.txt"; + + protected static final int STATION_LIST_ID_INDEX = 0; + protected static final int STATION_LIST_LAT_INDEX = 4; + protected static final int STATION_LIST_LONG_INDEX = 5; + protected static final int WEATHER_FILE_DATE_INDEX = 1; + protected static final int WEATHER_FILE_QUALITY_INDEX = 2; + protected static final int WEATHER_FILE_TEMPERATURE_INDEX = 4; + protected static final int WEATHER_FILE_STATION_ID_INDEX = 0; + + protected static final DateTimeFormatter WEATHER_FILE_DATE_PATTERN = DateTimeFormatter.ofPattern("yyyyMMddHHmm").withZone(ZoneOffset.UTC); + + @Resource + private SessionContext context; + + /** + * Imports all CSV files in the given folder where the filter returns {@code true} into the DB and deletes all old {@link CurrentWeatherEntity} + * + * @param currentWeatherPath the local folder where all CSV files are stored + * @param currentWeatherFilter a predicate to determine wether a given current weather csv file should get imported or not + * @throws IOException in case of IO errors + */ + @PermitAll + @TransactionAttribute(TransactionAttributeType.NEVER) + public void doSyncCurrentWeather(File currentWeatherPath, Predicate currentWeatherFilter) throws IOException { + Map stationPositions = getStationPositions(currentWeatherPath); + List allCurrentWeathers = getAllCurrentWeathers(currentWeatherPath, stationPositions, currentWeatherFilter); + + //route call through EJB proxy to enable transaction management + CurrentWeatherSyncSessionBean thisProxy = context.getBusinessObject(getClass()); + thisProxy.saveWeatherToDB(allCurrentWeathers); + } + + /** + * @param currentWeatherPath the local folder where all CSV files are stored + * @return the positions of all stations. Key is the station ID and value it's coordinate + * @throws IOException in case of IO errors + */ + protected Map getStationPositions(File currentWeatherPath) throws IOException { + Map stationPositions; + + File stationListFile = new File(currentWeatherPath, STATION_LIST_FILENAME); + try (Stream stream = Files.lines(stationListFile.toPath(), Charset.forName("Cp1252"))) { + stationPositions = stream.skip(2) + .map(line -> line.split("\\s+", 7)) + .filter(line -> line.length >= 6) + .collect(Collectors.toMap( + line -> Integer.parseInt(line[STATION_LIST_ID_INDEX]), + line -> new EmbeddedCoordinate(Double.parseDouble(line[STATION_LIST_LAT_INDEX]), Double.parseDouble(line[STATION_LIST_LONG_INDEX])) + )); + log.log(Level.INFO, "Station positions loaded. Found " + stationPositions.size() + " stations"); + } + return stationPositions; + } + + /** + * Reads all CSV files and creates {@link CurrentWeatherEntity} + * + * @param currentWeatherPath the local folder where all CSV files are stored + * @param stationPositions the positions of all stations. Key is the station ID and value it's coordinate + * @param currentWeatherFilter a predicate to determine wether a given current weather csv file should get imported or not + * @return a List of all {@link CurrentWeatherEntity} created out of the CSV files + * @throws IOException in case of IO errors + */ + protected List getAllCurrentWeathers(File currentWeatherPath, Map stationPositions, Predicate currentWeatherFilter) throws IOException { + List allCurrentWeathers = new LinkedList<>(); + for (File currentWeatherFile : currentWeatherPath.listFiles()) { + //only use weather data in zip files + if (currentWeatherFile.getName().endsWith(".zip") && currentWeatherFilter.test(currentWeatherFile)) { + try (ZipFile zipFile = new ZipFile(currentWeatherFile)) { + Enumeration entries = zipFile.entries(); + + if (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + + try (InputStream stream = zipFile.getInputStream(entry); + Reader reader = new InputStreamReader(stream); + CsvReader csvReader = new CsvReader(reader, true, ';')) { + log.log(Level.INFO, "Loading current weather data from file " + entry.getName()); + String[] latestRecord = null; + String[] currentRecord; + //search for the record with the highest date but with a quality index of at least 2 + while ((currentRecord = csvReader.readRow()) != null) { + if (latestRecord == null || currentRecord[WEATHER_FILE_DATE_INDEX].compareTo(latestRecord[WEATHER_FILE_DATE_INDEX]) > 0) { + if (Integer.parseInt(currentRecord[WEATHER_FILE_QUALITY_INDEX].trim()) > 1) { + latestRecord = currentRecord; + } + } + } + + if (latestRecord != null) { + CurrentWeatherEntity currentWeatherEntity = new CurrentWeatherEntity(); + ZonedDateTime measurementDate = ZonedDateTime.parse(latestRecord[WEATHER_FILE_DATE_INDEX], WEATHER_FILE_DATE_PATTERN); + float temperature = Float.parseFloat(latestRecord[WEATHER_FILE_TEMPERATURE_INDEX].trim()); + currentWeatherEntity.setMeasurementDate(measurementDate.toEpochSecond()); + currentWeatherEntity.setTemperature(temperature); + currentWeatherEntity.setCoordinate(stationPositions.get(Integer.parseInt(latestRecord[WEATHER_FILE_STATION_ID_INDEX].trim()))); + allCurrentWeathers.add(currentWeatherEntity); + } + else { + log.log(Level.WARNING, "No record with quality index > 1 found"); + } + } + } + else { + log.log(Level.WARNING, "There are no files in the zip file"); + } + } + } + } + log.log(Level.INFO, "Found current weather data for " + allCurrentWeathers.size() + " stations"); + return allCurrentWeathers; + } + + /** + * Imports all {@link CurrentWeatherEntity} into the DB and deletes all old {@link CurrentWeatherEntity} + * + * @param allCurrentWeathers the {@link CurrentWeatherEntity} to import + */ + @PermitAll + @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) + public void saveWeatherToDB(List allCurrentWeathers) { + if (allCurrentWeathers.size() > 0) { + log.log(Level.INFO, "Actually delete all CurrentWeatherEntities"); + int count = CurrentWeatherEntity.deleteAllEntries(em); + log.log(Level.INFO, "Actually deleted " + count + " CurrentWeatherEntities"); + + for (CurrentWeatherEntity currentWeather : allCurrentWeathers) { + em.persist(currentWeather); + } + log.log(Level.INFO, "Stored " + allCurrentWeathers.size() + " CurrentWeatherEntities in the DB"); + } + else { + log.log(Level.WARNING, "The allCurrentWeathers list was empty. Not deleting all data from the DB!"); + } + } +} diff --git a/service-ejb/src/main/java/com/mowesta/service/session/DataSessionBean.java b/service-ejb/src/main/java/com/mowesta/service/session/DataSessionBean.java index fbf54bf5..08847af8 100644 --- a/service-ejb/src/main/java/com/mowesta/service/session/DataSessionBean.java +++ b/service-ejb/src/main/java/com/mowesta/service/session/DataSessionBean.java @@ -1,26 +1,5 @@ package com.mowesta.service.session; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.annotation.security.PermitAll; -import javax.ejb.Asynchronous; -import javax.ejb.Stateless; -import javax.enterprise.context.Dependent; -import javax.inject.Inject; -import javax.persistence.EntityManager; -import javax.transaction.Transactional; -import javax.transaction.Transactional.TxType; - -import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; - import com.mowesta.api.access.Roles; import com.mowesta.data.nominatim.NominatimCity; import com.mowesta.data.nominatim.NominatimCountry; @@ -30,6 +9,25 @@ import com.mowesta.service.crypto.SecureHash; import com.mowesta.service.entity.EmailEntity; import com.mowesta.service.entity.RoleEntity; import com.mowesta.service.entity.UserEntity; +import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; + +import javax.annotation.security.PermitAll; +import javax.ejb.Asynchronous; +import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; +import javax.ejb.TransactionAttributeType; +import javax.enterprise.context.Dependent; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; /** * A bean that is executed by the startup bean to initialize the database. @@ -85,7 +83,7 @@ public class DataSessionBean implements IDataSessionBean { * Initializes the database with the default roles. */ @PermitAll - @Transactional(value = TxType.REQUIRED) + @TransactionAttribute(TransactionAttributeType.REQUIRED) public void initRoles() { log.log(Level.INFO, "Initializing roles (data)."); addRole(Roles.ADMIN, "Grants admin privileges."); @@ -121,7 +119,7 @@ public class DataSessionBean implements IDataSessionBean { * Initializes a default set of users. */ @PermitAll - @Transactional(value = TxType.REQUIRED) + @TransactionAttribute(TransactionAttributeType.REQUIRED) public void initUsers() { log.log(Level.INFO, "Initializing users."); initUser("admin", "Administrator", "admin", "nes-admin@uni-due.de", new String[] { Roles.ADMIN, Roles.USER}); @@ -155,7 +153,7 @@ public class DataSessionBean implements IDataSessionBean { */ @PermitAll @Asynchronous - @Transactional(value = TxType.NOT_SUPPORTED) + @TransactionAttribute(TransactionAttributeType.NEVER) public void initLocations() { addCountries(); // roughly 2 minutes (~220) addStates(); // roughly 5 minutes (~3K) diff --git a/service-ejb/src/main/java/com/mowesta/service/session/DebugDataSessionBean.java b/service-ejb/src/main/java/com/mowesta/service/session/DebugDataSessionBean.java index 77e52ad1..726d4b74 100644 --- a/service-ejb/src/main/java/com/mowesta/service/session/DebugDataSessionBean.java +++ b/service-ejb/src/main/java/com/mowesta/service/session/DebugDataSessionBean.java @@ -1,19 +1,18 @@ package com.mowesta.service.session; -import java.io.IOException; -import java.io.InputStream; -import java.util.logging.Level; - -import javax.annotation.security.PermitAll; -import javax.ejb.Stateless; -import javax.enterprise.context.Dependent; -import javax.enterprise.inject.Alternative; -import javax.transaction.Transactional; -import javax.transaction.Transactional.TxType; - import com.mowesta.api.access.Roles; import com.mowesta.service.entity.UserEntity; +import javax.annotation.security.PermitAll; +import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; +import javax.ejb.TransactionAttributeType; +import javax.enterprise.context.Dependent; +import javax.enterprise.inject.Alternative; +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; + /** * An extended implementation of the data session * bean that initializes the database in a more @@ -37,7 +36,7 @@ public class DebugDataSessionBean extends DataSessionBean implements IDataSessio @Override @PermitAll - @Transactional(value = TxType.NOT_SUPPORTED) + @TransactionAttribute(TransactionAttributeType.NEVER) public void initLocations() { super.initLocations(); } @@ -61,4 +60,4 @@ public class DebugDataSessionBean extends DataSessionBean implements IDataSessio } -} \ No newline at end of file +} diff --git a/service-ejb/src/main/java/com/mowesta/service/session/DebugWeatherSyncSessionBean.java b/service-ejb/src/main/java/com/mowesta/service/session/DebugWeatherSyncSessionBean.java new file mode 100644 index 00000000..1cd1b73e --- /dev/null +++ b/service-ejb/src/main/java/com/mowesta/service/session/DebugWeatherSyncSessionBean.java @@ -0,0 +1,29 @@ +package com.mowesta.service.session; + +import javax.ejb.ConcurrencyManagement; +import javax.ejb.ConcurrencyManagementType; +import javax.ejb.Singleton; +import javax.enterprise.inject.Alternative; +import java.io.File; +import java.util.function.Predicate; + +@Alternative // alternative implementation, selectable via beans.xml +@Singleton +@ConcurrencyManagement(ConcurrencyManagementType.BEAN) +public class DebugWeatherSyncSessionBean extends WeatherSyncSessionBean { + @Override + protected File getTempFolder() { + return new File("temp"); + } + + @Override + protected Predicate getGribFilter() { + //only import the first 6 files + return file -> file.getName().matches(".*00[0-5]_(?:[A-Z]+_)?[A-Z0-9]+\\.grib2\\.bz2"); + } + + @Override + protected Predicate getCurrentWeatherFilter() { + return file -> file.getName().startsWith("10minutenwerte_TU_00")|| file.getName().endsWith(".txt"); + } +} diff --git a/service-ejb/src/main/java/com/mowesta/service/session/MeasurementSessionBean.java b/service-ejb/src/main/java/com/mowesta/service/session/MeasurementSessionBean.java index cafdee92..52c9146d 100644 --- a/service-ejb/src/main/java/com/mowesta/service/session/MeasurementSessionBean.java +++ b/service-ejb/src/main/java/com/mowesta/service/session/MeasurementSessionBean.java @@ -1,24 +1,19 @@ package com.mowesta.service.session; -import javax.annotation.security.DeclareRoles; -import javax.annotation.security.PermitAll; -import javax.annotation.security.RolesAllowed; -import javax.ejb.Stateful; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; - import com.mowesta.api.PageConfig; import com.mowesta.api.access.Roles; import com.mowesta.api.measurement.Measurement; import com.mowesta.api.measurement.MeasurementPage; import com.mowesta.service.conversion.Convert; import com.mowesta.service.conversion.MeasurementConverter; -import com.mowesta.service.entity.AbstractEntity; -import com.mowesta.service.entity.DeviceEntity; -import com.mowesta.service.entity.EmbeddedCoordinate; -import com.mowesta.service.entity.EntityForbiddenException; -import com.mowesta.service.entity.EntityNotFoundException; -import com.mowesta.service.entity.MeasurementEntity; +import com.mowesta.service.entity.*; + +import javax.annotation.security.DeclareRoles; +import javax.annotation.security.PermitAll; +import javax.annotation.security.RolesAllowed; +import javax.ejb.Stateful; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; /** * A stateful session bean to manage measurements. @@ -43,8 +38,8 @@ public class MeasurementSessionBean extends AbstractUserSpecificSessionBean { entity.setAppVersion(measurment.getAppVersion()); entity.setCalculatedTemperature(measurment.getCalculatedTemperature()); entity.setContext(measurment.getContext()); - entity.setCoordinate(new EmbeddedCoordinate(measurment.getCoordinate().getLongitude(), - measurment.getCoordinate().getLatitude())); + entity.setCoordinate(new EmbeddedCoordinate(measurment.getCoordinate().getLatitude(), + measurment.getCoordinate().getLongitude())); entity.setDevice(device); entity.setHumidity(measurment.getHumidity()); entity.setMeasuredTemperature(measurment.getMeasuredTemperature()); diff --git a/service-ejb/src/main/java/com/mowesta/service/session/StartupBean.java b/service-ejb/src/main/java/com/mowesta/service/session/StartupBean.java index bd346b42..82203374 100644 --- a/service-ejb/src/main/java/com/mowesta/service/session/StartupBean.java +++ b/service-ejb/src/main/java/com/mowesta/service/session/StartupBean.java @@ -2,12 +2,8 @@ package com.mowesta.service.session; import javax.annotation.PostConstruct; import javax.annotation.security.PermitAll; -import javax.ejb.DependsOn; -import javax.ejb.Singleton; -import javax.ejb.Startup; +import javax.ejb.*; import javax.inject.Inject; -import javax.transaction.Transactional; -import javax.transaction.Transactional.TxType; /** * The bean that initializes the database @@ -26,16 +22,20 @@ public class StartupBean { @Inject protected IDataSessionBean dataSession; + @Inject + protected WeatherSyncSessionBean weatherSyncSession; + /** * Initializes the application. */ @PermitAll @PostConstruct - @Transactional(value = TxType.NOT_SUPPORTED) + @TransactionAttribute(TransactionAttributeType.NEVER) public void onConstruct() { dataSession.initRoles(); dataSession.initUsers(); dataSession.initLocations(); + weatherSyncSession.startTimer(); } } diff --git a/service-ejb/src/main/java/com/mowesta/service/session/SyncSessionBean.java b/service-ejb/src/main/java/com/mowesta/service/session/SyncSessionBean.java index 87f4a090..6cc050f1 100644 --- a/service-ejb/src/main/java/com/mowesta/service/session/SyncSessionBean.java +++ b/service-ejb/src/main/java/com/mowesta/service/session/SyncSessionBean.java @@ -12,9 +12,9 @@ import org.hibernate.search.jpa.Search; import javax.annotation.security.PermitAll; import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; +import javax.ejb.TransactionAttributeType; import javax.enterprise.context.Dependent; -import javax.transaction.Transactional; -import javax.transaction.Transactional.TxType; import java.util.List; import java.util.Map; import java.util.logging.Level; @@ -34,7 +34,7 @@ public class SyncSessionBean extends AbstractSessionBean { * @param countries The countries. */ @PermitAll - @Transactional(value = TxType.REQUIRES_NEW) + @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void syncCountries(List countries) { for (NominatimCountry country: countries) { CountryEntity e = AbstractLocationEntity.findByExternalId(em, CountryEntity.class, country.getId()); @@ -56,7 +56,7 @@ public class SyncSessionBean extends AbstractSessionBean { * @param states The states. */ @PermitAll - @Transactional(value = TxType.REQUIRES_NEW) + @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void syncStates(List states) { for (NominatimState state: states) { StateEntity e = AbstractLocationEntity.findByExternalId(em, StateEntity.class, state.getId()); @@ -85,7 +85,7 @@ public class SyncSessionBean extends AbstractSessionBean { * @param cities The cities. */ @PermitAll - @Transactional(value = TxType.REQUIRES_NEW) + @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void syncCities(List cities) { for (NominatimCity city: cities) { CityEntity e = AbstractLocationEntity.findByExternalId(em, CityEntity.class, city.getId()); @@ -120,7 +120,7 @@ public class SyncSessionBean extends AbstractSessionBean { * Rebuilds the lucene search index. */ @PermitAll - @Transactional(value = TxType.NOT_SUPPORTED) + @TransactionAttribute(TransactionAttributeType.NEVER) public void rebuildIndex() { try { log.log(Level.INFO, "Rebuilding search index."); @@ -149,7 +149,7 @@ public class SyncSessionBean extends AbstractSessionBean { */ private void updateLocation(NominatimObject object, AbstractLocationEntity entity) { entity.setAddressRank(object.getAddressRank()); - entity.setCoordinate(new EmbeddedCoordinate(object.getCentroid().getCoordinates().getLongitude(), object.getCentroid().getCoordinates().getLatitude())); + entity.setCoordinate(new EmbeddedCoordinate(object.getCentroid().getCoordinates().getLatitude(), object.getCentroid().getCoordinates().getLongitude())); entity.setDeleted(false); entity.setExternalId(object.getId()); entity.setImportance(object.getImportance()); diff --git a/service-ejb/src/main/java/com/mowesta/service/session/WeatherForecastSyncSessionBean.java b/service-ejb/src/main/java/com/mowesta/service/session/WeatherForecastSyncSessionBean.java new file mode 100644 index 00000000..e24366aa --- /dev/null +++ b/service-ejb/src/main/java/com/mowesta/service/session/WeatherForecastSyncSessionBean.java @@ -0,0 +1,356 @@ +package com.mowesta.service.session; + +import com.mowesta.data.grib2.Grib2Data; +import com.mowesta.data.grib2.Grib2File; +import com.mowesta.data.grib2.decoder.SimpleDataDecoder; +import com.mowesta.data.process.conversion.IDataConversion; +import com.mowesta.data.process.util.DoubleArray; +import com.mowesta.service.entity.EmbeddedCoordinate; +import com.mowesta.service.entity.SoilType; +import com.mowesta.service.entity.WeatherForecastEntity; +import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; + +import javax.annotation.Resource; +import javax.annotation.security.PermitAll; +import javax.ejb.*; +import java.io.*; +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.function.Predicate; +import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static com.mowesta.service.session.WeatherSyncSessionBean.WeatherSyncMetric; +import static com.mowesta.service.session.WeatherSyncSessionBean.WeatherSyncMetrics; + +@Singleton +@ConcurrencyManagement(ConcurrencyManagementType.BEAN) +public class WeatherForecastSyncSessionBean extends AbstractSessionBean { + protected static final List FILTERED_SOIL_TYPES = Arrays.asList(SoilType.SEA_WATER); + protected static final Pattern FILENAME_DATE_PATTERN = Pattern.compile(".+([0-9]{4}[0-1][0-9][0-3][0-9][0-2][0-9]).+"); + + @Resource + private SessionContext context; + + /** + * Imports all GRIB2 files in each {@link WeatherSyncMetric#localFolderFiles} where the filter returns {@code true} into the DB and deletes all old {@link WeatherForecastEntity} + * + * @param weatherForecastPathLat the path of the GRIB2 file containing the latitudes of each forecast position + * @param weatherForecastPathLon the path of the GRIB2 file containing the longitude of each forecast position + * @param weatherSyncMetrics the configuration for this import process + * @param weatherForecastPathSoiltyp the path of the GRIB2 file containing the soil type of each forecast position + * @param coordinateFilter a predicate to determine wether a given weather forecast GRIB2 file should get imported or not + * @throws IOException in case of IO errors + */ + @PermitAll + @TransactionAttribute(TransactionAttributeType.NEVER) + public void doSyncWeatherForecast(File weatherForecastPathLat, File weatherForecastPathLon, WeatherSyncMetrics weatherSyncMetrics, File weatherForecastPathSoiltyp, Predicate coordinateFilter) throws IOException { + final long dateCounts = weatherSyncMetrics.weatherSyncMetrics.stream() + .map(a -> a.localFolderFiles) + .flatMap(Collection::stream) + .map(File::getName) + .map(FILENAME_DATE_PATTERN::matcher) + .peek(Matcher::matches) + .map(matcher -> matcher.group(1)) + .distinct() + .count(); + if (dateCounts != 1) { + log.log(Level.WARNING, "Unequal dates in all filesnames across the folders. DWD is probably updating its files at the moment. Skipping forecast sync for now."); + return; + } + + final List forecastPositions = getForecastPositions(weatherForecastPathLat, weatherForecastPathLon); + final Map forecatPositionsNotInSea = filterForecastPositionsInSea(weatherForecastPathSoiltyp, forecastPositions, coordinateFilter); + saveWeatherForecastsToDB(weatherSyncMetrics, forecatPositionsNotInSea); + } + + /** + * combines the GRIB2 file for the latitude and longitude into a single {@link List} of {@link EmbeddedCoordinate} + * + * @param weatherForecastPathLat the path of the GRIB2 file containing the latitudes of each forecast position + * @param weatherForecastPathLon the path of the GRIB2 file containing the longitude of each forecast position + * @return the {@link List} of {@link EmbeddedCoordinate} + * @throws IOException in case of IO errors + */ + protected List getForecastPositions(File weatherForecastPathLat, File weatherForecastPathLon) throws IOException { + final File[] latFiles = weatherForecastPathLat.listFiles(); + final File[] lonFiles = weatherForecastPathLon.listFiles(); + List forecastPosition = new LinkedList<>(); + if (latFiles.length > 0 && lonFiles.length > 0) { + final DoubleArray latValues = getValues(latFiles[0]); + final DoubleArray lonValues = getValues(lonFiles[0]); + if (latValues.getSize() == lonValues.getSize()) { + for (int i = 0; i < latValues.getSize(); i++) { + forecastPosition.add(new EmbeddedCoordinate(latValues.getValue(i), lonValues.getValue(i))); + } + } + else { + log.log(Level.WARNING, "There are different number of lat information (" + latValues.getSize() + ") and lon information (" + lonValues.getSize() + ")"); + } + } + else { + log.log(Level.WARNING, "There is no lat and/or no long file present"); + } + log.log(Level.INFO, "Forecast positions loaded. Found " + forecastPosition.size() + " positions"); + return forecastPosition; + } + + /** + * filters the {@link List} of {@link EmbeddedCoordinate} to remove all {@link EmbeddedCoordinate} which are in the sea or where the filter returns false + * + * @param weatherForecastPathSoiltyp the path of the GRIB2 file containing the soil type of each forecast position + * @param forecastPositions the {@link List} of {@link EmbeddedCoordinate} + * @param coordinateFilter a predicate to determine wether a given weather forecast GRIB2 file should get imported or not + * @return a {@link Map} where the key is the index in the initial {@link List} and the value the {@link EmbeddedCoordinate} + * @throws IOException in case of IO errors + */ + protected Map filterForecastPositionsInSea(File weatherForecastPathSoiltyp, List forecastPositions, Predicate coordinateFilter) throws IOException { + final File[] files = weatherForecastPathSoiltyp.listFiles(); + Map forecasts = new TreeMap<>(); + if (files.length > 0) { + DoubleArray soils = getValues(files[0]); + if (soils.getSize() == forecastPositions.size()) { + int skipped = 0; + int i = 0; + for (EmbeddedCoordinate forecastPosition : forecastPositions) { + SoilType soilType = SoilType.getByDwdIndex((int) soils.getValue(i)); + if (FILTERED_SOIL_TYPES.contains(soilType)) { + skipped++; + } + else if (coordinateFilter.test(forecastPosition)) { + forecasts.put(i, forecastPosition); + } + i++; + } + log.log(Level.INFO, "Skipped " + skipped + " positions because they are in the sea"); + } + else { + log.log(Level.WARNING, "There are different number of soil information (" + soils.getSize() + ") and forecast positions (" + forecastPositions.size() + ")"); + } + } + else { + log.log(Level.WARNING, "There is no soils file present"); + } + return forecasts; + } + + /** + * Reads the different GRIB2 files, combines the metrics stored inside of them into {@link WeatherForecastEntity} and stores them into the DB. + * + * @param weatherSyncMetrics the configuration for this import process + * @param forecatPositionsNotInSea a {@link Map} containing all positions that should imported where the key is the index of the position and the value the {@link EmbeddedCoordinate} + */ + protected void saveWeatherForecastsToDB(WeatherSyncMetrics weatherSyncMetrics, Map forecatPositionsNotInSea) { + final int[] fileCounts = weatherSyncMetrics.weatherSyncMetrics.stream().map(a -> a.localFolderFiles).mapToInt(List::size).distinct().toArray(); + if (fileCounts.length != 1) throw new IllegalStateException("Unequal number of files across the folders"); + + //route call through EJB proxy to enable transaction management + WeatherForecastSyncSessionBean thisProxy = context.getBusinessObject(getClass()); + //mark all old forecasts as deleted to enable their actual deletion during the import of newer data + thisProxy.markAllForecastsAsDeleted(); + Future previousSaveToDB = CompletableFuture.completedFuture(null); + for (int fileIndex = 0; fileIndex < fileCounts[0]; fileIndex++) { + final int finalFileIndex = fileIndex; + //create a list of WeatherForecastEntities with a new WeatherForecastEntity object at each position. There will be one WeatherForecastEntity for each position in the list + List forecasts = Stream.generate(WeatherForecastEntity::new).limit(forecatPositionsNotInSea.size()).collect(Collectors.toCollection(LinkedList::new)); + + //reads the GRIB2 file for each metric and stores the value in the previously created WeatherForecastEntity objects. All metrics files get read parallel + weatherSyncMetrics.weatherSyncMetrics + .stream() + .map(weatherSyncMetric -> thisProxy.processweatherForecastFile(forecasts, weatherSyncMetric, finalFileIndex, forecatPositionsNotInSea)) + .collect(Collectors.toList()) + .forEach(this::uncheckedFutureGet); + //if this is not the first file, the saving process of the previous file may still be in progress. Waiting for it's termination + uncheckedFutureGet(previousSaveToDB); + + //chunk the forecasts to reduce the time needed for each transaction to avoid a transaction timeout + final Map> entityMap = forecasts.stream() + .peek(weatherSyncMetrics.additionalValueCalculator) + .collect(Collectors.groupingBy(a -> Math.abs(a.getCoordinate().getLongitude().intValue() / 9))); + previousSaveToDB = thisProxy.saveAllWeatherForecastChunksToDB(entityMap); + } + uncheckedFutureGet(previousSaveToDB); + + //delete all marked forecasts in case some of them were not deleted yet while importing the new data. That should only happen for forecasts that now lay in the past or where the new file could not be read + thisProxy.deleteAllMarkedForecasts(); + log.log(Level.INFO, "All forecast entities stored in the DB"); + } + + /** + * Reads a single GRIB2 file and stores it's value according the configuration in the {@link WeatherSyncMetric} + * + * @param forecasts the {@link List} containing all the target objects + * @param weatherSyncMetric the configuration for the current metric + * @param fileIndex the index of the GRIB2 file in the file system + * @param forecatPositionsNotInSea a {@link Map} containing all positions that should imported where the key is the index of the position and the value the {@link EmbeddedCoordinate} + * @return a AsyncResult to enable joining of the function call + */ + @PermitAll + @TransactionAttribute(TransactionAttributeType.NEVER) + @Asynchronous + public Future processweatherForecastFile(List forecasts, WeatherSyncMetric weatherSyncMetric, int fileIndex, Map forecatPositionsNotInSea) { + File weatherForecastFile = weatherSyncMetric.localFolderFiles.get(fileIndex); + log.log(Level.INFO, "Reading forecast data from " + weatherForecastFile.getName()); + try (InputStream inputStream = new FileInputStream(weatherForecastFile); + InputStream bufferedInputStream = new BufferedInputStream(inputStream); + InputStream bZipInputStream = new BZip2CompressorInputStream(bufferedInputStream); + Grib2File grib2File = new Grib2File(bZipInputStream)) { + getForecastsFromGribFile(forecasts, weatherSyncMetric, forecatPositionsNotInSea, grib2File); + log.log(Level.INFO, "Did read " + forecasts.size() + " forecast data entries from " + weatherForecastFile.getName()); + } + catch (Exception e) { + log.log(Level.WARNING, "Error while processing forecast file", e); + } + return new AsyncResult<>(null); + } + + protected void getForecastsFromGribFile(List forecasts, WeatherSyncMetric weatherSyncMetric, Map forecatPositionsNotInSea, Grib2File grib2File) throws IOException { + final Grib2Data data = grib2File.nextData(); + final T globalData = weatherSyncMetric.globalDataGetter.apply(data); + final SimpleDataDecoder decoder = new SimpleDataDecoder(data); + final long length = data.getGridSection().getPointCount(); + if (length >= forecatPositionsNotInSea.size()) { + int positionIndex = -1; + Iterator entityIterator = forecasts.iterator(); + for (Map.Entry positionEntry : forecatPositionsNotInSea.entrySet()) { + if (positionIndex > positionEntry.getKey()) { + throw new IllegalStateException("Map was not sorted"); + } + double value = Double.MIN_VALUE; + while (positionIndex < positionEntry.getKey()) { + positionIndex++; + value = decoder.readNext(); + } + for (IDataConversion dataConversion : weatherSyncMetric.conversions) { + value = dataConversion.convert(value); + } + WeatherForecastEntity weatherForecastEntity = entityIterator.next(); + weatherSyncMetric.setter.accept(weatherForecastEntity, value); + weatherSyncMetric.globalDataSetter.accept(globalData, weatherForecastEntity); + weatherSyncMetric.coordinateSetter.accept(weatherForecastEntity, positionEntry.getValue()); + } + } + else { + log.log(Level.WARNING, "There are more forecast measurements than positions"); + } + } + + /** + * Saves all chunks of {@link WeatherForecastEntity} in the DB + * + * @param entityMap a {@link Map} of all chunks. Key is the chunk identifier and value a list of all {@link WeatherForecastEntity} in this chunk + * @return a AsyncResult to enable joining the function call + */ + @PermitAll + @TransactionAttribute(TransactionAttributeType.NEVER) + @Asynchronous + public Future saveAllWeatherForecastChunksToDB(Map> entityMap) { + //route call through EJB proxy to enable transaction management + WeatherForecastSyncSessionBean thisProxy = context.getBusinessObject(getClass()); + for (Map.Entry> chunk : entityMap.entrySet()) { + try { + thisProxy.saveWeatherForecastChunkToDB(chunk.getKey(), chunk.getValue()); + } + catch (Exception e) { + log.log(Level.WARNING, "Error while saving forecasts", e); + } + } + return new AsyncResult<>(null); + } + + /** + * sets the deleted flag=true for all {@link WeatherForecastEntity} + */ + @PermitAll + @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) + public void markAllForecastsAsDeleted() { + log.log(Level.INFO, "Mark all WeatherForecastEntities as deleted"); + final int count = WeatherForecastEntity.markAllForecastsAsDeleted(em); + log.log(Level.INFO, "Marked " + count + " WeatherForecastEntities as deleted"); + } + + /** + * Actually deletes all {@link WeatherForecastEntity} with deleted=true and the given chunk and time + * + * @param chunk the chunk that should get deleted + * @param time the time that should get deleted + */ + protected void deleteAllMarkedForecastsAtTime(int chunk, long time) { + log.log(Level.INFO, "Actually delete all marked WeatherForecastEntities with chunk=" + chunk + " and time=" + time); + final int count = WeatherForecastEntity.deleteAllMarkedForecastsAtTime(em, chunk, time); + log.log(Level.INFO, "Actually deleted " + count + " marked WeatherForecastEntities with chunk=" + chunk + " and time=" + time); + } + + /** + * Actually deletes all {@link WeatherForecastEntity} with deleted=true + */ + @PermitAll + @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) + public void deleteAllMarkedForecasts() { + log.log(Level.INFO, "Actually delete all marked WeatherForecastEntities"); + final int count = WeatherForecastEntity.deleteAllMarkedForecasts(em); + log.log(Level.INFO, "Actually deleted " + count + " marked WeatherForecastEntities"); + } + + /** + * saves a single chunk of {@link WeatherForecastEntity} into the DB + * + * @param chunk the chunk key that gets inserted + * @param weatherForecastEntities the {@link WeatherForecastEntity} in this chunk + */ + @PermitAll + @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) + public void saveWeatherForecastChunkToDB(int chunk, List weatherForecastEntities) { + if (weatherForecastEntities.size() > 0) { + final long time = weatherForecastEntities.get(0).getPredictionStartTimestamp(); + deleteAllMarkedForecastsAtTime(chunk, time); + } + for (WeatherForecastEntity forecastEntity : weatherForecastEntities) { + em.persist(forecastEntity); + } + log.log(Level.INFO, "Stored " + weatherForecastEntities.size() + " WeatherForecastEntities in the DB"); + } + + /** + * Reads a GRIB2 file and stores all values in a {@link DoubleArray} + * + * @param input the location of the GRIB2 file + * @return the {@link DoubleArray} containing the values + * @throws IOException in case of IO errors + */ + protected DoubleArray getValues(File input) throws IOException { + try (InputStream inputStream = new FileInputStream(input); + InputStream bufferedInputStream = new BufferedInputStream(inputStream); + InputStream bZipInputStream = new BZip2CompressorInputStream(bufferedInputStream); + Grib2File grib2File = new Grib2File(bZipInputStream)) { + Grib2Data data = grib2File.nextData(); + SimpleDataDecoder decoder = new SimpleDataDecoder(data); + DoubleArray result = new DoubleArray((int) data.getGridSection().getPointCount()); + for (int i = 0; i < data.getGridSection().getPointCount(); i++) { + result.setValue(i, decoder.readNext()); + } + return result; + } + } + + /** + * executed {@link Future#get()}, catches the checked Exceptions and converts them into a RuntimeException + * + * @param future the {@link Future} on which the {@link Future#get()} should get executed + * @param the type of the {@link Future} + * @return the result of the {@link Future#get()} call + */ + protected T uncheckedFutureGet(Future future) { + try { + return future.get(); + } + catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + } +} diff --git a/service-ejb/src/main/java/com/mowesta/service/session/WeatherSyncSessionBean.java b/service-ejb/src/main/java/com/mowesta/service/session/WeatherSyncSessionBean.java new file mode 100644 index 00000000..ec1bdc3e --- /dev/null +++ b/service-ejb/src/main/java/com/mowesta/service/session/WeatherSyncSessionBean.java @@ -0,0 +1,386 @@ +package com.mowesta.service.session; + +import com.mowesta.data.ftp.FileStatus; +import com.mowesta.data.ftp.FtpFolderSync; +import com.mowesta.data.grib2.Grib2Data; +import com.mowesta.data.grib2.section.IdentificationSection; +import com.mowesta.data.grib2.template.product.ForecastProduct; +import com.mowesta.data.process.conversion.IDataConversion; +import com.mowesta.data.process.conversion.KelvinCelsiusConversion; +import com.mowesta.service.entity.*; + +import javax.annotation.Resource; +import javax.annotation.security.PermitAll; +import javax.ejb.*; +import javax.inject.Inject; +import java.io.File; +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.stream.Collectors; + +@Singleton +@ConcurrencyManagement(ConcurrencyManagementType.BEAN) +public class WeatherSyncSessionBean { + protected static final String SERVER_PATH = "/climate_environment/CDC/observations_germany/climate/10_minutes/air_temperature/now/"; + protected static final String SERVER_NAME = "opendata.dwd.de"; + + protected final Lock isRunning = new ReentrantLock(); + protected final AtomicBoolean isFirstExecution = new AtomicBoolean(true); + + @Resource + protected TimerService timerService; + @Inject + protected Logger log; + @Inject + protected CurrentWeatherSyncSessionBean currentWeatherSync; + @Inject + protected WeatherForecastSyncSessionBean weatherForecastSync; + @Resource + private SessionContext context; + + /** + * Uses a {@link TimerService} to start the Timer + */ + @PermitAll + @TransactionAttribute(TransactionAttributeType.NEVER) + public void startTimer() { + final TimerConfig timerConfig = new TimerConfig(SERVER_NAME, false); + timerService.createIntervalTimer(0, 10 * 60 * 1000, timerConfig); + } + + /** + * Gets called by the {@link TimerService} and asynchronously starts the weather sync process. Terminates immediately + * + * @param timer the {@link Timer} object created by the {@link TimerService} + */ + @Timeout + @TransactionAttribute(TransactionAttributeType.NEVER) + public void syncDWDData(Timer timer) { + if (!SERVER_NAME.equals(timer.getInfo())) { + log.log(Level.WARNING, "Timer was not called by our TimerService"); + return; + } + //JBoss does not seem to recognize the TransactionAttributeType.NEVER für the Timeout method as it still creates a transaction that times out after some time + //Therefore a asynchronous method is called for the sync management, so the Timout method terminates immediately. + WeatherSyncSessionBean thisProxy = context.getBusinessObject(getClass()); + thisProxy.startSyncWeatherAsynchronous(); + } + + /** + * Starts the weather sync process if no other sync process is still running + */ + @PermitAll + @TransactionAttribute(TransactionAttributeType.NEVER) + @Asynchronous + public void startSyncWeatherAsynchronous() { + if (isRunning.tryLock()) { + try { + log.log(Level.INFO, "Start weather synchronization"); + syncWeather(); + log.log(Level.INFO, "Weather synchronization done"); + } + catch (IOException e) { + throw new RuntimeException(e); + } + finally { + isRunning.unlock(); + } + } + else { + log.log(Level.WARNING, "Weather synchronization process is still running. Skipping this execution"); + } + } + + /** + * Downloads the newest files from the DWD's FTP server and loads them into the Database + * + * @throws IOException in case of IO errors + */ + @PermitAll + @TransactionAttribute(TransactionAttributeType.NEVER) + public void syncWeather() throws IOException { + final boolean isFirstExecution = this.isFirstExecution.getAndSet(false); + + //download current weather data + final AtomicBoolean didDownloadOneCurrent = new AtomicBoolean(isFirstExecution); + final File currentWeatherPath = getCurrentWeatherPath(); + + doFtpSync(currentWeatherPath, SERVER_PATH, didDownloadOneCurrent, getCurrentWeatherFilter()); + + //download forecast weather data + final AtomicBoolean didDownloadOneForecast = new AtomicBoolean(isFirstExecution); + final File weatherForecastPath = getWeatherForecastPath(); + final File weatherForecastPathLat = new File(weatherForecastPath, "clat"); + final File weatherForecastPathLon = new File(weatherForecastPath, "clon"); + final File weatherForecastPathSoiltyp = new File(weatherForecastPath, "soiltyp"); + + doFtpSync(weatherForecastPathLat, "/weather/nwp/icon/grib/00/clat/", didDownloadOneForecast); + doFtpSync(weatherForecastPathLon, "/weather/nwp/icon/grib/00/clon/", didDownloadOneForecast); + doFtpSync(weatherForecastPathSoiltyp, "/weather/nwp/icon/grib/00/soiltyp//", didDownloadOneForecast); + + final WeatherSyncMetrics weatherSyncMetrics = getWeatherSyncMetrics(weatherForecastPath); + for (WeatherSyncMetric weatherSyncMetric : weatherSyncMetrics.weatherSyncMetrics) { + doFtpSync(weatherSyncMetric.localFolder, "/weather/nwp/icon/grib/00/" + weatherSyncMetric.dwdFolder + "/", didDownloadOneForecast, getGribFilter()); + weatherSyncMetric.localFolderFiles = Arrays.stream(weatherSyncMetric.localFolder.listFiles()).filter(getGribFilter()).collect(Collectors.toList()); + } + + log.log(Level.INFO, "DWD weather data synchronized"); + + //import current weather data into the DB + if (didDownloadOneCurrent.get()) { + currentWeatherSync.doSyncCurrentWeather(currentWeatherPath, getCurrentWeatherFilter()); + } + else { + log.log(Level.INFO, "No new current weather data downloaded. Skipping import..."); + } + //import forecast weather data into the DB + if (didDownloadOneForecast.get()) { + weatherForecastSync.doSyncWeatherForecast(weatherForecastPathLat, weatherForecastPathLon, weatherSyncMetrics, weatherForecastPathSoiltyp, getCoordinateFilter()); + } + else { + log.log(Level.INFO, "No new weather forecast data downloaded. Skipping import..."); + } + } + + /** + * @return a predicate to determine wether a given current weather csv file should get imported or not + */ + protected Predicate getCurrentWeatherFilter() { + return file -> true; + } + + /** + * @return a predicate to determine wether a given weather forecast GRIB2 file should get imported or not + */ + protected Predicate getGribFilter() { + return file -> true; + } + + /** + * @return a predicate to determine wether a given position in the wheather forecast GRIB2 files should get imported or not + */ + protected Predicate getCoordinateFilter() { + return coordinate -> true; + } + + /** + * Downloads the latest data from the DWD's FTP server + * + * @param localPath the local path where the files should get downloaded to + * @param serverPath the path on the DTS's FTP server from where the files should get downloaded + * @param didDownloadOne an {@link AtomicBoolean} that will get set to true if any file was downloaded + * @throws IOException in case of IO errors + */ + protected void doFtpSync(File localPath, String serverPath, AtomicBoolean didDownloadOne) throws IOException { + FtpFolderSync ftps = new FtpFolderSync(localPath, SERVER_NAME, serverPath); + doFtpSync(didDownloadOne, ftps); + } + + /** + * Downloads the latest data from the DWD's FTP server + * + * @param localPath the local path where the files should get downloaded to + * @param serverPath the path on the DTS's FTP server from where the files should get downloaded + * @param didDownloadOne an {@link AtomicBoolean} that will get set to true if any file was downloaded + * @param fileFilter a predicate to determine wether a given file should get imported or not. The file is the file on the local file system where the remove file would get downloaded to in + * case this predicate returns true + * @throws IOException in case of IO errors + */ + protected void doFtpSync(File localPath, String serverPath, AtomicBoolean didDownloadOne, Predicate fileFilter) throws IOException { + FtpFolderSync ftps = new FtpFolderSync(localPath, SERVER_NAME, serverPath, fileFilter); + doFtpSync(didDownloadOne, ftps); + } + + /** + * Downloads the latest data from the DWD's FTP server + * + * @param didDownloadOne an {@link AtomicBoolean} that will get set to true if any file was downloaded + * @param ftps the configured {@link FtpFolderSync} object that should get used to download the files + * @throws IOException in case of IO errors + */ + protected void doFtpSync(AtomicBoolean didDownloadOne, FtpFolderSync ftps) throws IOException { + ftps.setStatusListener((source, status) -> { + if (status.getAction() == FileStatus.Action.DOWNLOADED) { + didDownloadOne.set(true); + } + log.log(Level.INFO, "Performed: " + status); + }); + ftps.synchronize(); + } + + /** + * @return the parent path where all local weather forecast GRIB2 files should get stored + */ + protected File getWeatherForecastPath() { + final File result = new File(getTempFolder(), "dwd/weatherforecast"); + if (result.mkdirs()) { + log.log(Level.INFO, "Weather Forecast folder created"); + } + else { + log.log(Level.INFO, "Weather Forecast folder already existed"); + } + return result; + } + + /** + * @return the parent path where all local current weather CSV files should get stored + */ + protected File getCurrentWeatherPath() { + final File result = new File(getTempFolder(), "dwd/currentweather"); + if (result.mkdirs()) { + log.log(Level.INFO, "Current weather folder created"); + } + else { + log.log(Level.INFO, "Current weather folder already existed"); + } + return result; + } + + /** + * @return the parent path where all local weather files should get stored + */ + protected File getTempFolder() { + return new File("/opt/data/temp"); + } + + /** + * @return the configuration which metrics should get downloaded and imported into the database + */ + protected WeatherSyncMetrics getWeatherSyncMetrics(File weatherForecastPath) { + final List> weatherSyncMetrics = Arrays.asList( + new WeatherSyncMetric<>("t_2m", Collections.singletonList(new KelvinCelsiusConversion()), WeatherForecastEntity::setAirTemperature2m, weatherForecastPath, + TimeDurationProductData::new, TimeDurationProductData::fillWeatherForecastEntity, AbstractPositionEntity::setCoordinate), + new WeatherSyncMetric<>("tmin_2m", Collections.singletonList(new KelvinCelsiusConversion()), WeatherForecastEntity::setAirTemperatureMin2m, weatherForecastPath), + new WeatherSyncMetric<>("tmax_2m", Collections.singletonList(new KelvinCelsiusConversion()), WeatherForecastEntity::setAirTemperatureMax2m, weatherForecastPath), + new WeatherSyncMetric<>("qv_s", Collections.emptyList(), WeatherForecastEntity::setHumidity2mSpecific, weatherForecastPath), + new WeatherSyncMetric<>("relhum_2m", Collections.emptyList(), WeatherForecastEntity::setHumidity2mRelative, weatherForecastPath), + new WeatherSyncMetric<>("ps", Collections.emptyList(), WeatherForecastEntity::setPressure, weatherForecastPath), + new WeatherSyncMetric<>("h_snow", Collections.emptyList(), WeatherForecastEntity::setSnowDepth, weatherForecastPath), + new WeatherSyncMetric<>("ww", Collections.emptyList(), (forecast, value) -> forecast.setWeatherInterpretationType(WeatherInterpretationType.getByDwdIndex(value.intValue())), weatherForecastPath), + new WeatherSyncMetric<>("u_10m", Collections.emptyList(), WeatherForecastEntity::setuWind10m, weatherForecastPath), + new WeatherSyncMetric<>("v_10m", Collections.emptyList(), WeatherForecastEntity::setvWind10m, weatherForecastPath) + ); + return new WeatherSyncMetrics(weatherSyncMetrics, weatherForecastEntity -> { + double u = weatherForecastEntity.getuWind10m(); + double v = weatherForecastEntity.getvWind10m(); + // formula: http://colaweb.gmu.edu/dev/clim301/lectures/wind/wind-uv + double windVelocity = Math.sqrt(Math.pow(u, 2) + Math.pow(v, 2)); + int angle = ((int) Math.round(Math.atan2(v, u) * 8d / Math.PI) * -1 + 10) % 8; + WindDirectionType windDirectionType = WindDirectionType.getByDwdIndex(angle); + weatherForecastEntity.setWindVelocity(windVelocity); + weatherForecastEntity.setWindDirection(windDirectionType); + weatherForecastEntity.setPredictionSystemType(PredictionSystemType.ICON); + }); + } + + /** + * Configuration class to store multiple metrics and an calculator to calculate additional values after each metric has been imported + */ + protected static class WeatherSyncMetrics { + public final List> weatherSyncMetrics; + public final Consumer additionalValueCalculator; + + /** + * @param weatherSyncMetrics a List of {@link WeatherSyncMetric} + * @param additionalValueCalculator an method that gets called after each metric has been imported. Can be used to manipulate the {@link WeatherSyncMetric} for example to calculate additional + * values + */ + public WeatherSyncMetrics(List> weatherSyncMetrics, Consumer additionalValueCalculator) { + this.weatherSyncMetrics = weatherSyncMetrics; + this.additionalValueCalculator = additionalValueCalculator; + } + } + + /** + * Configuration class to determine which metric should get imported and how it's values should get processed + * + * @param The type of the global data object that can be used + */ + protected static class WeatherSyncMetric { + public final String dwdFolder; + public final File localFolder; + public final List conversions; + public final BiConsumer setter; + public final Function globalDataGetter; + public final BiConsumer globalDataSetter; + public final BiConsumer coordinateSetter; + public List localFolderFiles; + + /** + * @param dwdFolder the subfolder's name on the DWD's FTP server + * @param conversions a list with conversions that should get applied to the value stored in the GRIB2 file + * @param setter a setter to store the value in the {@link WeatherForecastEntity} + * @param weatherForecastPath the parent path where all local weather forecast GRIB2 files should get stored + */ + public WeatherSyncMetric(String dwdFolder, List conversions, BiConsumer setter, File weatherForecastPath) { + this(dwdFolder, conversions, setter, weatherForecastPath, a -> null, (a, b) -> { + }, (a, b) -> { + }); + } + + /** + * @param dwdFolder the subfolder's name on the DWD's FTP server + * @param conversions a list with conversions that should get applied to the value stored in the GRIB2 file + * @param setter a setter to store the value in the {@link WeatherForecastEntity} + * @param weatherForecastPath the parent path where all local weather forecast GRIB2 files should get stored + * @param globalDataGetter function to create a {@link T} based on the data. The returned object will later get passed into the {@code globalDataSetter} function together with each {@link + * WeatherForecastEntity} + * @param globalDataSetter function that will get called for each {@link WeatherForecastEntity} together with the previous created {@link T} + * @param coordinateSetter function that will get called for each {@link WeatherForecastEntity} together with its {@link EmbeddedCoordinate} + */ + public WeatherSyncMetric(String dwdFolder, List conversions, BiConsumer setter, File weatherForecastPath, Function globalDataGetter, BiConsumer globalDataSetter, BiConsumer coordinateSetter) { + this.dwdFolder = dwdFolder; + this.conversions = conversions; + this.setter = setter; + this.globalDataGetter = globalDataGetter; + this.globalDataSetter = globalDataSetter; + this.coordinateSetter = coordinateSetter; + localFolder = new File(weatherForecastPath, dwdFolder); + } + } + + /** + * Class to store the prediction time and duration from a GRIB2 file + */ + protected static class TimeDurationProductData { + public final long time; + public final long duration; + + /** + * @param data the data section of the GRIB2 file + */ + public TimeDurationProductData(Grib2Data data) { + final ForecastProduct product = (ForecastProduct) data.getProductSection().getTemplate(); + final IdentificationSection identification = data.getIdentificationSection(); + final LocalDateTime forecastCreation = LocalDateTime.of(identification.getYear(), identification.getMonth(), identification.getDay(), identification.getHour(), identification + .getMinute(), identification.getSecond()); + final LocalDateTime forecastTime = forecastCreation.plusMinutes(product.time); + this.duration = product.time < TimeUnit.HOURS.toMinutes(78) ? TimeUnit.HOURS.toSeconds(1) : TimeUnit.HOURS.toSeconds(3); + this.time = forecastTime.toEpochSecond(ZoneOffset.UTC); + } + + /** + * fills the {@code time} and {@code duration} into a {@link WeatherForecastEntity} + * + * @param weatherForecastEntity the {@link WeatherForecastEntity} where the {@code time} and {@code duration} should get imported into + */ + public void fillWeatherForecastEntity(WeatherForecastEntity weatherForecastEntity) { + weatherForecastEntity.setPredictionStartTimestamp(time); + weatherForecastEntity.setPredictionDuration(duration); + } + } +} diff --git a/service-ejb/src/main/resources/META-INF/persistence.xml b/service-ejb/src/main/resources/META-INF/persistence.xml index 8217f663..e4c530e8 100644 --- a/service-ejb/src/main/resources/META-INF/persistence.xml +++ b/service-ejb/src/main/resources/META-INF/persistence.xml @@ -27,6 +27,7 @@ + - \ No newline at end of file + diff --git a/service-ejb/src/test/java/com/mowesta/service/mock/TestWeatherSyncSessionBean.java b/service-ejb/src/test/java/com/mowesta/service/mock/TestWeatherSyncSessionBean.java new file mode 100644 index 00000000..ad00399a --- /dev/null +++ b/service-ejb/src/test/java/com/mowesta/service/mock/TestWeatherSyncSessionBean.java @@ -0,0 +1,53 @@ +package com.mowesta.service.mock; + +import com.mowesta.service.entity.EmbeddedCoordinate; +import com.mowesta.service.session.DebugWeatherSyncSessionBean; + +import javax.annotation.security.PermitAll; +import javax.ejb.*; +import javax.enterprise.inject.Alternative; +import java.io.File; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Predicate; +import java.util.logging.Level; + +@Alternative // alternative implementation, selectable via beans.xml +@Singleton +@ConcurrencyManagement(ConcurrencyManagementType.BEAN) +public class TestWeatherSyncSessionBean extends DebugWeatherSyncSessionBean { + @PermitAll + @Override + public File getTempFolder() { + return new File(super.getTempFolder(), "test"); + } + + @Timeout + @TransactionAttribute(TransactionAttributeType.NEVER) + @Override + public void syncDWDData(Timer timer) { + log.log(Level.INFO, "Skipping automatic DWD sync during tests"); + } + + @Override + protected void doFtpSync(File localPath, String serverPath, AtomicBoolean didDownloadOne) throws IOException { + didDownloadOne.set(true); + } + + @Override + protected void doFtpSync(File localPath, String serverPath, AtomicBoolean didDownloadOne, Predicate fileFilter) throws IOException { + didDownloadOne.set(true); + } + + @Override + protected Predicate getCoordinateFilter() { + return embeddedCoordinate -> { + //germany only + if (embeddedCoordinate.getLatitude() > 55.0846d) return false; + if (embeddedCoordinate.getLatitude() < 47.271679d) return false; + if (embeddedCoordinate.getLongitude() > 15.043611d) return false; + if (embeddedCoordinate.getLongitude() < 5.866944d) return false; + return true; + }; + } +} diff --git a/service-ejb/src/test/java/com/mowesta/service/test/EjbDeployment.java b/service-ejb/src/test/java/com/mowesta/service/test/EjbDeployment.java index e16a39da..c2126697 100644 --- a/service-ejb/src/test/java/com/mowesta/service/test/EjbDeployment.java +++ b/service-ejb/src/test/java/com/mowesta/service/test/EjbDeployment.java @@ -2,6 +2,7 @@ package com.mowesta.service.test; import org.jboss.shrinkwrap.api.Filters; import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset; import org.jboss.shrinkwrap.api.asset.StringAsset; import org.jboss.shrinkwrap.api.spec.JavaArchive; @@ -31,7 +32,10 @@ public class EjbDeployment { .addAsManifestResource(new File("src/test/resources/META-INF/beans.xml"), "beans.xml") // use the persistence.xml from the test resource (in-memory db) .addAsManifestResource(new File("src/test/resources/META-INF/persistence.xml"), "persistence.xml") + .addAsResource(new ClassLoaderAsset("com/mowesta/data/grib2/code/GRIB2_23_0_0_CodeFlag_en.txt"), "com/mowesta/data/grib2/code/GRIB2_23_0_0_CodeFlag_en.txt") + .addAsResource(new ClassLoaderAsset("com/mowesta/data/grib2/template/util/GRIB2_23_0_0_Template_en.txt"), "com/mowesta/data/grib2/template/util/GRIB2_23_0_0_Template_en.txt") .addAsResource(new File("src/test/resources/emails/"), "/emails/") + .addAsResource(new File("src/test/resources/dwd/"), "/temp/dwd/") .addAsResource(new File("src/test/resources/nominatim/"), "/nominatim/"); } diff --git a/service-ejb/src/test/java/com/mowesta/service/test/session/AbstractSessionTest.java b/service-ejb/src/test/java/com/mowesta/service/test/session/AbstractSessionTest.java index 50b743dd..1cb00f81 100644 --- a/service-ejb/src/test/java/com/mowesta/service/test/session/AbstractSessionTest.java +++ b/service-ejb/src/test/java/com/mowesta/service/test/session/AbstractSessionTest.java @@ -1,22 +1,20 @@ package com.mowesta.service.test.session; -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.util.logging.Level; -import java.util.logging.Logger; - -import javax.security.auth.login.LoginContext; -import javax.security.auth.login.LoginException; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; - +import com.mowesta.service.test.EjbDeployment; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.security.auth.callback.UsernamePasswordHandler; import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; -import com.mowesta.service.test.EjbDeployment; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.util.logging.Level; +import java.util.logging.Logger; /** * An abstract base class for session tests that contains @@ -36,7 +34,7 @@ public abstract class AbstractSessionTest { /** * The logger. */ - private Logger log = Logger.getLogger(getClass().getName()); + protected Logger log = Logger.getLogger(getClass().getName()); /** * Creates the deployment. diff --git a/service-ejb/src/test/java/com/mowesta/service/test/session/WeatherSyncTest.java b/service-ejb/src/test/java/com/mowesta/service/test/session/WeatherSyncTest.java new file mode 100644 index 00000000..162bb171 --- /dev/null +++ b/service-ejb/src/test/java/com/mowesta/service/test/session/WeatherSyncTest.java @@ -0,0 +1,144 @@ +package com.mowesta.service.test.session; + +import com.mowesta.service.entity.*; +import com.mowesta.service.mock.TestWeatherSyncSessionBean; +import org.hibernate.search.jpa.Search; +import org.hibernate.search.spatial.impl.Point; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.vfs.VFS; +import org.jboss.vfs.VirtualFile; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.ejb.EJB; +import javax.inject.Inject; +import javax.persistence.EntityManager; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; + +@SuppressWarnings({"serial", "ResultOfMethodCallIgnored"}) +@RunWith(Arquillian.class) +//TODO check expected values and split the test in smaller parts +public class WeatherSyncTest extends AbstractSessionTest { + /** + * The entity manager + */ + @Inject + protected EntityManager em; + + @EJB + protected TestWeatherSyncSessionBean weatherSyncSessionBean; + + @Before + public void setUp() throws Exception { + tearDown(); + final VirtualFile virtualParent = VFS.getChild(getClass().getResource("/temp").toURI()); + File tempParent = weatherSyncSessionBean.getTempFolder(); + for (VirtualFile virtualFile : virtualParent.getChildrenRecursively()) { + File target = new File(tempParent, virtualFile.getPathNameRelativeTo(virtualParent)); + if (virtualFile.isDirectory()) { + target.mkdirs(); + } + else { + try (InputStream is = virtualFile.openStream()) { + Files.copy(is, target.toPath()); + } + } + } + weatherSyncSessionBean.syncWeather(); + } + + @After + public void tearDown() throws IOException { + final File tempFolder = weatherSyncSessionBean.getTempFolder(); + if (tempFolder.exists()) { + Files.walk(tempFolder.toPath()) + .map(Path::toFile) + .sorted((o1, o2) -> -o1.compareTo(o2)) + .forEach(File::delete); + } + tempFolder.getParentFile().delete(); + } + + @Test + public void testWeatherSync() throws IOException, InterruptedException { + final EmbeddedCoordinate coordiante = new EmbeddedCoordinate(52.4853d, 7.9126d); + final AbstractLocationEntity location = new AbstractLocationEntity(){{setCoordinate(coordiante);}}; + + final CurrentWeatherEntity currentWeatherForLocation = testCurrentWeatherInDB(coordiante, location); + final List currentWeatherForecastsForLocation = testWeatherForecastInDB(coordiante, location); + + weatherSyncSessionBean.syncWeather(); + Search.getFullTextEntityManager(em).createIndexer().startAndWait(); + + final CurrentWeatherEntity newCurrentWeatherForLocation = testCurrentWeatherInDB(coordiante, location); + final List newCurrentWeatherForecastsForLocation = testWeatherForecastInDB(coordiante, location); + + Assert.assertNotEquals("The previous current weather was not deleted", currentWeatherForLocation.getId(), newCurrentWeatherForLocation.getId()); + for (WeatherForecastEntity newCurrentWeatherForecastForLocation : newCurrentWeatherForecastsForLocation) { + final boolean foundWithSameId = currentWeatherForecastsForLocation.stream().mapToLong(AbstractEntity::getId).anyMatch(l -> newCurrentWeatherForecastForLocation.getId() == l); + Assert.assertFalse("The previous weather forecast was not deleted", foundWithSameId); + } + } + + private CurrentWeatherEntity testCurrentWeatherInDB(EmbeddedCoordinate coordiante, AbstractLocationEntity location) { + int countCurrent = CurrentWeatherEntity.getCount(em, CurrentWeatherEntity.class, false); + Assert.assertNotEquals("No current weather entity found in DB", 0, countCurrent); + Assert.assertEquals("Wrong number of current weather entites found in DB", 6, countCurrent); + + long a = System.currentTimeMillis(); + final CurrentWeatherEntity currentWeatherForLocation = AbstractPositionEntity.findEntityNearPosition(em, CurrentWeatherEntity.class, location); + long b = System.currentTimeMillis(); + log.log(Level.INFO, "Loading nearest current weather took " + (b-a) + "ms"); + + Assert.assertNotNull("No nearest weather found", currentWeatherForLocation); + Assert.assertEquals("Wrong nearest weather returned", coordiante, currentWeatherForLocation.getCoordinate()); + Assert.assertEquals("Wrong temperature", 8.8f, currentWeatherForLocation.getTemperature(), 0.05f); + return currentWeatherForLocation; + } + + private List testWeatherForecastInDB(EmbeddedCoordinate coordiante, AbstractLocationEntity location) { + int countForecast = WeatherForecastEntity.getCount(em, WeatherForecastEntity.class, false); + Assert.assertNotEquals("No weather forecast entity found in DB", 0, countForecast); + Assert.assertEquals("Wrong number of weather forecast entities found in DB", 2865, countForecast); + + long a = System.currentTimeMillis(); + final List weatherForecastEntities = AbstractPositionEntity.findEntitiesNearPosition(em, WeatherForecastEntity.class, location); + long b = System.currentTimeMillis(); + log.log(Level.INFO, "Loading nearest weather foreacst took " + (b-a) + "ms"); + + Assert.assertNotNull("No weather forecasts found", weatherForecastEntities); + Assert.assertNotEquals("No weather forecasts found", 0, weatherForecastEntities.size()); + final WeatherForecastEntity weatherForecastEntity = weatherForecastEntities.get(0); + Assert.assertNotNull("No coordinate found", weatherForecastEntity.getCoordinate()); + final double distance = Point.fromCoordinates(location.getCoordinate()).getDistanceTo(Point.fromCoordinates(weatherForecastEntity.getCoordinate())); + log.log(Level.INFO, weatherForecastEntity.toString()); + Assert.assertTrue("Distance between requested and returned coordinates too large: " + distance, distance <= 13d); + Assert.assertEquals("Air temperature wrong", 3.2008453369140852d, weatherForecastEntity.getAirTemperature2m(), 0.05f); + Assert.assertEquals("Min air temperature wrong", 3.1852203369140852d, weatherForecastEntity.getAirTemperatureMin2m(), 0.05f); + Assert.assertEquals("Max air temperature wrong", 3.8489471435547102d, weatherForecastEntity.getAirTemperatureMax2m(), 0.05f); + Assert.assertEquals("Relative humidity wrong", 83.07832336425781d, weatherForecastEntity.getHumidity2mRelative(), 0.05f); + Assert.assertEquals("Specific humidity wrong", 0.004034527695694123d, weatherForecastEntity.getHumidity2mSpecific(), 0.05f); + Assert.assertEquals("Pressure wrong", 101103.1484375d, weatherForecastEntity.getPressure(), 0.05f); + Assert.assertEquals("Snow depth wrong", 0d, weatherForecastEntity.getSnowDepth(), 0.05f); + Assert.assertEquals("u wind wrong", 4.010980606079102d, weatherForecastEntity.getuWind10m(), 0.05f); + Assert.assertEquals("v wind wrong", -0.1260204315185547d, weatherForecastEntity.getvWind10m(), 0.05f); + Assert.assertEquals("Wind direction wrong", WindDirectionType.EAST, weatherForecastEntity.getWindDirection()); + Assert.assertEquals("Wind velocity wrong", 4.012959826799017d, weatherForecastEntity.getWindVelocity(), 0.05f); + Assert.assertEquals("Weather interpreation wrong", WeatherInterpretationType.MAINLY_CLEAR, weatherForecastEntity.getWeatherInterpretationType()); + Assert.assertEquals("System type wrong", PredictionSystemType.ICON, weatherForecastEntity.getPredictionSystemType()); + Assert.assertEquals("Prediction start timestamp wrong", 1575936000L, weatherForecastEntity.getPredictionStartTimestamp()); + Assert.assertEquals("Prediction duration wrong", TimeUnit.HOURS.toSeconds(1), weatherForecastEntity.getPredictionDuration()); + + return weatherForecastEntities; + } +} diff --git a/service-ejb/src/test/resources/META-INF/beans.xml b/service-ejb/src/test/resources/META-INF/beans.xml index 792aafea..9ee1a7c5 100644 --- a/service-ejb/src/test/resources/META-INF/beans.xml +++ b/service-ejb/src/test/resources/META-INF/beans.xml @@ -9,9 +9,11 @@ com.mowesta.service.session.DebugDataSessionBean com.mowesta.service.session.DebugEmailSessionBean + + com.mowesta.service.mock.TestWeatherSyncSessionBean test - \ No newline at end of file + diff --git a/service-ejb/src/test/resources/META-INF/persistence.xml b/service-ejb/src/test/resources/META-INF/persistence.xml index ed5854c8..f18d0398 100644 --- a/service-ejb/src/test/resources/META-INF/persistence.xml +++ b/service-ejb/src/test/resources/META-INF/persistence.xml @@ -10,6 +10,7 @@ + - \ No newline at end of file + diff --git a/service-ejb/src/test/resources/arquillian.xml b/service-ejb/src/test/resources/arquillian.xml index f9789f3a..2d3e69a9 100644 --- a/service-ejb/src/test/resources/arquillian.xml +++ b/service-ejb/src/test/resources/arquillian.xml @@ -24,4 +24,4 @@ - \ No newline at end of file + diff --git a/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00044_now.zip b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00044_now.zip new file mode 100644 index 00000000..702e57be Binary files /dev/null and b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00044_now.zip differ diff --git a/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00071_now.zip b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00071_now.zip new file mode 100644 index 00000000..9d54ddc7 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00071_now.zip differ diff --git a/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00073_now.zip b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00073_now.zip new file mode 100644 index 00000000..09669802 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00073_now.zip differ diff --git a/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00078_now.zip b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00078_now.zip new file mode 100644 index 00000000..32f60613 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00078_now.zip differ diff --git a/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00091_now.zip b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00091_now.zip new file mode 100644 index 00000000..38496aac Binary files /dev/null and b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00091_now.zip differ diff --git a/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00096_now.zip b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00096_now.zip new file mode 100644 index 00000000..83ed5767 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/currentweather/10minutenwerte_TU_00096_now.zip differ diff --git a/service-ejb/src/test/resources/dwd/currentweather/zehn_now_tu_Beschreibung_Stationen.txt b/service-ejb/src/test/resources/dwd/currentweather/zehn_now_tu_Beschreibung_Stationen.txt new file mode 100644 index 00000000..7fe318b7 --- /dev/null +++ b/service-ejb/src/test/resources/dwd/currentweather/zehn_now_tu_Beschreibung_Stationen.txt @@ -0,0 +1,473 @@ +Stations_id von_datum bis_datum Stationshoehe geoBreite geoLaenge Stationsname Bundesland +----------- --------- --------- ------------- --------- --------- ----------------------------------------- ---------- +00044 20070209 20191202 44 52.9336 8.2370 Großenkneten Niedersachsen +00071 20091201 20191202 759 48.2156 8.9784 Albstadt-Badkap Baden-Württemberg +00073 20070214 20191202 340 48.6159 13.0506 Aldersbach-Kriestorf Bayern +00078 20041011 20191202 65 52.4853 7.9126 Alfhausen Niedersachsen +00091 20020820 20191202 300 50.7446 9.3450 Alsfeld-Eifa Hessen +00096 20190410 20191202 50 52.9437 12.8518 Neuruppin-Alt Ruppin Brandenburg +00131 20041101 20191202 296 51.0881 12.9326 Geringswalde-Altgeringswalde Sachsen +00142 20051026 20191202 510 48.4060 11.3117 Altomünster-Maisbrunn Bayern +00150 20050701 20191202 215 49.7273 8.1164 Alzey Rheinland-Pfalz +00151 20041124 20191202 382 49.4691 11.8546 Amberg-Unterammersricht Bayern +00154 20050113 20191202 515 48.0197 12.2924 Amerang-Pfaffing Bayern +00161 20110901 20191202 75 50.4237 7.4202 Andernach Rheinland-Pfalz +00164 19911102 20191202 54 53.0316 13.9908 Angermünde Brandenburg +00167 20040901 20191202 9 53.8412 13.6846 Anklam Mecklenburg-Vorpommern +00183 19911102 20191202 42 54.6792 13.4343 Arkona Mecklenburg-Vorpommern +00191 20041104 20191202 220 49.9695 9.9113 Arnstein-Müdesheim Bayern +00198 19911108 20191202 164 51.3745 11.2920 Artern Thüringen +00217 20041117 20191202 672 47.8774 11.3642 Attenkam Bayern +00222 19911102 20191202 387 50.5907 12.7140 Aue Sachsen +00232 19961108 20191202 461 48.4254 10.9420 Augsburg Bayern +00257 20020909 20191202 240 48.7270 8.2457 Baden-Baden-Geroldsau Baden-Württemberg +00259 20040701 20191202 273 47.8064 7.6387 Müllheim Baden-Württemberg +00282 19950601 20191202 240 49.8742 10.9206 Bamberg Bayern +00294 20040423 20191202 110 52.3199 9.4300 Barsinghausen-Hohenbostel Niedersachsen +00298 19911101 20191202 3 54.3406 12.7108 Barth Mecklenburg-Vorpommern +00303 19980101 20191202 55 52.0614 13.4996 Baruth Brandenburg +00314 20030714 20191202 232 51.1604 14.5042 Kubschütz, Kr. Bautzen Sachsen +00320 20060511 20191202 350 49.9667 11.5197 Heinersreuth-Vollhof Bayern +00330 20040609 20191202 450 49.5617 8.9673 Oberzent-Beerfelden Hessen +00342 20101202 20191202 103 52.3170 8.1694 Belm Niedersachsen +00377 20041001 20191202 210 49.1070 7.9967 Bergzabern, Bad Rheinland-Pfalz +00379 20170901 20191202 303 50.9074 11.2665 Berka, Bad (Flugplatz) Thüringen +00390 20030123 20191202 610 50.9837 8.3683 Berleburg, Bad-Stünzel Nordrhein-Westfalen +00400 20030610 20191202 60 52.6309 13.5022 Berlin-Buch Berlin +00410 20030807 20181210 33 52.4040 13.7309 Berlin-Kaniswall Berlin +00420 20070801 20191202 60 52.5447 13.5598 Berlin-Marzahn Berlin +00427 19911102 20191202 46 52.3807 13.5306 Berlin-Schönefeld Brandenburg +00430 19941223 20191202 36 52.5644 13.3088 Berlin-Tegel Berlin +00433 19950601 20191202 48 52.4675 13.4021 Berlin-Tempelhof Berlin +00445 20030528 20191202 84 51.8218 11.7109 Bernburg/Saale (Nord) Sachsen-Anhalt +00460 19931001 20191202 363 49.2640 6.6868 Berus Saarland +00535 20030701 20191202 417 50.0372 7.3079 Blankenrath Rheinland-Pfalz +00591 19911101 20191202 45 53.3911 10.6878 Boizenburg Mecklenburg-Vorpommern +00596 19911107 20191202 15 54.0028 11.1908 Boltenhagen Mecklenburg-Vorpommern +00603 20071026 20191128 144 50.7290 7.2047 Königswinter-Heiderhof Nordrhein-Westfalen +00617 20040601 20191202 47 51.8730 6.8863 Borken in Westfalen Nordrhein-Westfalen +00656 19910815 20191202 607 51.7234 10.6021 Braunlage Niedersachsen +00662 19970702 20191202 81 52.2915 10.4464 Braunschweig Niedersachsen +00691 19910620 20191202 4 53.0450 8.7979 Bremen Bremen +00701 19971120 20191202 7 53.5332 8.5761 Bremerhaven Bremen +00704 20020717 20191202 11 53.4451 9.1390 Bremervörde Niedersachsen +00722 19970605 20191202 1134 51.7986 10.6183 Brocken Sachsen-Anhalt +00755 20040324 20191202 340 49.5182 9.3213 Buchen, Kr. Neckar-Odenwald Baden-Württemberg +00757 20030326 20191202 445 47.9625 7.9983 Buchenbach Baden-Württemberg +00760 20171201 20191202 82 53.3629 9.9435 Rosengarten-Klecken Niedersachsen +00817 20040927 20191202 293 51.0306 8.8146 Burgwald-Bottendorf Hessen +00840 19950601 20191202 897 50.4313 12.6114 Carlsfeld Sachsen +00850 20080814 20150630 39 52.5959 10.0296 Celle Niedersachsen +00853 19911107 20191202 418 50.7913 12.8720 Chemnitz Sachsen +00856 20030501 20191129 551 47.8843 12.5404 Chieming Bayern +00867 19920215 20191202 344 50.3066 10.9679 Lautertal-Oberlauter Bayern +00880 19911101 20191202 69 51.7760 14.3168 Cottbus Brandenburg +00891 19990429 20191202 5 53.8713 8.7058 Cuxhaven Niedersachsen +00896 20030611 20191202 170 51.0778 10.8619 Dachwig Thüringen +00917 20040713 20191202 162 49.8809 8.6779 Darmstadt Hessen +00953 19970731 20191202 481 49.7619 7.0541 Deuselbach Rheinland-Pfalz +00963 19960614 20191202 38 52.5881 8.3424 Diepholz Niedersachsen +00979 20030708 20191202 314 50.7364 8.2672 Dillenburg Hessen +00983 20061201 20191202 419 48.5562 10.5599 Dillingen/Donau-Fristingen Bayern +00991 20040913 20191202 365 50.9117 13.7087 Dippoldiswalde-Reinberg Sachsen +01001 19911107 20191202 97 51.6451 13.5747 Doberlug-Kirchhain Brandenburg +01048 19911122 20191202 227 51.1280 13.7543 Dresden-Klotzsche Sachsen +01050 20050810 20191202 114 51.0221 13.8470 Dresden-Hosterwitz Sachsen +01051 20070301 20191202 120 51.0248 13.7750 Dresden-Strehlen Sachsen +01052 20030317 20191202 80 52.2174 12.1641 Drewitz bei Burg Sachsen-Anhalt +01072 20040506 20191202 107 49.4719 8.1929 Dürkheim, Bad Rheinland-Pfalz +01078 19920913 20191202 37 51.2960 6.7686 Düsseldorf Nordrhein-Westfalen +01103 20061001 20191202 592 48.1002 11.9872 Ebersberg-Halbing Bayern +01107 20041007 20191202 346 49.8520 10.4990 Ebrach Bayern +01161 20050201 20191127 384 48.8777 11.2349 Eichstätt-Landershofen Bayern +01197 20020830 20191202 460 48.9895 10.1312 Ellwangen-Rindelbach Baden-Württemberg +01200 20051125 20191202 3 54.0691 9.0105 Elpersbüttel Schleswig-Holstein +01207 20060301 20191202 560 50.2705 12.2742 Elster, Bad-Sohl Sachsen +01214 20040801 20191202 440 48.2012 8.1089 Elzach-Fisnacht Baden-Württemberg +01224 20021030 20191202 201 48.1378 7.8351 Emmendingen-Mundingen Baden-Württemberg +01246 20150801 20191202 104 51.8418 8.0607 Ennigerloh-Ostenfelde Nordrhein-Westfalen +01262 19920520 20191202 446 48.3477 11.8133 München-Flughafen Bayern +01266 20030912 20191202 18 54.2992 9.3162 Erfde Schleswig-Holstein +01270 19911105 20191202 316 50.9829 10.9608 Erfurt-Weimar Thüringen +01279 20060504 20191202 268 49.6497 11.0074 Möhrendorf-Kleinseebach Bayern +01297 20040407 20191202 156 51.2041 10.0138 Eschwege Hessen +01300 20040601 20191202 351 51.2540 8.1565 Eslohe Nordrhein-Westfalen +01303 19940504 20191202 150 51.4041 6.9677 Essen-Bredeney Nordrhein-Westfalen +01327 20040801 20191202 147 50.7119 6.7905 Weilerswist-Lommersum Nordrhein-Westfalen +01332 20041209 20191202 472 48.4832 12.7241 Falkenberg,Kr.Rottal-Inn Bayern +01346 19951027 20191202 1490 47.8749 8.0038 Feldberg/Schwarzwald Baden-Württemberg +01357 20041202 20191202 654 49.9807 11.8376 Fichtelberg/Oberfranken-Hüttstadl Bayern +01358 19911112 20191202 1213 50.4283 12.9535 Fichtelberg Sachsen +01411 20070101 20191202 745 50.5309 10.0480 Birx/Rhön Thüringen +01420 19930305 20191202 100 50.0259 8.5213 Frankfurt/Main Hessen +01424 20080624 20191202 124 50.1269 8.6694 Frankfurt/Main-Westend Hessen +01443 19940427 20191202 237 48.0232 7.8343 Freiburg Baden-Württemberg +01451 20030516 20191202 2 53.8277 9.2493 Freiburg/Elbe Niedersachsen +01468 19910102 20191202 797 48.4538 8.4090 Freudenstadt Baden-Württemberg +01503 20121001 20191202 6 53.0643 7.9022 Friesoythe-Altenoythe Niedersachsen +01526 20040914 20191202 242 50.5668 9.6533 Fulda-Horas Hessen +01544 19911102 20191202 47 52.5129 11.3941 Gardelegen Sachsen-Anhalt +01550 19910102 20191202 719 47.4830 11.0621 Garmisch-Partenkirchen Bayern +01580 19970101 20191202 110 49.9859 7.9549 Geisenheim Hessen +01584 20090601 20191202 672 47.9242 8.6473 Geisingen Baden-Württemberg +01587 20031210 20191202 536 48.9481 11.4289 Gelbelsee Bayern +01590 20021023 20191202 37 51.4942 6.2463 Geldern-Walbeck Nordrhein-Westfalen +01602 20040701 20191202 176 48.4329 7.9931 Ohlsbach Baden-Württemberg +01605 19980101 20191202 35 52.3875 12.1601 Genthin Sachsen-Anhalt +01612 19911107 20191202 311 50.8813 12.1289 Gera-Leumnitz Thüringen +01639 19961011 20191202 203 50.6017 8.6439 Gießen/Wettenberg Hessen +01645 20020820 20191202 340 50.9656 9.0500 Gilserberg-Moischeid Hessen +01684 19911102 20191202 238 51.1622 14.9506 Görlitz Sachsen +01691 19931110 20191202 167 51.5002 9.9507 Göttingen Niedersachsen +01694 19911107 20191202 58 53.6060 12.1033 Goldberg Mecklenburg-Vorpommern +01721 20060822 20191202 506 49.6640 11.2239 Gräfenberg-Kasberg Bayern +01735 20041213 20191202 628 48.7893 13.6291 Grainet-Rehberg Bayern +01736 20011102 20191202 27 53.5731 10.6797 Grambek Schleswig-Holstein +01757 19911102 20191202 2 54.0967 13.4056 Greifswald Mecklenburg-Vorpommern +01759 20001026 20191202 12 54.2437 13.9102 Greifswalder Oie Mecklenburg-Vorpommern +01766 19950705 20191202 48 52.1344 7.6969 Münster/Osnabrück Nordrhein-Westfalen +01803 20040831 20191202 34 54.0714 12.3238 Groß Lüsewitz Mecklenburg-Vorpommern +01832 19980226 20191202 1436 49.1129 13.1338 Großer Arber Bayern +01863 20071201 20191202 258 50.2667 9.1854 Gründau-Breitenborn Hessen +01869 19911102 20191202 56 53.3153 13.9338 Grünow Brandenburg +01886 20160901 20191202 444 48.4878 10.2607 Günzburg Bayern +01964 20050501 20191202 328 49.9445 6.3821 Olsdorf Rheinland-Pfalz +01975 19950829 20191202 14 53.6332 9.9881 Hamburg-Fuhlsbüttel Hamburg +01981 20050215 20191202 3 53.4777 9.8957 Hamburg-Neuwiedenthal Hamburg +02014 19920430 20191202 59 52.4644 9.6779 Hannover Niedersachsen +02023 20021114 20191202 501 48.7918 10.7062 Harburg Bayern +02039 20061031 20191202 201 51.9002 10.5699 Harzburg, Bad Niedersachsen +02044 19910115 20191202 404 51.6520 11.1367 Harzgerode Sachsen-Anhalt +02074 20030630 20191202 522 48.3751 8.9801 Hechingen Baden-Württemberg +02110 20021024 20191202 57 51.0411 6.1042 Heinsberg-Schleiden Nordrhein-Westfalen +02115 19961220 20191202 4 54.1750 7.8920 Helgoland Schleswig-Holstein +02171 19941221 20191202 272 50.8519 9.7378 Hersfeld, Bad Hessen +02174 20101101 20191202 238 51.6255 10.3695 Herzberg Niedersachsen +02201 20050601 20191202 1 54.5750 13.1044 Hiddensee-Vitte Mecklenburg-Vorpommern +02211 20030708 20191202 295 50.7371 7.6528 Hilgenroth Rheinland-Pfalz +02252 20050701 20191202 270 50.8990 14.7457 Bertsdorf-Hörnitz Sachsen +02261 19980212 20191202 565 50.3122 11.8761 Hof Bayern +02290 19931210 20191202 977 47.8009 11.0108 Hohenpeißenberg Bayern +02306 20050706 20191202 8 54.3194 10.6732 Hohwacht Schleswig-Holstein +02319 20050429 20191202 685 47.8823 11.6962 Holzkirchen Bayern +02323 20060701 20191202 110 51.8529 9.4953 Bevern, Kr. Holzminden Niedersachsen +02362 20040801 20191202 328 50.5651 7.4843 Hümmerich Rheinland-Pfalz +02429 20030705 20191202 21 53.9897 9.5696 Itzehoe Schleswig-Holstein +02444 20040512 20191202 155 50.9251 11.5830 Jena (Sternwarte) Thüringen +02480 20040716 20191202 107 50.0643 8.9930 Kahl/Main Bayern +02483 19950804 20191202 839 51.1803 8.4891 Kahler Asten Nordrhein-Westfalen +02485 20110501 20191202 489 48.9170 9.6871 Kaisersbach-Cronhütte Baden-Württemberg +02486 20050301 20191202 271 49.4262 7.7557 Kaiserslautern Rheinland-Pfalz +02497 20030605 20191202 505 50.5014 6.5264 Kall-Sistig Nordrhein-Westfalen +02559 19920430 20191202 705 47.7233 10.3348 Kempten Bayern +02564 20130501 20191202 28 54.3776 10.1424 Kiel-Holtenau Schleswig-Holstein +02575 20070522 20191202 426 49.1804 9.9800 Kirchberg/Jagst-Herboldshausen Baden-Württemberg +02578 20030723 20191202 12 53.9995 11.4341 Kirchdorf/Poel Mecklenburg-Vorpommern +02597 19950602 20191202 282 50.2241 10.0792 Kissingen, Bad Bayern +02600 20041103 20191202 193 49.7363 10.1781 Kitzingen Bayern +02601 19921002 20191202 826 50.2218 8.4469 Kleiner Feldberg/Taunus Hessen +02618 20040811 20191202 732 50.8458 10.4803 Kleiner Inselsberg Thüringen +02627 20030430 20191202 128 51.5555 13.8845 Klettwitz Brandenburg +02629 20021023 20191202 46 51.7612 6.0954 Kleve Nordrhein-Westfalen +02638 19921106 20191202 974 48.1054 8.7548 Klippeneck Baden-Württemberg +02641 20040419 20191202 85 51.5185 12.9065 Klitzschen bei Torgau Sachsen +02667 19931112 20191202 92 50.8646 7.1575 Köln-Bonn Nordrhein-Westfalen +02680 20050406 20191202 289 50.2840 10.4456 Königshofen, Bad Bayern +02700 20041025 20191202 416 48.8302 11.4872 Kösching Bayern +02704 20030606 20191202 76 51.7511 12.0094 Köthen (Anhalt) Sachsen-Anhalt +02708 20060607 20191202 742 47.6652 11.0805 Kohlgrub, Bad (Rosshof) Bayern +02712 19930813 20191202 443 47.6774 9.1901 Konstanz Baden-Württemberg +02750 20050801 20191202 312 50.2523 11.3209 Kronach Bayern +02794 19920316 20191202 40 52.9363 12.4093 Kyritz Brandenburg +02812 19960829 20191202 156 48.3647 7.8280 Lahr Baden-Württemberg +02814 20020904 20191202 685 48.5121 9.7645 Merklingen Baden-Württemberg +02856 20030722 20191202 91 51.9173 13.0878 Langenlipsdorf Brandenburg +02878 19930122 20191202 118 51.3910 11.8788 Lauchstädt, Bad Sachsen-Anhalt +02907 19990202 20191202 7 54.7903 8.9514 Leck Schleswig-Holstein +02925 19911104 20191202 356 51.3933 10.3123 Leinefelde Thüringen +02928 19970206 20191202 138 51.3151 12.4462 Leipzig-Holzhausen Sachsen +02932 19911101 20191202 131 51.4348 12.2396 Leipzig/Halle Sachsen +02947 20060831 20191202 286 51.1333 8.0348 Lennestadt-Theten Nordrhein-Westfalen +02951 20030305 20191202 20 53.1007 11.4864 Lenzen/Elbe Brandenburg +02953 20070401 20191202 852 47.8597 8.2308 Lenzkirch-Ruhbühl Baden-Württemberg +02961 20180809 20191202 31 54.4996 10.2737 Leuchtturm Kiel Schleswig-Holstein +02968 20081201 20191202 43 50.9894 6.9777 Köln-Stammheim Nordrhein-Westfalen +02985 19940601 20191202 321 50.9383 14.2093 Lichtenhain-Mittelndorf Sachsen +03015 19921107 20191202 98 52.2085 14.1180 Lindenberg Brandenburg +03023 19910102 20191202 22 52.5181 7.3081 Lingen Niedersachsen +03028 19920806 20191202 157 51.7855 8.8388 Lippspringe, Bad Nordrhein-Westfalen +03031 20020920 20191202 92 51.6336 8.3945 Lippstadt-Bökenförde Nordrhein-Westfalen +03032 19951202 20191202 25 55.0110 8.4125 List auf Sylt Schleswig-Holstein +03034 20061113 20191202 500 50.4505 11.6350 Lobenstein, Bad Thüringen +03042 20080423 20191129 230 50.5617 8.2386 Löhnberg-Obershausen Hessen +03083 20040930 20191202 57 51.9267 13.8797 Lübben-Blumenfelde Brandenburg +03086 19960702 20191202 15 53.8025 10.6989 Lübeck-Blankensee Schleswig-Holstein +03093 19930923 20191202 16 52.9724 11.1374 Lüchow Niedersachsen +03098 19940101 20191202 387 51.2452 7.6425 Lüdenscheid Nordrhein-Westfalen +03126 19911102 20191202 76 52.1029 11.5827 Magdeburg Sachsen-Anhalt +03137 20080228 20191202 195 49.9656 8.2139 Mainz-Lerchenberg (ZDF) Rheinland-Pfalz +03147 20130901 20191202 418 48.7725 12.2179 Mallersdorf-Pfaffenberg/Niederbayern Bayern +03155 20030612 20191202 413 50.1015 6.8009 Manderscheid-Sonnenhof Rheinland-Pfalz +03158 19911101 20191202 12 52.5468 14.5452 Manschnow Brandenburg +03164 20060701 20191202 187 50.8492 8.7746 Cölbe, Kr. Marburg-Biedenkopf Hessen +03166 19911103 20191202 639 50.6510 13.1469 Marienberg Sachsen +03167 19990602 20191202 547 50.6620 7.9602 Marienberg, Bad Rheinland-Pfalz +03196 19920617 20191202 81 53.3223 11.9319 Marnitz Mecklenburg-Vorpommern +03204 20080530 20191202 427 50.7334 10.8815 Martinroda Thüringen +03226 20060801 20191202 107 51.7259 11.5109 Aschersleben-Mehringen Sachsen-Anhalt +03231 19911102 20191202 450 50.5612 10.3771 Meiningen Thüringen +03234 20050201 20191202 157 51.1294 13.4327 Garsebach bei Meißen Sachsen +03244 20090720 20191202 615 47.9820 10.1384 Memmingen Bayern +03257 20040429 20191202 250 49.4773 9.7622 Mergentheim, Bad-Neunkirchen Baden-Württemberg +03268 20131001 20191202 900 48.1694 8.9433 Meßstetten-Appental Baden-Württemberg +03271 20041013 20191202 313 48.8548 12.9189 Metten Bayern +03278 20030101 20191202 354 48.5377 9.2734 Metzingen Baden-Württemberg +03284 20050406 20191202 240 49.6691 9.0085 Michelstadt Hessen +03287 19910102 20191202 453 49.7176 9.0997 Michelstadt-Vielbrunn Hessen +03289 20041101 20191202 355 50.7281 11.7838 Schmieritz-Weltwitz Thüringen +03307 20080128 20191202 984 47.4779 11.2653 Mittenwald-Buckelwiesen Bayern +03319 20060901 20191202 239 49.7644 9.2530 Röllbach Bayern +03340 20050501 20191202 265 50.4383 7.8061 Montabaur Rheinland-Pfalz +03348 20040421 20190626 240 51.7209 9.8352 Moringen-Lutterbeck Niedersachsen +03362 20060621 20191202 244 48.9721 8.8734 Mühlacker Baden-Württemberg +03366 19890307 20191202 406 48.2791 12.5024 Mühldorf Bayern +03376 20031219 20191202 63 52.5176 14.1232 Müncheberg Brandenburg +03379 19970712 20191202 515 48.1631 11.5429 München-Stadt Bayern +03402 20020904 20191202 750 48.3851 9.4837 Münsingen-Apfelstetten Baden-Württemberg +03426 20021218 20191202 125 51.5660 14.7009 Muskau, Bad Sachsen +03442 20041001 20191202 149 50.3574 8.7506 Nauheim, Bad Hessen +03485 20041122 20191202 486 48.3115 10.3773 Neuburg/Kammel-Langenhaslach Bayern +03490 20030707 20191202 111 50.5346 7.0853 Neuenahr, Bad-Ahrweiler Rheinland-Pfalz +03509 20041001 20191202 77 53.1020 13.0421 Menz Brandenburg +03513 19911103 20191202 845 50.5002 11.1344 Neuhaus am Rennweg Thüringen +03527 20030523 20191202 500 50.8923 9.4050 Neukirchen-Hauptschwenda Hessen +03540 20040818 20191202 195 50.8446 7.3720 Neunkirchen-Seelscheid-Krawinkel Nordrhein-Westfalen +03545 20050301 20191202 236 49.3440 7.2297 Neunkirchen-Wellesweiler Saarland +03571 20080301 20191202 452 49.8174 11.8638 Neustadt am Kulm-Filchendorf Bayern +03591 20030605 20191202 350 50.6743 6.4240 Nideggen-Schmidt Nordrhein-Westfalen +03612 20070222 20191202 25 52.6711 9.2229 Nienburg Niedersachsen +03621 20051109 20191202 435 48.8253 10.5067 Reimlingen Bayern +03631 19930915 20191202 12 53.7123 7.1519 Norderney Niedersachsen +03660 19950601 20191202 485 50.3601 6.8697 Nürburg-Barweiler Rheinland-Pfalz +03667 20041123 20191202 368 49.4258 11.2538 Nürnberg-Netzstall Bayern +03668 19950808 20191202 314 49.5030 11.0549 Nürnberg Bayern +03679 20061101 20191202 518 47.6187 12.1665 Kiefersfelden-Gach Bayern +03730 19940731 20191202 806 47.3984 10.2759 Oberstdorf Bayern +03734 20040701 20191202 230 49.1280 9.3525 Obersulm-Willsbach Baden-Württemberg +03739 20050110 20191202 596 49.4521 12.4365 Oberviechtach Bayern +03761 19920702 20191202 276 49.2070 9.5176 Öhringen Baden-Württemberg +03811 19911107 20191202 150 51.2960 13.0928 Oschatz Sachsen +03821 19911102 20191202 246 51.0873 11.9292 Osterfeld Sachsen-Anhalt +03836 20060301 20191202 312 50.4538 10.2211 Ostheim v.d. Rhön Bayern +03857 20041118 20191202 886 47.6362 10.3892 Oy-Mittelberg-Petersthal Bayern +03875 20041015 20191202 549 49.1510 11.6896 Parsberg/Oberpfalz-Eglwang Bayern +03897 20060804 20191202 2 54.0893 10.8773 Pelzerhaken Schleswig-Holstein +03904 20040901 20191202 152 49.5354 6.3789 Perl-Nennig Saarland +03925 20050901 20191202 333 48.9329 8.6973 Pforzheim-Ispringen Baden-Württemberg +03927 20040701 20191202 630 47.9344 9.2869 Pfullendorf Baden-Württemberg +03939 20041001 20191202 385 49.1912 7.5879 Pirmasens Rheinland-Pfalz +03946 19911102 20191202 386 50.4819 12.1300 Plauen Sachsen +03975 20050301 20191202 522 49.4777 11.5357 Pommelsbrunn-Mittelburg Bayern +03987 19920817 20191202 81 52.3813 13.0622 Potsdam Brandenburg +04024 19911102 20191202 40 54.3643 13.4771 Putbus Mecklenburg-Vorpommern +04032 20061201 20191202 142 51.7953 11.1320 Quedlinburg Sachsen-Anhalt +04036 20070117 20191202 204 51.3895 11.5412 Querfurt-Mühle Lodersleben Sachsen-Anhalt +04039 20030513 20191202 11 53.7331 9.8776 Quickborn Schleswig-Holstein +04063 20021022 20191202 41 52.4461 8.5906 Rahden-Kleinendorf Nordrhein-Westfalen +04094 20030717 20191202 440 47.8062 9.6206 Weingarten, Kr. Ravensburg Baden-Württemberg +04104 19940316 20191202 365 49.0425 12.1019 Regensburg Bayern +04127 20050101 20191202 350 50.9906 7.6958 Reichshof-Eckenhagen Nordrhein-Westfalen +04160 20040701 20191202 478 48.7425 8.9240 Renningen-Ihinger Hof Baden-Württemberg +04169 20021023 20191202 131 48.6703 7.9939 Rheinau-Memprechtshofen Baden-Württemberg +04175 20030410 20191202 282 47.5590 7.7721 Rheinfelden Baden-Württemberg +04177 20081101 20191202 116 48.9726 8.3301 Rheinstetten Baden-Württemberg +04189 20040801 20191202 533 48.1479 9.4596 Altheim, Kreis Biberach Baden-Württemberg +04261 20060208 20191202 442 47.8753 12.1280 Rosenheim Bayern +04271 19911114 20191202 4 54.1803 12.0808 Rostock-Warnemünde Mecklenburg-Vorpommern +04275 20041201 20191202 32 53.1288 9.3398 Rotenburg (Wümme) Niedersachsen +04280 20131211 20191202 386 49.2162 11.1035 Roth Bayern +04287 20041006 20191202 415 49.3848 10.1732 Rothenburg ob der Tauber Bayern +04300 20021119 20191202 588 48.1814 8.6356 Rottweil Baden-Württemberg +04301 20040831 20191202 102 49.8502 7.8710 Kreuznach, Bad Rheinland-Pfalz +04323 20050209 20191202 461 49.6468 7.8837 Ruppertsecken Rheinland-Pfalz +04336 19960621 20191202 320 49.2128 7.1077 Saarbrücken-Ensheim Saarland +04349 20040311 20191202 248 48.9569 9.0710 Sachsenheim Baden-Württemberg +04354 20051130 20191202 456 48.7832 13.3146 Saldenburg-Entschenreuth Bayern +04371 19920604 20191202 135 52.1042 8.7521 Salzuflen, Bad Nordrhein-Westfalen +04377 20050728 20191202 518 50.3518 10.0034 Sandberg Bayern +04393 19991203 20191202 5 54.3279 8.6031 Sankt Peter-Ording Schleswig-Holstein +04411 20011102 20191202 155 49.9195 8.9671 Schaafheim-Schlierbach Hessen +04445 19920304 20191202 609 51.7658 10.6533 Wernigerode-Schierke Sachsen-Anhalt +04464 19911101 20191202 501 50.5679 11.8041 Schleiz Thüringen +04466 19910418 20191202 43 54.5275 9.5487 Schleswig Schleswig-Holstein +04480 20021001 20191202 230 50.3447 9.5534 Schlüchtern-Herolz Hessen +04501 19921006 20191202 937 50.6546 10.7693 Schmücke Thüringen +04508 20030715 20191202 649 50.2968 6.4194 Schneifelforsthaus Rheinland-Pfalz +04548 20070701 20191202 608 50.2047 12.1435 Selb/Oberfranken-Lauterbach Bayern +04559 20041214 20191202 398 49.1644 12.6175 Schorndorf-Knöbling Bayern +04560 20040901 20191202 265 50.4925 9.1226 Schotten Hessen +04592 20050929 20191202 356 49.3278 12.0871 Schwandorf Bayern +04605 20030620 20191202 277 50.6441 11.1936 Schwarzburg Thüringen +04625 19911102 20191202 59 53.6425 11.3872 Schwerin Mecklenburg-Vorpommern +04642 19911102 20191202 21 52.8911 11.7297 Seehausen Sachsen-Anhalt +04651 20041014 20191202 186 51.9040 10.1885 Seesen Niedersachsen +04703 20020902 20191202 580 48.0719 9.1942 Sigmaringen-Laiz Baden-Württemberg +04704 20050118 20191202 507 47.5776 9.7404 Sigmarszell-Zeisertsweiler Bayern +04706 20050101 20191202 358 48.2718 13.0273 Simbach/Inn Bayern +04709 20111005 20191202 445 49.9996 7.5981 Simmern-Wahlbach Rheinland-Pfalz +04745 19921028 20191202 75 52.9604 9.7930 Soltau Niedersachsen +04763 20030520 20191202 265 51.0607 9.9266 Sontra Hessen +04841 20040512 20191202 1 53.6946 8.8735 Steinau, Kr. Cuxhaven Niedersachsen +04857 20040728 20191202 1 53.5534 9.6097 Mittelnkirchen-Hohenfelde Niedersachsen +04878 20050201 20191202 504 51.6646 10.8811 Oberharz am Brocken-Stiege Sachsen-Anhalt +04887 19941203 20191202 734 48.6656 9.8648 Stötten Baden-Württemberg +04896 20050518 20191202 40 54.6654 9.8050 Wagersrott Schleswig-Holstein +04911 19961025 20191202 351 48.8275 12.5597 Straubing Bayern +04928 19980605 20191202 314 48.8281 9.2000 Stuttgart (Schnarrenberg) Baden-Württemberg +04931 19950930 20191202 371 48.6883 9.2235 Stuttgart-Echterdingen Baden-Württemberg +04978 20021101 20191202 395 50.6390 10.0228 Tann/Rhön Hessen +04997 20041015 20191202 196 50.9771 12.3419 Starkenberg-Tegkwitz Thüringen +05009 19911101 20191202 38 53.7610 12.5574 Teterow Mecklenburg-Vorpommern +05014 20040512 20191202 7 53.2758 8.9857 Worpswede-Hüttenbusch Niedersachsen +05017 20050801 20191202 633 50.4002 11.3889 Teuschnitz Bayern +05029 19931111 20191202 386 49.4738 7.0386 Tholey Saarland +05046 20080301 20191202 501 49.8576 12.3542 Tirschenreuth-Lodermühl Bayern +05064 20041201 20191202 37 51.2897 6.4437 Tönisvorst Nordrhein-Westfalen +05097 20041123 20191202 10 54.0661 12.7675 Tribsees Mecklenburg-Vorpommern +05099 20080601 20191202 132 49.7326 6.6131 Trier-Zewen Rheinland-Pfalz +05100 20001019 20191202 265 49.7479 6.6582 Trier-Petrisberg Rheinland-Pfalz +05109 20131001 20191202 69 53.5997 13.3039 Trollenhagen Mecklenburg-Vorpommern +05111 20051220 20191202 559 48.0311 12.5396 Trostberg Bayern +05133 20040727 20191202 295 51.3344 8.9132 Twistetal-Mühlhausen Hessen +05142 19920817 20191202 1 53.7444 14.0697 Ueckermünde Mecklenburg-Vorpommern +05146 20040601 20191202 50 52.9414 10.5289 Uelzen Niedersachsen +05149 20050101 20191202 308 49.5741 10.1916 Gollhofen Bayern +05158 19911106 20191202 162 52.1601 11.1759 Ummendorf Sachsen-Anhalt +05229 20030415 20191202 720 48.0453 8.4608 Villingen-Schwenningen Baden-Württemberg +05275 20030314 20191202 105 49.2445 8.5374 Waghäusel-Kirrlach Baden-Württemberg +05279 20040602 20191202 176 51.6194 9.5749 Wahlsburg-Lippoldsberg Hessen +05280 20070217 20191202 35 53.9224 10.2267 Wittenborn Schleswig-Holstein +05300 20040701 20191202 380 50.2596 8.3607 Waldems-Reinborn Hessen +05335 20060801 20191202 348 50.8963 10.5484 Waltershausen Thüringen +05347 20060928 20191202 236 51.5040 9.1118 Warburg Nordrhein-Westfalen +05349 19940609 20191202 73 53.5196 12.6654 Waren (Müritz) Mecklenburg-Vorpommern +05371 19961024 20191202 921 50.4973 9.9428 Wasserkuppe Hessen +05397 19910705 20191202 440 49.6663 12.1845 Weiden Bayern +05404 19970102 20191202 477 48.4025 11.6946 Weihenstephan-Dürnast Bayern +05424 20070601 20191202 328 51.0177 11.3544 Weimar-Schöndorf Thüringen +05426 19931028 20191202 553 49.3758 8.1213 Weinbiet Rheinland-Pfalz +05433 20030515 20191202 380 49.5534 6.8120 Weiskirchen/Saar Saarland +05440 19930415 20191202 439 49.0116 10.9308 Weißenburg-Emetzheim Bayern +05480 20030910 20191202 85 51.5763 7.8879 Werl Nordrhein-Westfalen +05490 19911101 20191202 233 51.8454 10.7686 Wernigerode Sachsen-Anhalt +05516 19960801 20191202 3 54.5284 11.0605 Fehmarn Schleswig-Holstein +05538 20041117 20191202 550 47.8827 11.1576 Wielenbach (Demollstr.) Bayern +05541 20040712 20191202 263 50.1320 8.3170 Wiesbaden-Auringen Hessen +05546 19911102 20191130 187 52.1207 12.4585 Wiesenburg Brandenburg +05562 20040601 20191202 570 48.6516 8.6801 Neubulach-Oberhaugstett Baden-Württemberg +05629 19920417 20191202 105 51.8892 12.6445 Wittenberg Sachsen-Anhalt +05643 20040924 20191202 66 53.1864 12.4949 Wittstock-Rote Mühle Brandenburg +05664 20030325 20191202 291 48.2953 8.2391 Wolfach Baden-Württemberg +05676 20100720 20191202 82 52.3962 10.6892 Wolfsburg (Südwest) Niedersachsen +05688 20181101 20191202 880 47.7003 8.1057 Dachsberg-Wolpadingen Baden-Württemberg +05692 20040901 20191202 88 49.6051 8.3659 Worms Rheinland-Pfalz +05705 19921027 20191202 268 49.7703 9.9577 Würzburg Bayern +05717 20060706 20191202 134 51.2256 7.1052 Wuppertal-Buchenhofen Nordrhein-Westfalen +05731 20030716 20191202 398 47.6783 8.3801 Wutöschingen-Ofteringen Baden-Württemberg +05745 20040420 20191202 51 52.9664 13.3268 Zehdenick Brandenburg +05750 20041201 20191202 264 51.0314 12.1495 Zeitz Sachsen-Anhalt +05779 19911102 20191202 877 50.7314 13.7516 Zinnwald-Georgenfeld Sachsen +05792 19940731 20191202 2964 47.4209 10.9847 Zugspitze Bayern +05797 20051201 20191202 353 50.6878 12.4329 Lichtentanne Sachsen +05800 20060712 20191202 615 49.0280 13.2385 Zwiesel Bayern +05822 20040701 20190709 40 52.8630 8.6988 Bassum Niedersachsen +05825 20030108 20191202 40 52.6198 12.7867 Berge Brandenburg +05839 19970710 20191202 -0 53.3881 7.2287 Emden Niedersachsen +05856 19970103 20191202 476 48.5451 13.3531 Fürstenzell Bayern +05871 19981223 20191202 497 49.9462 7.2645 Hahn Rheinland-Pfalz +05906 19930715 20191202 98 49.5062 8.5585 Mannheim Baden-Württemberg +05930 20070928 20191202 1 54.6410 10.0238 Schönhagen (Ostseebad) Schleswig-Holstein +05941 20070301 20191202 686 47.6754 12.4698 Reit im Winkl Bayern +06093 20040501 20191202 62 53.2139 10.4704 Wendisch Evern Niedersachsen +06105 20030710 20191202 14 54.3194 9.8051 Ostenfeld (Rendsburg) Schleswig-Holstein +06109 20040601 20191202 50 53.3837 14.3728 Grambow-Schwennenz Mecklenburg-Vorpommern +06129 20040916 20191202 290 51.0593 14.4266 Sohland/Spree Sachsen +06157 20070822 20191202 8 53.6410 8.0808 Wangerland-Hooksiel Niedersachsen +06158 20040928 20191202 455 49.2247 10.6084 Weidenbach-Weiherschneidbach Bayern +06159 20081201 20191202 8 52.9542 7.3196 Dörpen Niedersachsen +06163 20061116 20191202 27 54.1654 10.3519 Dörnick Schleswig-Holstein +06170 20030312 20191202 40 52.0192 14.7254 Coschen Brandenburg +06197 20060928 20191202 258 51.8664 9.2709 Lügde-Paenbruch Nordrhein-Westfalen +06199 20040825 20191202 16 54.2484 13.0418 Steinhagen-Negast Mecklenburg-Vorpommern +06217 20040720 20191202 190 49.2406 6.9351 Saarbrücken-Burbach Saarland +06258 20030101 20191202 459 47.6845 9.4409 Friedrichshafen-Unterraderach Baden-Württemberg +06259 20040601 20191202 523 49.0210 9.6032 Großerlach-Mannenweiler Baden-Württemberg +06260 20021201 20191202 385 49.3328 9.7040 Ingelfingen-Stachenhausen Baden-Württemberg +06262 20021101 20191202 413 48.7695 9.8737 Schwäbisch Gmünd-Weiler Baden-Württemberg +06263 20040701 20191202 445 47.7738 8.8219 Singen Baden-Württemberg +06264 20040601 20191202 457 51.4140 8.6500 Brilon-Thülen Nordrhein-Westfalen +06265 20040501 20191202 36 52.3613 12.3867 Wusterwitz Brandenburg +06266 20040901 20191202 112 52.0304 10.9626 Huy-Pabstorf Sachsen-Anhalt +06272 20041001 20191202 283 50.8426 10.2518 Moorgrund Gräfen-Nitzendorf Thüringen +06273 20040601 20191202 36 52.5075 11.8551 Demker Sachsen-Anhalt +06275 20040701 20191202 325 48.6705 9.4627 Notzingen Baden-Württemberg +06305 20041201 20191202 193 51.2061 10.4978 Mühlhausen/Thüringen-Görmar Thüringen +06310 20040801 20191202 1 54.1049 13.8239 Karlshagen Mecklenburg-Vorpommern +06312 20041101 20191202 362 49.5314 10.6418 Markt Erlbach-Mosbach Bayern +06314 20050801 20191202 308 51.0507 13.3003 Nossen Sachsen +06336 20051101 20191202 288 50.0132 9.6540 Lohr/Main-Halsbach Bayern +06337 20040801 20191202 59 51.7663 7.5194 Lüdinghausen-Brochtrup Nordrhein-Westfalen +06344 20041201 20191201 168 50.3940 8.1423 Runkel-Ennerich Hessen +06346 20050201 20191202 531 48.2070 11.2035 Maisach-Galgen Bayern +06347 20050301 20191202 304 50.0579 10.2972 Schonungen-Mainberg Bayern +07075 20050201 20191202 425 48.7020 11.8493 Elsendorf-Horneck Bayern +07099 20041101 20191202 187 52.0111 10.3966 Liebenburg-Othfresen Niedersachsen +07105 20050601 20191202 719 47.8350 12.6548 Siegsdorf-Höll Bayern +07106 20060901 20191202 105 52.0714 8.4565 Bielefeld-Deppendorf Nordrhein-Westfalen +07187 20041201 20191202 193 49.7636 9.4063 Freudenberg/Main-Boxtal Baden-Württemberg +07298 20050701 20191202 5 54.5268 9.0425 Hattstedt Schleswig-Holstein +07319 20050301 20191202 435 48.7374 10.7393 Donauwörth-Osterweiler Bayern +07321 20050901 20191202 160 51.1507 11.3321 Olbersleben Thüringen +07329 20051101 20191202 465 50.5467 12.2863 Treuen Sachsen +07330 20051001 20191202 159 51.4633 7.9780 Arnsberg-Neheim Nordrhein-Westfalen +07331 20050901 20191202 468 48.6099 10.2674 Hermaringen-Allewind Baden-Württemberg +07341 20050715 20191202 119 50.0900 8.7862 Offenbach-Wetterpark Hessen +07343 20060401 20191202 688 50.6199 13.4816 Deutschneudorf-Brüderwiese Sachsen +07350 20060801 20191202 585 49.1088 12.8231 Prackenbach-Neuhäusl Bayern +07351 20050909 20191202 116 53.3175 13.4175 Feldberg/Mecklenburg Mecklenburg-Vorpommern +07364 20070101 20191202 74 51.6820 12.3042 Jeßnitz Sachsen-Anhalt +07367 20071201 20191202 144 51.9643 9.8072 Alfeld Niedersachsen +07368 20071101 20191202 312 51.0007 10.3621 Eisenach Thüringen +07369 20071101 20191202 475 49.1623 10.3662 Feuchtwangen-Heilbronn Bayern +07370 20061211 20191202 499 49.3910 12.6838 Waldmünchen Bayern +07373 20060301 20191202 3 53.5984 6.7024 Borkum-Flugplatz Niedersachsen +07374 20060301 20191202 46 52.0814 6.9410 Ahaus Nordrhein-Westfalen +07389 20061201 20191202 82 52.7461 13.8427 Heckelberg Brandenburg +07393 20100101 20191202 116 51.4493 14.2533 Hoyerswerda Sachsen +07394 20060602 20191202 622 50.0315 11.9745 Wunsiedel-Schönbrunn Bayern +07395 20071201 20191202 351 48.6595 12.5388 Gottfrieding Bayern +07396 20080501 20191202 743 50.5084 9.2247 Hoherodskopf/Vogelsberg Hessen +07403 20070330 20191202 672 47.7955 10.0324 Leutkirch-Herlazhofen Baden-Württemberg +07410 20110201 20191202 350 50.7513 9.0224 Neu-Ulrichstein Hessen +07412 20061001 20191202 340 50.0083 9.4239 Neuhütten/Spessart Bayern +07419 20061201 20191202 389 50.6610 12.0756 Langenwetzendorf-Göttendorf Thüringen +07420 20070401 20191202 246 51.1044 11.7112 Naumburg/Saale-Kreipitzsch Sachsen-Anhalt +07424 20061201 20191202 457 47.7724 12.9073 Piding Bayern +07427 20070901 20191202 17 54.0188 9.9255 Padenstedt (Pony-Park) Schleswig-Holstein +07428 20070501 20191202 397 50.4167 10.8156 Veilsdorf Thüringen +07431 20071101 20191202 604 48.0130 11.5524 Oberhaching-Laufzorn Bayern +07432 20070501 20191202 72 52.6423 10.6627 Wittingen-Vorhop Niedersachsen +13670 20070531 20191202 24 51.5088 6.7018 Duisburg-Baerl Nordrhein-Westfalen +13674 20070801 20191202 237 49.2943 8.9053 Waibstadt Baden-Württemberg +13675 20071101 20191202 77 52.0818 9.4077 Hameln-Hastenbeck Niedersachsen +13696 20071201 20191202 60 51.5966 7.4049 Waltrop-Abdinghof Nordrhein-Westfalen +13700 20080501 20191202 205 51.3329 7.3411 Gevelsberg-Oberbröking Nordrhein-Westfalen +13710 20080401 20191202 490 48.5734 12.2576 Landshut-Reithof Bayern +13711 20071201 20191202 289 50.6819 11.5150 Krölpa-Rockendorf Thüringen +13713 20071101 20191202 380 51.0899 7.6290 Meinerzhagen-Redlendorf Nordrhein-Westfalen +13777 20080601 20191202 110 52.2467 10.9592 Helmstedt-Emmerstedt Niedersachsen +13965 20081201 20191202 619 48.2639 8.8134 Balingen-Bronnhaupten Baden-Württemberg +15000 20110401 20191202 231 50.7983 6.0244 Aachen-Orsbach Nordrhein-Westfalen +15207 20131101 20191202 317 51.2835 9.3590 Schauenburg-Elgershausen Hessen +15444 20140901 20191202 593 48.4418 9.9216 Ulm-Mähringen Baden-Württemberg +15555 20160501 20191202 816 47.8761 10.5848 Kaufbeuren-Oberbeuren Bayern diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/clat/icon_global_icosahedral_time-invariant_2019121000_CLAT.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/clat/icon_global_icosahedral_time-invariant_2019121000_CLAT.grib2.bz2 new file mode 100644 index 00000000..716bbf60 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/clat/icon_global_icosahedral_time-invariant_2019121000_CLAT.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/clon/icon_global_icosahedral_time-invariant_2019121000_CLON.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/clon/icon_global_icosahedral_time-invariant_2019121000_CLON.grib2.bz2 new file mode 100644 index 00000000..fa49aa8c Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/clon/icon_global_icosahedral_time-invariant_2019121000_CLON.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/h_snow/icon_global_icosahedral_single-level_2019121000_000_H_SNOW.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/h_snow/icon_global_icosahedral_single-level_2019121000_000_H_SNOW.grib2.bz2 new file mode 100644 index 00000000..c1d70d11 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/h_snow/icon_global_icosahedral_single-level_2019121000_000_H_SNOW.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/ps/icon_global_icosahedral_single-level_2019121000_000_PS.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/ps/icon_global_icosahedral_single-level_2019121000_000_PS.grib2.bz2 new file mode 100644 index 00000000..db2142fd Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/ps/icon_global_icosahedral_single-level_2019121000_000_PS.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/qv_s/icon_global_icosahedral_single-level_2019121000_000_QV_S.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/qv_s/icon_global_icosahedral_single-level_2019121000_000_QV_S.grib2.bz2 new file mode 100644 index 00000000..dd9cd4cf Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/qv_s/icon_global_icosahedral_single-level_2019121000_000_QV_S.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/relhum_2m/icon_global_icosahedral_single-level_2019121000_000_RELHUM_2M.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/relhum_2m/icon_global_icosahedral_single-level_2019121000_000_RELHUM_2M.grib2.bz2 new file mode 100644 index 00000000..2222c897 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/relhum_2m/icon_global_icosahedral_single-level_2019121000_000_RELHUM_2M.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/soiltyp/icon_global_icosahedral_time-invariant_2019121000_SOILTYP.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/soiltyp/icon_global_icosahedral_time-invariant_2019121000_SOILTYP.grib2.bz2 new file mode 100644 index 00000000..b1bf4fc6 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/soiltyp/icon_global_icosahedral_time-invariant_2019121000_SOILTYP.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/t_2m/icon_global_icosahedral_single-level_2019121000_000_T_2M.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/t_2m/icon_global_icosahedral_single-level_2019121000_000_T_2M.grib2.bz2 new file mode 100644 index 00000000..c3a8c068 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/t_2m/icon_global_icosahedral_single-level_2019121000_000_T_2M.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/tmax_2m/icon_global_icosahedral_single-level_2019121000_000_TMAX_2M.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/tmax_2m/icon_global_icosahedral_single-level_2019121000_000_TMAX_2M.grib2.bz2 new file mode 100644 index 00000000..29e5628c Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/tmax_2m/icon_global_icosahedral_single-level_2019121000_000_TMAX_2M.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/tmin_2m/icon_global_icosahedral_single-level_2019121000_000_TMIN_2M.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/tmin_2m/icon_global_icosahedral_single-level_2019121000_000_TMIN_2M.grib2.bz2 new file mode 100644 index 00000000..c37b40f2 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/tmin_2m/icon_global_icosahedral_single-level_2019121000_000_TMIN_2M.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/u_10m/icon_global_icosahedral_single-level_2019121000_000_U_10M.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/u_10m/icon_global_icosahedral_single-level_2019121000_000_U_10M.grib2.bz2 new file mode 100644 index 00000000..fddd32b9 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/u_10m/icon_global_icosahedral_single-level_2019121000_000_U_10M.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/v_10m/icon_global_icosahedral_single-level_2019121000_000_V_10M.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/v_10m/icon_global_icosahedral_single-level_2019121000_000_V_10M.grib2.bz2 new file mode 100644 index 00000000..da1f5d84 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/v_10m/icon_global_icosahedral_single-level_2019121000_000_V_10M.grib2.bz2 differ diff --git a/service-ejb/src/test/resources/dwd/weatherforecast/ww/icon_global_icosahedral_single-level_2019121000_000_WW.grib2.bz2 b/service-ejb/src/test/resources/dwd/weatherforecast/ww/icon_global_icosahedral_single-level_2019121000_000_WW.grib2.bz2 new file mode 100644 index 00000000..fc493bf8 Binary files /dev/null and b/service-ejb/src/test/resources/dwd/weatherforecast/ww/icon_global_icosahedral_single-level_2019121000_000_WW.grib2.bz2 differ diff --git a/service-thorntail/src/main/java/com/mowesta/service/thorntail/MowestaThorntail.java b/service-thorntail/src/main/java/com/mowesta/service/thorntail/MowestaThorntail.java index 98717997..745b0076 100644 --- a/service-thorntail/src/main/java/com/mowesta/service/thorntail/MowestaThorntail.java +++ b/service-thorntail/src/main/java/com/mowesta/service/thorntail/MowestaThorntail.java @@ -1,7 +1,5 @@ package com.mowesta.service.thorntail; -import java.io.File; - import org.jboss.shrinkwrap.api.GenericArchive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset; @@ -19,17 +17,14 @@ import org.wildfly.swarm.config.security.SecurityDomain.CacheType; import org.wildfly.swarm.config.security.SecurityDomainConsumer; import org.wildfly.swarm.config.security.security_domain.JaspiAuthentication; import org.wildfly.swarm.config.security.security_domain.JaspiAuthenticationConsumer; -import org.wildfly.swarm.config.security.security_domain.authentication.AuthModule; -import org.wildfly.swarm.config.security.security_domain.authentication.AuthModuleConsumer; -import org.wildfly.swarm.config.security.security_domain.authentication.LoginModule; -import org.wildfly.swarm.config.security.security_domain.authentication.LoginModuleConsumer; -import org.wildfly.swarm.config.security.security_domain.authentication.LoginModuleStack; -import org.wildfly.swarm.config.security.security_domain.authentication.LoginModuleStackConsumer; +import org.wildfly.swarm.config.security.security_domain.authentication.*; import org.wildfly.swarm.datasources.DatasourcesFraction; import org.wildfly.swarm.jaxrs.JAXRSArchive; import org.wildfly.swarm.mail.MailFraction; import org.wildfly.swarm.security.SecurityFraction; +import java.io.File; + /** * A thorntail launcher that can run the service with an embedded * container. @@ -101,6 +96,8 @@ public class MowestaThorntail { deployment.addAsResource(new ClassLoaderAsset("emails/new-email.txt"), "emails/new-email.txt"); deployment.addAsResource(new ClassLoaderAsset("emails/new-user.txt"), "emails/new-user.txt"); deployment.addAsResource(new ClassLoaderAsset("emails/reset-user.txt"), "emails/reset-user.txt"); + deployment.addAsResource(new ClassLoaderAsset("com/mowesta/data/grib2/code/GRIB2_23_0_0_CodeFlag_en.txt"), "com/mowesta/data/grib2/code/GRIB2_23_0_0_CodeFlag_en.txt"); + deployment.addAsResource(new ClassLoaderAsset("com/mowesta/data/grib2/template/util/GRIB2_23_0_0_Template_en.txt"), "com/mowesta/data/grib2/template/util/GRIB2_23_0_0_Template_en.txt"); deployment.addAsResource(new File(nominatimFolder + "cities.json.bz2"), "nominatim/cities.json.bz2"); deployment.addAsResource(new File(nominatimFolder + "states.json.bz2"), "nominatim/states.json.bz2"); deployment.addAsResource(new File(nominatimFolder + "countries.json.bz2"), "nominatim/countries.json.bz2"); diff --git a/service-thorntail/src/main/resources/beans.xml b/service-thorntail/src/main/resources/beans.xml index fd1afee5..1a0cf023 100644 --- a/service-thorntail/src/main/resources/beans.xml +++ b/service-thorntail/src/main/resources/beans.xml @@ -9,8 +9,10 @@ com.mowesta.service.session.DebugDataSessionBean com.mowesta.service.session.DebugEmailSessionBean + + com.mowesta.service.session.DebugWeatherSyncSessionBean - \ No newline at end of file + diff --git a/service-thorntail/src/main/resources/persistence.xml b/service-thorntail/src/main/resources/persistence.xml index 61220b2b..d973754d 100644 --- a/service-thorntail/src/main/resources/persistence.xml +++ b/service-thorntail/src/main/resources/persistence.xml @@ -6,6 +6,9 @@ + + + - \ No newline at end of file + diff --git a/service-war/src/test/java/com/mowesta/service/mock/DisableWeatherSyncSessionBean.java b/service-war/src/test/java/com/mowesta/service/mock/DisableWeatherSyncSessionBean.java new file mode 100644 index 00000000..3b4395b4 --- /dev/null +++ b/service-war/src/test/java/com/mowesta/service/mock/DisableWeatherSyncSessionBean.java @@ -0,0 +1,20 @@ +package com.mowesta.service.mock; + +import com.mowesta.service.session.DebugWeatherSyncSessionBean; + +import javax.ejb.*; +import javax.enterprise.inject.Alternative; +import java.util.logging.Level; + +@Alternative // alternative implementation, selectable via beans.xml +@Singleton +@ConcurrencyManagement(ConcurrencyManagementType.BEAN) +public class DisableWeatherSyncSessionBean extends DebugWeatherSyncSessionBean { + + @Timeout + @TransactionAttribute(TransactionAttributeType.NEVER) + @Override + public void syncDWDData(Timer timer) { + log.log(Level.INFO, "Skipping automatic DWD sync during tests"); + } +} diff --git a/service-war/src/test/java/com/mowesta/service/test/WarDeployment.java b/service-war/src/test/java/com/mowesta/service/test/WarDeployment.java index b46309dc..15984dfb 100644 --- a/service-war/src/test/java/com/mowesta/service/test/WarDeployment.java +++ b/service-war/src/test/java/com/mowesta/service/test/WarDeployment.java @@ -37,6 +37,7 @@ public class WarDeployment { .addPackages(true, "com.mowesta.service.injection") .addPackages(true, "com.mowesta.service.session") .addPackages(true, "com.mowesta.service.template") + .addPackages(true, "com.mowesta.service.mock") .addPackages(true, "org.mapstruct") .addAsResource(new File("../service-ejb/src/test/resources/nominatim/cities.json.bz2"), "nominatim/cities.json.bz2") .addAsResource(new File("../service-ejb/src/test/resources/nominatim/states.json.bz2"), "nominatim/states.json.bz2") diff --git a/service-war/src/test/resources/META-INF/beans.xml b/service-war/src/test/resources/META-INF/beans.xml index e7ee1bcf..ac421893 100644 --- a/service-war/src/test/resources/META-INF/beans.xml +++ b/service-war/src/test/resources/META-INF/beans.xml @@ -9,8 +9,10 @@ com.mowesta.service.session.DebugDataSessionBean com.mowesta.service.session.DebugEmailSessionBean + + com.mowesta.service.mock.DisableWeatherSyncSessionBean - \ No newline at end of file + diff --git a/service-war/src/test/resources/META-INF/persistence.xml b/service-war/src/test/resources/META-INF/persistence.xml index ed5854c8..f18d0398 100644 --- a/service-war/src/test/resources/META-INF/persistence.xml +++ b/service-war/src/test/resources/META-INF/persistence.xml @@ -10,6 +10,7 @@ + - \ No newline at end of file +