mirror of
https://github.com/nicobo/dataprovence.git
synced 2026-04-10 07:55:35 +02:00
+ dataprovence
This commit is contained in:
commit
0a9b396782
9
.classpath
Normal file
9
.classpath
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
33
.project
Normal file
33
.project
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>dataprovence</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
7
.settings/org.eclipse.jdt.core.prefs
Normal file
7
.settings/org.eclipse.jdt.core.prefs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
||||
14
AndroidManifest.xml
Normal file
14
AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="groomservice.dataprovence"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" />
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:theme="@style/AppTheme">
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
BIN
libs/android-support-v4.jar
Normal file
BIN
libs/android-support-v4.jar
Normal file
Binary file not shown.
BIN
libs/gson-2.2.2.jar
Normal file
BIN
libs/gson-2.2.2.jar
Normal file
Binary file not shown.
BIN
libs/logback-classic-1.0.7.jar
Normal file
BIN
libs/logback-classic-1.0.7.jar
Normal file
Binary file not shown.
BIN
libs/logback-core-1.0.7.jar
Normal file
BIN
libs/logback-core-1.0.7.jar
Normal file
Binary file not shown.
BIN
libs/slf4j-api-1.7.2.jar
Normal file
BIN
libs/slf4j-api-1.7.2.jar
Normal file
Binary file not shown.
20
proguard-project.txt
Normal file
20
proguard-project.txt
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
15
project.properties
Normal file
15
project.properties
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system edit
|
||||
# "ant.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
#
|
||||
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
|
||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||
|
||||
# Project target.
|
||||
target=Google Inc.:Google APIs:14
|
||||
android.library=true
|
||||
BIN
res/drawable-hdpi/ic_launcher.png
Normal file
BIN
res/drawable-hdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
BIN
res/drawable-mdpi/ic_launcher.png
Normal file
BIN
res/drawable-mdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.1 KiB |
BIN
res/drawable-xhdpi/ic_launcher.png
Normal file
BIN
res/drawable-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
11
res/values-v11/styles.xml
Normal file
11
res/values-v11/styles.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 11+. This theme completely replaces
|
||||
AppBaseTheme from res/values/styles.xml on API 11+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
|
||||
<!-- API 11 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
12
res/values-v14/styles.xml
Normal file
12
res/values-v14/styles.xml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 14+. This theme completely replaces
|
||||
AppBaseTheme from BOTH res/values/styles.xml and
|
||||
res/values-v11/styles.xml on API 14+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
|
||||
<!-- API 14 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
5
res/values/strings.xml
Normal file
5
res/values/strings.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">dataprovence</string>
|
||||
|
||||
</resources>
|
||||
20
res/values/styles.xml
Normal file
20
res/values/styles.xml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme, dependent on API level. This theme is replaced
|
||||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="android:Theme.Light">
|
||||
<!--
|
||||
Theme customizations available in newer API levels can go in
|
||||
res/values-vXX/styles.xml, while customizations related to
|
||||
backward-compatibility can go here.
|
||||
-->
|
||||
</style>
|
||||
|
||||
<!-- Application theme. -->
|
||||
<style name="AppTheme" parent="AppBaseTheme">
|
||||
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
1
src/RestaurantsGastronomiques_cdtRestaurant.json
Normal file
1
src/RestaurantsGastronomiques_cdtRestaurant.json
Normal file
File diff suppressed because one or more lines are too long
19
src/bma/groomservice/data/Poi.java
Normal file
19
src/bma/groomservice/data/Poi.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package bma.groomservice.data;
|
||||
|
||||
public class Poi {
|
||||
|
||||
public String entityid;
|
||||
public String raisonsociale;
|
||||
public String tlphone;
|
||||
public String adresseWeb;
|
||||
public double latitude;
|
||||
public double longitude;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Poi [entityid=" + entityid + ", raisonsociale=" + raisonsociale
|
||||
+ ", tlphone=" + tlphone + ", adresseWeb=" + adresseWeb
|
||||
+ ", latitude=" + latitude + ", longitude=" + longitude + "]";
|
||||
}
|
||||
|
||||
}
|
||||
12
src/bma/groomservice/data/PoiList.java
Normal file
12
src/bma/groomservice/data/PoiList.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package bma.groomservice.data;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class PoiList {
|
||||
public Poi[] d;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PoiList [d=" + Arrays.toString(d) + "]";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package bma.groomservice.data.dataprovence;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.ParseException;
|
||||
import java.util.Map;
|
||||
|
||||
import bma.groomservice.data.PoiList;
|
||||
|
||||
/**
|
||||
* Utiliser pour les tests locaux : lit les données à partir d'un fichier JSON
|
||||
* local
|
||||
*
|
||||
* @author nicobo
|
||||
*/
|
||||
public class DataprovenceFileHelper extends DataprovenceHelper {
|
||||
|
||||
String filename;
|
||||
|
||||
/**
|
||||
* @param filename
|
||||
* Nom du fichier (dans le CLASSPATH) Ex:
|
||||
* "RestaurantsGastronomiques_cdtRestaurant.json"
|
||||
*/
|
||||
public DataprovenceFileHelper(String filename) {
|
||||
super(null, null, null);
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PoiList parse(Map<String, Object> filters) throws IOException,
|
||||
ParseException {
|
||||
InputStream fis = null;
|
||||
try {
|
||||
fis = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream(filename);
|
||||
return getContent(fis);
|
||||
} finally {
|
||||
if (fis != null) {
|
||||
fis.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
110
src/bma/groomservice/data/dataprovence/DataprovenceHelper.java
Normal file
110
src/bma/groomservice/data/dataprovence/DataprovenceHelper.java
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
package bma.groomservice.data.dataprovence;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import bma.groomservice.data.Poi;
|
||||
import bma.groomservice.data.PoiList;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public class DataprovenceHelper {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(DataprovenceHelper.class);
|
||||
|
||||
private final String rootUrl;
|
||||
private final String datasetName;
|
||||
private final Map<String, Object> filters;
|
||||
|
||||
public DataprovenceHelper(String rootUrl, String datasetName,
|
||||
Map<String, Object> filters) {
|
||||
this.rootUrl = rootUrl;
|
||||
this.datasetName = datasetName;
|
||||
this.filters = filters;
|
||||
}
|
||||
|
||||
public DataprovenceHelper(String rootUrl, String datasetName) {
|
||||
this(rootUrl, datasetName, null);
|
||||
}
|
||||
|
||||
public DataprovenceHelper(String datasetName) {
|
||||
this("http://dataprovence.cloudapp.net:8080/v1/dataprovencetourisme",
|
||||
datasetName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit le contenu total du flux dans une {@link String}
|
||||
*/
|
||||
protected String readStream(InputStream is) throws IOException {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (int c = is.read(); c != -1; c = is.read()) {
|
||||
b.append((char) c);
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit un {@link PoiList} depuis un {@link InputStream} donné
|
||||
* <b>Attention</b> à bien fermer l'input stream après.
|
||||
*/
|
||||
protected PoiList getContent(InputStream is) throws IOException,
|
||||
ParseException {
|
||||
|
||||
String json = readStream(is);
|
||||
logger.debug("json={}", json);
|
||||
Gson gson = new Gson();
|
||||
|
||||
PoiList all = gson.fromJson(json, PoiList.class);
|
||||
return all;
|
||||
}
|
||||
|
||||
protected PoiList parse(Map<String, Object> filters)
|
||||
throws IOException, ParseException {
|
||||
|
||||
Map<String, Object> ff = filters;
|
||||
if (ff == null) {
|
||||
ff = this.filters;
|
||||
}
|
||||
|
||||
StringBuilder surl = new StringBuilder(rootUrl + "/" + datasetName
|
||||
+ "?format=json");
|
||||
if (ff != null) {
|
||||
for (String filter : filters.keySet()) {
|
||||
// ex : filter = "type" -> value = "cdt:Restaurant"
|
||||
surl.append("&$filter=eq%20'").append(filters.get(filter))
|
||||
.append("'");
|
||||
}
|
||||
}
|
||||
|
||||
URL url = new URL(surl.toString());
|
||||
|
||||
HttpURLConnection urlConnection = (HttpURLConnection) url
|
||||
.openConnection();
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = new BufferedInputStream(urlConnection.getInputStream());
|
||||
return getContent(in);
|
||||
} finally {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
urlConnection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Poi> find(Map<String, Object> filters)
|
||||
throws IOException, ParseException {
|
||||
PoiList gl = parse(filters);
|
||||
return Arrays.asList(gl.d);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package bma.groomservice.data.dataprovence;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import bma.groomservice.data.Poi;
|
||||
|
||||
public class DataprovenceParserTest extends TestCase {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(DataprovenceParserTest.class);
|
||||
|
||||
public void testRestaurantsGastronomiques() {
|
||||
Map<String, Object> filters = new HashMap<String, Object>();
|
||||
filters.put("type", "cdt:Restaurant");
|
||||
try {
|
||||
// DataprovenceHelper parser = new DataprovenceHelper(
|
||||
// "RestaurantsGastronomiques");
|
||||
DataprovenceHelper parser = new DataprovenceFileHelper(
|
||||
"RestaurantsGastronomiques_cdtRestaurant.json");
|
||||
List<Poi> gs = parser.find(filters);
|
||||
logger.debug("RestaurantsGastronomiques={}", gs);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testParcsEtJardins() {
|
||||
try {
|
||||
DataprovenceHelper parser = new DataprovenceHelper("ParcsEtJardins");
|
||||
// DataprovenceHelper parser = new DataprovenceFileHelper(
|
||||
// "ParcsEtJardins.json");
|
||||
List<Poi> gs = parser.find(null);
|
||||
logger.debug("ParcsEtJardins={}", gs);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue