22
22
23
23
import javax .annotation .PostConstruct ;
24
24
25
+ import com .ericsson .ei .jmespath .JmesPathInterface ;
25
26
import lombok .Getter ;
26
27
import org .slf4j .Logger ;
27
28
import org .slf4j .LoggerFactory ;
34
35
import com .fasterxml .jackson .databind .JsonNode ;
35
36
import com .mongodb .BasicDBObject ;
36
37
import com .mongodb .util .JSON ;
38
+ import org .springframework .util .LinkedMultiValueMap ;
39
+ import org .springframework .util .MultiValueMap ;
37
40
38
41
/**
39
42
* This class represents the REST POST notification mechanism and the alternate
@@ -63,6 +66,9 @@ public class InformSubscription {
63
66
@ Value ("${notification.ttl.value}" )
64
67
private int ttlValue ;
65
68
69
+ @ Autowired
70
+ private JmesPathInterface jmespath ;
71
+
66
72
@ Autowired
67
73
SpringRestTemplate restTemplate ;
68
74
@@ -89,21 +95,34 @@ public void informSubscriber(String aggregatedObject, JsonNode subscriptionJson)
89
95
log .info ("NotificationType : " + notificationType );
90
96
String notificationMeta = subscriptionJson .get ("notificationMeta" ).toString ().replaceAll ("^\" |\" $" , "" );
91
97
log .info ("NotificationMeta : " + notificationMeta );
92
- if (notificationType .trim ().equals ("REST_POST" )) {
98
+ String notificationMessage = subscriptionJson .get ("notificationMessage" ).toString ().replaceAll ("^\" |\" $" , "" );
99
+ String filteredAggregatedObject = jmespath .runRuleOnEvent (notificationMessage , aggregatedObject ).toString ();
100
+ if (notificationType .trim ().equals ("REST_POST" ) || notificationType .trim ().equals ("REST_POST_JENKINS" )) {
93
101
log .info ("Notification through REST_POST" );
94
- int result = restTemplate .postData (aggregatedObject , notificationMeta );
102
+ int result = -1 ;
103
+ if (notificationType .trim ().equals ("REST_POST" )){result = restTemplate .postData (filteredAggregatedObject , notificationMeta );}
104
+ if (notificationType .trim ().equals ("REST_POST_JENKINS" )){
105
+ MultiValueMap <String , String > map = new LinkedMultiValueMap <String , String >();
106
+ map .add ("json" , filteredAggregatedObject );
107
+ result = restTemplate .postDataMultiValue (notificationMeta , map );
108
+ }
95
109
if (result == HttpStatus .OK .value () || result == HttpStatus .CREATED .value () || result == HttpStatus .NO_CONTENT .value ()) {
96
110
log .info ("The result is : " + result );
97
111
} else {
98
112
for (int i = 0 ; i < failAttempt ; i ++) {
99
- result = restTemplate .postData (aggregatedObject , notificationMeta );
100
- log .info ("After trying for " + (i + 1 ) + " times, the result is : " + result );
113
+ if (notificationType .trim ().equals ("REST_POST" )){result = restTemplate .postData (filteredAggregatedObject , notificationMeta );}
114
+ if (notificationType .trim ().equals ("REST_POST_JENKINS" )){
115
+ MultiValueMap <String , String > map = new LinkedMultiValueMap <String , String >();
116
+ map .add ("json" , filteredAggregatedObject );
117
+ result = restTemplate .postDataMultiValue (notificationMeta , map );
118
+ }
119
+ log .info ("After trying for " + (i + 1 ) + " times, the result is : " + result );
101
120
if (result == HttpStatus .OK .value ())
102
121
break ;
103
122
}
104
123
105
124
if (result != HttpStatus .OK .value () && result != HttpStatus .CREATED .value () && result != HttpStatus .NO_CONTENT .value ()) {
106
- String input = prepareMissedNotification (aggregatedObject , subscriptionName , notificationMeta );
125
+ String input = prepareMissedNotification (filteredAggregatedObject , subscriptionName , notificationMeta );
107
126
log .info ("Input missed Notification document : " + input );
108
127
mongoDBHandler .createTTLIndex (missedNotificationDataBaseName , missedNotificationCollectionName ,
109
128
"Time" , ttlValue );
@@ -120,7 +139,7 @@ public void informSubscriber(String aggregatedObject, JsonNode subscriptionJson)
120
139
}
121
140
else if (notificationType .trim ().equals ("MAIL" )) {
122
141
log .info ("Notification through EMAIL" );
123
- sendMail .sendMail (notificationMeta , aggregatedObject );
142
+ sendMail .sendMail (notificationMeta , filteredAggregatedObject );
124
143
125
144
}
126
145
}
0 commit comments