From ff1627abc8d62d7d7cfb6e8d6c7136e4f2470937 Mon Sep 17 00:00:00 2001 From: Peter Schubert Date: Wed, 2 May 2018 13:08:16 +0300 Subject: [PATCH] add primary section in sections list --- messaging/mapper.go | 14 ++++++++------ messaging/testdata/exampleElasticModel.json | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/messaging/mapper.go b/messaging/mapper.go index 58a2ac5..9483220 100644 --- a/messaging/mapper.go +++ b/messaging/mapper.go @@ -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) } } @@ -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 { diff --git a/messaging/testdata/exampleElasticModel.json b/messaging/testdata/exampleElasticModel.json index c2c64cd..2ebefd9 100644 --- a/messaging/testdata/exampleElasticModel.json +++ b/messaging/testdata/exampleElasticModel.json @@ -44,6 +44,7 @@ "cmr_specialreports": null, "cmr_specialreports_ids": null, "cmr_sections": [ + "Equities", "Investor activism", "Markets Insight", "Opinion", @@ -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",