1
+ package stroom .dashboard .client .table ;
2
+
3
+ import stroom .dashboard .client .main .SearchModel ;
4
+ import stroom .dashboard .shared .ColumnValues ;
5
+ import stroom .dashboard .shared .ColumnValuesRequest ;
6
+ import stroom .dashboard .shared .ComponentResultRequest ;
7
+ import stroom .dashboard .shared .DashboardResource ;
8
+ import stroom .dashboard .shared .DashboardSearchRequest ;
9
+ import stroom .dashboard .shared .Search ;
10
+ import stroom .dashboard .shared .TableComponentSettings ;
11
+ import stroom .dashboard .shared .TableResultRequest ;
12
+ import stroom .dispatch .client .RestErrorHandler ;
13
+ import stroom .dispatch .client .RestFactory ;
14
+ import stroom .query .api .ColumnValueSelection ;
15
+ import stroom .query .api .ConditionalFormattingRule ;
16
+ import stroom .query .api .DateTimeSettings ;
17
+ import stroom .query .api .OffsetRange ;
18
+ import stroom .query .api .QueryKey ;
19
+ import stroom .query .api .ResultRequest .Fetch ;
20
+ import stroom .query .api .TableSettings ;
21
+ import stroom .util .shared .PageRequest ;
22
+ import stroom .util .shared .PageResponse ;
23
+
24
+ import com .google .gwt .core .client .GWT ;
25
+ import com .google .gwt .view .client .Range ;
26
+
27
+ import java .util .ArrayList ;
28
+ import java .util .Collections ;
29
+ import java .util .List ;
30
+ import java .util .Map ;
31
+ import java .util .function .Consumer ;
32
+
33
+ public class TableColumnValuesDataSupplier extends ColumnValuesDataSupplier {
34
+
35
+ private static final DashboardResource DASHBOARD_RESOURCE = GWT .create (DashboardResource .class );
36
+
37
+ private final RestFactory restFactory ;
38
+ private final SearchModel searchModel ;
39
+ private final DashboardSearchRequest searchRequest ;
40
+
41
+ public TableColumnValuesDataSupplier (
42
+ final RestFactory restFactory ,
43
+ final SearchModel searchModel ,
44
+ final stroom .query .api .Column column ,
45
+ final TableSettings tableSettings ,
46
+ final DateTimeSettings dateTimeSettings ,
47
+ final String tableName ,
48
+ final List <ConditionalFormattingRule > conditionalFormattingRules ) {
49
+ super (column .copy ().build (), conditionalFormattingRules );
50
+ this .restFactory = restFactory ;
51
+ this .searchModel = searchModel ;
52
+
53
+ DashboardSearchRequest dashboardSearchRequest = null ;
54
+ if (searchModel != null ) {
55
+ final QueryKey queryKey = searchModel .getCurrentQueryKey ();
56
+ final Search currentSearch = searchModel .getCurrentSearch ();
57
+ if (queryKey != null && currentSearch != null ) {
58
+ final List <ComponentResultRequest > requests = new ArrayList <>();
59
+ currentSearch .getComponentSettingsMap ().entrySet ()
60
+ .stream ()
61
+ .filter (settings -> settings .getValue () instanceof TableComponentSettings )
62
+ .forEach (componentSettings -> requests .add (TableResultRequest
63
+ .builder ()
64
+ .componentId (componentSettings .getKey ())
65
+ .requestedRange (OffsetRange .UNBOUNDED )
66
+ .tableName (tableName )
67
+ .tableSettings (tableSettings )
68
+ .fetch (Fetch .ALL )
69
+ .build ()));
70
+
71
+ final Search search = Search
72
+ .builder ()
73
+ .dataSourceRef (currentSearch .getDataSourceRef ())
74
+ .expression (currentSearch .getExpression ())
75
+ .componentSettingsMap (currentSearch .getComponentSettingsMap ())
76
+ .params (currentSearch .getParams ())
77
+ .timeRange (currentSearch .getTimeRange ())
78
+ .incremental (true )
79
+ .queryInfo (currentSearch .getQueryInfo ())
80
+ .build ();
81
+
82
+ dashboardSearchRequest = DashboardSearchRequest
83
+ .builder ()
84
+ .searchRequestSource (searchModel .getSearchRequestSource ())
85
+ .queryKey (queryKey )
86
+ .search (search )
87
+ .componentResultRequests (requests )
88
+ .dateTimeSettings (dateTimeSettings )
89
+ .build ();
90
+ }
91
+ }
92
+
93
+ searchRequest = dashboardSearchRequest ;
94
+ }
95
+
96
+ @ Override
97
+ protected void exec (final Range range ,
98
+ final Consumer <ColumnValues > dataConsumer ,
99
+ final RestErrorHandler errorHandler ,
100
+ final Map <String , ColumnValueSelection > selections ) {
101
+ if (searchRequest == null ) {
102
+ clear (dataConsumer );
103
+
104
+ } else {
105
+ final PageRequest pageRequest = new PageRequest (range .getStart (), range .getLength ());
106
+ final ColumnValuesRequest columnValuesRequest = new ColumnValuesRequest (
107
+ searchRequest ,
108
+ getColumn (),
109
+ getNameFilter (),
110
+ pageRequest ,
111
+ getConditionalFormattingRules (),
112
+ selections );
113
+
114
+ restFactory
115
+ .create (DASHBOARD_RESOURCE )
116
+ .method (res -> res .getColumnValues (searchModel .getCurrentNode (),
117
+ columnValuesRequest ))
118
+ .onSuccess (dataConsumer )
119
+ .onFailure (e -> clear (dataConsumer ))
120
+ .taskMonitorFactory (getTaskMonitorFactory ())
121
+ .exec ();
122
+ }
123
+ }
124
+
125
+ private void clear (final Consumer <ColumnValues > dataConsumer ) {
126
+ dataConsumer .accept (new ColumnValues (Collections .emptyList (), PageResponse .empty ()));
127
+ }
128
+ }
0 commit comments