package eu.dnetlib.repo.manager.utils; import eu.dnetlib.repo.manager.domain.Timezone; import org.apache.commons.codec.digest.DigestUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.Objects; public class Converter { private static final Logger logger = LoggerFactory.getLogger(Converter.class); private Converter() { } public static List readFile(String filename) { String line; List list = new ArrayList<>(); try { InputStream in = Converter.class.getResourceAsStream("/eu/**/" + filename); BufferedReader br = new BufferedReader(new InputStreamReader(in)); // It may throw an NPE. while ((line = br.readLine()) != null) { list.add(line.trim()); } br.close(); } catch (Exception e) { logger.error("Error opening file!", e); } return list; // It may be empty. } public static List toTimezones(List timezones) { List tmz = new ArrayList<>(); for (String t : timezones) { String[] s = t.split("\t"); tmz.add(new Timezone(s[1], Double.parseDouble(s[0]))); } return tmz; } public static String getOpenaireId(String repositoryId) { if (repositoryId != null && repositoryId.contains("::")) return repositoryId.split("::")[0] + "::" + DigestUtils.md5Hex(repositoryId.split("::")[1]); return null; } public static Boolean convertStringToBoolean(String value) { return value.equals("null") ? null : Boolean.valueOf(value); } public static Double toDouble(String number) { if (Objects.equals(number, "null")) return 0.0; else return Double.valueOf(number); } }