Search in sources :

Example 31 with Poi

use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.

the class PoiManager method queryForId.

/**
 * Query for a Poi with a given id eagerly.
 *
 * @param id The id of the Poi to load.
 * @return The queried Poi.
 */
public Poi queryForId(Long id) {
    Poi poi = poiDao.queryForId(id);
    if (poi == null) {
        return null;
    }
    poiTypeDao.refresh(poi.getType());
    poi.setTags(loadLazyForeignCollection(poi.getTags()));
    return poi;
}
Also used : Poi(io.jawg.osmcontributor.model.entities.Poi)

Example 32 with Poi

use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.

the class PoiManager method loadPoiForEdition.

// *********************************
// ************ private ************
// *********************************
/**
 * Send a {@link PoiForEditionLoadedEvent} containing the Poi to edit and the suggestions for the PoiTypeTags.
 *
 * @param id The id of the Poi to edit.
 */
private void loadPoiForEdition(Long id) {
    Poi poi = queryForId(id);
    bus.post(new PoiForEditionLoadedEvent(poi, suggestionsForTagsValue(poi.getType().getTags())));
}
Also used : Poi(io.jawg.osmcontributor.model.entities.Poi) PoiForEditionLoadedEvent(io.jawg.osmcontributor.model.events.PoiForEditionLoadedEvent)

Example 33 with Poi

use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.

the class OSMSyncWayManager method downloadPoiForWayEdition.

/**
 * {@inheritDoc}
 */
@Override
public List<Poi> downloadPoiForWayEdition(List<Long> ids) {
    // get noderefs to update
    List<PoiNodeRef> poiNodeRefs = poiNodeRefDao.queryByPoiNodeRefIds(ids);
    // get Pois corresponding to noderefs to update
    List<Poi> pois = getPoiWaysToUpdate();
    List<PoiNodeRef> poiNodeRefsToSave = new ArrayList<>();
    Map<String, PoiNodeRef> poiNodeRefMap = new HashMap<>();
    for (PoiNodeRef poiNodeRef : poiNodeRefs) {
        poiNodeRefMap.put(poiNodeRef.getNodeBackendId(), poiNodeRef);
    }
    // apply new lat lng to poi
    for (Poi poi : pois) {
        PoiNodeRef poiNodeRef = poiNodeRefMap.get(poi.getBackendId());
        if (poiNodeRef != null) {
            poi.setLatitude(poiNodeRef.getLatitude());
            poi.setLongitude(poiNodeRef.getLongitude());
            poi.setUpdated(true);
            poiNodeRef.setUpdated(false);
            Long oldId = poiNodeRef.getOldPoiId();
            if (oldId != null) {
                poiNodeRefDao.deleteById(oldId);
            }
            poiNodeRef.setOldPoiId(null);
            poiNodeRefsToSave.add(poiNodeRef);
        }
    }
    // save changes
    pois = poiManager.savePois(pois);
    poiManager.savePoiNodeRefs(poiNodeRefsToSave);
    return pois;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef)

Example 34 with Poi

use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.

the class PoiManagerTest method getPoi.

private Poi getPoi(PoiType poiType, int i) {
    Poi poi = new Poi();
    poi.setType(poiType);
    poi.setName("MyPoi" + i);
    poi.setLatitude(42.0);
    poi.setLongitude(73.0);
    poi.setUpdated(false);
    Map<String, String> tags = new HashMap<>();
    tags.put("tag1", "value1");
    poi.applyChanges(tags);
    return poi;
}
Also used : HashMap(java.util.HashMap) Poi(io.jawg.osmcontributor.model.entities.Poi)

Example 35 with Poi

use of io.jawg.osmcontributor.model.entities.Poi in project osm-contributor by jawg.

the class PoiManagerTest method testBulkSaveAndBulkUpdate.

@Test
public void testBulkSaveAndBulkUpdate() {
    PoiManager poiManager = component.getPoiManager();
    PoiType poiType = poiManager.savePoiType(getPoiType());
    // try to save and then update 1000 pois.
    // 1000 because it can happen in real life and pose problems if we try to do an "IN" sql clause
    List<Poi> pois = new ArrayList<>(1000);
    for (int i = 0; i < 1000; i++) {
        pois.add(getPoi(poiType, i));
    }
    poiManager.savePois(pois);
    for (Poi poi : pois) {
        assertThat(poi.getId()).isNotNull();
    }
    for (Poi poi : pois) {
        Map<String, String> tags = new HashMap<>();
        tags.put("tag2", "value2");
        poi.getTags().clear();
        poi.applyChanges(tags);
    }
    List<Poi> savedPois = poiManager.savePois(pois);
    for (Poi poi : savedPois) {
        assertThat(poi.getTags()).hasSize(1);
        PoiTag tag = poi.getTags().iterator().next();
        assertThat(tag.getKey()).isEqualTo("tag2");
        assertThat(tag.getValue()).isEqualTo("value2");
    }
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) HashMap(java.util.HashMap) PoiType(io.jawg.osmcontributor.model.entities.PoiType) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiManager(io.jawg.osmcontributor.ui.managers.PoiManager) Test(org.junit.Test)

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