-
Notifications
You must be signed in to change notification settings - Fork 1k
/
SearchController.java
executable file
·761 lines (663 loc) · 28.6 KB
/
SearchController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/*
* Copyright 2012-2015 TORCH GmbH, 2015 Graylog, Inc.
*
* This file is part of Graylog.
*
* Graylog is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Graylog is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Graylog. If not, see <http://www.gnu.org/licenses/>.
*/
package controllers;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Collections2;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.net.MediaType;
import lib.SearchTools;
import lib.security.RestPermissions;
import org.graylog2.rest.models.system.indexer.responses.IndexRangeSummary;
import org.graylog2.restclient.lib.APIException;
import org.graylog2.restclient.lib.ApiClient;
import org.graylog2.restclient.lib.Field;
import org.graylog2.restclient.lib.ServerNodes;
import org.graylog2.restclient.lib.timeranges.InvalidRangeParametersException;
import org.graylog2.restclient.lib.timeranges.RelativeRange;
import org.graylog2.restclient.lib.timeranges.TimeRange;
import org.graylog2.restclient.models.ClusterEntity;
import org.graylog2.restclient.models.Input;
import org.graylog2.restclient.models.MessagesService;
import org.graylog2.restclient.models.Node;
import org.graylog2.restclient.models.NodeService;
import org.graylog2.restclient.models.Radio;
import org.graylog2.restclient.models.SavedSearch;
import org.graylog2.restclient.models.SavedSearchService;
import org.graylog2.restclient.models.SearchSort;
import org.graylog2.restclient.models.Stream;
import org.graylog2.restclient.models.StreamService;
import org.graylog2.restclient.models.UniversalSearch;
import org.graylog2.restclient.models.api.responses.QueryParseError;
import org.graylog2.restclient.models.api.results.DateHistogramResult;
import org.graylog2.restclient.models.api.results.MessageResult;
import org.graylog2.restclient.models.api.results.SearchResult;
import org.joda.time.DateTime;
import org.joda.time.Minutes;
import play.Logger;
import play.libs.Json;
import play.mvc.Result;
import javax.annotation.Nullable;
import javax.inject.Inject;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static views.helpers.Permissions.isPermitted;
public class SearchController extends AuthenticatedController {
// guess high, so we never have a bad resolution
private static final int DEFAULT_ASSUMED_GRAPH_RESOLUTION = 4000;
@Inject
protected UniversalSearch.Factory searchFactory;
@Inject
protected MessagesService messagesService;
@Inject
protected SavedSearchService savedSearchService;
@Inject
private ServerNodes serverNodes;
@Inject
private StreamService streamService;
@Inject
private NodeService nodeService;
@Inject
private ObjectMapper objectMapper;
public Result index(String q,
String rangeType,
int relative,
String from, String to,
String keyword,
String interval,
int page,
String savedSearchId,
String sortField, String sortOrder,
String fields,
int displayWidth) {
if (isPermitted(RestPermissions.SEARCHES_ABSOLUTE)
|| isPermitted(RestPermissions.SEARCHES_RELATIVE)
|| isPermitted(RestPermissions.SEARCHES_KEYWORD)) {
SearchSort sort = buildSearchSort(sortField, sortOrder);
return renderSearch(q,
Strings.isNullOrEmpty(rangeType) ? "relative" : rangeType, // stupid
relative,
from,
to,
keyword,
interval,
page,
savedSearchId,
fields,
displayWidth,
sort,
null,
null);
} else {
return redirect(routes.StreamsController.index());
}
}
protected Result renderSearch(String q,
String rangeType,
int relative,
String from,
String to,
String keyword,
String interval,
int page,
String savedSearchId,
String fields,
int displayWidth,
SearchSort sort,
Stream stream,
String filter) {
UniversalSearch search;
try {
search = getSearch(q, filter, rangeType, relative, from, to, keyword, page, sort);
} catch (InvalidRangeParametersException e2) {
return status(400, views.html.errors.error.render("Invalid range parameters provided.", e2, request()));
} catch (IllegalArgumentException e1) {
return status(400, views.html.errors.error.render("Invalid range type provided.", e1, request()));
}
SearchResult searchResult;
DateHistogramResult histogramResult;
SavedSearch savedSearch = null;
Set<String> selectedFields = getSelectedFields(fields);
String formattedHistogramResults;
Set<StreamDescription> streams;
Set<InputDescription> inputs = Sets.newHashSet();
Map<String, NodeDescription> nodes = Maps.newHashMap();
nodes.putAll(Maps.transformEntries(serverNodes.asMap(),
new Maps.EntryTransformer<String, Node, NodeDescription>() {
@Override
public NodeDescription transformEntry(
@Nullable String key,
@Nullable Node value) {
return new NodeDescription(value);
}
}));
try {
if (savedSearchId != null && !savedSearchId.isEmpty()) {
savedSearch = savedSearchService.get(savedSearchId);
}
searchResult = search.search();
// TODO create a bulk call to get stream and input details (and restrict the fields that come back)
final Set<String> streamIds = Sets.newHashSet();
final HashMultimap<String, String> usedInputIds = HashMultimap.create();
final HashMultimap<String, String> usedRadioIds = HashMultimap.create();
for (MessageResult messageResult : searchResult.getMessages()) {
streamIds.addAll(messageResult.getStreamIds());
usedInputIds.put(messageResult.getSourceNodeId(), messageResult.getSourceInputId());
if (messageResult.getSourceRadioId() != null) {
usedRadioIds.put(messageResult.getSourceRadioId(), messageResult.getSourceRadioInputId());
}
}
// resolve all stream information in the result set
final HashSet<Stream> allStreams = Sets.newHashSet(streamService.all().iterator());
streams = Sets.newHashSet(Collections2.transform(Sets.filter(allStreams, new Predicate<Stream>() {
@Override
public boolean apply(Stream input) {
return streamIds.contains(input.getId());
}
}), new Function<Stream, StreamDescription>() {
@Nullable
@Override
public StreamDescription apply(@Nullable Stream stream) {
return new StreamDescription(stream);
}
}));
// resolve all used inputs and nodes from the result set
final Map<String, Node> nodeMap = serverNodes.asMap();
for (final String nodeId : usedInputIds.keySet()) {
final HashSet<Input> allInputs = Sets.newHashSet(nodeMap.get(nodeId).getInputs());
inputs = Sets.newHashSet(Collections2.transform(Sets.filter(allInputs, new Predicate<Input>() {
@Override
public boolean apply(Input input) {
return usedInputIds.get(nodeId).contains(input.getId());
}
}), new Function<Input, InputDescription>() {
@Nullable
@Override
public InputDescription apply(Input input) {
return new InputDescription(input);
}
}));
}
// resolve radio inputs
for (final String radioId : usedRadioIds.keySet()) {
try {
final Radio radio = nodeService.loadRadio(radioId);
nodes.put(radio.getId(), new NodeDescription(radio));
final HashSet<Input> allRadioInputs = Sets.newHashSet(radio.getInputs());
inputs.addAll(Collections2.transform(Sets.filter(allRadioInputs, new Predicate<Input>() {
@Override
public boolean apply(Input input) {
return usedRadioIds.get(radioId).contains(input.getId());
}
}), new Function<Input, InputDescription>() {
@Override
public InputDescription apply(Input input) {
return new InputDescription(input);
}
}));
} catch (NodeService.NodeNotFoundException e) {
Logger.warn("Could not load radio node " + radioId, e);
}
}
searchResult.setAllFields(getAllFields());
// histogram resolution (strangely aka interval)
if (interval == null || interval.isEmpty() || !SearchTools.isAllowedDateHistogramInterval(interval)) {
interval = determineHistogramResolution(searchResult);
}
histogramResult = search.dateHistogram(interval);
formattedHistogramResults = formatHistogramResults(histogramResult.getResults(), displayWidth);
} catch (IOException e) {
return status(504, views.html.errors.error.render(ApiClient.ERROR_MSG_IO, e, request()));
} catch (APIException e) {
if (e.getHttpCode() == 400) {
try {
QueryParseError qpe = objectMapper.readValue(e.getResponseBody(), QueryParseError.class);
return ok(views.html.search.queryerror.render(currentUser(), q, qpe, savedSearch, fields, stream));
} catch (IOException ioe) {
// Ignore
}
}
String message = "There was a problem with your search. We expected HTTP 200, but got a HTTP " + e.getHttpCode() + ".";
return status(504, views.html.errors.error.render(message, e, request()));
}
return ok(views.html.search.index.render(currentUser(),
q,
search,
page,
savedSearch,
selectedFields,
searchResult,
histogramResult,
formattedHistogramResults,
nodes,
Maps.uniqueIndex(streams, new Function<StreamDescription, String>() {
@Nullable
@Override
public String apply(@Nullable StreamDescription stream) {
return stream == null ? null : stream.getId();
}
}),
Maps.uniqueIndex(inputs, new Function<InputDescription, String>() {
@Nullable
@Override
public String apply(@Nullable InputDescription input) {
return input == null ? null : input.getId();
}
}),
stream));
}
protected String determineHistogramResolution(final SearchResult searchResult) {
final String interval;
final int HOUR = 60;
final int DAY = HOUR * 24;
final int WEEK = DAY * 7;
final int MONTH = HOUR * 24 * 30;
final int YEAR = MONTH * 12;
// Return minute as default resolution if search from and to DateTimes are not available
if (searchResult.getFromDateTime() == null && searchResult.getToDateTime() == null) {
return "minute";
}
int queryRangeInMinutes;
// We don't want to use fromDateTime coming from the search query if the user asked for all messages
if (isEmptyRelativeRange(searchResult.getTimeRange())) {
List<IndexRangeSummary> usedIndices = searchResult.getUsedIndices();
Collections.sort(usedIndices, new Comparator<IndexRangeSummary>() {
@Override
public int compare(IndexRangeSummary o1, IndexRangeSummary o2) {
return o1.start().compareTo(o2.start());
}
});
IndexRangeSummary oldestIndex = usedIndices.get(0);
queryRangeInMinutes = Minutes.minutesBetween(oldestIndex.start(),
searchResult.getToDateTime()).getMinutes();
} else {
queryRangeInMinutes = Minutes.minutesBetween(searchResult.getFromDateTime(),
searchResult.getToDateTime()).getMinutes();
}
if (queryRangeInMinutes < DAY / 2) {
interval = "minute";
} else if (queryRangeInMinutes < DAY * 2) {
interval = "hour";
} else if (queryRangeInMinutes < MONTH) {
interval = "day";
} else if (queryRangeInMinutes < MONTH * 6) {
interval = "week";
} else if (queryRangeInMinutes < YEAR * 2) {
interval = "month";
} else if (queryRangeInMinutes < YEAR * 10) {
interval = "quarter";
} else {
interval = "year";
}
return interval;
}
private boolean isEmptyRelativeRange(TimeRange timeRange) {
return (timeRange.getType() == TimeRange.Type.RELATIVE) && (((RelativeRange) timeRange).isEmptyRange());
}
/**
* [{ x: -1893456000, y: 92228531 }, { x: -1577923200, y: 106021568 }]
*
* @return A JSON string representation of the result, suitable for Rickshaw data graphing.
*/
protected String formatHistogramResults(Map<String, Long> histogramResults, int displayWidth) {
final int saneDisplayWidth = (displayWidth == -1 || displayWidth < 100 || displayWidth > DEFAULT_ASSUMED_GRAPH_RESOLUTION) ? DEFAULT_ASSUMED_GRAPH_RESOLUTION : displayWidth;
final List<Map<String, Long>> points = Lists.newArrayList();
// using the absolute value guarantees, that there will always be enough values for the given resolution
final int factor = (saneDisplayWidth != -1 && histogramResults.size() > saneDisplayWidth) ? histogramResults.size() / saneDisplayWidth : 1;
int index = 0;
for (Map.Entry<String, Long> result : histogramResults.entrySet()) {
// TODO: instead of sampling we might consider interpolation (compare DashboardsApiController)
if (index % factor == 0) {
Map<String, Long> point = Maps.newHashMap();
point.put("x", Long.parseLong(result.getKey()));
point.put("y", result.getValue());
points.add(point);
}
index++;
}
return Json.stringify(Json.toJson(points));
}
protected Set<String> getSelectedFields(String fields) {
Set<String> selectedFields = Sets.newLinkedHashSet();
if (fields != null && !fields.isEmpty()) {
Iterables.addAll(selectedFields, Splitter.on(',').split(fields));
} else {
selectedFields.addAll(Field.STANDARD_SELECTED_FIELDS);
}
return selectedFields;
}
public Result exportAsCsv(String q,
String filter,
String rangeType,
int relative,
String from,
String to,
String keyword,
String fields) {
UniversalSearch search;
try {
search = getSearch(q,
filter.isEmpty() ? null : filter,
rangeType,
relative,
from,
to,
keyword,
0,
UniversalSearch.DEFAULT_SORT);
} catch (InvalidRangeParametersException e2) {
return status(400, views.html.errors.error.render("Invalid range parameters provided.", e2, request()));
} catch (IllegalArgumentException e1) {
return status(400, views.html.errors.error.render("Invalid range type provided.", e1, request()));
}
final InputStream stream;
try {
Set<String> selectedFields = getSelectedFields(fields);
stream = search.searchAsCsv(selectedFields);
} catch (IOException e) {
return status(504, views.html.errors.error.render(ApiClient.ERROR_MSG_IO, e, request()));
} catch (APIException e) {
String message = "There was a problem with your search. We expected HTTP 200, but got a HTTP " + e.getHttpCode() + ".";
return status(504, views.html.errors.error.render(message, e, request()));
}
response().setContentType(MediaType.CSV_UTF_8.toString());
response().setHeader("Content-Disposition", "attachment; filename=graylog-searchresult.csv");
return ok(stream);
}
protected List<Field> getAllFields() {
List<Field> allFields = Lists.newArrayList();
for (String f : messagesService.getMessageFields()) {
allFields.add(new Field(f));
}
return allFields;
}
protected UniversalSearch getSearch(String q,
String filter,
String rangeType,
int relative,
String from,
String to,
String keyword,
int page,
SearchSort order)
throws InvalidRangeParametersException, IllegalArgumentException {
if (q == null || q.trim().isEmpty()) {
q = "*";
}
// Determine timerange type.
TimeRange timerange = TimeRange.factory(rangeType, relative, from, to, keyword);
UniversalSearch search;
if (filter == null) {
search = searchFactory.queryWithRangePageAndOrder(q, timerange, page, order);
} else {
search = searchFactory.queryWithFilterRangePageAndOrder(q, filter, timerange, page, order);
}
return search;
}
protected SearchSort buildSearchSort(String sortField, String sortOrder) {
if (sortField == null || sortOrder == null || sortField.isEmpty() || sortOrder.isEmpty()) {
return UniversalSearch.DEFAULT_SORT;
}
try {
return new SearchSort(sortField, SearchSort.Direction.valueOf(sortOrder.toUpperCase()));
} catch (IllegalArgumentException e) {
return UniversalSearch.DEFAULT_SORT;
}
}
public static class InputDescription {
@JsonIgnore
private final Input input;
public InputDescription(Input input) {
this.input = input;
}
@JsonProperty
public String getId() {
return input.getId();
}
@JsonProperty
public String getName() {
return input.getName();
}
@JsonProperty
public String getTitle() {
return input.getTitle();
}
@JsonProperty
public String getCreatorUser() {
return input.getCreatorUser().getName();
}
@JsonProperty
public Boolean getGlobal() {
return input.getGlobal();
}
@JsonProperty
public DateTime getCreatedAt() {
return input.getCreatedAt();
}
@JsonProperty
public String getType() {
return input.getType();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
InputDescription that = (InputDescription) o;
return input.equals(that.input);
}
@Override
public int hashCode() {
return input.hashCode();
}
}
public static class StreamDescription {
@JsonIgnore
private final Stream stream;
public StreamDescription(Stream stream) {
this.stream = stream;
}
public static StreamDescription of(Stream stream) {
if (stream == null) {
return null;
}
return new StreamDescription(stream);
}
@JsonProperty
public String getDescription() {
return stream.getDescription();
}
@JsonProperty
public String getTitle() {
return stream.getTitle();
}
@JsonProperty
public String getCreatorUser() {
return stream.getCreatorUser().getName();
}
@JsonProperty
public DateTime getCreatedAt() {
return stream.getCreatedAt();
}
@JsonProperty
public String getId() {
return stream.getId();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
StreamDescription that = (StreamDescription) o;
return stream.equals(that.stream);
}
@Override
public int hashCode() {
return stream.hashCode();
}
}
public static class NodeDescription {
@JsonIgnore
private final ClusterEntity entity;
public NodeDescription(ClusterEntity cluster) {
this.entity = cluster;
}
@JsonProperty
public String getNodeId() {
return entity.getNodeId();
}
@JsonProperty
public String getShortNodeId() {
return entity.getShortNodeId();
}
@JsonProperty
public String getHostname() {
return entity.getHostname();
}
@JsonProperty
public boolean isMaster() {
return entity instanceof Node && ((Node) entity).isMaster();
}
@JsonProperty
public boolean isRadio() {
return entity instanceof Radio;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
NodeDescription that = (NodeDescription) o;
return entity.equals(that.entity);
}
@Override
public int hashCode() {
return entity.hashCode();
}
}
public Result showMessage(String index, String id) {
final Set<InputDescription> inputs = Sets.newHashSet();
final Set<StreamDescription> streams = Sets.newHashSet();
final Set<NodeDescription> nodes = Sets.newHashSet();
try {
final MessageResult message = messagesService.getMessage(index, id);
final Node sourceNode = getSourceNode(message);
final Radio sourceRadio = getSourceRadio(message);
final Input sourceInput = getSourceInput(sourceNode, message);
final Input sourceRadioInput = getSourceInput(sourceRadio, message);
nodes.add(new NodeDescription(sourceNode));
if (sourceRadio != null) {
nodes.add(new NodeDescription(sourceRadio));
}
inputs.add(new InputDescription(sourceInput));
if (sourceRadioInput != null) {
inputs.add(new InputDescription(sourceRadioInput));
}
for (String streamId : message.getStreamIds()) {
if (isPermitted(RestPermissions.STREAMS_READ, streamId)) {
try {
final Stream stream = streamService.get(streamId);
streams.add(new StreamDescription(stream));
} catch (APIException e) {
// We get a 404 if the stream no longer exists.
Logger.debug("Skipping stream of message", e);
}
}
}
return ok(views.html.search.show_message.render(currentUser(),
message,
Maps.uniqueIndex(nodes, new Function<NodeDescription, String>() {
@Nullable
@Override
public String apply(@Nullable NodeDescription node) {
return node == null ? null : node.getNodeId();
}
}),
Maps.uniqueIndex(streams, new Function<StreamDescription, String>() {
@Nullable
@Override
public String apply(@Nullable StreamDescription stream) {
return stream == null ? null : stream.getId();
}
}),
Maps.uniqueIndex(inputs, new Function<InputDescription, String>() {
@Nullable
@Override
public String apply(@Nullable InputDescription input) {
return input == null ? null : input.getId();
}
})));
} catch (IOException e) {
return status(500, views.html.errors.error.render(ApiClient.ERROR_MSG_IO, e, request()));
} catch (APIException e) {
String message = "Could not get message. We expected HTTP 200, but got a HTTP " + e.getHttpCode() + ".";
return status(500, views.html.errors.error.render(message, e, request()));
}
}
private Node getSourceNode(MessageResult m) {
try {
return nodeService.loadNode(m.getSourceNodeId());
} catch (Exception e) {
Logger.warn("Could not derive source node from message <" + m.getId() + ">.", e);
}
return null;
}
private Radio getSourceRadio(MessageResult m) {
if (m.viaRadio()) {
try {
return nodeService.loadRadio(m.getSourceRadioId());
} catch (Exception e) {
Logger.warn("Could not derive source radio from message <" + m.getId() + ">.", e);
}
}
return null;
}
private static Input getSourceInput(Node node, MessageResult m) {
if (node != null && isPermitted(RestPermissions.INPUTS_READ, m.getSourceInputId())) {
try {
return node.getInput(m.getSourceInputId());
} catch (Exception e) {
Logger.warn("Could not derive source input from message <" + m.getId() + ">.", e);
}
}
return null;
}
private static Input getSourceInput(Radio radio, MessageResult m) {
if (radio != null) {
try {
return radio.getInput(m.getSourceRadioInputId());
} catch (Exception e) {
Logger.warn("Could not derive source radio input from message <" + m.getId() + ">.", e);
}
}
return null;
}
}