/**
  * Update the date of last use of a PoiType.
  *
  * @param id The id of the PoiType to update.
  */
 public void updatePoiTypeLastUse(long id) {
   PoiType poiType = poiTypeDao.queryForId(id);
   if (poiType != null) {
     poiType.setLastUse(new DateTime());
     Timber.d("Update date of : %s", poiType);
     poiTypeDao.createOrUpdate(poiType);
   }
 }
 /**
  * Get all the PoiTypes in the database.
  *
  * @return A ID,PoiType map with all the PoiTypes.
  */
 public Map<Long, PoiType> loadPoiTypes() {
   List<PoiType> poiTypes = poiTypeDao.queryForAll();
   Map<Long, PoiType> result = new HashMap<>();
   for (PoiType poiType : poiTypes) {
     result.put(poiType.getId(), poiType);
   }
   return result;
 }
 /**
  * Update the PoiTypes in the database with the given List of PoiTypes.
  *
  * @param newPoiTypes The PoiTypes to update.
  */
 public void updatePoiTypes(List<PoiType> newPoiTypes) {
   for (PoiType newPoiType : newPoiTypes) {
     PoiType byBackendId = poiTypeDao.findByBackendId(newPoiType.getBackendId());
     if (byBackendId != null) {
       newPoiType.setId(byBackendId.getId());
     }
     savePoiType(newPoiType);
   }
 }
 /**
  * Query for a Poi with a given id eagerly.
  *
  * @param id The id of the Poi to load.
  * @return The queried Poi.
  */
 public Poi queryForId(Long id) {
   Poi poi = poiDao.queryForId(id);
   if (poi == null) {
     return null;
   }
   poiTypeDao.refresh(poi.getType());
   poi.setTags(loadLazyForeignCollection(poi.getTags()));
   poi.getType().setTags(loadLazyForeignCollection(poi.getType().getTags()));
   return poi;
 }
  /**
   * Send a {@link io.mapsquare.osmcontributor.core.events.PoiForEditionLoadedEvent} containing the
   * suggestions for the PoiTypeTags and a new Poi to complete.
   *
   * @param event Event containing the position, level and PoiType of the Poi to create.
   */
  private void loadPoiForCreation(PleaseLoadPoiForCreationEvent event) {
    Poi poi = new Poi();
    Set<Double> level = new HashSet<>();
    level.add(event.getLevel());
    poi.setLevel(level);
    poi.setLatitude(event.getLat());
    poi.setLongitude(event.getLng());
    poi.setType(poiTypeDao.queryForId(event.getPoiType()));

    Map<String, String> defaultTags = new HashMap<>();
    for (PoiTypeTag poiTypeTag : poi.getType().getTags()) {
      if (poiTypeTag.getValue() != null) { // default tags should be set in the corresponding POI
        defaultTags.put(poiTypeTag.getKey(), poiTypeTag.getValue());
      }
    }
    poi.applyChanges(defaultTags);

    bus.post(new PoiForEditionLoadedEvent(poi, suggestionsForTagsValue(poi.getType().getTags())));
  }
 /**
  * Check whether the database has been initialized.
  *
  * @return Whether the database has been initialized.
  */
 public boolean isDbInitialized() {
   long count = poiTypeDao.countOf();
   Timber.d("pois in database : %s", count);
   return count > 0;
 }
 /**
  * Get all the PoiTypes last use sorted.
  *
  * @return The List of PoiTypes last use sorted.
  */
 public List<PoiType> getPoiTypesSortedByLastUse() {
   return poiTypeDao.queryAllSortedByLastUse();
 }
 /**
  * Get the PoiType with the given id.
  *
  * @param id The id of the PoiType.
  * @return The PoiType.
  */
 public PoiType getPoiType(Long id) {
   return poiTypeDao.queryForId(id);
 }