@@ -250,88 +250,18 @@ private void doDeleteNotification(UUID uuid) {
250
250
private PrnfbSettings doGetPrnfbSettings () {
251
251
Object storedSettings = this .pluginSettings .get (STORAGE_KEY );
252
252
if (storedSettings == null ) {
253
+ this .logger .info ("No settings found for " + STORAGE_KEY + ", looking for legacy settings." );
253
254
try {
254
- se .bjurr .prnfb .settings .legacy .PrnfbSettings oldSettings = SettingsStorage .getPrnfbSettings (this .pluginSettings );
255
-
256
- String ks = oldSettings .getKeyStore ().orNull ();
257
- String ksp = oldSettings .getKeyStorePassword ().orNull ();
258
- String kst = oldSettings .getKeyStoreType ();
259
- USER_LEVEL adminRestr = USER_LEVEL .SYSTEM_ADMIN ;
260
- if (oldSettings .isAdminsAllowed ()) {
261
- adminRestr = USER_LEVEL .ADMIN ;
255
+ se .bjurr .prnfb .settings .legacy .PrnfbSettings legacySettings = SettingsStorage .getPrnfbSettings (this .pluginSettings );
256
+ if (this .pluginSettings .get (se .bjurr .prnfb .settings .legacy .SettingsStorage .STORAGE_KEY ) != null
257
+ || this .pluginSettings .get (se .bjurr .prnfb .settings .legacy .SettingsStorage .STORAGE_KEY_PRNFS ) != null ) {
258
+ this .logger .info ("Using legacy settings." );
259
+ return settingsFromLegacy (legacySettings );
262
260
}
263
- if (oldSettings .isUsersAllowed ()) {
264
- adminRestr = USER_LEVEL .EVERYONE ;
265
- }
266
-
267
- boolean shouldAcceptAnyCertificate = false ;
268
-
269
- List <PrnfbButton > newButtons = newArrayList ();
270
- for (se .bjurr .prnfb .settings .legacy .PrnfbButton oldButton : oldSettings .getButtons ()) {
271
- USER_LEVEL userLevel = USER_LEVEL .SYSTEM_ADMIN ;
272
- if (oldButton .getVisibility () == BUTTON_VISIBILITY .ADMIN ) {
273
- userLevel = USER_LEVEL .ADMIN ;
274
- }
275
- if (oldButton .getVisibility () == BUTTON_VISIBILITY .EVERYONE ) {
276
- userLevel = USER_LEVEL .EVERYONE ;
277
- }
278
- newButtons .add (new PrnfbButton (UUID .randomUUID (), oldButton .getTitle (), userLevel , null , null ));
279
- }
280
-
281
- List <PrnfbNotification > newNotifications = newArrayList ();
282
- for (se .bjurr .prnfb .settings .legacy .PrnfbNotification oldNotification : oldSettings .getNotifications ()) {
283
- try {
284
- PrnfbNotificationBuilder builder = prnfbNotificationBuilder ()//
285
- .withFilterRegexp (oldNotification .getFilterRegexp ().orNull ())//
286
- .withFilterString (oldNotification .getFilterString ().orNull ())//
287
- .withInjectionUrl (oldNotification .getInjectionUrl ().orNull ())//
288
- .withInjectionUrlRegexp (oldNotification .getInjectionUrlRegexp ().orNull ())//
289
- .withMethod (oldNotification .getMethod ())//
290
- .withName (oldNotification .getName ())//
291
- .withPassword (oldNotification .getPassword ().orNull ())//
292
- .withPostContent (oldNotification .getPostContent ().orNull ())//
293
- .withProxyPassword (oldNotification .getProxyPassword ().orNull ())//
294
- .withProxyPort (oldNotification .getProxyPort ())//
295
- .withProxyServer (oldNotification .getProxyServer ().orNull ())//
296
- .withProxyUser (oldNotification .getProxyUser ().orNull ())//
297
- .withTriggerIfCanMerge (TRIGGER_IF_MERGE .valueOf (oldNotification .getTriggerIfCanMerge ().name ()))//
298
- .withUrl (oldNotification .getUrl ())//
299
- .withUser (oldNotification .getUser ().orNull ());
300
-
301
- for (Header h : oldNotification .getHeaders ()) {
302
- builder .withHeader (h .getName (), h .getValue ());
303
- }
304
-
305
- for (PullRequestState t : oldNotification .getTriggerIgnoreStateList ()) {
306
- builder .withTriggerIgnoreState (t );
307
- }
308
-
309
- for (PrnfbPullRequestAction t : oldNotification .getTriggers ()) {
310
- builder .withTrigger (t );
311
- }
312
-
313
- newNotifications .add (builder .build ());
314
- } catch (ValidationException e ) {
315
- this .logger .error ("" , e );
316
- }
317
- }
318
-
319
- return prnfbSettingsBuilder ()//
320
- .setPrnfbSettingsData (//
321
- prnfbSettingsDataBuilder ()//
322
- .setAdminRestriction (adminRestr )//
323
- .setKeyStore (ks )//
324
- .setKeyStorePassword (ksp )//
325
- .setKeyStoreType (kst )//
326
- .setShouldAcceptAnyCertificate (shouldAcceptAnyCertificate )//
327
- .build ())//
328
- .setButtons (newButtons )//
329
- .setNotifications (newNotifications )//
330
- .build ();
331
-
332
- } catch (se .bjurr .prnfb .settings .legacy .ValidationException e ) {
261
+ } catch (Exception e ) {
333
262
this .logger .error ("" , e );
334
263
}
264
+ this .logger .info ("Creating new default settings." );
335
265
return prnfbSettingsBuilder ()//
336
266
.setPrnfbSettingsData (//
337
267
prnfbSettingsDataBuilder ()//
@@ -358,6 +288,84 @@ public T perform() throws RuntimeException {
358
288
});
359
289
}
360
290
291
+ private PrnfbSettings settingsFromLegacy (se .bjurr .prnfb .settings .legacy .PrnfbSettings oldSettings ) {
292
+ String ks = oldSettings .getKeyStore ().orNull ();
293
+ String ksp = oldSettings .getKeyStorePassword ().orNull ();
294
+ String kst = oldSettings .getKeyStoreType ();
295
+ USER_LEVEL adminRestr = USER_LEVEL .SYSTEM_ADMIN ;
296
+ if (oldSettings .isAdminsAllowed ()) {
297
+ adminRestr = USER_LEVEL .ADMIN ;
298
+ }
299
+ if (oldSettings .isUsersAllowed ()) {
300
+ adminRestr = USER_LEVEL .EVERYONE ;
301
+ }
302
+
303
+ boolean shouldAcceptAnyCertificate = false ;
304
+
305
+ List <PrnfbButton > newButtons = newArrayList ();
306
+ for (se .bjurr .prnfb .settings .legacy .PrnfbButton oldButton : oldSettings .getButtons ()) {
307
+ USER_LEVEL userLevel = USER_LEVEL .SYSTEM_ADMIN ;
308
+ if (oldButton .getVisibility () == BUTTON_VISIBILITY .ADMIN ) {
309
+ userLevel = USER_LEVEL .ADMIN ;
310
+ }
311
+ if (oldButton .getVisibility () == BUTTON_VISIBILITY .EVERYONE ) {
312
+ userLevel = USER_LEVEL .EVERYONE ;
313
+ }
314
+ newButtons .add (new PrnfbButton (UUID .randomUUID (), oldButton .getTitle (), userLevel , null , null ));
315
+ }
316
+
317
+ List <PrnfbNotification > newNotifications = newArrayList ();
318
+ for (se .bjurr .prnfb .settings .legacy .PrnfbNotification oldNotification : oldSettings .getNotifications ()) {
319
+ try {
320
+ PrnfbNotificationBuilder builder = prnfbNotificationBuilder ()//
321
+ .withFilterRegexp (oldNotification .getFilterRegexp ().orNull ())//
322
+ .withFilterString (oldNotification .getFilterString ().orNull ())//
323
+ .withInjectionUrl (oldNotification .getInjectionUrl ().orNull ())//
324
+ .withInjectionUrlRegexp (oldNotification .getInjectionUrlRegexp ().orNull ())//
325
+ .withMethod (oldNotification .getMethod ())//
326
+ .withName (oldNotification .getName ())//
327
+ .withPassword (oldNotification .getPassword ().orNull ())//
328
+ .withPostContent (oldNotification .getPostContent ().orNull ())//
329
+ .withProxyPassword (oldNotification .getProxyPassword ().orNull ())//
330
+ .withProxyPort (oldNotification .getProxyPort ())//
331
+ .withProxyServer (oldNotification .getProxyServer ().orNull ())//
332
+ .withProxyUser (oldNotification .getProxyUser ().orNull ())//
333
+ .withTriggerIfCanMerge (TRIGGER_IF_MERGE .valueOf (oldNotification .getTriggerIfCanMerge ().name ()))//
334
+ .withUrl (oldNotification .getUrl ())//
335
+ .withUser (oldNotification .getUser ().orNull ());
336
+
337
+ for (Header h : oldNotification .getHeaders ()) {
338
+ builder .withHeader (h .getName (), h .getValue ());
339
+ }
340
+
341
+ for (PullRequestState t : oldNotification .getTriggerIgnoreStateList ()) {
342
+ builder .withTriggerIgnoreState (t );
343
+ }
344
+
345
+ for (PrnfbPullRequestAction t : oldNotification .getTriggers ()) {
346
+ builder .withTrigger (t );
347
+ }
348
+
349
+ newNotifications .add (builder .build ());
350
+ } catch (ValidationException e ) {
351
+ this .logger .error ("" , e );
352
+ }
353
+ }
354
+
355
+ return prnfbSettingsBuilder ()//
356
+ .setPrnfbSettingsData (//
357
+ prnfbSettingsDataBuilder ()//
358
+ .setAdminRestriction (adminRestr )//
359
+ .setKeyStore (ks )//
360
+ .setKeyStorePassword (ksp )//
361
+ .setKeyStoreType (kst )//
362
+ .setShouldAcceptAnyCertificate (shouldAcceptAnyCertificate )//
363
+ .build ())//
364
+ .setButtons (newButtons )//
365
+ .setNotifications (newNotifications )//
366
+ .build ();
367
+ }
368
+
361
369
private Predicate <HasUuid > withUuid (UUID uuid ) {
362
370
return new Predicate <HasUuid >() {
363
371
@ Override
0 commit comments