17
17
function DiscoveryUtils ( ) { }
18
18
DiscoveryUtils . prototype = {
19
19
20
- buildParams : function ( msg , config ) {
21
- var params = { } ;
20
+ buildParamsForName : function ( msg , config , params ) {
22
21
if ( msg . discoveryparams && msg . discoveryparams . environmentname ) {
23
22
params . name = msg . discoveryparams . environmentname ;
24
23
} else if ( config . environmentname ) {
@@ -28,39 +27,63 @@ DiscoveryUtils.prototype = {
28
27
} else if ( config . configurationname ) {
29
28
params . name = config . cofigurationname ;
30
29
}
30
+ return params ;
31
+ } ,
31
32
32
- if ( msg . discoveryparams && msg . discoveryparams . environment_id ) {
33
- params . environment_id = msg . discoveryparams . environment_id ;
34
- } else if ( config . environment_id ) {
35
- params . environment_id = config . environment_id ;
33
+ buildParamsFor : function ( msg , config , params , field ) {
34
+ if ( msg . discoveryparams && msg . discoveryparams [ field ] ) {
35
+ params [ field ] = msg . discoveryparams [ field ] ;
36
+ } else if ( config [ field ] ) {
37
+ params [ field ] = config [ field ] ;
36
38
}
39
+ return params ;
40
+ } ,
37
41
38
- if ( msg . discoveryparams && msg . discoveryparams . collection_id ) {
39
- params . collection_id = msg . discoveryparams . collection_id ;
40
- } else if ( config . collection_id ) {
41
- params . collection_id = config . collection_id ;
42
+ buildParamsFromConfig : function ( config , params , field ) {
43
+ if ( config [ field ] ) {
44
+ params [ field ] = config [ field ] ;
42
45
}
46
+ return params ;
47
+ } ,
43
48
44
- if ( msg . discoveryparams && msg . discoveryparams . configuration_id ) {
45
- params . configuration_id = msg . discoveryparams . configuration_id ;
46
- } else if ( config . configuration_id ) {
47
- params . configuration_id = config . configuration_id ;
48
- }
49
+ buildParams : function ( msg , config ) {
50
+ var params = { } ;
51
+
52
+ params = DiscoveryUtils . prototype . buildParamsForName ( msg , config , params ) ;
53
+
54
+ [ 'environment_id' , 'collection_id' , 'configuration_id' , 'query' ] . forEach ( function ( f ) {
55
+ params = DiscoveryUtils . prototype . buildParamsFor ( msg , config , params , f ) ;
56
+ } ) ;
57
+
58
+ [ 'count' , 'filter' , 'aggregation' , 'return' ] . forEach ( function ( f ) {
59
+ params = DiscoveryUtils . prototype . buildParamsFromConfig ( config , params , f ) ;
60
+ } ) ;
49
61
50
- if ( config . count ) {
51
- params . count = config . count ;
62
+ return params ;
63
+ } ,
64
+
65
+ buildMsgOverrides : function ( msg , config ) {
66
+ var params = { } ;
67
+ if ( config . environment ) {
68
+ params . environment_id = config . environment ;
52
69
}
53
- if ( config . query ) {
54
- params . query = config . query ;
70
+ if ( config . collection ) {
71
+ params . collection_id = config . collection ;
55
72
}
56
- if ( config . filter ) {
57
- params . filter = config . filter ;
73
+ if ( config . query1 && config . queryvalue1 ) {
74
+ params . query = config . query1 + ':"' + config . queryvalue1 + '"' ;
58
75
}
59
- if ( config . aggregation ) {
60
- params . aggregation = config . aggregation ;
76
+ if ( config . query2 && config . queryvalue2 ) {
77
+ if ( params . query ) {
78
+ params . query += ',' ;
79
+ }
80
+ params . query += config . query2 + ':"' + config . queryvalue2 + '"' ;
61
81
}
62
- if ( config . return ) {
63
- params . return = config . return ;
82
+ if ( config . query3 && config . queryvalue3 ) {
83
+ if ( params . query ) {
84
+ params . query += ',' ;
85
+ }
86
+ params . query += config . query3 + ':"' + config . queryvalue3 + '"' ;
64
87
}
65
88
66
89
return params ;
@@ -90,6 +113,53 @@ DiscoveryUtils.prototype = {
90
113
return response ;
91
114
} ,
92
115
116
+ // Looking for Text, Type and label
117
+ buildFieldByStep : function ( d , fields , txt ) {
118
+ for ( var k in d ) {
119
+ var t = txt ;
120
+ if ( isNaN ( k ) ) {
121
+ t += txt ? '.' : '' ;
122
+ t += k ;
123
+ }
124
+
125
+ if ( 'object' === typeof d [ k ] ) {
126
+ fields = DiscoveryUtils . prototype . buildFieldByStep ( d [ k ] , fields , t ) ;
127
+ } else {
128
+ switch ( k ) {
129
+ case 'text' :
130
+ case 'type' :
131
+ case 'label' :
132
+ fields . push ( t ) ;
133
+ break ;
134
+ }
135
+ }
136
+ }
137
+ return fields ;
138
+ } ,
139
+
140
+ // sorting functions
141
+ uniqueFilter : function ( value , index , self ) {
142
+ return self . indexOf ( value ) === index ;
143
+ } ,
144
+
145
+ // Looking for Text, Type and label
146
+ buildFieldList : function ( schemaData ) {
147
+ var fields = [ ] ;
148
+ if ( 'object' === typeof schemaData ) {
149
+ for ( var k in schemaData ) {
150
+ if ( 'results' === k &&
151
+ 'object' === typeof schemaData [ k ] &&
152
+ 'object' === typeof schemaData [ k ] [ 0 ] ) {
153
+ fields = DiscoveryUtils . prototype . buildFieldByStep ( schemaData [ k ] [ 0 ] , fields , '' ) ;
154
+ }
155
+ }
156
+ if ( fields . length ) {
157
+ fields = fields . filter ( DiscoveryUtils . prototype . uniqueFilter ) ;
158
+ }
159
+ }
160
+ return fields ;
161
+ } ,
162
+
93
163
reportError : function ( node , msg , message ) {
94
164
var messageTxt = message . error ? message . error : message ;
95
165
node . status ( { fill :'red' , shape :'dot' , text : messageTxt } ) ;
0 commit comments