Ejemplo n.º 1
0
  @Override
  public Poi getPoi(int id) throws IOException, ClientException {

    if (log.isDebugEnabled()) {
      log.debug("getPoi(): " + id + "...");
    }

    final fr.univmobile.backend.core.Poi dsPoi = poiDataSource.getByUid(id);

    final MutablePoi poi = createPoiFromData(dsPoi);

    if (poi == null) {
      throw new PoiNotFoundException(id);
    }

    return poi;
  }
Ejemplo n.º 2
0
  @Override
  public MutablePois getPois() throws IOException {

    log.debug("getPois()...");

    final Map<String, fr.univmobile.backend.core.Region> dsRegions //
        = regionDataSource.getAllBy(String.class, "uid");

    // final Map<String, PoiTree> dsPoitree //
    // = poitreeDataSource.getAllBy(String.class, "uid");

    final PoiGroup[] poiGroups = new PoiGroup[dsRegions.size()];

    int i = 0;

    final Set<fr.univmobile.backend.core.Region> sortedSet =
        new TreeSet<fr.univmobile.backend.core.Region>(
            new Comparator<fr.univmobile.backend.core.Region>() {

              @Override
              public int compare(
                  final fr.univmobile.backend.core.Region r1,
                  final fr.univmobile.backend.core.Region r2) {

                final Form form = Form.NFD;

                final String n1 = Normalizer.normalize(r1.getLabel(), form);
                final String n2 = Normalizer.normalize(r2.getLabel(), form);

                return n1.compareTo(n2);
              }
            });

    sortedSet.addAll(dsRegions.values());

    int markerIndex = 0;

    for (final fr.univmobile.backend.core.Region dsRegion : sortedSet) {

      final MutablePoiGroup poiGroup =
          DataBeans //
              .instantiate(MutablePoiGroup.class) //
              .setGroupLabel("Région : " + dsRegion.getLabel());

      poiGroups[i] = poiGroup;

      ++i;

      final String regionId = dsRegion.getUid();

      if (poitreeDataSource.isNullByUid(regionId)) { // TODO

        System.err.println("Cannot load PoiTree for region: " + regionId);

        continue;
      }

      final PoiTree poiTree = poitreeDataSource.getByUid(regionId);

      for (final PoiTree root : poiTree.getRoots()) {

        final int poiUid = Integer.parseInt(root.getUid());

        final fr.univmobile.backend.core.Poi dsPoi = poiDataSource.getByUid(poiUid);

        final MutablePoi poi = createPoiFromData(dsPoi);

        if (poi == null) {
          continue; // Skip empty POIs
        }

        poi.setMarkerType("green");
        poi.setMarkerIndex(Character.toString((char) ('A' + markerIndex)));

        markerIndex = (markerIndex + 1) % 26;

        poiGroup.addToPois(poi);
      }
    }

    final MutablePois pois = DataBeans.instantiate(MutablePois.class);

    for (final PoiGroup poiGroup : poiGroups) {

      pois.addToGroups(poiGroup);
    }

    return pois;
  }