use of io.jawg.osmcontributor.rest.dtos.osm.CombinationsDto in project osm-contributor by jawg.
the class TypeManager method getPoiTypeSuggested.
// *********************************
// ************ private ************
// *********************************
/**
* Return the PoiType suggested for a given key.
*
* @param key The name of the wished PoiType.
* @return The suggested PoiType.
*/
private PoiType getPoiTypeSuggested(String key) {
if (StringUtils.isEmpty(key)) {
return null;
}
Wiki wiki = tagInfoRestClient.getWikiPages(key);
PoiType poiType = new PoiType();
poiType.setName(key);
poiType.setIcon(key);
poiType.setLastUse(DateTime.now());
int ordinal = 0;
List<PoiTypeTag> poiTypeTags = new ArrayList<>();
// Request for the English wiki and keep the tags of the tags_combination field.
for (WikiDataDto data : wiki.getDatas()) {
if ("en".equals(data.getLang())) {
for (String tagCombination : data.getTagsCombination()) {
String[] splitResult = tagCombination.split("=");
if (splitResult.length > 1) {
poiTypeTags.add(PoiTypeTag.builder().key(splitResult[0]).value(splitResult[1]).mandatory(true).poiType(poiType).ordinal(ordinal++).build());
} else {
poiTypeTags.add(PoiTypeTag.builder().key(tagCombination).mandatory(false).poiType(poiType).ordinal(ordinal++).build());
}
}
break;
}
}
// If there was no relevant information in the English wiki, query for tags combinations.
if (poiTypeTags.size() == 0) {
CombinationsDto combinationsDto = tagInfoRestClient.getCombinations(key, 1, 5);
for (CombinationsDataDto data : combinationsDto.getData()) {
if (tagsGroup.contains(data.getOtherKey())) {
poiTypeTags.add(PoiTypeTag.builder().key(data.getOtherKey()).value(key).mandatory(true).poiType(poiType).ordinal(ordinal++).build());
} else {
poiTypeTags.add(PoiTypeTag.builder().key(data.getOtherKey()).mandatory(false).poiType(poiType).ordinal(ordinal++).build());
}
}
}
poiType.setTags(poiTypeTags);
return poiType;
}
Aggregations