use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PoiManager method queryForId.
/**
* 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()));
return poi;
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PoiManager method loadPoiForEdition.
// *********************************
// ************ private ************
// *********************************
/**
* Send a {@link PoiForEditionLoadedEvent} containing the Poi to edit and the suggestions for the PoiTypeTags.
*
* @param id The id of the Poi to edit.
*/
private void loadPoiForEdition(Long id) {
Poi poi = queryForId(id);
bus.post(new PoiForEditionLoadedEvent(poi, suggestionsForTagsValue(poi.getType().getTags())));
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class OSMSyncWayManager method downloadPoiForWayEdition.
/**
* {@inheritDoc}
*/
@Override
public List<Poi> downloadPoiForWayEdition(List<Long> ids) {
// get noderefs to update
List<PoiNodeRef> poiNodeRefs = poiNodeRefDao.queryByPoiNodeRefIds(ids);
// get Pois corresponding to noderefs to update
List<Poi> pois = getPoiWaysToUpdate();
List<PoiNodeRef> poiNodeRefsToSave = new ArrayList<>();
Map<String, PoiNodeRef> poiNodeRefMap = new HashMap<>();
for (PoiNodeRef poiNodeRef : poiNodeRefs) {
poiNodeRefMap.put(poiNodeRef.getNodeBackendId(), poiNodeRef);
}
// apply new lat lng to poi
for (Poi poi : pois) {
PoiNodeRef poiNodeRef = poiNodeRefMap.get(poi.getBackendId());
if (poiNodeRef != null) {
poi.setLatitude(poiNodeRef.getLatitude());
poi.setLongitude(poiNodeRef.getLongitude());
poi.setUpdated(true);
poiNodeRef.setUpdated(false);
Long oldId = poiNodeRef.getOldPoiId();
if (oldId != null) {
poiNodeRefDao.deleteById(oldId);
}
poiNodeRef.setOldPoiId(null);
poiNodeRefsToSave.add(poiNodeRef);
}
}
// save changes
pois = poiManager.savePois(pois);
poiManager.savePoiNodeRefs(poiNodeRefsToSave);
return pois;
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PoiManagerTest method getPoi.
private Poi getPoi(PoiType poiType, int i) {
Poi poi = new Poi();
poi.setType(poiType);
poi.setName("MyPoi" + i);
poi.setLatitude(42.0);
poi.setLongitude(73.0);
poi.setUpdated(false);
Map<String, String> tags = new HashMap<>();
tags.put("tag1", "value1");
poi.applyChanges(tags);
return poi;
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PoiManagerTest method testBulkSaveAndBulkUpdate.
@Test
public void testBulkSaveAndBulkUpdate() {
PoiManager poiManager = component.getPoiManager();
PoiType poiType = poiManager.savePoiType(getPoiType());
// try to save and then update 1000 pois.
// 1000 because it can happen in real life and pose problems if we try to do an "IN" sql clause
List<Poi> pois = new ArrayList<>(1000);
for (int i = 0; i < 1000; i++) {
pois.add(getPoi(poiType, i));
}
poiManager.savePois(pois);
for (Poi poi : pois) {
assertThat(poi.getId()).isNotNull();
}
for (Poi poi : pois) {
Map<String, String> tags = new HashMap<>();
tags.put("tag2", "value2");
poi.getTags().clear();
poi.applyChanges(tags);
}
List<Poi> savedPois = poiManager.savePois(pois);
for (Poi poi : savedPois) {
assertThat(poi.getTags()).hasSize(1);
PoiTag tag = poi.getTags().iterator().next();
assertThat(tag.getKey()).isEqualTo("tag2");
assertThat(tag.getValue()).isEqualTo("value2");
}
}
Aggregations