@@ -82,7 +82,7 @@ public PrnfbNotification addOrUpdateNotification(PrnfbNotification prnfbNotifica
82
82
public PrnfbNotification doInTransaction () {
83
83
try {
84
84
return doAddOrUpdateNotification (prnfbNotification );
85
- } catch (ValidationException e ) {
85
+ } catch (final ValidationException e ) {
86
86
propagate (e );
87
87
}
88
88
return null ;
@@ -121,7 +121,7 @@ public Optional<PrnfbNotification> findNotification(UUID notificationUuid) {
121
121
}
122
122
123
123
public PrnfbButton getButton (UUID buttionUuid ) {
124
- Optional <PrnfbButton > foundOpt = findButton (buttionUuid );
124
+ final Optional <PrnfbButton > foundOpt = findButton (buttionUuid );
125
125
if (!foundOpt .isPresent ()) {
126
126
throw new RuntimeException (buttionUuid + " not fond in:\n " + on ('\n' ).join (getButtons ()));
127
127
}
@@ -133,8 +133,8 @@ public List<PrnfbButton> getButtons() {
133
133
}
134
134
135
135
public List <PrnfbButton > getButtons (String projectKey ) {
136
- List <PrnfbButton > found = newArrayList ();
137
- for (PrnfbButton candidate : getPrnfbSettings ().getButtons ()) {
136
+ final List <PrnfbButton > found = newArrayList ();
137
+ for (final PrnfbButton candidate : getPrnfbSettings ().getButtons ()) {
138
138
if (candidate .getProjectKey ().isPresent ()
139
139
&& candidate .getProjectKey ().get ().equals (projectKey )) {
140
140
found .add (candidate );
@@ -144,8 +144,8 @@ public List<PrnfbButton> getButtons(String projectKey) {
144
144
}
145
145
146
146
public List <PrnfbButton > getButtons (String projectKey , String repositorySlug ) {
147
- List <PrnfbButton > found = newArrayList ();
148
- for (PrnfbButton candidate : getPrnfbSettings ().getButtons ()) {
147
+ final List <PrnfbButton > found = newArrayList ();
148
+ for (final PrnfbButton candidate : getPrnfbSettings ().getButtons ()) {
149
149
if (candidate .getProjectKey ().isPresent ()
150
150
&& candidate .getProjectKey ().get ().equals (projectKey ) //
151
151
&& candidate .getRepositorySlug ().isPresent ()
@@ -165,8 +165,8 @@ public List<PrnfbNotification> getNotifications() {
165
165
}
166
166
167
167
public List <PrnfbNotification > getNotifications (String projectKey ) {
168
- List <PrnfbNotification > found = newArrayList ();
169
- for (PrnfbNotification candidate : getPrnfbSettings ().getNotifications ()) {
168
+ final List <PrnfbNotification > found = newArrayList ();
169
+ for (final PrnfbNotification candidate : getPrnfbSettings ().getNotifications ()) {
170
170
if (candidate .getProjectKey ().isPresent ()
171
171
&& candidate .getProjectKey ().get ().equals (projectKey )) {
172
172
found .add (candidate );
@@ -176,8 +176,8 @@ public List<PrnfbNotification> getNotifications(String projectKey) {
176
176
}
177
177
178
178
public List <PrnfbNotification > getNotifications (String projectKey , String repositorySlug ) {
179
- List <PrnfbNotification > found = newArrayList ();
180
- for (PrnfbNotification candidate : getPrnfbSettings ().getNotifications ()) {
179
+ final List <PrnfbNotification > found = newArrayList ();
180
+ for (final PrnfbNotification candidate : getPrnfbSettings ().getNotifications ()) {
181
181
if (candidate .getProjectKey ().isPresent ()
182
182
&& candidate .getProjectKey ().get ().equals (projectKey ) //
183
183
&& candidate .getRepositorySlug ().isPresent ()
@@ -208,8 +208,8 @@ public void setPrnfbSettingsData(PrnfbSettingsData prnfbSettingsData) {
208
208
new TransactionCallback <Void >() {
209
209
@ Override
210
210
public Void doInTransaction () {
211
- PrnfbSettings oldSettings = doGetPrnfbSettings ();
212
- PrnfbSettings newPrnfbSettings =
211
+ final PrnfbSettings oldSettings = doGetPrnfbSettings ();
212
+ final PrnfbSettings newPrnfbSettings =
213
213
prnfbSettingsBuilder (oldSettings ) //
214
214
.setPrnfbSettingsData (prnfbSettingsData ) //
215
215
.build ();
@@ -224,8 +224,8 @@ private PrnfbButton doAddOrUpdateButton(PrnfbButton prnfbButton) {
224
224
doDeleteButton (prnfbButton .getUuid ());
225
225
}
226
226
227
- PrnfbSettings originalSettings = doGetPrnfbSettings ();
228
- PrnfbSettings updated =
227
+ final PrnfbSettings originalSettings = doGetPrnfbSettings ();
228
+ final PrnfbSettings updated =
229
229
prnfbSettingsBuilder (originalSettings ) //
230
230
.withButton (prnfbButton ) //
231
231
.build ();
@@ -236,28 +236,39 @@ private PrnfbButton doAddOrUpdateButton(PrnfbButton prnfbButton) {
236
236
237
237
private PrnfbNotification doAddOrUpdateNotification (PrnfbNotification newNotification )
238
238
throws ValidationException {
239
- Optional <PrnfbNotification > oldNotification = findNotification (newNotification .getUuid ());
239
+ final UUID notificationUuid = newNotification .getUuid ();
240
+
241
+ Optional <String > oldUser = Optional .absent ();
242
+ Optional <String > oldPassword = Optional .absent ();
243
+ Optional <String > oldProxyUser = Optional .absent ();
244
+ Optional <String > oldProxyPassword = Optional .absent ();
245
+ final Optional <PrnfbNotification > oldNotification = findNotification (notificationUuid );
246
+ if (oldNotification .isPresent ()) {
247
+ oldUser = oldNotification .get ().getUser ();
248
+ oldPassword = oldNotification .get ().getPassword ();
249
+ oldProxyUser = oldNotification .get ().getProxyUser ();
250
+ oldProxyPassword = oldNotification .get ().getProxyPassword ();
251
+ }
252
+
253
+ final String user = keepIfUnchanged (newNotification .getUser (), oldUser );
254
+ final String password = keepIfUnchanged (newNotification .getPassword (), oldPassword );
255
+ final String proxyUser = keepIfUnchanged (newNotification .getProxyUser (), oldProxyUser );
256
+ final String proxyPassword =
257
+ keepIfUnchanged (newNotification .getProxyPassword (), oldProxyPassword );
258
+ newNotification =
259
+ prnfbNotificationBuilder (newNotification ) //
260
+ .withUser (user ) //
261
+ .withPassword (password ) //
262
+ .withProxyUser (proxyUser ) //
263
+ .withProxyPassword (proxyPassword ) //
264
+ .build ();
265
+
240
266
if (oldNotification .isPresent ()) {
241
- String user = keepIfUnchanged (newNotification .getUser (), oldNotification .get ().getUser ());
242
- String password =
243
- keepIfUnchanged (newNotification .getPassword (), oldNotification .get ().getPassword ());
244
- String proxyUser =
245
- keepIfUnchanged (newNotification .getProxyUser (), oldNotification .get ().getProxyUser ());
246
- String proxyPassword =
247
- keepIfUnchanged (
248
- newNotification .getProxyPassword (), oldNotification .get ().getProxyPassword ());
249
- newNotification =
250
- prnfbNotificationBuilder (newNotification ) //
251
- .withUser (user ) //
252
- .withPassword (password ) //
253
- .withProxyUser (proxyUser ) //
254
- .withProxyPassword (proxyPassword ) //
255
- .build ();
256
- doDeleteNotification (newNotification .getUuid ());
267
+ doDeleteNotification (notificationUuid );
257
268
}
258
269
259
- PrnfbSettings originalSettings = doGetPrnfbSettings ();
260
- PrnfbSettings updated =
270
+ final PrnfbSettings originalSettings = doGetPrnfbSettings ();
271
+ final PrnfbSettings updated =
261
272
prnfbSettingsBuilder (originalSettings ) //
262
273
.withNotification (newNotification ) //
263
274
.build ();
@@ -267,29 +278,29 @@ private PrnfbNotification doAddOrUpdateNotification(PrnfbNotification newNotific
267
278
}
268
279
269
280
private String keepIfUnchanged (Optional <String > newValue , Optional <String > oldValue ) {
270
- boolean isUnchanged = newValue .isPresent () && newValue .get ().equals (UNCHANGED );
281
+ final boolean isUnchanged = newValue .isPresent () && newValue .get ().equals (UNCHANGED );
271
282
if (isUnchanged ) {
272
283
return oldValue .orNull ();
273
284
}
274
285
return newValue .orNull ();
275
286
}
276
287
277
288
private void doDeleteButton (UUID uuid ) {
278
- PrnfbSettings originalSettings = doGetPrnfbSettings ();
279
- List <PrnfbButton > keep =
289
+ final PrnfbSettings originalSettings = doGetPrnfbSettings ();
290
+ final List <PrnfbButton > keep =
280
291
newArrayList (filter (originalSettings .getButtons (), not (withUuid (uuid ))));
281
- PrnfbSettings withoutDeleted =
292
+ final PrnfbSettings withoutDeleted =
282
293
prnfbSettingsBuilder (originalSettings ) //
283
294
.setButtons (keep ) //
284
295
.build ();
285
296
doSetPrnfbSettings (withoutDeleted );
286
297
}
287
298
288
299
private void doDeleteNotification (UUID uuid ) {
289
- PrnfbSettings originalSettings = doGetPrnfbSettings ();
290
- List <PrnfbNotification > keep =
300
+ final PrnfbSettings originalSettings = doGetPrnfbSettings ();
301
+ final List <PrnfbNotification > keep =
291
302
newArrayList (filter (originalSettings .getNotifications (), not (withUuid (uuid ))));
292
- PrnfbSettings withoutDeleted =
303
+ final PrnfbSettings withoutDeleted =
293
304
prnfbSettingsBuilder (originalSettings ) //
294
305
.setNotifications (keep ) //
295
306
.build ();
@@ -307,12 +318,12 @@ private PrnfbSettings doGetPrnfbSettings() {
307
318
!= null ) {
308
319
try {
309
320
this .logger .info ("Using legacy settings." );
310
- se .bjurr .prnfb .settings .legacy .PrnfbSettings legacySettings =
321
+ final se .bjurr .prnfb .settings .legacy .PrnfbSettings legacySettings =
311
322
SettingsStorage .getPrnfbSettings (this .pluginSettings );
312
- PrnfbSettings fromLegacy = settingsFromLegacy (legacySettings );
323
+ final PrnfbSettings fromLegacy = settingsFromLegacy (legacySettings );
313
324
doSetPrnfbSettings (fromLegacy );
314
325
storedSettings = this .pluginSettings .get (STORAGE_KEY );
315
- } catch (Exception e ) {
326
+ } catch (final Exception e ) {
316
327
this .logger .error ("" , e );
317
328
}
318
329
} else {
@@ -329,23 +340,23 @@ private PrnfbSettings doGetPrnfbSettings() {
329
340
}
330
341
331
342
private void doSetPrnfbSettings (PrnfbSettings newSettings ) {
332
- PrnfbSettingsData oldSettingsData = doGetPrnfbSettings ().getPrnfbSettingsData ();
333
- PrnfbSettingsData newSettingsData = newSettings .getPrnfbSettingsData ();
334
- String keyStorePassword =
343
+ final PrnfbSettingsData oldSettingsData = doGetPrnfbSettings ().getPrnfbSettingsData ();
344
+ final PrnfbSettingsData newSettingsData = newSettings .getPrnfbSettingsData ();
345
+ final String keyStorePassword =
335
346
keepIfUnchanged (
336
347
newSettingsData .getKeyStorePassword (), oldSettingsData .getKeyStorePassword ());
337
348
338
- PrnfbSettingsData adjustedSettingsData =
349
+ final PrnfbSettingsData adjustedSettingsData =
339
350
prnfbSettingsDataBuilder (newSettingsData ) //
340
351
.setKeyStorePassword (keyStorePassword ) //
341
352
.build ();
342
353
343
- PrnfbSettings adjustedSettings =
354
+ final PrnfbSettings adjustedSettings =
344
355
prnfbSettingsBuilder (newSettings ) //
345
356
.setPrnfbSettingsData (adjustedSettingsData ) //
346
357
.build ();
347
358
348
- String data = gson .toJson (adjustedSettings );
359
+ final String data = gson .toJson (adjustedSettings );
349
360
this .pluginSettings .put (STORAGE_KEY , data );
350
361
}
351
362
@@ -363,9 +374,9 @@ public T perform() throws RuntimeException {
363
374
364
375
private PrnfbSettings settingsFromLegacy (
365
376
se .bjurr .prnfb .settings .legacy .PrnfbSettings oldSettings ) {
366
- String ks = oldSettings .getKeyStore ().orNull ();
367
- String ksp = oldSettings .getKeyStorePassword ().orNull ();
368
- String kst = oldSettings .getKeyStoreType ();
377
+ final String ks = oldSettings .getKeyStore ().orNull ();
378
+ final String ksp = oldSettings .getKeyStorePassword ().orNull ();
379
+ final String kst = oldSettings .getKeyStoreType ();
369
380
USER_LEVEL adminRestr = USER_LEVEL .SYSTEM_ADMIN ;
370
381
if (oldSettings .isAdminsAllowed ()) {
371
382
adminRestr = USER_LEVEL .ADMIN ;
@@ -374,10 +385,10 @@ private PrnfbSettings settingsFromLegacy(
374
385
adminRestr = USER_LEVEL .EVERYONE ;
375
386
}
376
387
377
- boolean shouldAcceptAnyCertificate = false ;
388
+ final boolean shouldAcceptAnyCertificate = false ;
378
389
379
- List <PrnfbButton > newButtons = newArrayList ();
380
- for (se .bjurr .prnfb .settings .legacy .PrnfbButton oldButton : oldSettings .getButtons ()) {
390
+ final List <PrnfbButton > newButtons = newArrayList ();
391
+ for (final se .bjurr .prnfb .settings .legacy .PrnfbButton oldButton : oldSettings .getButtons ()) {
381
392
USER_LEVEL userLevel = USER_LEVEL .SYSTEM_ADMIN ;
382
393
if (oldButton .getVisibility () == BUTTON_VISIBILITY .ADMIN ) {
383
394
userLevel = USER_LEVEL .ADMIN ;
@@ -397,11 +408,11 @@ private PrnfbSettings settingsFromLegacy(
397
408
null ));
398
409
}
399
410
400
- List <PrnfbNotification > newNotifications = newArrayList ();
401
- for (se .bjurr .prnfb .settings .legacy .PrnfbNotification oldNotification :
411
+ final List <PrnfbNotification > newNotifications = newArrayList ();
412
+ for (final se .bjurr .prnfb .settings .legacy .PrnfbNotification oldNotification :
402
413
oldSettings .getNotifications ()) {
403
414
try {
404
- PrnfbNotificationBuilder builder =
415
+ final PrnfbNotificationBuilder builder =
405
416
prnfbNotificationBuilder () //
406
417
.withFilterRegexp (oldNotification .getFilterRegexp ().orNull ()) //
407
418
.withFilterString (oldNotification .getFilterString ().orNull ()) //
@@ -420,20 +431,20 @@ private PrnfbSettings settingsFromLegacy(
420
431
.withUrl (oldNotification .getUrl ()) //
421
432
.withUser (oldNotification .getUser ().orNull ());
422
433
423
- for (Header h : oldNotification .getHeaders ()) {
434
+ for (final Header h : oldNotification .getHeaders ()) {
424
435
builder .withHeader (h .getName (), h .getValue ());
425
436
}
426
437
427
- for (PullRequestState t : oldNotification .getTriggerIgnoreStateList ()) {
438
+ for (final PullRequestState t : oldNotification .getTriggerIgnoreStateList ()) {
428
439
builder .withTriggerIgnoreState (t );
429
440
}
430
441
431
- for (PrnfbPullRequestAction t : oldNotification .getTriggers ()) {
442
+ for (final PrnfbPullRequestAction t : oldNotification .getTriggers ()) {
432
443
builder .withTrigger (t );
433
444
}
434
445
435
446
newNotifications .add (builder .build ());
436
- } catch (ValidationException e ) {
447
+ } catch (final ValidationException e ) {
437
448
this .logger .error ("" , e );
438
449
}
439
450
}
0 commit comments