Skip to content

Commit

Permalink
More refactor simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
utas-raymondng committed Feb 11, 2025
1 parent f3512fd commit 24f06b1
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public class VocabServiceImpl implements VocabService {
@Value("${elasticsearch.vocabs_index.name}")
protected String vocabsIndexName;

protected static final String NARROWER = "narrower";
protected static final String LABEL = "label";
protected static final String ABOUT = "about";

// self-injection to avoid self-invocation problems when calling the cachable method within the same bean
@Lazy
@Autowired
Expand Down Expand Up @@ -96,12 +100,12 @@ public List<String> extractVocabLabelsFromThemes(List<ThemesModel> themes, Vocab
if (!vocabs.isEmpty() && !themes.isEmpty()) {
// vocabs already filtered by non-null during the get operation
vocabs.forEach(topLevelVocab -> {
if (topLevelVocab.has("narrower") && !topLevelVocab.get("narrower").isEmpty()) {
for (JsonNode secondLevelVocab : topLevelVocab.get("narrower")) {
if (secondLevelVocab != null && secondLevelVocab.has("label") && secondLevelVocab.has("about")) {
if (topLevelVocab.has(NARROWER) && !topLevelVocab.get(NARROWER).isEmpty()) {
for (JsonNode secondLevelVocab : topLevelVocab.get(NARROWER)) {
if (secondLevelVocab != null && secondLevelVocab.has(LABEL) && secondLevelVocab.has(ABOUT)) {
ConceptModel secondLevelVocabAsConcept = ConceptModel.builder()
.id(secondLevelVocab.get("label").asText().toLowerCase())
.url(secondLevelVocab.get("about").asText())
.id(secondLevelVocab.get(LABEL).asText().toLowerCase())
.url(secondLevelVocab.get(ABOUT).asText())
.build();

themes.stream().filter(Objects::nonNull).forEach(theme -> {
Expand All @@ -111,13 +115,13 @@ public List<String> extractVocabLabelsFromThemes(List<ThemesModel> themes, Vocab
}

// if the record's theme is leaf-node (bottom-level vocab)
if (secondLevelVocab.has("narrower") && !secondLevelVocab.get("narrower").isEmpty()) {
for (JsonNode bottomLevelVocab : secondLevelVocab.get("narrower")) {
if (bottomLevelVocab != null && bottomLevelVocab.has("label") && bottomLevelVocab.has("about")) {
if (secondLevelVocab.has(NARROWER) && !secondLevelVocab.get(NARROWER).isEmpty()) {
for (JsonNode bottomLevelVocab : secondLevelVocab.get(NARROWER)) {
if (bottomLevelVocab != null && bottomLevelVocab.has(LABEL) && bottomLevelVocab.has(ABOUT)) {
// map the original values to a ConceptModel object for doing comparison
ConceptModel leafVocabAsConcept = ConceptModel.builder()
.id(bottomLevelVocab.get("label").asText())
.url(bottomLevelVocab.get("about").asText())
.id(bottomLevelVocab.get(LABEL).asText())
.url(bottomLevelVocab.get(ABOUT).asText())
.build();

// Compare with themes' concepts
Expand Down

0 comments on commit 24f06b1

Please sign in to comment.