Search in sources :

Example 6 with PoiTag

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

the class PoiUpdateWrapper method initDescriptions.

private void initDescriptions() {
    Collection<PoiTag> oldTags = oldPoi == null ? new ArrayList<PoiTag>() : oldPoi.getTags();
    Collection<PoiTag> newTags = newPoi == null ? new ArrayList<PoiTag>() : newPoi.getTags();
    Map<String, String> newTagsMap = new HashMap<>();
    // if the poi is deleted there is not any new values
    if (action != PoiAction.DELETED) {
        // add all new tags in a map
        for (PoiTag poiTag : newTags) {
            newTagsMap.put(poiTag.getKey(), poiTag.getValue());
        }
    }
    // add all old tags with the new value if there is one
    for (PoiTag poiTagOld : oldTags) {
        String key = poiTagOld.getKey();
        String newTagValue = null;
        if (newTagsMap.containsKey(key)) {
            newTagValue = newTagsMap.remove(key);
        }
        poiDiff.add(new PoiDiffWrapper(key, poiTagOld.getValue(), newTagValue));
    }
    // adding all tags created by the user
    for (String key : newTagsMap.keySet()) {
        poiDiff.add(new PoiDiffWrapper(key, null, newTagsMap.get(key)));
    }
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) HashMap(java.util.HashMap)

Example 7 with PoiTag

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

the class TagMapper method mapPoiTags.

/**
 * Map all remaining tags of the poi not referenced in the PoiType.
 */
private void mapPoiTags() {
    for (PoiTag poiTag : poi.getTags()) {
        String key = poiTag.getKey();
        String value = poiTag.getValue();
        Map<String, String> values = removeDuplicate(tagValueSuggestionsMap.get(key), Collections.singletonList(value));
        TagItem tagItem = new SingleTagItem.SingleTagItemBuilder(key, value).mandatory(false).values(values).type(TEXT).isConform(true).show(true).build();
        if (!mappedTags.contains(tagItem) && !constantTags.contains(tagItem)) {
            mappedTags.add(getPosition(false), tagItem);
        }
    }
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag)

Example 8 with PoiTag

use of io.jawg.osmcontributor.model.entities.PoiTag 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

PoiTag (io.jawg.osmcontributor.model.entities.PoiTag)8 ArrayList (java.util.ArrayList)4 Poi (io.jawg.osmcontributor.model.entities.Poi)3 HashMap (java.util.HashMap)3 PoiNodeRef (io.jawg.osmcontributor.model.entities.PoiNodeRef)2 PoiType (io.jawg.osmcontributor.model.entities.PoiType)2 TagDto (io.jawg.osmcontributor.rest.dtos.osm.TagDto)2 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 Action (io.jawg.osmcontributor.model.entities.Action)1 Condition (io.jawg.osmcontributor.model.entities.Condition)1 Constraint (io.jawg.osmcontributor.model.entities.Constraint)1 PoiTypeTag (io.jawg.osmcontributor.model.entities.PoiTypeTag)1 Source (io.jawg.osmcontributor.model.entities.Source)1 NdDto (io.jawg.osmcontributor.rest.dtos.osm.NdDto)1 PoiNoTypeCreated (io.jawg.osmcontributor.ui.events.map.PoiNoTypeCreated)1 PoiManager (io.jawg.osmcontributor.ui.managers.PoiManager)1 Subscribe (org.greenrobot.eventbus.Subscribe)1 Test (org.junit.Test)1