Class MapRouletteConnection

  • All Implemented Interfaces:
    java.io.Serializable, TaskLoader

    public class MapRouletteConnection
    extends java.lang.Object
    implements TaskLoader, java.io.Serializable
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long create​(java.lang.String getURI, java.lang.String postURI, java.lang.String putURI, com.google.gson.JsonObject data, java.lang.String logSuccessMessage)
      Will create a challenge if it has not already been created
      long createChallenge​(Project project, Challenge challenge)
      Creates a new challenge with the given Challenge, if already exists then will attempt to update
      long createProject​(Project project)
      Creates a new project with the Project, if already exists then will attempt to update
      java.lang.String getConnectionInfo()
      Retrieve the connection info for this connection
      org.openstreetmap.atlas.streaming.resource.http.HttpResource setAuth​(org.openstreetmap.atlas.streaming.resource.http.HttpResource resource)  
      boolean uploadBatchTasks​(long challengeId, java.util.Set<Task> data)
      Uploads tasks as a batch, instead of one at a time
      boolean uploadTask​(long challengeId, Task task)
      Uploads a task to MapRoulette
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • create

        public long create​(java.lang.String getURI,
                           java.lang.String postURI,
                           java.lang.String putURI,
                           com.google.gson.JsonObject data,
                           java.lang.String logSuccessMessage)
                    throws java.io.UnsupportedEncodingException,
                           java.net.URISyntaxException
        Will create a challenge if it has not already been created
        Parameters:
        getURI - The URI used to retrieve the object
        postURI - The URI used to create the object
        putURI - The URI used to update the object
        data - The data of the object to create/update
        logSuccessMessage - The message to display on successful creation/update of object
        Returns:
        The id of the created object
        Throws:
        java.io.UnsupportedEncodingException - if cannot encode string for post/put to map roulette
        java.net.URISyntaxException - if URI supplied is invalid and cannot be built
      • createChallenge

        public long createChallenge​(Project project,
                                    Challenge challenge)
                             throws java.io.UnsupportedEncodingException,
                                    java.net.URISyntaxException
        Description copied from interface: TaskLoader
        Creates a new challenge with the given Challenge, if already exists then will attempt to update
        Specified by:
        createChallenge in interface TaskLoader
        Parameters:
        project - The parent project object of the challenge
        challenge - The challenge to create or update
        Returns:
        The id for the challenge
        Throws:
        java.io.UnsupportedEncodingException - if json data for API payload cannot be encoded correctly
        java.net.URISyntaxException - if the URI for getting/creating/updating project is incorrectly generated
      • createProject

        public long createProject​(Project project)
                           throws java.io.UnsupportedEncodingException,
                                  java.net.URISyntaxException
        Description copied from interface: TaskLoader
        Creates a new project with the Project, if already exists then will attempt to update
        Specified by:
        createProject in interface TaskLoader
        Parameters:
        project - The project object containing name and description
        Returns:
        The id for the project
        Throws:
        java.io.UnsupportedEncodingException - if json data for API payload cannot be encoded correctly
        java.net.URISyntaxException - if the URI for getting/creating/updating project is incorrectly generated
      • getConnectionInfo

        public java.lang.String getConnectionInfo()
        Description copied from interface: TaskLoader
        Retrieve the connection info for this connection
        Specified by:
        getConnectionInfo in interface TaskLoader
        Returns:
        A string
      • setAuth

        public org.openstreetmap.atlas.streaming.resource.http.HttpResource setAuth​(org.openstreetmap.atlas.streaming.resource.http.HttpResource resource)
      • uploadBatchTasks

        public boolean uploadBatchTasks​(long challengeId,
                                        java.util.Set<Task> data)
                                 throws java.io.UnsupportedEncodingException,
                                        java.net.URISyntaxException
        Description copied from interface: TaskLoader
        Uploads tasks as a batch, instead of one at a time
        Specified by:
        uploadBatchTasks in interface TaskLoader
        Parameters:
        challengeId - The id of the parent challenge
        data - The list of tasks that should be uploaded for the challenge
        Returns:
        The JSON payload used to upload the task
        Throws:
        java.io.UnsupportedEncodingException - Exception could be thrown when you try and upload the batch.
        java.net.URISyntaxException - if the URI cannot be built correctly
      • uploadTask

        public boolean uploadTask​(long challengeId,
                                  Task task)
                           throws java.io.UnsupportedEncodingException,
                                  java.net.URISyntaxException
        Description copied from interface: TaskLoader
        Uploads a task to MapRoulette
        Specified by:
        uploadTask in interface TaskLoader
        Parameters:
        challengeId - The id of the parent challenge
        task - The JSON payload used to upload the task
        Returns:
        true if the task was uploaded successfully
        Throws:
        java.io.UnsupportedEncodingException - If the JSON is invalid, which it never should be
        java.net.URISyntaxException - if the URI cannot be built correctly