Search in sources :

Example 11 with Poi

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();
}
Also used : Poi(io.jawg.osmcontributor.model.entities.Poi) PoiManager(io.jawg.osmcontributor.ui.managers.PoiManager) Test(org.junit.Test)

Example 12 with Poi

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());
}
Also used : ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi)

Example 13 with Poi

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;
}
Also used : OsmDto(io.jawg.osmcontributor.rest.dtos.osm.OsmDto) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi) IOException(java.io.IOException) NodeDto(io.jawg.osmcontributor.rest.dtos.osm.NodeDto)

Example 14 with Poi

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;
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) NdDto(io.jawg.osmcontributor.rest.dtos.osm.NdDto) ArrayList(java.util.ArrayList) PoiType(io.jawg.osmcontributor.model.entities.PoiType) TagDto(io.jawg.osmcontributor.rest.dtos.osm.TagDto) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef)

Example 15 with 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();
            }
        }
    });
}
Also used : OAuthRequest(io.jawg.osmcontributor.flickr.oauth.OAuthRequest) FlickrAddTagClient(io.jawg.osmcontributor.flickr.rest.FlickrAddTagClient) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Poi(io.jawg.osmcontributor.model.entities.Poi) TreeMap(java.util.TreeMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Aggregations

Poi (io.jawg.osmcontributor.model.entities.Poi)36 ArrayList (java.util.ArrayList)9 Subscribe (org.greenrobot.eventbus.Subscribe)9 HashMap (java.util.HashMap)7 PoiNodeRef (io.jawg.osmcontributor.model.entities.PoiNodeRef)5 Bitmap (android.graphics.Bitmap)3 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)3 PoiTag (io.jawg.osmcontributor.model.entities.PoiTag)3 Note (io.jawg.osmcontributor.model.entities.Note)2 PoiType (io.jawg.osmcontributor.model.entities.PoiType)2 PoiTypeTag (io.jawg.osmcontributor.model.entities.PoiTypeTag)2 PoiForEditionLoadedEvent (io.jawg.osmcontributor.model.events.PoiForEditionLoadedEvent)2 OsmDto (io.jawg.osmcontributor.rest.dtos.osm.OsmDto)2 PoiChangesApplyEvent (io.jawg.osmcontributor.ui.events.edition.PoiChangesApplyEvent)2 PleaseChangeValuesDetailPoiFragmentEvent (io.jawg.osmcontributor.ui.events.map.PleaseChangeValuesDetailPoiFragmentEvent)2 PoiManager (io.jawg.osmcontributor.ui.managers.PoiManager)2 MapElement (io.jawg.osmcontributor.utils.core.MapElement)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2