Search in sources :

Example 1 with ChangeSetDto

use of io.jawg.osmcontributor.rest.dtos.osm.ChangeSetDto 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;
}
Also used : OsmDto(io.jawg.osmcontributor.rest.dtos.osm.OsmDto) ChangeSetDto(io.jawg.osmcontributor.rest.dtos.osm.ChangeSetDto) TagDto(io.jawg.osmcontributor.rest.dtos.osm.TagDto) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SyncUploadRetrofitErrorEvent(io.jawg.osmcontributor.rest.events.error.SyncUploadRetrofitErrorEvent) ResponseBody(okhttp3.ResponseBody)

Aggregations

ChangeSetDto (io.jawg.osmcontributor.rest.dtos.osm.ChangeSetDto)1 OsmDto (io.jawg.osmcontributor.rest.dtos.osm.OsmDto)1 TagDto (io.jawg.osmcontributor.rest.dtos.osm.TagDto)1 SyncUploadRetrofitErrorEvent (io.jawg.osmcontributor.rest.events.error.SyncUploadRetrofitErrorEvent)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ResponseBody (okhttp3.ResponseBody)1