Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logging messages #156

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
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;

import javax.annotation.PostConstruct;
import java.io.*;
import java.nio.file.Files;
import java.util.*;
import java.util.stream.Collectors;


@Slf4j
Expand All @@ -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) {
Expand All @@ -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);

Expand All @@ -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<String> extractGcmdKeywordLastWords(List<ThemesModel> themes) {
log.info("Extracting GCMD keywords from record's themes");
Set<String> 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")) {
Expand All @@ -86,6 +100,8 @@ protected String getParameterVocabByGcmdKeywordLastWord(String gcmdKeywordLastWo
public List<String> getMappedParameterVocabsFromGcmdKeywords(List<ThemesModel> themes) {
Set<String> results = new HashSet<>();

log.info("Get parameter vocabs from record's GCMD keywords");

List<String> gcmdKeywordLastWords = extractGcmdKeywordLastWords(themes);

if (!gcmdKeywordLastWords.isEmpty()) {
Expand Down
Loading