Search in sources :

Example 1 with CombinationsDto

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;
}
Also used : CombinationsDataDto(io.jawg.osmcontributor.rest.dtos.osm.CombinationsDataDto) PoiType(io.jawg.osmcontributor.model.entities.PoiType) ArrayList(java.util.ArrayList) Wiki(io.jawg.osmcontributor.rest.dtos.osm.Wiki) CombinationsDto(io.jawg.osmcontributor.rest.dtos.osm.CombinationsDto) PoiTypeTag(io.jawg.osmcontributor.model.entities.PoiTypeTag) WikiDataDto(io.jawg.osmcontributor.rest.dtos.osm.WikiDataDto)

Aggregations

PoiType (io.jawg.osmcontributor.model.entities.PoiType)1 PoiTypeTag (io.jawg.osmcontributor.model.entities.PoiTypeTag)1 CombinationsDataDto (io.jawg.osmcontributor.rest.dtos.osm.CombinationsDataDto)1 CombinationsDto (io.jawg.osmcontributor.rest.dtos.osm.CombinationsDto)1 Wiki (io.jawg.osmcontributor.rest.dtos.osm.Wiki)1 WikiDataDto (io.jawg.osmcontributor.rest.dtos.osm.WikiDataDto)1 ArrayList (java.util.ArrayList)1