diff --git a/indexer/src/main/java/au/org/aodn/esindexer/utils/GcmdKeywordUtils.java b/indexer/src/main/java/au/org/aodn/esindexer/utils/GcmdKeywordUtils.java index 99f6df2e..b11f7f60 100644 --- a/indexer/src/main/java/au/org/aodn/esindexer/utils/GcmdKeywordUtils.java +++ b/indexer/src/main/java/au/org/aodn/esindexer/utils/GcmdKeywordUtils.java @@ -3,6 +3,8 @@ import au.org.aodn.stac.model.ConceptModel; import au.org.aodn.stac.model.ThemesModel; import lombok.extern.slf4j.Slf4j; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; import org.springframework.stereotype.Component; import org.springframework.util.ResourceUtils; @@ -10,6 +12,7 @@ import java.io.*; import java.nio.file.Files; import java.util.*; +import java.util.stream.Collectors; @Slf4j @@ -20,7 +23,7 @@ public class GcmdKeywordUtils { @PostConstruct public void init() { - loadCsvToMap("classpath:config_files/gcmd-mapping.csv"); + loadCsvToMap("config_files/gcmd-mapping.csv"); } private String getLastWord(String keyword) { @@ -37,13 +40,21 @@ private String getLastWord(String keyword) { private static String readResourceFile(String path) throws IOException { - File f = ResourceUtils.getFile(path); - return new String(Files.readAllBytes(f.toPath())); + Resource resource = new ClassPathResource(path); + InputStream fStream = resource.getInputStream(); + try ( BufferedReader reader = new BufferedReader( + new InputStreamReader(fStream)) ) { + return reader.lines() + .collect(Collectors.joining("\n")); + } } // Load the CSV file into a HashMap private void loadCsvToMap(String path) { try { + + log.info("Loading GCMD mapping contents from CSV resource: {}", path); + // Read the file as a single String String fileContent = readResourceFile(path); @@ -60,12 +71,15 @@ private void loadCsvToMap(String path) { gcmdMapping.put(key, value); } } + + log.info("Successfully loaded GCMD mapping contents from CSV resource: {}", path); } catch (IOException e) { - log.error(e.getMessage()); + log.error("Error while loading GCMD mapping contents from CSV resource: {}", path, e); } } protected List extractGcmdKeywordLastWords(List themes) { + log.info("Extracting GCMD keywords from record's themes"); Set keywords = new HashSet<>(); for (ThemesModel themesModel : themes) { if ((themesModel.getTitle().toLowerCase().contains("gcmd") || themesModel.getTitle().toLowerCase().contains("global change master directory")) && !themesModel.getTitle().toLowerCase().contains("palaeo temporal coverage")) { @@ -86,6 +100,8 @@ protected String getParameterVocabByGcmdKeywordLastWord(String gcmdKeywordLastWo public List getMappedParameterVocabsFromGcmdKeywords(List themes) { Set results = new HashSet<>(); + log.info("Get parameter vocabs from record's GCMD keywords"); + List gcmdKeywordLastWords = extractGcmdKeywordLastWords(themes); if (!gcmdKeywordLastWords.isEmpty()) {