use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.
the class TypeManager method onInternalSavePoiTypeEvent.
// ********************************
// ************ Events ************
// ********************************
@Subscribe(threadMode = ThreadMode.ASYNC)
public void onInternalSavePoiTypeEvent(InternalSavePoiTypeEvent event) {
PoiType poiType = event.getPoiType();
poiManager.savePoiType(poiType);
bus.post(new PoiTypeCreatedEvent(poiType));
}
use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.
the class TypeListActivityPresenter method onPleaseSavePoiTag.
/* ========== POI type/tag edition ========== */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onPleaseSavePoiTag(PleaseSavePoiTag event) {
PoiTypeTag poiTypeTag = null;
PoiType poiType = currentPoiType;
if (poiType == null) {
throw new IllegalStateException("Not currently displaying tags of a specific POI type");
}
Long id = event.getId();
if (id != null) {
// We edit an existing tag, so find it in the list...
for (PoiTypeTag tag : poiType.getTags()) {
if (tag.getId().equals(id)) {
poiTypeTag = tag;
break;
}
}
if (poiTypeTag == null) {
throw new IllegalStateException("Edited tag not found in current POI type");
}
} else {
// Create a new tag
poiTypeTag = new PoiTypeTag();
poiTypeTag.setPoiType(poiType);
Collection<PoiTypeTag> tags = poiType.getTags();
poiTypeTag.setOrdinal(tags.size());
tags.add(poiTypeTag);
}
poiTypeTag.setKey(event.getKey());
poiTypeTag.setValue(event.getValue());
poiTypeTag.setMandatory(event.isMandatory());
typeManager.savePoiTag(poiTypeTag);
}
use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.
the class SyncManager method syncDownloadPoiTypes.
// ********************************
// ************ public ************
// ********************************
/**
* Download the list of PoiType from the backend and actualize the database.
* <br/>
* If there was new, modified or a deleted PoiType, send a
* {@link PoiTypesLoaded} event containing the new list of PoiTypes.
*/
public void syncDownloadPoiTypes() {
List<PoiType> poiTypes = backend.getPoiTypes();
PoiType dbPoiType;
boolean modified = false;
List<PoiType> oldTypes = poiTypeDao.queryForAll();
// Create and update the PoiTypes in database with the result from backend
for (PoiType type : poiTypes) {
dbPoiType = type.getBackendId() != null ? poiTypeDao.findByBackendId(type.getBackendId()) : null;
if (dbPoiType != null) {
type.setId(dbPoiType.getId());
}
type = poiManager.savePoiType(type);
if (!modified && !type.equals(dbPoiType)) {
modified = true;
}
}
// Delete from database the PoiTypes who aren't in the new list of the backend.
for (PoiType type : oldTypes) {
if (!poiTypes.contains(type)) {
poiManager.deletePoiType(type);
modified = true;
}
}
if (modified) {
bus.postSticky(new PoiTypesLoaded(poiManager.getPoiTypesSortedByName()));
}
}
use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.
the class PoiTypePickerAdapter method getView.
@Override
public View getView(int position, View view, ViewGroup parent) {
ViewHolder holder = null;
if (view != null) {
holder = (ViewHolder) view.getTag();
if (holder instanceof ExpertViewHolder ^ expertMode) {
holder = null;
}
}
if (holder == null) {
if (expertMode) {
view = inflater.inflate(R.layout.single_expert_poitype_autocomplete_layout, parent, false);
holder = new ExpertViewHolder(view);
} else {
view = inflater.inflate(R.layout.single_poitype_autocomplete_layout, parent, false);
holder = new ViewHolder(view);
}
view.setTag(holder);
}
final PoiType value = filteredValues.get(position);
holder.onBind(value);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
eventBus.post(new NewPoiTypeSelected(value));
closeKeyboard();
}
});
return view;
}
use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.
the class PoiTypeMapper method convert.
private PoiType convert(PoiTypeDto dto) {
PoiType type = new PoiType();
type.setName(getTranslationFormJson(dto.getLabel(), getName(dto.getName())));
type.setTechnicalName(dto.getName());
type.setDescription(getTranslationFormJson(dto.getDescription(), ""));
type.setKeyWords(getKeywordsFormJson(dto.getKeywords()));
type.setIcon(getName(dto.getName()));
// When creating a new PoiType from file, put the same date of last use to all new PoiTypes : 1970-01-01T00:00:00Z
type.setLastUse(dateTime);
int ordinal = 0;
if (dto.getTags() != null) {
ArrayList<PoiTypeTag> tags = new ArrayList<>(dto.getTags().size());
type.setTags(tags);
type.setQuery(dto.getQuery());
for (PoiTypeTagDto tagDto : dto.getTags()) {
// If the tag is implied, do not keep it
PoiTypeTag poiTypeTag = new PoiTypeTag();
poiTypeTag.setPoiType(type);
poiTypeTag.setKey(tagDto.getKey());
poiTypeTag.setValue(tagDto.getValue());
poiTypeTag.setMandatory(tagDto.getRequired());
poiTypeTag.setOrdinal(ordinal++);
poiTypeTag.setShow(tagDto.getShow());
if (tagDto.getValues() != null && !tagDto.getValues().isEmpty()) {
List<String> possibleValues = new ArrayList<>();
for (Map<String, Map<String, String>> valuesMap : tagDto.getValues()) {
for (Map.Entry<String, Map<String, String>> value : valuesMap.entrySet()) {
possibleValues.add(value.getKey() + VALUE_SEPARATOR + getTranslationFormJson(value.getValue(), ""));
}
}
poiTypeTag.setPossibleValues(getPossibleValues(possibleValues));
}
poiTypeTag.setTagType(tagDto.getType());
tags.add(poiTypeTag);
}
}
ordinal = 0;
if (dto.getConstraints() != null) {
ArrayList<Constraint> constraints = new ArrayList<>();
type.setConstraints(constraints);
for (ConstraintDto constraintDto : dto.getConstraints()) {
// Constraint's Source
Source source = Source.builder().setType(constraintDto.getSource().getType()).setKey(constraintDto.getSource().getKey()).build();
// Constraint's Condition
Condition condition = Condition.builder().setType(constraintDto.getCondition().getType()).setValue(constraintDto.getCondition().getValue()).build();
// Constraint's Action
Action action = Action.builder().setType(constraintDto.getAction().getType()).setKey(constraintDto.getAction().getKey()).setValue(constraintDto.getAction().getValue()).build();
// Complete constraint
Constraint constraint = Constraint.builder().setPoiType(type).setSource(source).setCondition(condition).setAction(action).setOrdinal(ordinal++).build();
// Add constraint to the list
constraints.add(constraint);
}
}
return type;
}
Aggregations