Search in sources :

Example 1 with WayDto

use of io.jawg.osmcontributor.rest.dtos.osm.WayDto in project osm-contributor by jawg.

the class OsmBackend method updatePoi.

/**
 * {@inheritDoc}
 */
@Override
public UpdateResult updatePoi(final Poi poi, String transactionId) {
    final OsmDto osmDto = new OsmDto();
    if (poi.getWay()) {
        WayDto nodeDto = poiMapper.convertPoiToWayDto(poi, transactionId);
        osmDto.setWayDtoList(singletonList(nodeDto));
    } else {
        NodeDto nodeDto = poiMapper.convertPoiToNodeDto(poi, transactionId);
        osmDto.setNodeDtoList(singletonList(nodeDto));
    }
    Call<ResponseBody> versionCall;
    if (poi.getWay()) {
        versionCall = osmRestClient.updateWay(poi.getBackendId(), osmDto);
    } else {
        versionCall = osmRestClient.updateNode(poi.getBackendId(), osmDto);
    }
    try {
        Response<ResponseBody> response = versionCall.execute();
        if (response.isSuccessful()) {
            return new UpdateResult(ModificationStatus.SUCCESS, response.body().string());
        } else {
            if (response.code() == 400) {
                Timber.e("Couldn't update node, conflicting version");
                return new UpdateResult(ModificationStatus.FAILURE_CONFLICT, null);
            } else if (response.code() == 404) {
                Timber.e("Couldn't update node, no existing node found with the id " + poi.getId());
                return new UpdateResult(ModificationStatus.FAILURE_NOT_EXISTING, null);
            } else {
                Timber.e("Couldn't update node");
                return new UpdateResult(ModificationStatus.FAILURE_UNKNOWN, null);
            }
        }
    } catch (IOException e) {
        Timber.e(e, e.getMessage());
    }
    return new UpdateResult(ModificationStatus.FAILURE_UNKNOWN, null);
}
Also used : OsmDto(io.jawg.osmcontributor.rest.dtos.osm.OsmDto) WayDto(io.jawg.osmcontributor.rest.dtos.osm.WayDto) IOException(java.io.IOException) NodeDto(io.jawg.osmcontributor.rest.dtos.osm.NodeDto) ResponseBody(okhttp3.ResponseBody)

Example 2 with WayDto

use of io.jawg.osmcontributor.rest.dtos.osm.WayDto in project osm-contributor by jawg.

the class OsmBackend method addPoi.

/**
 * {@inheritDoc}
 */
@Override
public CreationResult addPoi(final Poi poi, String transactionId) {
    final OsmDto osmDto = new OsmDto();
    if (poi.getWay()) {
        WayDto nodeDto = poiMapper.convertPoiToWayDto(poi, transactionId);
        osmDto.setWayDtoList(singletonList(nodeDto));
    } else {
        NodeDto nodeDto = poiMapper.convertPoiToNodeDto(poi, transactionId);
        osmDto.setNodeDtoList(singletonList(nodeDto));
    }
    Call<ResponseBody> getCall;
    if (poi.getWay()) {
        getCall = osmRestClient.addWay(osmDto);
    } else {
        getCall = osmRestClient.addNode(osmDto);
    }
    try {
        Response<ResponseBody> response = getCall.execute();
        if (response.isSuccessful()) {
            return new CreationResult(ModificationStatus.SUCCESS, response.body().string());
        }
    } catch (IOException e) {
        Timber.e(e, e.getMessage());
    }
    return new CreationResult(ModificationStatus.FAILURE_UNKNOWN, null);
}
Also used : OsmDto(io.jawg.osmcontributor.rest.dtos.osm.OsmDto) WayDto(io.jawg.osmcontributor.rest.dtos.osm.WayDto) IOException(java.io.IOException) NodeDto(io.jawg.osmcontributor.rest.dtos.osm.NodeDto) ResponseBody(okhttp3.ResponseBody)

Example 3 with WayDto

use of io.jawg.osmcontributor.rest.dtos.osm.WayDto in project osm-contributor by jawg.

the class OsmBackend method deletePoi.

/**
 * {@inheritDoc}
 */
@Override
public ModificationStatus deletePoi(final Poi poi, String transactionId) {
    final OsmDto osmDto = new OsmDto();
    if (poi.getWay()) {
        WayDto nodeDto = poiMapper.convertPoiToWayDto(poi, transactionId);
        osmDto.setWayDtoList(singletonList(nodeDto));
    } else {
        NodeDto nodeDto = poiMapper.convertPoiToNodeDto(poi, transactionId);
        osmDto.setNodeDtoList(singletonList(nodeDto));
    }
    Call<ResponseBody> deleteCall;
    if (poi.getWay()) {
        deleteCall = osmRestClient.deleteWay(poi.getBackendId(), osmDto);
        Timber.d("Deleted way %s", poi.getBackendId());
    } else {
        deleteCall = osmRestClient.deleteNode(poi.getBackendId(), osmDto);
        Timber.d("Deleted node %s", poi.getBackendId());
    }
    poiManager.deletePoi(poi);
    try {
        Response<ResponseBody> response = deleteCall.execute();
        if (response.isSuccessful()) {
            return ModificationStatus.SUCCESS;
        } else {
            if (response.code() == 400) {
                return ModificationStatus.FAILURE_CONFLICT;
            } else if (response.code() == 404) {
                // the point doesn't exist
                return ModificationStatus.FAILURE_NOT_EXISTING;
            } else if (response.code() == 410) {
                // the poi was already deleted
                return ModificationStatus.FAILURE_NOT_EXISTING;
            }
        }
    } catch (IOException e) {
        Timber.e(e, e.getMessage());
    }
    return ModificationStatus.FAILURE_UNKNOWN;
}
Also used : OsmDto(io.jawg.osmcontributor.rest.dtos.osm.OsmDto) WayDto(io.jawg.osmcontributor.rest.dtos.osm.WayDto) IOException(java.io.IOException) NodeDto(io.jawg.osmcontributor.rest.dtos.osm.NodeDto) ResponseBody(okhttp3.ResponseBody)

Example 4 with WayDto

use of io.jawg.osmcontributor.rest.dtos.osm.WayDto in project osm-contributor by jawg.

the class PoiMapper method convertPoiToWayDto.

public WayDto convertPoiToWayDto(Poi poi, String changeSetId) {
    WayDto wayDto = new WayDto();
    wayDto.setId(poi.getBackendId());
    wayDto.setChangeset(changeSetId);
    if (poi.getVersion() != null) {
        wayDto.setVersion(Integer.parseInt(poi.getVersion()));
    }
    wayDto.setTagsDtoList(poiTagMapper.convertFromPoiTag(poi.getTags()));
    List<NdDto> ndDtos = new ArrayList<>();
    for (PoiNodeRef poiNodeRef : poi.getNodeRefs()) {
        NdDto ndDto = new NdDto();
        ndDto.setRef(poiNodeRef.getNodeBackendId());
    }
    wayDto.setNdDtoList(ndDtos);
    return wayDto;
}
Also used : NdDto(io.jawg.osmcontributor.rest.dtos.osm.NdDto) WayDto(io.jawg.osmcontributor.rest.dtos.osm.WayDto) ArrayList(java.util.ArrayList) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef)

Example 5 with WayDto

use of io.jawg.osmcontributor.rest.dtos.osm.WayDto in project osm-contributor by jawg.

the class PoiLoader method loadAndSavePoisFromBackend.

private void loadAndSavePoisFromBackend(MapArea toLoadArea, boolean clean) {
    loadingStatus = LOADING_FROM_SERVER;
    publishProgress();
    loadedElements = 0L;
    nodeDtos.clear();
    osmDtos = backend.getPoisDtosInBox(toLoadArea.getBox());
    for (OsmDto osmDto : osmDtos) {
        killIfNeeded();
        if (osmDto != null) {
            List<NodeDto> nodeDtoList = osmDto.getNodeDtoList();
            if (nodeDtoList != null) {
                nodeDtos.addAll(nodeDtoList);
            }
            List<WayDto> wayDtoList = osmDto.getWayDtoList();
            if (wayDtoList != null) {
                nodeDtos.addAll(wayDtoList);
            }
        }
    }
    osmDtos.clear();
    loadingStatus = MAPPING_POIS;
    totalsElements = nodeDtos.size();
    if (clean) {
        cleanArea(toLoadArea);
    }
    savePoisInDB();
}
Also used : OsmDto(io.jawg.osmcontributor.rest.dtos.osm.OsmDto) WayDto(io.jawg.osmcontributor.rest.dtos.osm.WayDto) NodeDto(io.jawg.osmcontributor.rest.dtos.osm.NodeDto)

Aggregations

WayDto (io.jawg.osmcontributor.rest.dtos.osm.WayDto)5 NodeDto (io.jawg.osmcontributor.rest.dtos.osm.NodeDto)4 OsmDto (io.jawg.osmcontributor.rest.dtos.osm.OsmDto)4 IOException (java.io.IOException)3 ResponseBody (okhttp3.ResponseBody)3 PoiNodeRef (io.jawg.osmcontributor.model.entities.PoiNodeRef)1 NdDto (io.jawg.osmcontributor.rest.dtos.osm.NdDto)1 ArrayList (java.util.ArrayList)1