Search in sources :

Example 1 with Challenge

use of org.openstreetmap.atlas.checks.maproulette.data.Challenge 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 Challenge

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

the class ChallengeDeserializer method deserialize.

@Override
public Challenge deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
    final JsonObject challengeObject = json.getAsJsonObject();
    ChallengeDifficulty difficulty;
    try {
        difficulty = ChallengeDifficulty.valueOf(this.getStringValue(challengeObject, KEY_DIFFICULTY, ""));
    } catch (final IllegalArgumentException e) {
        logger.trace("Failed to read difficulty value from Challenge JSON, defaulting to EASY");
        difficulty = ChallengeDifficulty.EASY;
    }
    ChallengePriority priority;
    try {
        priority = ChallengePriority.valueOf(this.getStringValue(challengeObject, Challenge.KEY_DEFAULT_PRIORITY, ""));
    } catch (final IllegalArgumentException e) {
        logger.trace("Failed to read priority value from Challenge JSON, defaulting to NONE");
        priority = ChallengePriority.NONE;
    }
    return new Challenge(this.getStringValue(challengeObject, Challenge.KEY_NAME, ""), this.getStringValue(challengeObject, KEY_DESCRIPTION, ""), this.getStringValue(challengeObject, KEY_BLURB, ""), this.getStringValue(challengeObject, KEY_INSTRUCTION, ""), difficulty, priority, this.getValue(challengeObject, Challenge.KEY_HIGH_PRIORITY, null), this.getValue(challengeObject, Challenge.KEY_MEDIUM_PRIORITY, null), this.getValue(challengeObject, Challenge.KEY_LOW_PRIORITY, null), this.getStringValue(challengeObject, Challenge.KEY_TAGS, ""));
}
Also used : JsonObject(com.google.gson.JsonObject) ChallengePriority(org.openstreetmap.atlas.checks.maproulette.data.ChallengePriority) ChallengeDifficulty(org.openstreetmap.atlas.checks.maproulette.data.ChallengeDifficulty) Challenge(org.openstreetmap.atlas.checks.maproulette.data.Challenge)

Aggregations

Challenge (org.openstreetmap.atlas.checks.maproulette.data.Challenge)2 JsonObject (com.google.gson.JsonObject)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URISyntaxException (java.net.URISyntaxException)1 ChallengeDifficulty (org.openstreetmap.atlas.checks.maproulette.data.ChallengeDifficulty)1 ChallengePriority (org.openstreetmap.atlas.checks.maproulette.data.ChallengePriority)1 Project (org.openstreetmap.atlas.checks.maproulette.data.Project)1 Task (org.openstreetmap.atlas.checks.maproulette.data.Task)1