use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class EditPoiManager method onPleaseApplyPoiChanges.
@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseApplyPoiChanges(PleaseApplyPoiChanges event) {
Timber.d("please apply poi changes");
Poi editPoi = poiManager.queryForId(event.getPoiChanges().getId());
if (editPoi.hasChanges(event.getPoiChanges().getTagsMap())) {
editPoi.setOldPoiId(saveOldVersionOfPoi(editPoi));
// this is the edition of a new poi or we already edited this poi
editPoi.applyChanges(event.getPoiChanges().getTagsMap());
editPoi.applyChanges(applyConstraints(editPoi));
editPoi.setUpdated(true);
poiManager.savePoi(editPoi);
poiManager.updatePoiTypeLastUse(editPoi.getType().getId());
}
eventBus.post(new PoiChangesApplyEvent());
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class EditPoiManager method onPleaseDeletePoiEvent.
@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseDeletePoiEvent(PleaseDeletePoiEvent event) {
Timber.d("Please delete poi");
Poi poi = event.getPoi();
if (poi.getId() != null) {
poi = poiManager.queryForId(poi.getId());
}
if (poi.getBackendId() == null) {
poiManager.deletePoi(poi);
} else {
poi.setOldPoiId(saveOldVersionOfPoi(poi));
poi.setToDelete(true);
poiManager.savePoi(poi);
}
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PoiManager method savePoisFromAssets.
/**
* Load pois from assets and save them in the database.
*/
public void savePoisFromAssets() {
List<Poi> pois = poiAssetLoader.loadPoisFromAssets();
Timber.d("Loaded %s poi, trying to insert them", pois.size());
for (Poi poi : pois) {
Timber.d("saving poi %s", poi);
savePoi(poi);
Timber.d("poi saved");
}
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PoiManager method revertPoi.
/**
* Get the backup data and put it back in the active Poi, at the end the backup Poi is deleted.
*
* @param poiId The Id of the Poi to revert.
*/
private Poi revertPoi(Long poiId) {
Poi poi = poiDao.queryForId(poiId);
Poi backup = null;
Long oldPoiId = poi.getOldPoiId();
if (oldPoiId != null) {
backup = poiDao.queryForId(oldPoiId);
// we retrieve the backup data and put it back
backup.setOld(false);
backup.setId(poi.getId());
savePoi(backup);
// we prepare to delete the modifications
poi.setId(oldPoiId);
}
deletePoi(poi);
return backup;
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PoiManager method deleteOldPoiAssociated.
public void deleteOldPoiAssociated(Poi poi) {
Long oldId = poi.getOldPoiId();
if (oldId != null) {
Poi old = poiDao.queryForId(oldId);
if (old != null) {
deletePoi(old);
}
poi.setOldPoiId(null);
}
}
Aggregations