Skip to content

Commit

Permalink
add primary section in sections list
Browse files Browse the repository at this point in the history
  • Loading branch information
peterschubert committed May 2, 2018
1 parent 12df298 commit ff1627a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions messaging/mapper.go
Expand Up @@ -258,14 +258,12 @@ func handleSectionMapping(annotation content.Thing, model *content.IndexModel, a
model.CmrSections = appendIfNotExists(model.CmrSections, annotation.PrefLabel)
model.CmrSectionsIds = prepareElasticField(model.CmrSectionsIds, annIDs)
case isPrimaryClassifiedBy:
model.CmrSections = appendIfNotExists(model.CmrSections, annotation.PrefLabel)
model.CmrSectionsIds = prepareElasticField(model.CmrSectionsIds, annIDs)
model.CmrPrimarysection = new(string)
*model.CmrPrimarysection = annotation.PrefLabel
model.CmrPrimarysectionID = new(string)
if len(annIDs) == 1 {
*model.CmrPrimarysectionID = annIDs[0]
} else {
*model.CmrPrimarysectionID = annIDs[1]
}
*model.CmrPrimarysectionID = getCmrIDWithFallback("Sections", annIDs)
}
}

Expand Down Expand Up @@ -297,7 +295,11 @@ func getCmrIDWithFallback(taxonomy string, annotationIDs []string) string {
return annID
}
}
return annotationIDs[0]
if len(annotationIDs) > 1 {
return annotationIDs[1]
} else {
return annotationIDs[0]
}
}

func appendIfNotExists(s []string, e string) []string {
Expand Down
3 changes: 3 additions & 0 deletions messaging/testdata/exampleElasticModel.json
Expand Up @@ -44,6 +44,7 @@
"cmr_specialreports": null,
"cmr_specialreports_ids": null,
"cmr_sections": [
"Equities",
"Investor activism",
"Markets Insight",
"Opinion",
Expand All @@ -53,6 +54,8 @@
"UK"
],
"cmr_sections_ids": [
"b7ea3c33-ea8c-432e-bb7e-e3bbc8fdc2bb",
"OTg=-U2VjdGlvbnM=",
"aeada5a9-39cb-4bb6-b795-5baba8acf3fb",
"OWIwMDQ1MTEtOWIxYi00MmEzLWFjOGQtY2VhMDM0MjJlZjI3-VG9waWNz",
"f021ef0a-e3a5-3530-9394-21a1eaf9f3f6",
Expand Down

0 comments on commit ff1627a

Please sign in to comment.