mirror of
https://github.com/nicobo/dataprovence.git
synced 2026-04-10 16:06:23 +02:00
+ findAll( liste des themes ) -> fait toutes les requetes necessaires et retourne la liste des pois
This commit is contained in:
parent
30973459ac
commit
2d4ec896fc
|
|
@ -3,7 +3,7 @@
|
|||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" />
|
||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="16" />
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15" />
|
||||
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="16" />
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -2,7 +2,6 @@ package bma.groomservice.data.dataprovence;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.ParseException;
|
||||
import java.util.Collection;
|
||||
|
||||
import bma.groomservice.data.Filter;
|
||||
|
|
@ -29,8 +28,7 @@ public class DataprovenceFileHelper extends DataprovenceHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected PoiList parse(Collection<Filter> filters) throws IOException,
|
||||
ParseException {
|
||||
protected PoiList parse(Collection<Filter> filters) throws IOException {
|
||||
InputStream fis = null;
|
||||
try {
|
||||
fis = Thread.currentThread().getContextClassLoader()
|
||||
|
|
|
|||
|
|
@ -5,10 +5,15 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -23,6 +28,34 @@ public class DataprovenceHelper {
|
|||
|
||||
Logger logger = LoggerFactory.getLogger(DataprovenceHelper.class);
|
||||
|
||||
//
|
||||
// Constantes des "thèmes"
|
||||
//
|
||||
|
||||
public static final String THEME_PLEINAIR = "PLEIN AIR";
|
||||
public static final String THEME_RESTAURATION = "RESTAURATION";
|
||||
public static final String THEME_SPORT = "SPORT";
|
||||
public static final String THEME_CULTURE = "CULTURE";
|
||||
|
||||
public static final Map<String, String[]> DATASETS = new HashMap<String, String[]>();
|
||||
static {
|
||||
DATASETS.put(THEME_PLEINAIR, new String[] { "ServicesDeGuides",
|
||||
"LocationDeVelo", "CentresEquestres",
|
||||
"AccompagnateurDeMoyenneMontagneEtMoniteursDEscalade",
|
||||
"ParcsAThemesEtAnimaliers", "GolfsEtMinigolfs",
|
||||
"ParcsAcrobatiquesForestiers", "ParcsEtJardins",
|
||||
"SitesNaturelsIncontournables", "Plages" });
|
||||
DATASETS.put(THEME_RESTAURATION, new String[] {
|
||||
"RestaurantsGastronomiques", "Restaurants" });
|
||||
DATASETS.put(THEME_SPORT, new String[] { "SportNautique",
|
||||
"LocationDeVelo", "CentresEquestres",
|
||||
"AccompagnateurDeMoyenneMontagneEtMoniteursDEscalade",
|
||||
"GolfsEtMinigolfs", "ParcsAcrobatiquesForestiers" });
|
||||
DATASETS.put(THEME_CULTURE, new String[] { "ServicesDeGuides",
|
||||
"SitesNaturelsIncontournables", "Musees",
|
||||
"MonumentsEtStesCulturels" });
|
||||
}
|
||||
|
||||
private final String rootUrl;
|
||||
private final String datasetName;
|
||||
private final Collection<Filter> filters;
|
||||
|
|
@ -43,6 +76,44 @@ public class DataprovenceHelper {
|
|||
datasetName, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result
|
||||
+ ((datasetName == null) ? 0 : datasetName.hashCode());
|
||||
result = prime * result + ((filters == null) ? 0 : filters.hashCode());
|
||||
result = prime * result + ((rootUrl == null) ? 0 : rootUrl.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
DataprovenceHelper other = (DataprovenceHelper) obj;
|
||||
if (datasetName == null) {
|
||||
if (other.datasetName != null)
|
||||
return false;
|
||||
} else if (!datasetName.equals(other.datasetName))
|
||||
return false;
|
||||
if (filters == null) {
|
||||
if (other.filters != null)
|
||||
return false;
|
||||
} else if (!filters.equals(other.filters))
|
||||
return false;
|
||||
if (rootUrl == null) {
|
||||
if (other.rootUrl != null)
|
||||
return false;
|
||||
} else if (!rootUrl.equals(other.rootUrl))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lit le contenu total du flux dans une {@link String}
|
||||
*/
|
||||
|
|
@ -58,8 +129,7 @@ public class DataprovenceHelper {
|
|||
* 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 {
|
||||
protected PoiList getContent(InputStream is) throws IOException {
|
||||
|
||||
String json = readStream(is);
|
||||
logger.debug("json={}", json);
|
||||
|
|
@ -69,8 +139,7 @@ public class DataprovenceHelper {
|
|||
return all;
|
||||
}
|
||||
|
||||
protected PoiList parse(Collection<Filter> filters) throws IOException,
|
||||
ParseException {
|
||||
protected PoiList parse(Collection<Filter> filters) throws IOException {
|
||||
|
||||
Collection<Filter> ff = filters;
|
||||
if (ff == null) {
|
||||
|
|
@ -108,9 +177,39 @@ public class DataprovenceHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public List<Poi> find(Collection<Filter> filters) throws IOException,
|
||||
ParseException {
|
||||
public List<Poi> find(Collection<Filter> filters) throws IOException {
|
||||
PoiList gl = parse(filters);
|
||||
return Arrays.asList(gl.d);
|
||||
}
|
||||
|
||||
protected static Collection<DataprovenceHelper> findHelpers(
|
||||
Collection<String> tags) {
|
||||
ArrayList<DataprovenceHelper> helpers = new ArrayList<DataprovenceHelper>();
|
||||
for (String tag : tags) {
|
||||
String[] datasets = DATASETS.get(tag);
|
||||
for (int d = 0; d < datasets.length; d++) {
|
||||
helpers.add(new DataprovenceHelper(datasets[d]));
|
||||
}
|
||||
}
|
||||
return helpers;
|
||||
}
|
||||
|
||||
public static List<Poi> findAll(Collection<String> tags) throws IOException {
|
||||
|
||||
Set<DataprovenceHelper> helpers = new HashSet<DataprovenceHelper>();
|
||||
helpers.addAll(findHelpers(tags));
|
||||
|
||||
TreeSet<Poi> pois = new TreeSet<Poi>();
|
||||
for (DataprovenceHelper helper : findHelpers(tags)) {
|
||||
pois.addAll(helper.find(null));
|
||||
}
|
||||
|
||||
return new ArrayList<Poi>(pois);
|
||||
|
||||
}
|
||||
|
||||
public static List<Poi> findAll(String[] tags) throws IOException {
|
||||
return findAll(Arrays.asList(tags));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,26 +4,38 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import android.test.AndroidTestCase;
|
||||
import bma.groomservice.data.Filter;
|
||||
import bma.groomservice.data.Poi;
|
||||
|
||||
public class DataprovenceParserTest extends TestCase {
|
||||
public class DataprovenceParserTest extends AndroidTestCase {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(DataprovenceParserTest.class);
|
||||
|
||||
// DataprovenceHelper parser = new DataprovenceHelper(
|
||||
// "RestaurantsGastronomiques");
|
||||
DataprovenceHelper parser;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
parser = new DataprovenceFileHelper(
|
||||
"RestaurantsGastronomiques_cdtRestaurant.json");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
parser = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testRestaurantsGastronomiques() {
|
||||
Collection<Filter> filters = new ArrayList<Filter>();
|
||||
filters.add(Filter.eq("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);
|
||||
|
||||
|
|
@ -35,9 +47,6 @@ public class DataprovenceParserTest extends TestCase {
|
|||
|
||||
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);
|
||||
|
||||
|
|
@ -46,4 +55,33 @@ public class DataprovenceParserTest extends TestCase {
|
|||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testfindHelpersCulture() {
|
||||
try {
|
||||
List<Poi> pois = DataprovenceHelper
|
||||
.findAll(new String[] { "CULTURE" });
|
||||
assertEquals(4, pois.size());
|
||||
assertTrue(pois
|
||||
.contains(new DataprovenceHelper("ServicesDeGuides")));
|
||||
assertTrue(pois.contains(new DataprovenceHelper(
|
||||
"SitesNaturelsIncontournables")));
|
||||
assertTrue(pois.contains(new DataprovenceHelper("Musees")));
|
||||
assertTrue(pois.contains(new DataprovenceHelper(
|
||||
"MonumentsEtStesCulturels")));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testfindHelpersCultureSport() {
|
||||
try {
|
||||
List<Poi> pois = DataprovenceHelper.findAll(new String[] {
|
||||
"CULTURE", "PLEIN AIR" });
|
||||
assertEquals(12, pois.size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue