use of io.jawg.osmcontributor.rest.Backend in project osm-contributor by jawg.
the class SyncManager method remoteUpdatePoi.
/**
* Update a Poi of the backend.
*
* @param poi The Poi to update.
* @param changeSetId The changeSet in which the Poi is sent.
* @return Whether the update was a success or not.
*/
private boolean remoteUpdatePoi(final Poi poi, String changeSetId) {
Backend.UpdateResult updateResult = backend.updatePoi(poi, changeSetId);
poiManager.deleteOldPoiAssociated(poi);
switch(updateResult.getStatus()) {
case SUCCESS:
poi.setVersion(updateResult.getVersion());
poi.setUpdated(false);
poiManager.savePoi(poi);
OsmAnswers.remotePoiAction(poi.getType().getTechnicalName(), "update");
return true;
case FAILURE_CONFLICT:
bus.post(new SyncConflictingNodeErrorEvent(poi.getName(), poi.getId()));
Timber.e("Couldn't update poi %s: conflict, redownloading last version of poi", poi);
deleteAndRetrieveUnmodifiedPoi(poi);
return false;
case FAILURE_NOT_EXISTING:
Timber.e("Couldn't update poi %s, it didn't exist. Deleting the incriminated poi", poi);
poiManager.deletePoi(poi);
bus.post(new SyncConflictingNodeErrorEvent(poi.getName(), poi.getId()));
return false;
case FAILURE_UNKNOWN:
default:
Timber.e("Couldn't update poi %s. Deleting the incriminated poi", poi);
poiManager.deletePoi(poi);
bus.post(new SyncUploadRetrofitErrorEvent(poi.getId()));
return false;
}
}
use of io.jawg.osmcontributor.rest.Backend in project osm-contributor by jawg.
the class SyncManager method remoteAddPoi.
/**
* Add a Poi to the backend.
*
* @param poi The Poi to add to the backend.
* @param changeSetId The changeSet in which the Poi is sent.
* @return Whether the addition was a success or not.
*/
private boolean remoteAddPoi(final Poi poi, String changeSetId) {
Backend.CreationResult creationResult = backend.addPoi(poi, changeSetId);
switch(creationResult.getStatus()) {
case SUCCESS:
poi.setBackendId(creationResult.getBackendId());
poi.setUpdated(false);
poiManager.savePoi(poi);
OsmAnswers.remotePoiAction(poi.getType().getTechnicalName(), "add");
return true;
case FAILURE_UNKNOWN:
default:
poiManager.deletePoi(poi);
bus.post(new SyncNewNodeErrorEvent(poi.getName(), poi.getId()));
return false;
}
}
use of io.jawg.osmcontributor.rest.Backend in project osm-contributor by jawg.
the class SyncManager method remoteDeletePoi.
/**
* Delete a Poi of the backend.
*
* @param poi The Poi to delete.
* @param changeSetId The changeSet in which the Poi is sent.
* @return Whether the delete was a success or not.
*/
private boolean remoteDeletePoi(final Poi poi, String changeSetId) {
Backend.ModificationStatus modificationStatus = backend.deletePoi(poi, changeSetId);
poiManager.deleteOldPoiAssociated(poi);
switch(modificationStatus) {
case SUCCESS:
case FAILURE_NOT_EXISTING:
OsmAnswers.remotePoiAction(poi.getType().getTechnicalName(), "delete");
poiManager.deletePoi(poi);
return true;
case FAILURE_CONFLICT:
bus.post(new SyncConflictingNodeErrorEvent(poi.getName(), poi.getId()));
Timber.e("Couldn't update poi %s: conflict, redownloading last version of poi", poi);
deleteAndRetrieveUnmodifiedPoi(poi);
return false;
case FAILURE_UNKNOWN:
default:
Timber.e("Couldn't delete poi %s", poi);
bus.post(new SyncUploadRetrofitErrorEvent(poi.getId()));
return false;
}
}
Aggregations