/*
 *  Copyright (C) 2016-2019 Stichting Akvo (Akvo Foundation)
 *
 *  This file is part of Akvo FLOW.
 *
 *  Akvo FLOW is free software: you can redistribute it and modify it under the terms of
 *  the GNU Affero General Public License (AGPL) as published by the Free Software Foundation,
 *  either version 3 of the License or any later version.
 *
 *  Akvo FLOW is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Affero General Public License included below for more details.
 *
 *  The full license text can also be seen at <http://www.gnu.org/licenses/agpl.html>.
 */

package com.gallatinsystems.survey.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import org.akvo.flow.util.FlowJsonObjectReader;
import org.waterforpeople.mapping.domain.CaddisflyResource;

import java.net.URL;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Dao for listing Caddisfly resources Note: this class doesn't need to implement baseDAO as it
 * consists of only a single method.
 */
public class CaddisflyResourceDao {

    public static String DEFAULT_CADDISFLY_TESTS_FILE_URL = "https://akvoflow-public.s3.amazonaws.com/caddisfly-tests-v2-dev.json";

    private static final Logger log = Logger.getLogger(CascadeResourceDao.class
            .getName());

    public List<CaddisflyResource> listResources(String caddisflyTestsUrl) {
        Map<String, List<CaddisflyResource>> testsMap = null;
        FlowJsonObjectReader jsonReader = new FlowJsonObjectReader();

        try {
            URL caddisflyFileUrl = new URL(caddisflyTestsUrl);
            testsMap = jsonReader.readObject(caddisflyFileUrl, new TypeReference<Map<String, List<CaddisflyResource>>>() {});
        } catch (Exception e) {
            log.log(Level.SEVERE,
                    "Error parsing Caddisfly resource: " + e.getMessage(), e);
        }

        if (testsMap != null && testsMap.get("tests") != null) {
            return testsMap.get("tests");
        } else {
            return Collections.emptyList();
        }
    }

    /**
     * lists caddisfly resources using default caddisfly tests definition file URL
     */
    public List<CaddisflyResource> listResources() {
        return listResources(DEFAULT_CADDISFLY_TESTS_FILE_URL);
    }
}

@@ -755,163 +755,74 @@
 ort 
-com.fasterxml.jackson.core.type.TypeReference;%0Aimport org.akvo.flow.util.FlowJsonObjectReader;%0Aimport org.waterforpeople.mapping.domain.CaddisflyResource;%0A
+java.net.URL;%0Aimport java.util.Collections;%0Aimport java.util.List;
 %0Aimp
@@ -822,39 +822,40 @@
 st;%0Aimport java.
-net.URL
+util.Map
 ;%0Aimport java.ut
@@ -853,35 +853,37 @@
 t java.util.
-Collections
+logging.Level
 ;%0Aimport jav
@@ -893,99 +893,185 @@
 til.
-List
+logging.Logger
 ;%0A
+%0A
 import 
-java.util.Map;%0Aimport java
+com.fasterxml.jackson.core.type.TypeReference;%0Aimport org.akvo.flow
 .util.
+F
 lo
-gging.Level;%0Aimport java.util.logging.Logger
+wJsonObjectReader;%0Aimport org.waterforpeople.mapping.domain.CaddisflyResource
 ;%0A%0A/
@@ -1371,12 +1371,8 @@
 s-v2
--dev
 .jso

Revert "Temporary use caddisfly dev file to test newly added test (#3616)" (#3617)