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)));
}
}
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);
}
}
}
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");
}
}
Aggregations