Search in sources :

Example 1 with PoisToUpdateLoadedEvent

use of io.jawg.osmcontributor.model.events.PoisToUpdateLoadedEvent in project osm-contributor by jawg.

the class PoiManager method onPleaseLoadPoisToUpdateEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseLoadPoisToUpdateEvent(PleaseLoadPoisToUpdateEvent event) {
    List<Poi> updatedPois = poiDao.queryForAllUpdated();
    List<Poi> newPois = poiDao.queryForAllNew();
    List<Poi> toDeletePois = poiDao.queryToDelete();
    List<PoiNodeRef> wayPoiNodeRef = poiNodeRefDao.queryAllToUpdate();
    List<PoiUpdateWrapper> allPois = new ArrayList<>();
    for (Poi p : updatedPois) {
        Long oldPoiId = p.getOldPoiId();
        if (oldPoiId != null) {
            allPois.add(new PoiUpdateWrapper(true, p, poiDao.queryForId(oldPoiId), null, PoiUpdateWrapper.PoiAction.UPDATE));
        }
    }
    for (Poi p : newPois) {
        allPois.add(new PoiUpdateWrapper(true, p, null, null, PoiUpdateWrapper.PoiAction.CREATE));
    }
    for (Poi p : toDeletePois) {
        allPois.add(new PoiUpdateWrapper(true, p, poiDao.queryForId(p.getOldPoiId()), null, PoiUpdateWrapper.PoiAction.DELETED));
    }
    for (PoiNodeRef p : wayPoiNodeRef) {
        allPois.add(new PoiUpdateWrapper(false, null, null, p, PoiUpdateWrapper.PoiAction.UPDATE));
    }
    bus.post(new PoisToUpdateLoadedEvent(allPois));
}
Also used : PoisToUpdateLoadedEvent(io.jawg.osmcontributor.model.events.PoisToUpdateLoadedEvent) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef) PoiUpdateWrapper(io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper) Subscribe(org.greenrobot.eventbus.Subscribe)

Aggregations

Poi (io.jawg.osmcontributor.model.entities.Poi)1 PoiNodeRef (io.jawg.osmcontributor.model.entities.PoiNodeRef)1 PoisToUpdateLoadedEvent (io.jawg.osmcontributor.model.events.PoisToUpdateLoadedEvent)1 PoiUpdateWrapper (io.jawg.osmcontributor.utils.upload.PoiUpdateWrapper)1 ArrayList (java.util.ArrayList)1 Subscribe (org.greenrobot.eventbus.Subscribe)1