77import static com .google .common .collect .Iterables .find ;
88import static com .google .common .collect .Iterables .tryFind ;
99import static com .google .common .collect .Lists .newArrayList ;
10+ import static se .bjurr .prnfb .settings .PrnfbNotificationBuilder .prnfbNotificationBuilder ;
1011import static se .bjurr .prnfb .settings .PrnfbSettingsBuilder .prnfbSettingsBuilder ;
1112import static se .bjurr .prnfb .settings .PrnfbSettingsDataBuilder .prnfbSettingsDataBuilder ;
1213
1314import java .util .List ;
1415import java .util .UUID ;
1516
17+ import org .slf4j .Logger ;
18+ import org .slf4j .LoggerFactory ;
19+
20+ import se .bjurr .prnfb .listener .PrnfbPullRequestAction ;
1621import se .bjurr .prnfb .settings .HasUuid ;
1722import se .bjurr .prnfb .settings .PrnfbButton ;
1823import se .bjurr .prnfb .settings .PrnfbNotification ;
24+ import se .bjurr .prnfb .settings .PrnfbNotificationBuilder ;
1925import se .bjurr .prnfb .settings .PrnfbSettings ;
2026import se .bjurr .prnfb .settings .PrnfbSettingsData ;
27+ import se .bjurr .prnfb .settings .TRIGGER_IF_MERGE ;
2128import se .bjurr .prnfb .settings .USER_LEVEL ;
2229import se .bjurr .prnfb .settings .ValidationException ;
30+ import se .bjurr .prnfb .settings .legacy .AdminFormValues .BUTTON_VISIBILITY ;
31+ import se .bjurr .prnfb .settings .legacy .Header ;
32+ import se .bjurr .prnfb .settings .legacy .SettingsStorage ;
2333
34+ import com .atlassian .bitbucket .pull .PullRequestState ;
2435import com .atlassian .bitbucket .user .SecurityService ;
2536import com .atlassian .bitbucket .util .Operation ;
2637import com .atlassian .sal .api .pluginsettings .PluginSettings ;
@@ -36,6 +47,7 @@ public class SettingsService {
3647
3748 public static final String STORAGE_KEY = "se.bjurr.prnfb.pull-request-notifier-for-bitbucket-3" ;
3849 private static Gson gson = new Gson ();
50+ private final Logger logger = LoggerFactory .getLogger (SettingsService .class );
3951 private final PluginSettings pluginSettings ;
4052 private final SecurityService securityService ;
4153 private final TransactionTemplate transactionTemplate ;
@@ -233,6 +245,88 @@ private void doDeleteNotification(UUID uuid) {
233245 private PrnfbSettings doGetPrnfbSettings () {
234246 Object storedSettings = this .pluginSettings .get (STORAGE_KEY );
235247 if (storedSettings == null ) {
248+ try {
249+ se .bjurr .prnfb .settings .legacy .PrnfbSettings oldSettings = SettingsStorage .getPrnfbSettings (this .pluginSettings );
250+
251+ String ks = oldSettings .getKeyStore ().orNull ();
252+ String ksp = oldSettings .getKeyStorePassword ().orNull ();
253+ String kst = oldSettings .getKeyStoreType ();
254+ USER_LEVEL adminRestr = USER_LEVEL .SYSTEM_ADMIN ;
255+ if (oldSettings .isAdminsAllowed ()) {
256+ adminRestr = USER_LEVEL .ADMIN ;
257+ }
258+ if (oldSettings .isUsersAllowed ()) {
259+ adminRestr = USER_LEVEL .EVERYONE ;
260+ }
261+
262+ boolean shouldAcceptAnyCertificate = false ;
263+
264+ List <PrnfbButton > newButtons = newArrayList ();
265+ for (se .bjurr .prnfb .settings .legacy .PrnfbButton oldButton : oldSettings .getButtons ()) {
266+ USER_LEVEL userLevel = USER_LEVEL .SYSTEM_ADMIN ;
267+ if (oldButton .getVisibility () == BUTTON_VISIBILITY .ADMIN ) {
268+ userLevel = USER_LEVEL .ADMIN ;
269+ }
270+ if (oldButton .getVisibility () == BUTTON_VISIBILITY .EVERYONE ) {
271+ userLevel = USER_LEVEL .EVERYONE ;
272+ }
273+ newButtons .add (new PrnfbButton (UUID .randomUUID (), oldButton .getTitle (), userLevel , null , null ));
274+ }
275+
276+ List <PrnfbNotification > newNotifications = newArrayList ();
277+ for (se .bjurr .prnfb .settings .legacy .PrnfbNotification oldNotification : oldSettings .getNotifications ()) {
278+ try {
279+ PrnfbNotificationBuilder builder = prnfbNotificationBuilder ()//
280+ .withFilterRegexp (oldNotification .getFilterRegexp ().orNull ())//
281+ .withFilterString (oldNotification .getFilterString ().orNull ())//
282+ .withInjectionUrl (oldNotification .getInjectionUrl ().orNull ())//
283+ .withInjectionUrlRegexp (oldNotification .getInjectionUrlRegexp ().orNull ())//
284+ .withMethod (oldNotification .getMethod ())//
285+ .withName (oldNotification .getName ())//
286+ .withPassword (oldNotification .getPassword ().orNull ())//
287+ .withPostContent (oldNotification .getPostContent ().orNull ())//
288+ .withProxyPassword (oldNotification .getProxyPassword ().orNull ())//
289+ .withProxyPort (oldNotification .getProxyPort ())//
290+ .withProxyServer (oldNotification .getProxyServer ().orNull ())//
291+ .withProxyUser (oldNotification .getProxyUser ().orNull ())//
292+ .withTriggerIfCanMerge (TRIGGER_IF_MERGE .valueOf (oldNotification .getTriggerIfCanMerge ().name ()))//
293+ .withUrl (oldNotification .getUrl ())//
294+ .withUser (oldNotification .getUser ().orNull ());
295+
296+ for (Header h : oldNotification .getHeaders ()) {
297+ builder .withHeader (h .getName (), h .getValue ());
298+ }
299+
300+ for (PullRequestState t : oldNotification .getTriggerIgnoreStateList ()) {
301+ builder .withTriggerIgnoreState (t );
302+ }
303+
304+ for (PrnfbPullRequestAction t : oldNotification .getTriggers ()) {
305+ builder .withTrigger (t );
306+ }
307+
308+ newNotifications .add (builder .build ());
309+ } catch (ValidationException e ) {
310+ this .logger .error ("" , e );
311+ }
312+ }
313+
314+ return prnfbSettingsBuilder ()//
315+ .setPrnfbSettingsData (//
316+ prnfbSettingsDataBuilder ()//
317+ .setAdminRestriction (adminRestr )//
318+ .setKeyStore (ks )//
319+ .setKeyStorePassword (ksp )//
320+ .setKeyStoreType (kst )//
321+ .setShouldAcceptAnyCertificate (shouldAcceptAnyCertificate )//
322+ .build ())//
323+ .setButtons (newButtons )//
324+ .setNotifications (newNotifications )//
325+ .build ();
326+
327+ } catch (se .bjurr .prnfb .settings .legacy .ValidationException e ) {
328+ this .logger .error ("" , e );
329+ }
236330 return prnfbSettingsBuilder ()//
237331 .setPrnfbSettingsData (//
238332 prnfbSettingsDataBuilder ()//
0 commit comments