--- /dev/null
+/*******************************************************************************
+ * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
+ *
+ * This file is part of the work and learning management system Pentila Nero.
+ *
+ * Pentila Nero is free software. You can redistribute it and/or modify since
+ * you respect the terms of either (at least one of the both license) :
+ * - under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ * - the CeCILL-C as published by CeCILL-C; either version 1 of the
+ * License, or any later version
+ * - the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the license,
+ * or (at your option) any later version.
+ *
+ * There are special exceptions to the terms and conditions of the
+ * licenses as they are applied to this software. View the full text of
+ * the exception in file LICENSE-PROJECT.txt in the directory of this software
+ * distribution.
+ *
+ * Pentila Nero 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
+ * Licenses for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * and the CeCILL-C and the GNU Lesser General Public License along with
+ * Pentila Nero. If not, see :
+ * <http://www.gnu.org/licenses/> and
+ * <http://www.cecill.info/licences.fr.html>.
+ ******************************************************************************/
+package com.pentila.entSavoie.portlets.userManagement.util;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import com.csvreader.CsvReader;
+import com.pentila.entSavoie.portlets.userManagement.ldap.util.LDAPUtil;
+
+public class CSVLoader {
+
+ static Map<String, Map<String, String>> disciplines = null;
+
+ static Map<String, Map<String, String>> fonctions = null;
+
+ static Map<String, String> instruments = null;
+
+ public static Map<String, String> getDiscipline(String searchId) {
+
+ init();
+ return disciplines.get(searchId);
+
+ }
+
+ public static Map<String, String> getDisciplines() {
+ Map<String, String> m = new HashMap<String, String>();
+
+ init();
+
+ for (Map<String, String> d : disciplines.values()) {
+ m.put(d.get("DISCIPLINE_POSTE"), d.get("LIBELLE_LONG"));
+ }
+
+ return m;
+ }
+
+ public static Map<String, String> getFonction(String searchId) {
+
+ init();
+ return fonctions.get(searchId);
+
+ }
+
+ public static Map<String, String> getFonctionByValue(String value) {
+ Map<String, String> m = new HashMap<String, String>();
+ init();
+
+ for (Map<String, String> f : fonctions.values()) {
+
+ if (f.get("LIBELLE_LONG").equals(value)) {
+ return f;
+ }
+ }
+
+ return m;
+
+ }
+
+ public static Map<String, String> getFonctions() {
+ Map<String, String> m = new HashMap<String, String>();
+
+ init();
+ for (Map<String, String> d : fonctions.values()) {
+ m.put(d.get("ID"), d.get("LIBELLE_LONG"));
+ }
+
+ return m;
+
+ }
+
+ public static Map<String, String> getInstruments() {
+ init();
+ return instruments;
+ }
+
+ public static void init() {
+ if (disciplines == null) {
+ disciplines = new HashMap<String, Map<String, String>>();
+ CsvReader disciplinesReader = new CsvReader(Thread.currentThread()
+ .getContextClassLoader().getResourceAsStream(
+ "n_discipline_poste.csv"), Charset.defaultCharset());
+
+ try {
+ disciplinesReader.readHeaders();
+
+ Set<String> o = new HashSet<String>();
+
+ while (disciplinesReader.readRecord()) {
+ String id = disciplinesReader.get("DISCIPLINE_POSTE");
+ String dd = disciplinesReader.get("LIBELLE_LONG");
+ if (!o.contains(dd)) {
+
+ disciplines.put(id, new HashMap<String, String>());
+
+ for (String h : disciplinesReader.getHeaders()) {
+ disciplines.get(id)
+ .put(h, disciplinesReader.get(h));
+ }
+ o.add(dd);
+ }
+
+ }
+
+ disciplinesReader.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ if (fonctions == null) {
+ fonctions = new HashMap<String, Map<String, String>>();
+ CsvReader fonctionsReader = new CsvReader(Thread.currentThread()
+ .getContextClassLoader().getResourceAsStream(
+ "n_fonction_filiere.csv"), Charset.defaultCharset());
+ try {
+ fonctionsReader.readHeaders();
+
+ while (fonctionsReader.readRecord()) {
+ String id = fonctionsReader.get("ID");
+ if (!fonctions.containsKey(id)) {
+
+ fonctions.put(id, new HashMap<String, String>());
+
+ for (String h : fonctionsReader.getHeaders()) {
+ fonctions.get(id).put(h, fonctionsReader.get(h));
+ }
+
+ }
+
+ }
+
+ fonctionsReader.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ if (instruments == null) {
+ instruments = new HashMap<String, String>();
+ CsvReader instrumentsReader = new CsvReader(Thread.currentThread()
+ .getContextClassLoader().getResourceAsStream(
+ "instruments.csv"), Charset.defaultCharset());
+ try {
+ instrumentsReader.readHeaders();
+
+ while (instrumentsReader.readRecord()) {
+ String instrument = instrumentsReader.get("INSTRUMENT_NAME");
+ instruments.put(LDAPUtil.formatGroupName(instrument), instrument);
+ }
+
+ instrumentsReader.close();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+}