Search in sources :

Example 1 with PoiTag

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

the class PoiManager method savePoiNoTransaction.

/**
 * Method saving a poi and all the associated foreign collections without transaction management.
 * <p/>
 * Do not call the DAO directly to save a poi, use this method.
 *
 * @param poi The poi to save
 * @return The saved poi
 * @see #savePoi(Poi)
 */
private Poi savePoiNoTransaction(Poi poi) {
    List<PoiTag> poiTagsToRemove = poiTagDao.queryByPoiId(poi.getId());
    poiTagsToRemove.removeAll(poi.getTags());
    for (PoiTag poiTag : poiTagsToRemove) {
        poiTagDao.delete(poiTag);
    }
    List<PoiNodeRef> poiNodeRefsToRemove = poiNodeRefDao.queryByPoiId(poi.getId());
    poiNodeRefsToRemove.removeAll(poi.getNodeRefs());
    for (PoiNodeRef poiNodeRef : poiNodeRefsToRemove) {
        poiNodeRefDao.delete(poiNodeRef);
    }
    poiDao.createOrUpdate(poi);
    if (poi.getTags() != null) {
        for (PoiTag poiTag : poi.getTags()) {
            poiTag.setPoi(poi);
            poiTagDao.createOrUpdate(poiTag);
        }
    }
    if (poi.getNodeRefs() != null) {
        for (PoiNodeRef poiNodeRef : poi.getNodeRefs()) {
            poiNodeRef.setPoi(poi);
            poiNodeRefDao.createOrUpdate(poiNodeRef);
        }
    }
    return poi;
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) PoiNodeRef(io.jawg.osmcontributor.model.entities.PoiNodeRef)

Example 2 with PoiTag

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

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

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

the class EditPoiManager method onPleaseCreateNoTagPoiEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onPleaseCreateNoTagPoiEvent(PleaseCreateNoTagPoiEvent event) {
    Poi poi = new Poi();
    LatLng latLng = event.getLatLng();
    poi.setLatitude(latLng.getLatitude());
    poi.setLongitude(latLng.getLongitude());
    poi.setType(event.getPoiType());
    List<PoiTag> defaultTags = new ArrayList<>();
    for (PoiTypeTag poiTypeTag : poi.getType().getTags()) {
        if (poiTypeTag.getValue() != null) {
            // default tags should be set in the corresponding POI
            PoiTag poiTag = new PoiTag();
            poiTag.setKey(poiTypeTag.getKey());
            poiTag.setValue(poiTypeTag.getValue());
            defaultTags.add(poiTag);
        }
    }
    poi.setTags(defaultTags);
    poi.setUpdated(true);
    poiManager.savePoi(poi);
    poiManager.updatePoiTypeLastUse(event.getPoiType().getId());
    eventBus.post(new PoiNoTypeCreated());
}
Also used : PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) PoiNoTypeCreated(io.jawg.osmcontributor.ui.events.map.PoiNoTypeCreated) ArrayList(java.util.ArrayList) Poi(io.jawg.osmcontributor.model.entities.Poi) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) PoiTypeTag(io.jawg.osmcontributor.model.entities.PoiTypeTag) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 5 with PoiTag

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

the class EditPoiManager method applyConstraints.

private Map<String, String> applyConstraints(Poi poi) {
    Map<String, String> tagsMap = new HashMap<>();
    Collection<Constraint> constraints = poi.getType().getConstraints();
    if (constraints != null) {
        for (Constraint constraint : constraints) {
            Source source = constraint.getSource();
            Condition condition = constraint.getCondition();
            Action action = constraint.getAction();
            PoiTag poiTag = null;
            switch(source.getType()) {
                case TAG:
                    poiTag = findTagByKey(poi, source.getKey());
                    break;
            }
            switch(condition.getType()) {
                case EXISTS:
                    // if the value is true and tag exists
                    if (poiTag != null && condition.getValue().equalsIgnoreCase(Condition.ExistsValues.TRUE.getValue())) {
                        continue;
                    // if the value is false and tag doesn't exists
                    } else if (poiTag == null && condition.getValue().equalsIgnoreCase(Condition.ExistsValues.FALSE.getValue())) {
                        continue;
                    // If none is valid
                    } else {
                        break;
                    }
                case EQUALS:
                    if (poiTag != null && poiTag.getValue().equalsIgnoreCase(condition.getValue())) {
                        break;
                    }
                default:
                    continue;
            }
            switch(action.getType()) {
                case SET_TAG_VALUE:
                    // Add to map of tags
                    tagsMap.put(action.getKey(), action.getValue());
                    break;
                case REMOVE_TAG:
                    // Set value to empty string to remove
                    tagsMap.put(action.getKey(), "");
            }
        }
    }
    return tagsMap;
}
Also used : Condition(io.jawg.osmcontributor.model.entities.Condition) PoiTag(io.jawg.osmcontributor.model.entities.PoiTag) Action(io.jawg.osmcontributor.model.entities.Action) HashMap(java.util.HashMap) Constraint(io.jawg.osmcontributor.model.entities.Constraint) Source(io.jawg.osmcontributor.model.entities.Source)

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