content: /*
   *  Copyright (C) 2010-2017, 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 org.waterforpeople.mapping.dataexport;
  
  import com.gallatinsystems.framework.dataexport.applet.DataExporter;
  import com.gallatinsystems.framework.dataexport.applet.DataImportExportFactory;
  import com.gallatinsystems.framework.dataexport.applet.DataImporter;
  
  import java.util.HashMap;
  import java.util.Map;
  
  /**
   * Factory to create a DataExporter or DataImporter instance based on the type passed in
   *
   * @author Christopher Fagiani
   */
  public class SurveyDataImportExportFactory implements DataImportExportFactory {
  
      private static final Map<String, Class<? extends DataExporter>> EXPORTER_MAP = new HashMap<String, Class<? extends DataExporter>>() {
          private static final long serialVersionUID = 6562869574473763867L;
  
          {
              put("SURVEY_SUMMARY", SurveySummaryExporter.class);
              put("DATA_CLEANING", GraphicalSurveySummaryExporter.class);
              put("DATA_ANALYSIS", GraphicalSurveySummaryExporter.class);
              put("COMPREHENSIVE", GraphicalSurveySummaryExporter.class);
              put("SURVEY_FORM", SurveyFormExporter.class);
              put("STATISTICS", StatisticsExporter.class);
          }
      };
  
      private static final Map<String, Class<? extends DataImporter>> IMPORTER_MAP = new HashMap<String, Class<? extends DataImporter>>() {
          private static final long serialVersionUID = 6562869574473763867L;
  
          {
              put("RAW_DATA", RawDataSpreadsheetImporter.class);
          }
      };
  
      @Override
      public DataExporter getExporter(String type) {
          Class<? extends DataExporter> exporterClass = EXPORTER_MAP.get(type);
          if (exporterClass != null) {
              try {
                  return exporterClass.newInstance();
              } catch (Exception e) {
                  throw new RuntimeException("Could not initialize constructor");
              }
          } else {
              throw new RuntimeException("Unknown Exporter Type: " + type);
          }
      }
  
      @Override
      public DataImporter getImporter(String type) {
          Class<? extends DataImporter> importerClass = IMPORTER_MAP.get(type);
          if (importerClass != null) {
              try {
                  return importerClass.newInstance();
              } catch (Exception e) {
                  throw new RuntimeException("Could not initialize constructor");
              }
          } else {
              throw new RuntimeException("Unknown Importer Type: " + type);
          }
      }
  }
  