Search in sources :

Example 1 with Task

use of org.openstreetmap.atlas.checks.maproulette.data.Task in project atlas-checks by osmlab.

the class MapRouletteClient method upload.

private void upload(final Tuple<String, String> key) {
    final Set<Task> batchList = this.batch.get(key);
    if (batchList != null && batchList.size() > 0) {
        try {
            // retrieve the already created project and challenge
            final Project project = this.projects.get(key.getFirst());
            if (project == null) {
                logger.warn("Failed to upload batch to MapRoulette, Project {} has not been created.", key.getFirst());
            } else {
                final Challenge challenge = this.challenges.get(project.getId()).get(key.getSecond());
                if (challenge == null) {
                    logger.warn("Failed to upload batch to MapRoulette, Challenge {} has not been created.", key.getSecond());
                } else {
                    this.connection.uploadBatchTasks(challenge.getId(), batchList);
                    batchList.clear();
                }
            }
        } catch (final UnsupportedEncodingException e) {
            logger.debug("Failed to upload batch to map roulette [{}]", this.connection.getConnectionInfo());
        } catch (final URISyntaxException e) {
            logger.debug("Failed to upload batch to map roulette", e);
        }
    }
}
Also used : Project(org.openstreetmap.atlas.checks.maproulette.data.Project) Task(org.openstreetmap.atlas.checks.maproulette.data.Task) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URISyntaxException(java.net.URISyntaxException) Challenge(org.openstreetmap.atlas.checks.maproulette.data.Challenge)

Example 2 with Task

use of org.openstreetmap.atlas.checks.maproulette.data.Task in project atlas-checks by osmlab.

the class CheckFlag method getMapRouletteTask.

/**
 * Builds a MapRouletted {@link Task} from this {@link CheckFlag}
 *
 * @return a {@link Task}
 */
public Task getMapRouletteTask() {
    final Task task = new Task();
    task.setInstruction(this.getInstructions());
    task.setProjectName(this.getCountryISO());
    task.setChallengeName(this.getChallengeName().orElse(this.getClass().getSimpleName()));
    task.setTaskIdentifier(this.identifier);
    // Add custom pin point(s), if supplied.
    final Set<Location> points = getPoints();
    if (!points.isEmpty()) {
        task.setPoints(points);
    } else {
        final Set<PolyLine> polyLines = getPolyLines();
        if (!polyLines.isEmpty()) {
            // Retrieve the first item in the list and retrieve the first point in the
            // geometry for the object
            task.setPoint(polyLines.iterator().next().iterator().next());
        }
    }
    final JsonArray features = new JsonArray();
    this.getLocationIterableProperties().forEach(shape -> features.add(new GeoJsonBuilder().create(shape)));
    task.setGeoJson(Optional.of(features));
    return task;
}
Also used : JsonArray(com.google.gson.JsonArray) Task(org.openstreetmap.atlas.checks.maproulette.data.Task) PolyLine(org.openstreetmap.atlas.geography.PolyLine) GeoJsonBuilder(org.openstreetmap.atlas.geography.geojson.GeoJsonBuilder) Location(org.openstreetmap.atlas.geography.Location)

Aggregations

Task (org.openstreetmap.atlas.checks.maproulette.data.Task)2 JsonArray (com.google.gson.JsonArray)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 Challenge (org.openstreetmap.atlas.checks.maproulette.data.Challenge)1 Project (org.openstreetmap.atlas.checks.maproulette.data.Project)1 Location (org.openstreetmap.atlas.geography.Location)1 PolyLine (org.openstreetmap.atlas.geography.PolyLine)1 GeoJsonBuilder (org.openstreetmap.atlas.geography.geojson.GeoJsonBuilder)1