use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PoiManagerTest method testSaveAndQuery.
@Test
public void testSaveAndQuery() {
PoiManager poiManager = component.getPoiManager();
Poi poi = getPoi(poiManager.savePoiType(getPoiType()), 1);
Poi saved = poiManager.savePoi(poi);
Poi queried = poiManager.queryForId(saved.getId());
assertThat(queried.getName()).isEqualTo("MyPoi1");
assertThat(queried.getLatitude()).isEqualTo(42.0);
assertThat(queried.getLongitude()).isEqualTo(73.0);
assertThat(queried.getUpdated()).isFalse();
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class SyncManager method remoteAddOrUpdateOrDeletePois.
/**
* Send in a unique changeSet all the new POIs, modified and suppressed ones from ids send in params.
* <p/>
* Send a {@link io.jawg.osmcontributor.rest.events.SyncFinishUploadPoiEvent} with the counts.
*
* @param comment The comment of the changeSet.
* @param poisId Pois to upload
* @param poiNodeRefsId PoisNodeRef to upload
*/
public void remoteAddOrUpdateOrDeletePois(String comment, List<Long> poisId, List<Long> poiNodeRefsId) {
final List<Poi> pois = poiDao.queryForIds(poisId);
final List<Poi> updatedPois = new ArrayList<>();
final List<Poi> newPois = new ArrayList<>();
final List<Poi> toDeletePois = new ArrayList<>();
updatedPois.addAll(syncWayManager.downloadPoiForWayEdition(poiNodeRefsId));
for (Poi p : pois) {
if (p.getBackendId() == null) {
newPois.add(p);
continue;
}
if (p.getToDelete()) {
toDeletePois.add(p);
continue;
}
updatedPois.add(p);
}
remoteAddOrUpdateOrDeletePois(comment, poiDao.queryForAllUpdated(), poiDao.queryForAllNew(), poiDao.queryToDelete());
}
use of io.jawg.osmcontributor.model.entities.Poi 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;
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PoiMapper method convertDtoToPoi.
public Poi convertDtoToPoi(boolean typeFiltering, List<PoiType> availableTypes, PoiDto dto) {
List<PoiNodeRef> nodeRefs = new ArrayList<>();
List<PoiTag> tags = new ArrayList<>();
PoiType type;
if (FlavorUtils.isBus()) {
type = availableTypes.get(0);
} else {
type = findType(dto, availableTypes);
}
if (type == null && typeFiltering) {
return null;
}
Poi poi = new Poi();
poi.setType(type);
poi.setLatitude(dto.getLat());
poi.setLongitude(dto.getLon());
poi.setBackendId(dto.getId());
poi.setVersion(String.valueOf(dto.getVersion()));
poi.setUpdated(false);
poi.setUpdateDate(dto.getTimestamp());
poi.setWay(dto.isWay());
for (TagDto tagDto : dto.getTagsDtoList()) {
PoiTag tag = new PoiTag();
tag.setPoi(poi);
tag.setKey(tagDto.getKey());
tag.setValue(tagDto.getValue());
tags.add(tag);
if (tag.getKey().equals("name")) {
poi.setName(tag.getValue());
}
if (tag.getKey().equals("level")) {
poi.setLevel(tag.getValue());
}
}
poi.setTags(tags);
int counter = 0;
for (NdDto ndDto : dto.getNdDtoList()) {
PoiNodeRef nodeRef = new PoiNodeRef();
nodeRef.setPoi(poi);
nodeRef.setNodeBackendId(ndDto.getRef());
nodeRef.setOrdinal(counter++);
nodeRef.setLatitude(ndDto.getLat());
nodeRef.setLongitude(ndDto.getLon());
nodeRef.setUpdated(false);
nodeRefs.add(nodeRef);
}
poi.setNodeRefs(nodeRefs);
return poi;
}
use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.
the class PhotoActivity method setPhotoTag.
private void setPhotoTag(final String photoId) throws UnsupportedEncodingException {
// Create the machine tag for Flickr to associate picture to this Poi
Poi currentPoi = application.getOsmTemplateComponent().getPoiManager().queryForId(poiId);
StringBuilder flickrOsmTagBuilder = new StringBuilder(FLICKR_DEFAULT_TAG);
if (currentPoi.getBackendId() != null && currentPoi.getBackendId().length() > 0) {
flickrOsmTagBuilder.append(",osm:");
flickrOsmTagBuilder.append((currentPoi.getWay()) ? "way" : "node");
flickrOsmTagBuilder.append("=");
flickrOsmTagBuilder.append(currentPoi.getBackendId());
} else {
// TODO Handle pictures added on new POIs which haven't an OSM ID yet
// Such POIs might be sent to OSM first, and when an ID is defined, update the Flickr picture
}
String flickrOsmTag = URLEncoder.encode(flickrOsmTagBuilder.toString(), UTF_8);
OAuthRequest oauthRequest = flickrOAuth.getOAuthRequest();
if (oauthRequest == null) {
oauthRequest = new OAuthRequest(application.getFlickr().getApiKey(), application.getFlickr().getSharedSecret());
oauthRequest.setOAuthToken(configManager.getFlickrToken());
oauthRequest.setOAuthTokenSecret(configManager.getFlickrTokenSecret());
flickrOAuth.setOAuthRequest(oauthRequest);
}
oauthRequest.setRequestUrl(FLICKR_API_SERVICES);
oauthRequest.initParam(OAuthParams.getOAuthParams().put(OAuthParams.OAUTH_TOKEN, oauthRequest.getOAuthToken()).put("method", FLICKR_METHOD_ADDTAGS).put("photo_id", photoId).put("tags", flickrOsmTag).toMap());
oauthRequest.signRequest(Verb.POST);
// Filter params for Authorization header
Map<String, String> oauthParams = new TreeMap<String, String>();
for (Map.Entry<String, String> entry : oauthRequest.getParams().entrySet()) {
if (entry.getKey().startsWith(PARAM_OAUTH_PREFIX)) {
oauthParams.put(entry.getKey(), entry.getValue());
}
}
flickrAddTagClient = FlickrPhotoUtils.getAdapter(oauthParams).create(FlickrAddTagClient.class);
flickrAddTagClient.addTags(new StringBuilder("method=").append(FLICKR_METHOD_ADDTAGS).append("&photo_id=").append(photoId).append("&tags=").append(flickrOsmTag).toString()).enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
if (response.isSuccessful()) {
String responseAsString = response.body();
Log.d(TAG, responseAsString);
progressDialog.dismiss();
photoFile.delete();
Toast.makeText(PhotoActivity.this, R.string.picture_sent_success, Toast.LENGTH_LONG).show();
if (ImageAdapter.getPhotoUrlsCachedThumbs(poiId) == null || ImageAdapter.getPhotoUrlsCachedThumbs(poiId).isEmpty()) {
finish();
}
} else {
onFailure(call, new Exception());
}
}
@Override
public void onFailure(Call<String> call, Throwable t) {
if (nbTry < MAX_RETRY_UPLOAD) {
nbTry++;
try {
setPhotoTag(photoId);
} catch (UnsupportedEncodingException e) {
Timber.e(e, e.getMessage());
}
} else {
nbTry = 0;
Toast.makeText(PhotoActivity.this, R.string.poi_association_failure, Toast.LENGTH_LONG).show();
progressDialog.dismiss();
}
}
});
}
Aggregations