Add a source value to the MapWithAIInfo object

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-06-26 08:33:39 -06:00
rodzic 97dc67abc1
commit ab03e83100
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
3 zmienionych plików z 93 dodań i 13 usunięć

Wyświetl plik

@ -156,13 +156,17 @@ class BoundingBoxMapWithAIDownloader extends BoundingBoxDownloader {
OsmReader.Options.SAVE_ORIGINAL_ID);
}
if (url != null && info.getUrl() != null && !info.getUrl().trim().isEmpty()) {
GetDataRunnable.addMapWithAISourceTag(ds, getSourceTag(info));
if (info.getSource() != null) {
GetDataRunnable.addSourceTag(ds, info.getSource());
} else {
GetDataRunnable.addMapWithAISourceTag(ds, getMapWithAISourceTag(info));
}
}
GetDataRunnable.cleanup(ds, downloadArea, info);
return ds;
}
private static String getSourceTag(MapWithAIInfo info) {
private static String getMapWithAISourceTag(MapWithAIInfo info) {
return info.getName() == null ? MapWithAIPlugin.NAME : info.getName();
}

Wyświetl plik

@ -68,7 +68,16 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
private static final double ARTIFACT_ANGLE = 0.1745; // 10 degrees in radians
/**
* The source tag to be used to populate source values. Not seen on objects
* post-upload.
*/
public static final String MAPWITHAI_SOURCE_TAG_KEY = "mapwithai:source";
/**
* The source tag to be added to all objects from the source. Seen on objects
* post-upload.
*/
public static final String SOURCE_TAG_KEY = "source";
/**
* @param bbox The initial bbox to get data from (don't reduce beforehand --
@ -529,23 +538,39 @@ public class GetDataRunnable extends RecursiveTask<DataSet> {
/**
* Add source tags to primitives
*
* @param dataSet The dataset to add the mapwithai source tag to
* @param dataSet The dataset to add the mapwithai source tag to (not visible on
* object post-upload)
* @param source The source to associate with the data
* @return The dataset for easy chaining
*/
public static DataSet addMapWithAISourceTag(DataSet dataSet, String source) {
dataSet.getNodes().parallelStream().filter(GetDataRunnable::checkIfMapWithAISourceShouldBeAdded)
.filter(node -> node.getReferrers().isEmpty())
.forEach(node -> node.put(MAPWITHAI_SOURCE_TAG_KEY, source));
dataSet.getWays().parallelStream().filter(GetDataRunnable::checkIfMapWithAISourceShouldBeAdded)
.forEach(way -> way.put(MAPWITHAI_SOURCE_TAG_KEY, source));
dataSet.getRelations().parallelStream().filter(GetDataRunnable::checkIfMapWithAISourceShouldBeAdded)
.forEach(rel -> rel.put(MAPWITHAI_SOURCE_TAG_KEY, source));
return addTag(dataSet, MAPWITHAI_SOURCE_TAG_KEY, source);
}
/**
* Add source tags to primitives
*
* @param dataSet The dataset to add the source tag to (visible on object
* post-upload)
* @param source The source to associate with the data
* @return The dataset for easy chaining
*/
public static DataSet addSourceTag(DataSet dataSet, String source) {
return addTag(dataSet, SOURCE_TAG_KEY, source);
}
private static DataSet addTag(DataSet dataSet, String key, String value) {
dataSet.getNodes().parallelStream().filter(p -> checkIfMapWithAISourceShouldBeAdded(p, key))
.filter(node -> node.getReferrers().isEmpty()).forEach(node -> node.put(key, value));
dataSet.getWays().parallelStream().filter(p -> checkIfMapWithAISourceShouldBeAdded(p, key))
.forEach(way -> way.put(key, value));
dataSet.getRelations().parallelStream().filter(p -> checkIfMapWithAISourceShouldBeAdded(p, key))
.forEach(rel -> rel.put(key, value));
return dataSet;
}
private static boolean checkIfMapWithAISourceShouldBeAdded(OsmPrimitive prim) {
return !prim.isDeleted() && !prim.hasTag(MAPWITHAI_SOURCE_TAG_KEY);
private static boolean checkIfMapWithAISourceShouldBeAdded(OsmPrimitive prim, String key) {
return !prim.isDeleted() && !prim.hasTag(key);
}
/**

Wyświetl plik

@ -14,6 +14,8 @@ import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
@ -37,6 +39,11 @@ public class MapWithAIInfo extends
private Map<String, String> replacementTags;
private boolean conflate;
private String conflationUrl;
/**
* The preferred source string for the source. This is added as a source tag on
* the object _and_ is added to the changeset tags.
*/
private String source;
private JsonArray conflationParameters;
private String alreadyConflatedKey;
/** This is for categories that cannot be conflated */
@ -67,6 +74,8 @@ public class MapWithAIInfo extends
String categories;
@StructEntry
String alreadyConflatedKey;
@StructEntry
String source;
/**
* Constructs a new empty {@link MapWithAIPreferenceEntry}
@ -92,6 +101,7 @@ public class MapWithAIInfo extends
if (i.replacementTags != null) {
replacementTags = i.replacementTags;
}
source = i.source;
conflate = i.conflate;
conflationUrl = i.conflationUrl;
if (i.categories != null) {
@ -181,6 +191,7 @@ public class MapWithAIInfo extends
}
}
}
setSource(e.source);
if (e.replacementTags != null) {
setReplacementTags(e.replacementTags);
}
@ -237,6 +248,7 @@ public class MapWithAIInfo extends
setEulaAcceptanceRequired(i.getEulaAcceptanceRequired());
setBounds(i.getBounds());
setDescription(i.getDescription());
setSource(i.getSource());
this.langDescription = i.langDescription;
this.attributionText = i.attributionText;
this.privacyPolicyURL = i.privacyPolicyURL;
@ -271,6 +283,7 @@ public class MapWithAIInfo extends
&& Objects.equals(this.conflationParameters, other.conflationParameters)
&& Objects.equals(this.categories, other.categories)
&& Objects.equals(this.alreadyConflatedKey, other.alreadyConflatedKey)
&& (this.source == null || other.source == null || Objects.equals(this.source, other.source))
&& ((this.parameters == null && other.parameters == null)
|| Objects.equals(this.parameters, other.parameters));
// CHECKSTYLE.ON: BooleanExpressionComplexity
@ -281,16 +294,54 @@ public class MapWithAIInfo extends
localizedCountriesCache.put("", tr("Worldwide"));
}
/**
* Set the desired source for this object. This is added to source tags on
* objects and is reported via the source changeset tag.
*
* @param source The desired source
*/
public void setSource(String source) {
this.source = source;
}
/**
* Get the source string to be used for sources on objects and should be used in
* the source changeset tag.
*
* @return The desired source tag, or {@code null}.
*/
@CheckForNull
public String getSource() {
return this.source;
}
/**
* Set the MapWithAI category
*
* @param category (i.e., buildings, featured, preview, addresses, etc)
*/
public void setCategory(MapWithAICategory category) {
this.category = category;
}
/**
* Set the description for the info (may be shown in a mouse hover)
*
* @param description The description for the source
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Get the MapWithAI category
*
* @return The primary category (i.e., buildings, featured, preview, addresses,
* etc)
*/
@Nonnull
public MapWithAICategory getCategory() {
return category;
return category == null ? MapWithAICategory.OTHER.getDefault() : category;
}
public void setParameters(JsonArray parameters) {