package org.pdxfinder.utils;

import org.pdxfinder.dataloaders.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class DataProviders implements ApplicationContextAware {

    @Autowired protected static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }

    public DataProviders() {}

    public enum DataProviderGroup {
        All,
        EurOPDX,
    }

    public static List<DataProvider> getProvidersFrom(DataProviderGroup group) {
        EnumMap<DataProviderGroup, List<DataProvider>> map = new EnumMap<>(DataProviderGroup.class);
        map.put(DataProviderGroup.All, Arrays.asList(DataProvider.values()));
        map.put(DataProviderGroup.EurOPDX, Arrays.asList(
                DataProvider.Curie_BC,
                DataProvider.Curie_LC,
                DataProvider.Curie_OV,
                DataProvider.IRCC_CRC,
                DataProvider.IRCC_GC,
                DataProvider.TRACE,
                DataProvider.UOC_BC,
                DataProvider.UOM_BC,
                DataProvider.VHIO_BC,
                DataProvider.VHIO_CRC
        ));
        return map.get(group);
    }

    public enum DataProvider {
        Test_Minimal,
        CRL,
        Curie_BC,
        Curie_LC,
        Curie_OV,
        IRCC_CRC {
            @Override
            public void load() {
                LoadIRCC loadIRCC = (LoadIRCC) applicationContext.getBean("loadIRCC");
                try { loadIRCC.run(); }
                catch (Exception e) { log.error("{}", e); }
            }},
        IRCC_GC,
        JAX {
            @Override
            public void load() {
                LoadJAXData loadJAXData = (LoadJAXData) applicationContext.getBean("loadJAXData");
                try { loadJAXData.run(); }
                catch (Exception e) { log.error("{}", e); }
        }},
        PDMR {
            @Override
            public void load() {
                LoadPDMRData loadPDMRData = (LoadPDMRData) applicationContext.getBean("loadPDMRData");
                try { loadPDMRData.run(); }
                catch (Exception e) { log.error("{}", e); }
            }},
        PMLB,
        PDXNet_HCI_BCM {
            @Override
            public void load() {
                LoadHCI loadHCI = (LoadHCI) applicationContext.getBean("loadHCI");
                try { loadHCI.run(); }
                catch (Exception e) { log.error("{}", e); }
            }},
        PDXNet_MDAnderson {
            @Override
            public void load() {
                LoadMDAnderson loadMDAnderson = (LoadMDAnderson) applicationContext.getBean("loadMDAnderson");
                try { loadMDAnderson.run(); }
                catch (Exception e) { log.error("{}", e); }
            }},
        PDXNet_Wistar_MDAnderson_Penn {
            @Override
            public void load() {
                LoadWISTAR loadWISTAR = (LoadWISTAR) applicationContext.getBean("loadWISTAR");
                try { loadWISTAR.run(); }
                catch (Exception e) { log.error("{}", e); }
            }},
        PDXNet_WUSTL {
            @Override
            public void load() {
                LoadWUSTL loadWUSTL = (LoadWUSTL) applicationContext.getBean("loadWUSTL");
                try { loadWUSTL.run(); }
                catch (Exception e) { log.error("{}", e); }
            }},
        TRACE,
        UOC_BC,
        UOM_BC,
        VHIO_BC,
        VHIO_CRC;

        Logger log = LoggerFactory.getLogger(DataProviders.class);

        DataProvider() {}

        public void load() {
            LoadUniversal loadUniversal = (LoadUniversal) applicationContext.getBean("loadUniversal");
            try { loadUniversal.run(); }
            catch (Exception e) { log.error("{}", e); }
        }

    }

}

@@ -765,16 +765,31 @@
 urOPDX,%0A
+        UPDOG,%0A
     %7D%0A%0A 
@@ -1493,24 +1493,502 @@
         ));%0A
+        map.put(DataProviderGroup.UPDOG, Arrays.asList(%0A                DataProvider.IRCC_GC,%0A                DataProvider.CRL,%0A                DataProvider.TRACE,%0A                DataProvider.Curie_BC,%0A                DataProvider.Curie_LC,%0A                DataProvider.Curie_OV,%0A                DataProvider.PMLB,%0A                DataProvider.UOC_BC,%0A                DataProvider.UOM_BC,%0A                DataProvider.VHIO_BC,%0A                DataProvider.VHIO_CRC%0A        ));%0A
         retu
@@ -4528,24 +4528,40 @@
        try %7B
+%0A               
  loadUnivers
@@ -4563,28 +4563,37 @@
 iversal.run(
+this.name()
 );
- %7D
 %0A           
@@ -4584,32 +4584,34 @@
 ());%0A           
+ %7D
  catch (Exceptio
@@ -4608,32 +4608,48 @@
  (Exception e) %7B
+%0A               
  log.error(%22%7B%7D%22,
@@ -4644,32 +4644,44 @@
 .error(%22%7B%7D%22, e);
+%0A           
  %7D%0A        %7D%0A%0A  

Add Universal Loader Data Loading Group (-g UPDOG)