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