34
34
import static org .atlasapi .media .entity .Publisher .TALK_TALK ;
35
35
import static org .atlasapi .media .entity .Publisher .YOUTUBE ;
36
36
import static org .atlasapi .media .entity .Publisher .YOUVIEW ;
37
+ import static org .atlasapi .media .entity .Publisher .YOUVIEW_STAGE ;
37
38
38
39
import java .io .File ;
39
40
import java .util .Set ;
71
72
import org .atlasapi .equiv .results .persistence .FileEquivalenceResultStore ;
72
73
import org .atlasapi .equiv .results .persistence .RecentEquivalenceResultStore ;
73
74
import org .atlasapi .equiv .results .scores .Score ;
74
- import org .atlasapi .equiv .scorers .BroadcastItemTitleScorer ;
75
75
import org .atlasapi .equiv .scorers .ContainerHierarchyMatchingScorer ;
76
76
import org .atlasapi .equiv .scorers .CrewMemberScorer ;
77
77
import org .atlasapi .equiv .scorers .EquivalenceScorer ;
88
88
import org .atlasapi .equiv .update .NullEquivalenceUpdater ;
89
89
import org .atlasapi .equiv .update .SourceSpecificEquivalenceUpdater ;
90
90
import org .atlasapi .media .channel .ChannelResolver ;
91
+ import org .atlasapi .media .entity .Broadcast ;
91
92
import org .atlasapi .media .entity .Container ;
92
93
import org .atlasapi .media .entity .Content ;
93
94
import org .atlasapi .media .entity .Item ;
94
95
import org .atlasapi .media .entity .Publisher ;
95
96
import org .atlasapi .media .entity .Song ;
96
- import org .atlasapi .messaging .v3 .AtlasMessagingModule ;
97
+ import org .atlasapi .messaging .v3 .ContentEquivalenceAssertionMessage ;
98
+ import org .atlasapi .messaging .v3 .JacksonMessageSerializer ;
99
+ import org .atlasapi .messaging .v3 .KafkaMessagingModule ;
97
100
import org .atlasapi .persistence .content .ContentResolver ;
98
101
import org .atlasapi .persistence .content .ScheduleResolver ;
99
102
import org .atlasapi .persistence .content .SearchResolver ;
100
103
import org .atlasapi .persistence .lookup .LookupWriter ;
104
+ import org .joda .time .DateTime ;
101
105
import org .joda .time .Duration ;
102
106
import org .springframework .beans .factory .annotation .Autowired ;
103
107
import org .springframework .beans .factory .annotation .Value ;
104
108
import org .springframework .context .annotation .Bean ;
105
109
import org .springframework .context .annotation .Configuration ;
106
110
import org .springframework .context .annotation .Import ;
107
- import org .springframework .jms .core .JmsTemplate ;
108
111
109
112
import com .google .common .base .Predicate ;
113
+ import com .google .common .base .Predicates ;
110
114
import com .google .common .collect .ImmutableList ;
111
115
import com .google .common .collect .ImmutableSet ;
112
116
import com .google .common .collect .Iterables ;
113
117
import com .google .common .collect .Sets ;
118
+ import com .metabroadcast .common .queue .MessageSender ;
119
+ import com .metabroadcast .common .time .DateTimeZones ;
114
120
115
121
@ Configuration
116
- @ Import ({AtlasMessagingModule .class })
122
+ @ Import ({KafkaMessagingModule .class })
117
123
public class EquivModule {
118
124
119
125
private @ Value ("${equiv.results.directory}" ) String equivResultsDirectory ;
@@ -126,7 +132,7 @@ public class EquivModule {
126
132
private @ Autowired EquivalenceSummaryStore equivSummaryStore ;
127
133
private @ Autowired LookupWriter lookupWriter ;
128
134
129
- private @ Autowired AtlasMessagingModule messaging ;
135
+ private @ Autowired KafkaMessagingModule messaging ;
130
136
131
137
public @ Bean RecentEquivalenceResultStore equivalenceResultStore () {
132
138
return new RecentEquivalenceResultStore (new FileEquivalenceResultStore (new File (equivResultsDirectory )));
@@ -143,8 +149,10 @@ private EquivalenceResultHandler<Container> containerResultHandlers(Iterable<Pub
143
149
}
144
150
145
151
@ Bean
146
- protected JmsTemplate equivAssertDestination () {
147
- return messaging .queueHelper ().makeVirtualTopicProducer (equivAssertDest );
152
+ protected MessageSender <ContentEquivalenceAssertionMessage > equivAssertDestination () {
153
+ return messaging .messageSenderFactory ()
154
+ .makeMessageSender (equivAssertDest ,
155
+ JacksonMessageSerializer .forType (ContentEquivalenceAssertionMessage .class ));
148
156
}
149
157
150
158
private <T extends Content > EquivalenceFilter <T > standardFilter () {
@@ -161,10 +169,14 @@ private <T extends Content> EquivalenceFilter<T> standardFilter(Iterable<Equival
161
169
}
162
170
163
171
private ContentEquivalenceUpdater .Builder <Item > standardItemUpdater (Set <Publisher > acceptablePublishers , Set <? extends EquivalenceScorer <Item >> scorers ) {
172
+ return standardItemUpdater (acceptablePublishers , scorers , Predicates .alwaysTrue ());
173
+ }
174
+
175
+ private ContentEquivalenceUpdater .Builder <Item > standardItemUpdater (Set <Publisher > acceptablePublishers , Set <? extends EquivalenceScorer <Item >> scorers , Predicate <? super Broadcast > filter ) {
164
176
return ContentEquivalenceUpdater .<Item > builder ()
165
177
.withGenerators (ImmutableSet .<EquivalenceGenerator <Item >> of (
166
178
new BroadcastMatchingItemEquivalenceGenerator (scheduleResolver ,
167
- channelResolver , acceptablePublishers , Duration .standardMinutes (10 ))
179
+ channelResolver , acceptablePublishers , Duration .standardMinutes (10 ), filter )
168
180
))
169
181
.withScorers (scorers )
170
182
.withCombiner (new NullScoreAwareAveragingCombiner <Item >())
@@ -220,7 +232,7 @@ public boolean apply(Publisher input) {
220
232
Set <Publisher > acceptablePublishers = ImmutableSet .copyOf (Sets .difference (
221
233
Publisher .all (),
222
234
Sets .union (
223
- ImmutableSet .of (PREVIEW_NETWORKS , BBC_REDUX , RADIO_TIMES , LOVEFILM , NETFLIX , YOUVIEW ),
235
+ ImmutableSet .of (PREVIEW_NETWORKS , BBC_REDUX , RADIO_TIMES , LOVEFILM , NETFLIX , YOUVIEW , YOUVIEW_STAGE ),
224
236
Sets .union (musicPublishers , roviPublishers )
225
237
)
226
238
));
@@ -230,7 +242,7 @@ public boolean apply(Publisher input) {
230
242
EquivalenceUpdater <Container > topLevelContainerUpdater = topLevelContainerUpdater (acceptablePublishers );
231
243
232
244
Set <Publisher > nonStandardPublishers = ImmutableSet .copyOf (Sets .union (
233
- ImmutableSet .of (ITUNES , BBC_REDUX , RADIO_TIMES , FACEBOOK , LOVEFILM , NETFLIX , YOUVIEW , TALK_TALK , PA ),
245
+ ImmutableSet .of (ITUNES , BBC_REDUX , RADIO_TIMES , FACEBOOK , LOVEFILM , NETFLIX , YOUVIEW , YOUVIEW_STAGE , TALK_TALK , PA ),
234
246
Sets .union (musicPublishers , roviPublishers )
235
247
));
236
248
final EquivalenceUpdaters updaters = new EquivalenceUpdaters ();
@@ -242,31 +254,37 @@ public boolean apply(Publisher input) {
242
254
.build ());
243
255
}
244
256
245
- Set <Publisher > paPublishers = Sets .union (acceptablePublishers , ImmutableSet .of (YOUVIEW ));
246
-
247
- updaters .register (PA , SourceSpecificEquivalenceUpdater .builder (PA )
248
- .withItemUpdater (standardItemUpdater (paPublishers , ImmutableSet .<EquivalenceScorer <Item >>of ()).build ())
249
- .withTopLevelContainerUpdater (topLevelContainerUpdater (paPublishers ))
250
- .withNonTopLevelContainerUpdater (NullEquivalenceUpdater .<Container >get ())
251
- .build ());
252
-
253
257
updaters .register (RADIO_TIMES , SourceSpecificEquivalenceUpdater .builder (RADIO_TIMES )
254
258
.withItemUpdater (rtItemEquivalenceUpdater ())
255
259
.withTopLevelContainerUpdater (NullEquivalenceUpdater .<Container >get ())
256
260
.withNonTopLevelContainerUpdater (NullEquivalenceUpdater .<Container >get ())
257
261
.build ());
258
262
259
- Set <Publisher > youViewPublishers = Sets .union (acceptablePublishers , ImmutableSet .of (YOUVIEW ));
263
+ Set <Publisher > youViewPublishers = Sets .union (Sets .difference (acceptablePublishers , ImmutableSet .of (YOUVIEW_STAGE )), ImmutableSet .of (YOUVIEW ));
264
+ Predicate <Broadcast > youviewBroadcastFilter = new Predicate <Broadcast >(){
265
+ @ Override
266
+ public boolean apply (Broadcast input ) {
267
+ DateTime twoWeeksAgo = new DateTime (DateTimeZones .UTC ).minusDays (15 );
268
+ return input .getTransmissionTime ().isAfter (twoWeeksAgo );
269
+ }
270
+ };
260
271
updaters .register (YOUVIEW , SourceSpecificEquivalenceUpdater .builder (YOUVIEW )
261
- .withItemUpdater (broadcastItemEquivalenceUpdater (youViewPublishers , Score .negativeOne ()))
272
+ .withItemUpdater (broadcastItemEquivalenceUpdater (youViewPublishers , Score .negativeOne (), youviewBroadcastFilter ))
262
273
.withTopLevelContainerUpdater (broadcastItemContainerEquivalenceUpdater (youViewPublishers ))
263
274
.withNonTopLevelContainerUpdater (NullEquivalenceUpdater .<Container >get ())
264
275
.build ());
276
+
277
+ Set <Publisher > youViewStagePublishers = Sets .union (Sets .difference (acceptablePublishers , ImmutableSet .of (YOUVIEW )), ImmutableSet .of (YOUVIEW_STAGE ));
278
+ updaters .register (YOUVIEW_STAGE , SourceSpecificEquivalenceUpdater .builder (YOUVIEW_STAGE )
279
+ .withItemUpdater (broadcastItemEquivalenceUpdater (youViewStagePublishers , Score .negativeOne (),youviewBroadcastFilter ))
280
+ .withTopLevelContainerUpdater (broadcastItemContainerEquivalenceUpdater (youViewStagePublishers ))
281
+ .withNonTopLevelContainerUpdater (NullEquivalenceUpdater .<Container >get ())
282
+ .build ());
265
283
266
284
Set <Publisher > reduxPublishers = Sets .union (acceptablePublishers , ImmutableSet .of (BBC_REDUX ));
267
285
268
286
updaters .register (BBC_REDUX , SourceSpecificEquivalenceUpdater .builder (BBC_REDUX )
269
- .withItemUpdater (broadcastItemEquivalenceUpdater (reduxPublishers , Score .nullScore ()))
287
+ .withItemUpdater (broadcastItemEquivalenceUpdater (reduxPublishers , Score .nullScore (), Predicates . alwaysTrue () ))
270
288
.withTopLevelContainerUpdater (broadcastItemContainerEquivalenceUpdater (reduxPublishers ))
271
289
.withNonTopLevelContainerUpdater (NullEquivalenceUpdater .<Container >get ())
272
290
.build ());
@@ -466,12 +484,13 @@ private EquivalenceUpdater<Container> broadcastItemContainerEquivalenceUpdater(S
466
484
.build ();
467
485
}
468
486
469
- private EquivalenceUpdater <Item > broadcastItemEquivalenceUpdater (Set <Publisher > sources , Score titleMismatch ) {
487
+ private EquivalenceUpdater <Item > broadcastItemEquivalenceUpdater (Set <Publisher > sources , Score titleMismatch ,
488
+ Predicate <? super Broadcast > filter ) {
470
489
return standardItemUpdater (sources , ImmutableSet .of (
471
490
new TitleMatchingItemScorer (),
472
491
new SequenceItemScorer (),
473
492
new TitleSubsetBroadcastItemScorer (contentResolver , titleMismatch , 80 /*percent*/ )
474
- )).build ();
493
+ ), filter ).build ();
475
494
}
476
495
477
496
private EquivalenceUpdater <Item > rtItemEquivalenceUpdater () {
0 commit comments