use of io.jawg.osmcontributor.rest.dtos.osm.NodeDto 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);
}
use of io.jawg.osmcontributor.rest.dtos.osm.NodeDto 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);
}
use of io.jawg.osmcontributor.rest.dtos.osm.NodeDto 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;
}
use of io.jawg.osmcontributor.rest.dtos.osm.NodeDto in project osm-contributor by jawg.
the class PoiMapperTest method getNodeDto.
private NodeDto getNodeDto(String... tags) {
NodeDto nodeDto = new NodeDto();
nodeDto.setLat(1.0);
nodeDto.setLon(1.0);
List<TagDto> tagDtos = new ArrayList<>();
if (tags.length % 2 != 0) {
throw new AssertionError("Malformed tags ! Array must be an even number");
}
for (int i = 0; i < tags.length; i += 2) {
tagDtos.add(tagDto(tags[i], tags[i + 1]));
}
nodeDto.setTagsDtoList(tagDtos);
return nodeDto;
}
use of io.jawg.osmcontributor.rest.dtos.osm.NodeDto in project osm-contributor by jawg.
the class OSMSyncWayManager method getPoiWaysToUpdate.
/**
* Download from backend all the NodeRefs to update as POIs.
*
* @return The list of POIs to update.
*/
private List<Poi> getPoiWaysToUpdate() {
final List<Long> ids = poiNodeRefDao.queryAllUpdated();
List<Poi> pois = new ArrayList<>();
if (ids != null && !ids.isEmpty()) {
Call<OsmDto> callOsm = osmRestClient.getNode(formatIdList(ids));
try {
Response<OsmDto> response = callOsm.execute();
if (response.isSuccessful()) {
OsmDto osmDto = response.body();
if (osmDto != null) {
List<NodeDto> nodeDtoList = osmDto.getNodeDtoList();
pois = poiMapper.convertDtosToPois(nodeDtoList, false);
}
return pois;
}
} catch (IOException e) {
Timber.e(e, e.getMessage());
}
Timber.w("The poi with id %s couldn't be found on OSM", 1);
}
return pois;
}
Aggregations