use of io.jawg.osmcontributor.rest.events.error.SyncUploadRetrofitErrorEvent 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.events.error.SyncUploadRetrofitErrorEvent in project osm-contributor by jawg.
the class OsmBackend method initializeTransaction.
/**
* {@inheritDoc}
*/
@Override
public String initializeTransaction(String comment) {
final OsmDto osmDto = new OsmDto();
ChangeSetDto changeSetDto = new ChangeSetDto();
List<TagDto> tagDtos = new ArrayList<>();
osmDto.setChangeSetDto(changeSetDto);
tagDtos.add(new TagDto(comment, "comment"));
tagDtos.add(new TagDto(BuildConfig.APP_NAME + " " + BuildConfig.VERSION_NAME, "created_by"));
changeSetDto.setTagDtoList(tagDtos);
Call<ResponseBody> callChangeSet;
if (loginPreferences.retrieveOAuthParams() != null) {
callChangeSet = osmRestClient.addChangeSet(AuthenticationRequestInterceptor.getOAuthRequest(loginPreferences, BuildConfig.BASE_OSM_URL + "changeset/create", Verb.PUT).getOAuthHeader(), osmDto);
} else {
callChangeSet = osmRestClient.addChangeSet(osmDto);
}
try {
Response<ResponseBody> response = callChangeSet.execute();
if (response.isSuccessful() && response.body() != null) {
return response.body().string();
}
} catch (IOException e) {
Timber.e("Retrofit error, couldn't create Changeset!");
}
bus.post(new SyncUploadRetrofitErrorEvent(-1L));
return null;
}
use of io.jawg.osmcontributor.rest.events.error.SyncUploadRetrofitErrorEvent 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