Search in sources :

Example 1 with TagDto

use of io.jawg.osmcontributor.rest.dtos.osm.TagDto in project osm-contributor by jawg.

the class PoiMapperTest method tagDto.

private TagDto tagDto(String key1, String value) {
    TagDto tagDto = new TagDto();
    tagDto.setKey(key1);
    tagDto.setValue(value);
    return tagDto;
}
Also used : TagDto(io.jawg.osmcontributor.rest.dtos.osm.TagDto)

Example 2 with TagDto

use of io.jawg.osmcontributor.rest.dtos.osm.TagDto in project osm-contributor by jawg.

the class PoiMapperTest method getNodeDto.

private NodeDto getNodeDto(String... tags) {
    NodeDto nodeDto = new NodeDto();
    nodeDto.setLat(1.0);
    nodeDto.setLon(1.0);
    List<TagDto> tagDtos = new ArrayList<>();
    if (tags.length % 2 != 0) {
        throw new AssertionError("Malformed tags ! Array must be an even number");
    }
    for (int i = 0; i < tags.length; i += 2) {
        tagDtos.add(tagDto(tags[i], tags[i + 1]));
    }
    nodeDto.setTagsDtoList(tagDtos);
    return nodeDto;
}
Also used : TagDto(io.jawg.osmcontributor.rest.dtos.osm.TagDto) ArrayList(java.util.ArrayList) NodeDto(io.jawg.osmcontributor.rest.dtos.osm.NodeDto)

Example 3 with TagDto

use of io.jawg.osmcontributor.rest.dtos.osm.TagDto in project osm-contributor by jawg.

the class PoiMapper method convertDtoToPoi.

public Poi convertDtoToPoi(boolean typeFiltering, List<PoiType> availableTypes, PoiDto dto) {
    List<PoiNodeRef> nodeRefs = new ArrayList<>();
    List<PoiTag> tags = new ArrayList<>();
    PoiType type;
    if (FlavorUtils.isBus()) {
        type = availableTypes.get(0);
    } else {
        type = findType(dto, availableTypes);
    }
    if (type == null && typeFiltering) {
        return null;
    }
    Poi poi = new Poi();
    poi.setType(type);
    poi.setLatitude(dto.getLat());
    poi.setLongitude(dto.getLon());
    poi.setBackendId(dto.getId());
    poi.setVersion(String.valueOf(dto.getVersion()));
    poi.setUpdated(false);
    poi.setUpdateDate(dto.getTimestamp());
    poi.setWay(dto.isWay());
    for (TagDto tagDto : dto.getTagsDtoList()) {
        PoiTag tag = new PoiTag();
        tag.setPoi(poi);
        tag.setKey(tagDto.getKey());
        tag.setValue(tagDto.getValue());
        tags.add(tag);
        if (tag.getKey().equals("name")) {
            poi.setName(tag.getValue());
        }
        if (tag.getKey().equals("level")) {
            poi.setLevel(tag.getValue());
        }
    }
    poi.setTags(tags);
    int counter = 0;
    for (NdDto ndDto : dto.getNdDtoList()) {
        PoiNodeRef nodeRef = new PoiNodeRef();
        nodeRef.setPoi(poi);
        nodeRef.setNodeBackendId(ndDto.getRef());
        nodeRef.setOrdinal(counter++);
        nodeRef.setLatitude(ndDto.getLat());
        nodeRef.setLongitude(ndDto.getLon());
        nodeRef.setUpdated(false);
        nodeRefs.add(nodeRef);
    }
    poi.setNodeRefs(nodeRefs);
    return poi;
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) NdDto(io.jawg.osmcontributor.rest.dtos.osm.NdDto) ArrayList(java.util.ArrayList) PoiType(io.jawg.osmcontributor.model.entities.PoiType) TagDto(io.jawg.osmcontributor.rest.dtos.osm.TagDto) Poi(io.jawg.osmcontributor.model.entities.Poi) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef)

Example 4 with TagDto

use of io.jawg.osmcontributor.rest.dtos.osm.TagDto in project osm-contributor by jawg.

the class PoiTagMapper method convertFromPoiTag.

public List<TagDto> convertFromPoiTag(Collection<PoiTag> poiTags) {
    List<TagDto> result = new ArrayList<>();
    for (PoiTag tag : poiTags) {
        TagDto tagDto = new TagDto();
        tagDto.setKey(tag.getKey());
        tagDto.setValue(tag.getValue());
        result.add(tagDto);
    }
    return result;
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) TagDto(io.jawg.osmcontributor.rest.dtos.osm.TagDto) ArrayList(java.util.ArrayList)

Example 5 with TagDto

use of io.jawg.osmcontributor.rest.dtos.osm.TagDto in project osm-contributor by jawg.

the class OsmBackend method initializeTransaction.

/**
 * {@inheritDoc}
 */
@Override
public String initializeTransaction(String comment) {
    final OsmDto osmDto = new OsmDto();
    ChangeSetDto changeSetDto = new ChangeSetDto();
    List<TagDto> tagDtos = new ArrayList<>();
    osmDto.setChangeSetDto(changeSetDto);
    tagDtos.add(new TagDto(comment, "comment"));
    tagDtos.add(new TagDto(BuildConfig.APP_NAME + " " + BuildConfig.VERSION_NAME, "created_by"));
    changeSetDto.setTagDtoList(tagDtos);
    Call<ResponseBody> callChangeSet;
    if (loginPreferences.retrieveOAuthParams() != null) {
        callChangeSet = osmRestClient.addChangeSet(AuthenticationRequestInterceptor.getOAuthRequest(loginPreferences, BuildConfig.BASE_OSM_URL + "changeset/create", Verb.PUT).getOAuthHeader(), osmDto);
    } else {
        callChangeSet = osmRestClient.addChangeSet(osmDto);
    }
    try {
        Response<ResponseBody> response = callChangeSet.execute();
        if (response.isSuccessful() && response.body() != null) {
            return response.body().string();
        }
    } catch (IOException e) {
        Timber.e("Retrofit error, couldn't create Changeset!");
    }
    bus.post(new SyncUploadRetrofitErrorEvent(-1L));
    return null;
}
Also used : OsmDto(io.jawg.osmcontributor.rest.dtos.osm.OsmDto) ChangeSetDto(io.jawg.osmcontributor.rest.dtos.osm.ChangeSetDto) TagDto(io.jawg.osmcontributor.rest.dtos.osm.TagDto) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SyncUploadRetrofitErrorEvent(io.jawg.osmcontributor.rest.events.error.SyncUploadRetrofitErrorEvent) ResponseBody(okhttp3.ResponseBody)

Aggregations

TagDto (io.jawg.osmcontributor.rest.dtos.osm.TagDto)5 ArrayList (java.util.ArrayList)4 PoiTag (io.jawg.osmcontributor.model.entities.PoiTag)2 Poi (io.jawg.osmcontributor.model.entities.Poi)1 PoiNodeRef (io.jawg.osmcontributor.model.entities.PoiNodeRef)1 PoiType (io.jawg.osmcontributor.model.entities.PoiType)1 ChangeSetDto (io.jawg.osmcontributor.rest.dtos.osm.ChangeSetDto)1 NdDto (io.jawg.osmcontributor.rest.dtos.osm.NdDto)1 NodeDto (io.jawg.osmcontributor.rest.dtos.osm.NodeDto)1 OsmDto (io.jawg.osmcontributor.rest.dtos.osm.OsmDto)1 SyncUploadRetrofitErrorEvent (io.jawg.osmcontributor.rest.events.error.SyncUploadRetrofitErrorEvent)1 IOException (java.io.IOException)1 ResponseBody (okhttp3.ResponseBody)1