Class DataExchangeHelper


  • public class DataExchangeHelper
    extends Object
    Helper class for communicating with a Data Exchange server.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • DataExchangeHelper

        public DataExchangeHelper()
    • Method Detail

      • initRequest

        protected static com.github.fracpete.requests4j.request.Request initRequest​(adams.core.base.BaseURL server,
                                                                                    AbstractClientAuthentication auth,
                                                                                    adams.core.MessageCollection errors)
      • upload

        public static String upload​(File file,
                                    adams.core.base.BaseURL server,
                                    AbstractClientAuthentication auth,
                                    adams.core.MessageCollection errors)
        Uploads the file to the data exchange server.
        Parameters:
        file - the file to upload
        server - the server to upload to
        auth - the authentication to use, needs to have the flow context set
        errors - for collecting errors
        Returns:
        the token, null in case of error
      • upload

        public static String upload​(byte[] data,
                                    adams.core.base.BaseURL server,
                                    AbstractClientAuthentication auth,
                                    adams.core.MessageCollection errors)
        Uploads the file to the data exchange server.
        Parameters:
        data - the data to upload
        server - the server to upload to
        auth - the authentication to use, needs to have the flow context set
        errors - for collecting errors
        Returns:
        the token, null in case of error
      • download

        public static byte[] download​(String token,
                                      adams.core.base.BaseURL server,
                                      AbstractClientAuthentication auth,
                                      adams.core.MessageCollection errors)
        Downloads the data associated with the token.
        Parameters:
        token - the token to use for downloading
        server - the server to connect to
        auth - the authentication to use
        errors - for collecting errors
        Returns:
        the data, null in case of an error
      • remove

        public static adams.flow.container.HttpRequestResult remove​(String token,
                                                                    adams.core.base.BaseURL server,
                                                                    AbstractClientAuthentication auth,
                                                                    adams.core.MessageCollection errors)
        Removes the data associated with the token.
        Parameters:
        token - the token to remove the data for
        server - the server to connect to
        auth - the authentication to use
        errors - for collecting errors
        Returns:
        the request response, null in case of an error
      • buildURL

        public static adams.core.base.BaseURL buildURL​(adams.core.base.BaseURL server,
                                                       String path)
        Builds the actual URL to use.
        Parameters:
        server - the server URL
        path - the path to append to the server's URL
        Returns:
        the complete URL