Skip to content

Commit

Permalink
Fix writing Audio in elasticsearch when kafka header is missing; Fix
Browse files Browse the repository at this point in the history
schema checker
  • Loading branch information
gotha committed Jul 6, 2020
1 parent 5827f47 commit 100a61b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
AudioType = "audio"

PACOrigin = "http://cmdb.ft.com/systems/pac"

ContentTypeAudio = "Audio"
)

type ESContentTypeMetadataMap map[string]schema.ContentType
Expand Down
3 changes: 2 additions & 1 deletion pkg/es/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ func (s *ElasticsearchService) GetSchemaHealth() (string, error) {
return "", err
}

fullReferenceJSON := []byte(fmt.Sprintf(`{"ft": %s}`, string(referenceJSON)))
fullReferenceJSON := []byte(fmt.Sprintf(`{"%s": %s}`, s.IndexName, string(referenceJSON)))
err = json.Unmarshal(fullReferenceJSON, &referenceIndex.index)
if err != nil {
return "", err
}
}

if referenceIndex.index[s.IndexName] == nil || referenceIndex.index[s.IndexName].Settings == nil || referenceIndex.index[s.IndexName].Mappings == nil {
return "not ok, wrong referenceIndex", nil
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/message/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package message

import (
"encoding/json"
"fmt"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -100,7 +101,7 @@ func (h *Handler) handleMessage(msg consumer.Message) {

uuid := combinedPostPublicationEvent.UUID
log = log.WithUUID(uuid)
log.Info("Processing combined post publication event")
log.Info(fmt.Sprintf("Processing combined post publication event with type %s", combinedPostPublicationEvent.Content.Type))

contentType := h.readContentType(msg, combinedPostPublicationEvent)
if contentType == "" && msg.Headers[originHeader] != config.PACOrigin {
Expand Down Expand Up @@ -136,7 +137,7 @@ func (h *Handler) handleMessage(msg consumer.Message) {

func (h *Handler) readContentType(msg consumer.Message, event schema.EnrichedContent) string {
typeHeader := msg.Headers[contentTypeHeader]
if strings.Contains(typeHeader, audioContentTypeHeader) {
if strings.Contains(typeHeader, audioContentTypeHeader) || event.Content.Type == config.ContentTypeAudio {
return config.AudioType
}
if strings.Contains(typeHeader, articleContentTypeHeader) {
Expand Down
19 changes: 19 additions & 0 deletions pkg/message/message_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,25 @@ func TestHandleWriteMessageAudio(t *testing.T) {
concordanceAPIMock.AssertExpectations(t)
}

func TestHandleWriteMessageAudioWithoutHeader(t *testing.T) {

inputJSON := tst.ReadTestResource("exampleAudioModel.json")
input := strings.Replace(string(inputJSON), "FTCOM-METHODE", "NEXT-VIDEO-EDITOR", 1)

serviceMock := &esServiceMock{}
serviceMock.On("WriteData", "FTAudios", "aae9611e-f66c-4fe4-a6c6-2e2bdea69060", mock.Anything).Return(&elastic.IndexResult{}, nil)

concordanceAPIMock := new(concordanceAPIMock)

_, handler := mockMessageHandler(defaultESClient, serviceMock, concordanceAPIMock)
handler.handleMessage(consumer.Message{
Body: input,
Headers: map[string]string{},
})

serviceMock.AssertExpectations(t)
}

func TestHandleWriteMessageArticleByHeaderType(t *testing.T) {
input := modifyTestInputAuthority("invalid")

Expand Down
58 changes: 58 additions & 0 deletions test/testdata/exampleAudioModel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"uuid": "aae9611e-f66c-4fe4-a6c6-2e2bdea69060",
"content": {
"accessLevel": "subscribed",
"alternativeStandfirsts": {
"promotionalStandfirst": "promotionalStandfirst"
},
"alternativeTitles": {
"contentPackageTitle": null,
"promotionalTitle": "promotionalTitle"
},
"body": "example body",
"byline": "byline",
"canBeDistributed": "yes",
"canBeSyndicated": "yes",
"comments": {
"enabled": true
},
"contentPackage": null,
"copyright": null,
"description": null,
"editorialDesk": "/FT/MarketNews",
"externalBinaryUrl": null,
"firstPublishedDate": "2017-06-26T04:00:17.000Z",
"identifiers": [
{
"authority": "http://api.ft.com/system/FTCOM-METHODE",
"identifierValue": "aae9611e-f66c-4fe4-a6c6-2e2bdea69060"
}
],
"internalBinaryUrl": null,
"lastModified": "2018-04-04T12:58:00.347Z",
"mainImage": "5546cbc4-d4f7-47f9-a158-03856a0d3706",
"masterSource": null,
"mediaType": null,
"members": null,
"pixelHeight": null,
"pixelWidth": null,
"publishReference": "tid_123",
"publishedDate": "2017-06-26T04:00:17.000Z",
"rightsGroup": null,
"standfirst": "",
"standout": {
"editorsChoice": false,
"exclusive": false,
"scoop": false
},
"storyPackage": null,
"title": "Example audio",
"type": "Audio",
"uuid": "aae9611e-f66c-4fe4-a6c6-2e2bdea69060",
"webUrl": null
},
"metadata": [],
"contentUri": "http://methode-article-mapper.svc.ft.com/content/aae9611e-f66c-4fe4-a6c6-2e2bdea69060",
"lastModified": "2020-07-06T12:58:00.347Z",
"markedDeleted": "false"
}

0 comments on commit 100a61b

Please sign in to comment.