package no.uio.ifi.trackfind.backend.data.providers.example;

import com.google.common.collect.HashMultimap;
import lombok.extern.slf4j.Slf4j;
import no.uio.ifi.trackfind.backend.data.providers.AbstractDataProvider;
import org.springframework.stereotype.Component;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * Draft of Data Provider for TrackHubRegistry.
 *
 * @author Dmytro Titov
 */
@Slf4j
@Component
public class ExampleDataProvider extends AbstractDataProvider {

    private static final String FETCH_URL = "https://raw.githubusercontent.com/fairtracks/fairtracks_standard/master/json/examples/fairtracks.example.json";

    /**
     * {@inheritDoc}
     */
    @Override
    protected void fetchData(String hubName) {
        HashMultimap<String, String> mapToSave = HashMultimap.create();
        try (InputStream inputStream = new URL(FETCH_URL).openStream();
             InputStreamReader reader = new InputStreamReader(inputStream)) {
            Map topMap = gson.fromJson(reader, Map.class);
            mapToSave.put("studies", gson.toJson(((List)topMap.get("studies")).get(0)));
            mapToSave.put("experiments", gson.toJson(((List)topMap.get("experiments")).get(0)));
            mapToSave.put("samples", gson.toJson(((List)topMap.get("samples")).get(0)));
            mapToSave.put("tracks", gson.toJson(((List)topMap.get("tracks")).get(0)));
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        save(hubName, mapToSave.asMap());
    }

}

@@ -363,18 +363,14 @@
 til.
-Collection
+Arrays
 ;%0Aim
@@ -1132,145 +1132,133 @@
     
-mapToSave.put(%22studies%22, gson.toJson(((List)topMap.get(%22studies%22)).get(0)));%0A            mapToSave.put(%22experiments%22, gson.toJson((
+for (String category : Arrays.asList(%22studies%22, %22experiments%22, %22samples%22, %22tracks%22)) %7B%0A                List objects = 
 (List)
+ 
 topM
@@ -1268,123 +1268,75 @@
 get(
-%22experiments%22)).get(0)));%0A            mapToSave.put(%22samples%22, gson.toJson(((List)topMap.get(%22samples%22)).get(0)));%0A
+category);%0A                for (Object object : objects) %7B%0A        
     
@@ -1357,24 +1357,24 @@
 ave.put(
-%22tracks%22
+category
 , gson.t
@@ -1383,46 +1383,49 @@
 son(
-((List)topMap.get(%22tracks%22)).get(0)));
+object));%0A                %7D%0A            %7D
 %0A   

Fix docker-compose file