// Path: app/src/main/java/org/secuso/privacyfriendlyweather/http/HttpRequestType.java
// public enum HttpRequestType {
//     POST,
//     GET,
//     PUT,
//     DELETE
// }
// 
// Path: app/src/main/java/org/secuso/privacyfriendlyweather/http/IHttpRequest.java
// public interface IHttpRequest {
// 
//     /**
//      * Makes an HTTP request and processes the response.
//      *
//      * @param URL              The target of the HTTP request.
//      * @param method           Which method to use for the HTTP request (e.g. GET or POST)
//      * @param requestProcessor This object with its implemented methods processSuccessScenario and
//      *                         processFailScenario defines how to handle the response in the success
//      *                         and error case respectively.
//      */
//     void make(final String URL, HttpRequestType method, IProcessHttpRequest requestProcessor);
// 
// }
// 
// Path: app/src/main/java/org/secuso/privacyfriendlyweather/http/VolleyHttpRequest.java
// public class VolleyHttpRequest implements IHttpRequest {
// 
//     private Context context;
// 
//     /**
//      * Constructor.
//      *
//      * @param context Volley needs a context "for creating the cache dir".
//      * @see Volley#newRequestQueue(Context)
//      */
//     public VolleyHttpRequest(Context context) {
//         this.context = context;
//     }
// 
//     /**
//      * @see IHttpRequest#make(String, HttpRequestType, IProcessHttpRequest)
//      */
//     @Override
//     public void make(String URL, HttpRequestType method, final IProcessHttpRequest requestProcessor) {
//         RequestQueue queue = Volley.newRequestQueue(context, new HurlStack(null, getSocketFactory()));
// 
//         // Set the request method
//         int requestMethod;
//         switch (method) {
//             case POST:
//                 requestMethod = Request.Method.POST;
//                 break;
//             case GET:
//                 requestMethod = Request.Method.GET;
//                 break;
//             case PUT:
//                 requestMethod = Request.Method.PUT;
//                 break;
//             case DELETE:
//                 requestMethod = Request.Method.DELETE;
//                 break;
//             default:
//                 requestMethod = Request.Method.GET;
//         }
// 
//         // Execute the request and handle the response
//         StringRequest stringRequest = new StringRequest(requestMethod, URL,
//                 new Response.Listener<String>() {
//                     @Override
//                     public void onResponse(String response) {
//                         requestProcessor.processSuccessScenario(response);
//                     }
//                 },
//                 new Response.ErrorListener() {
//                     @Override
//                     public void onErrorResponse(VolleyError error) {
//                         requestProcessor.processFailScenario(error);
//                     }
//                 }
//         );
// 
//         queue.add(stringRequest);
//     }
// 
//     private SSLSocketFactory getSocketFactory() {
// 
//         CertificateFactory cf = null;
//         try {
//             // Load CAs from an InputStream
//             cf = CertificateFactory.getInstance("X.509");
//             InputStream caInput = new BufferedInputStream(context.getAssets().open("SectigoRSADomainValidationSecureServerCA.crt"));
// 
//             Certificate ca;
//             try {
//                 ca = cf.generateCertificate(caInput);
//                 Log.e("CERT", "ca=" + ((X509Certificate) ca).getSubjectDN());
//             } finally {
//                 caInput.close();
//             }
// 
//             // Create a KeyStore containing our trusted CAs
//             String keyStoreType = KeyStore.getDefaultType();
//             KeyStore keyStore = KeyStore.getInstance(keyStoreType);
//             keyStore.load(null, null);
//             keyStore.setCertificateEntry("ca", ca);
// 
//             // Create a TrustManager that trusts the CAs in our KeyStore
//             String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
//             TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
//             tmf.init(keyStore);
// 
//             // Create an SSLContext that uses our TrustManager
//             SSLContext context = SSLContext.getInstance("TLS");
//             context.init(null, tmf.getTrustManagers(), null);
// 
//             SSLSocketFactory sf = context.getSocketFactory();
// 
//             return sf;
// 
//         } catch (CertificateException e) {
//             Log.e("CERT", "CertificateException");
//             e.printStackTrace();
//         } catch (NoSuchAlgorithmException e) {
//             Log.e("CERT", "NoSuchAlgorithmException");
//             e.printStackTrace();
//         } catch (KeyStoreException e) {
//             Log.e("CERT", "KeyStoreException");
//             e.printStackTrace();
//         } catch (FileNotFoundException e) {
//             Log.e("CERT", "FileNotFoundException");
//             e.printStackTrace();
//         } catch (IOException e) {
//             Log.e("CERT", "IOException");
//             e.printStackTrace();
//         } catch (KeyManagementException e) {
//             Log.e("CERT", "KeyManagementException");
//             e.printStackTrace();
//         }
// 
//         return null;
//     }
// 
// }
// 
// Path: app/src/main/java/org/secuso/privacyfriendlyweather/weather_api/IHttpRequestForOneCallAPI.java
// public interface IHttpRequestForOneCallAPI {
// 
//     /**
//      * @param lat The latitude of the city to get the data for.
//      * @param lon The longitude of the city to get the data for.
//      */
//     void perform(float lat, float lon);
// 
// }


import android.content.Context;
import org.secuso.privacyfriendlyweather.http.HttpRequestType;
import org.secuso.privacyfriendlyweather.http.IHttpRequest;
import org.secuso.privacyfriendlyweather.http.VolleyHttpRequest;
import org.secuso.privacyfriendlyweather.weather_api.IHttpRequestForOneCallAPI;
package org.secuso.privacyfriendlyweather.weather_api.open_weather_map;



/**
 * This class provides the functionality for making and processing HTTP requests to the
 * OpenWeatherMap to retrieve the latest weather data for all stored cities.
 */
public class OwmHttpRequestForOneCallAPI extends OwmHttpRequest implements IHttpRequestForOneCallAPI {

    /**
     * Member variables.
     */
    private Context context;

    /**
     * @param context The context to use.
     */
    public OwmHttpRequestForOneCallAPI(Context context) {
        this.context = context;
    }


    @Override
    public void perform(float lat, float lon) {
        IHttpRequest httpRequest = new VolleyHttpRequest(context);
        final String URL = getUrlForQueryingOneCallAPI(context, lat, lon);
        //       Log.d("OneCallURL",URL);
// Path: app/src/main/java/org/secuso/privacyfriendlyweather/http/HttpRequestType.java
// public enum HttpRequestType {
//     POST,
//     GET,
//     PUT,
//     DELETE
// }
// 
// Path: app/src/main/java/org/secuso/privacyfriendlyweather/http/IHttpRequest.java
// public interface IHttpRequest {
// 
//     /**
//      * Makes an HTTP request and processes the response.
//      *
//      * @param URL              The target of the HTTP request.
//      * @param method           Which method to use for the HTTP request (e.g. GET or POST)
//      * @param requestProcessor This object with its implemented methods processSuccessScenario and
//      *                         processFailScenario defines how to handle the response in the success
//      *                         and error case respectively.
//      */
//     void make(final String URL, HttpRequestType method, IProcessHttpRequest requestProcessor);
// 
// }
// 
// Path: app/src/main/java/org/secuso/privacyfriendlyweather/http/VolleyHttpRequest.java
// public class VolleyHttpRequest implements IHttpRequest {
// 
//     private Context context;
// 
//     /**
//      * Constructor.
//      *
//      * @param context Volley needs a context "for creating the cache dir".
//      * @see Volley#newRequestQueue(Context)
//      */
//     public VolleyHttpRequest(Context context) {
//         this.context = context;
//     }
// 
//     /**
//      * @see IHttpRequest#make(String, HttpRequestType, IProcessHttpRequest)
//      */
//     @Override
//     public void make(String URL, HttpRequestType method, final IProcessHttpRequest requestProcessor) {
//         RequestQueue queue = Volley.newRequestQueue(context, new HurlStack(null, getSocketFactory()));
// 
//         // Set the request method
//         int requestMethod;
//         switch (method) {
//             case POST:
//                 requestMethod = Request.Method.POST;
//                 break;
//             case GET:
//                 requestMethod = Request.Method.GET;
//                 break;
//             case PUT:
//                 requestMethod = Request.Method.PUT;
//                 break;
//             case DELETE:
//                 requestMethod = Request.Method.DELETE;
//                 break;
//             default:
//                 requestMethod = Request.Method.GET;
//         }
// 
//         // Execute the request and handle the response
//         StringRequest stringRequest = new StringRequest(requestMethod, URL,
//                 new Response.Listener<String>() {
//                     @Override
//                     public void onResponse(String response) {
//                         requestProcessor.processSuccessScenario(response);
//                     }
//                 },
//                 new Response.ErrorListener() {
//                     @Override
//                     public void onErrorResponse(VolleyError error) {
//                         requestProcessor.processFailScenario(error);
//                     }
//                 }
//         );
// 
//         queue.add(stringRequest);
//     }
// 
//     private SSLSocketFactory getSocketFactory() {
// 
//         CertificateFactory cf = null;
//         try {
//             // Load CAs from an InputStream
//             cf = CertificateFactory.getInstance("X.509");
//             InputStream caInput = new BufferedInputStream(context.getAssets().open("SectigoRSADomainValidationSecureServerCA.crt"));
// 
//             Certificate ca;
//             try {
//                 ca = cf.generateCertificate(caInput);
//                 Log.e("CERT", "ca=" + ((X509Certificate) ca).getSubjectDN());
//             } finally {
//                 caInput.close();
//             }
// 
//             // Create a KeyStore containing our trusted CAs
//             String keyStoreType = KeyStore.getDefaultType();
//             KeyStore keyStore = KeyStore.getInstance(keyStoreType);
//             keyStore.load(null, null);
//             keyStore.setCertificateEntry("ca", ca);
// 
//             // Create a TrustManager that trusts the CAs in our KeyStore
//             String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
//             TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
//             tmf.init(keyStore);
// 
//             // Create an SSLContext that uses our TrustManager
//             SSLContext context = SSLContext.getInstance("TLS");
//             context.init(null, tmf.getTrustManagers(), null);
// 
//             SSLSocketFactory sf = context.getSocketFactory();
// 
//             return sf;
// 
//         } catch (CertificateException e) {
//             Log.e("CERT", "CertificateException");
//             e.printStackTrace();
//         } catch (NoSuchAlgorithmException e) {
//             Log.e("CERT", "NoSuchAlgorithmException");
//             e.printStackTrace();
//         } catch (KeyStoreException e) {
//             Log.e("CERT", "KeyStoreException");
//             e.printStackTrace();
//         } catch (FileNotFoundException e) {
//             Log.e("CERT", "FileNotFoundException");
//             e.printStackTrace();
//         } catch (IOException e) {
//             Log.e("CERT", "IOException");
//             e.printStackTrace();
//         } catch (KeyManagementException e) {
//             Log.e("CERT", "KeyManagementException");
//             e.printStackTrace();
//         }
// 
//         return null;
//     }
// 
// }
// 
// Path: app/src/main/java/org/secuso/privacyfriendlyweather/weather_api/IHttpRequestForOneCallAPI.java
// public interface IHttpRequestForOneCallAPI {
// 
//     /**
//      * @param lat The latitude of the city to get the data for.
//      * @param lon The longitude of the city to get the data for.
//      */
//     void perform(float lat, float lon);
// 
// }


// Path: app/src/main/java/org/secuso/privacyfriendlyweather/weather_api/open_weather_map/OwmHttpRequestForOneCallAPI.java
import android.content.Context;
import org.secuso.privacyfriendlyweather.http.HttpRequestType;
import org.secuso.privacyfriendlyweather.http.IHttpRequest;
import org.secuso.privacyfriendlyweather.http.VolleyHttpRequest;
import org.secuso.privacyfriendlyweather.weather_api.IHttpRequestForOneCallAPI;

package org.secuso.privacyfriendlyweather.weather_api.open_weather_map;



/**
 * This class provides the functionality for making and processing HTTP requests to the
 * OpenWeatherMap to retrieve the latest weather data for all stored cities.
 */
public class OwmHttpRequestForOneCallAPI extends OwmHttpRequest implements IHttpRequestForOneCallAPI {

    /**
     * Member variables.
     */
    private Context context;

    /**
     * @param context The context to use.
     */
    public OwmHttpRequestForOneCallAPI(Context context) {
        this.context = context;
    }


    @Override
    public void perform(float lat, float lon) {
        IHttpRequest httpRequest = new VolleyHttpRequest(context);
        final String URL = getUrlForQueryingOneCallAPI(context, lat, lon);
        //       Log.d("OneCallURL",URL);
        httpRequest.make(URL, HttpRequestType.GET, new ProcessOwmForecastOneCallAPIRequest(context));