Commit 3c52d678 authored by Mohamed Khalil LABIDI's avatar Mohamed Khalil LABIDI Committed by Mohamed Khalil Labidi
Browse files

Fix GeoLocation DB handling (#15)

* Testing chargeCloudGLsDB method

* Try readerFor instead of forType when creating the object reader

* Cleaning branch code

(cherry picked from commit fd50e6a1f3e52541785c5a029f09dcbdafec8c13)
parent 3dd97cb6
...@@ -41,9 +41,9 @@ dependencies { ...@@ -41,9 +41,9 @@ dependencies {
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.7.1' compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.7.1'
compile group: 'org.json', name: 'json', version: '20200518' compile group: 'org.json', name: 'json', version: '20200518'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6' compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.11.3' compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.12.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.0' compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.1'
compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-csv', version: '2.12.0' compile group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-csv', version: '2.12.1'
compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.common', version: '2.20.0' compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.common', version: '2.20.0'
annotationProcessor "org.projectlombok:lombok:1.18.12" annotationProcessor "org.projectlombok:lombok:1.18.12"
} }
......
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId> <artifactId>jackson-annotations</artifactId>
<version>2.11.3</version> <version>2.12.1</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
...@@ -86,13 +86,13 @@ ...@@ -86,13 +86,13 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.11.3</version> <version>2.12.1</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId> <groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-csv</artifactId> <artifactId>jackson-dataformat-csv</artifactId>
<version>2.11.3</version> <version>2.12.1</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
......
...@@ -37,4 +37,16 @@ public class GeoLocationData { ...@@ -37,4 +37,16 @@ public class GeoLocationData {
return Objects.equals(this.cloud, geoLocation.cloud) && return Objects.equals(this.cloud, geoLocation.cloud) &&
Objects.equals(this.region, geoLocation.region); Objects.equals(this.region, geoLocation.region);
} }
@Override
public String toString() {
return "GeoLocationData{" +
"city='" + city + '\'' +
", country='" + country + '\'' +
", latitude=" + latitude +
", longitude=" + longitude +
", region='" + region + '\'' +
", cloud='" + cloud + '\'' +
'}';
}
} }
package org.activeeon.morphemic.service; package org.activeeon.morphemic.service;
import com.fasterxml.jackson.databind.MappingIterator; import com.fasterxml.jackson.databind.MappingIterator;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.dataformat.csv.CsvMapper; import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema; import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import lombok.Getter; import lombok.Getter;
...@@ -10,6 +11,7 @@ import org.apache.log4j.Logger; ...@@ -10,6 +11,7 @@ import org.apache.log4j.Logger;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
...@@ -30,20 +32,25 @@ public class GeoLocationUtils { ...@@ -30,20 +32,25 @@ public class GeoLocationUtils {
} }
private List<GeoLocationData> chargeCloudGLsDB() { private List<GeoLocationData> chargeCloudGLsDB() {
LOGGER.info("Charging Cloud GeoLocations DB ...");
List<GeoLocationData> cloudsGLDB = new LinkedList<>(); List<GeoLocationData> cloudsGLDB = new LinkedList<>();
File input = null; File input = null;
try { try {
input = TemporaryFilesHelper.createTempFileFromResource(File.separator + "db_cloud_regions.csv"); input = TemporaryFilesHelper.createTempFileFromResource(File.separator + "db_cloud_regions.csv");
CsvSchema csv = CsvSchema.emptySchema().withHeader().withColumnSeparator(' ').withNullValue(""); CsvSchema csv = CsvSchema.emptySchema().withHeader().withColumnSeparator(' ').withNullValue("");
CsvMapper csvMapper = new CsvMapper(); CsvMapper csvMapper = new CsvMapper();
MappingIterator<Map<?, ?>> mappingIterator = csvMapper.reader().forType(Map.class).with(csv).readValues(input); ObjectReader objectReader = csvMapper.readerFor(Map.class).with(csv);
LOGGER.debug("Reading GeoLocation values from objectReader: " + objectReader);
MappingIterator<Map<?, ?>> mappingIterator = objectReader.readValues(input);
List<Map<?, ?>> list = mappingIterator.readAll(); List<Map<?, ?>> list = mappingIterator.readAll();
LOGGER.debug("List of GeoLocations got: " + list);
list.forEach(map -> cloudsGLDB.add(new GeoLocationData(map.get("CITY").toString(), list.forEach(map -> cloudsGLDB.add(new GeoLocationData(map.get("CITY").toString(),
map.get("COUNTRY").toString(), map.get("COUNTRY").toString(),
Double.valueOf(map.get("LATITUDE").toString()), Double.valueOf(map.get("LATITUDE").toString()),
Double.valueOf(map.get("LONGITUDE").toString()), Double.valueOf(map.get("LONGITUDE").toString()),
map.get("REGION").toString(), map.get("REGION").toString(),
map.get("CLOUD").toString()))); map.get("CLOUD").toString())));
LOGGER.info("Cloud GeoLocations DB loaded successfully: " + cloudsGLDB);
} catch (IOException ioe) { } catch (IOException ioe) {
LOGGER.error("Charging the Geolocation database failed due to: " + Arrays.toString(ioe.getStackTrace())); LOGGER.error("Charging the Geolocation database failed due to: " + Arrays.toString(ioe.getStackTrace()));
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment