Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Removing migration code for legacy settings #251
Browse files Browse the repository at this point in the history
Removing code that looks for, and migrates, legacy settings (Stash 3.x) to Bitbucket Server (4.x and 5.x).
  • Loading branch information
tomasbjerre committed Oct 6, 2017
1 parent 1de97c9 commit 0a81203
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 1,213 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

Changelog of Pull Request Notifier for Bitbucket.

## Unreleased
### No issue
inject leading spaces so markdown list elements nest/indent as intended

[5fc911633acc3cb](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/5fc911633acc3cb) Kevin Goodwin *2017-09-23 04:01:08*

Doc

[515cbe1b1a88624](https://github.com/tomasbjerre/pull-request-notifier-for-bitbucket/commit/515cbe1b1a88624) Tomas Bjerre *2017-09-14 17:38:03*

## 3.14
### No issue
Doc
Expand Down
133 changes: 8 additions & 125 deletions src/main/java/se/bjurr/prnfb/service/SettingsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import se.bjurr.prnfb.listener.PrnfbPullRequestAction;
import se.bjurr.prnfb.presentation.dto.ON_OR_OFF;
import se.bjurr.prnfb.settings.HasUuid;
import se.bjurr.prnfb.settings.PrnfbButton;
import se.bjurr.prnfb.settings.PrnfbNotification;
import se.bjurr.prnfb.settings.PrnfbNotificationBuilder;
import se.bjurr.prnfb.settings.PrnfbSettings;
import se.bjurr.prnfb.settings.PrnfbSettingsData;
import se.bjurr.prnfb.settings.TRIGGER_IF_MERGE;
import se.bjurr.prnfb.settings.USER_LEVEL;
import se.bjurr.prnfb.settings.ValidationException;
import se.bjurr.prnfb.settings.legacy.AdminFormValues.BUTTON_VISIBILITY;
import se.bjurr.prnfb.settings.legacy.Header;
import se.bjurr.prnfb.settings.legacy.SettingsStorage;

import com.atlassian.bitbucket.pull.PullRequestState;
import com.atlassian.bitbucket.user.SecurityService;
import com.atlassian.bitbucket.util.Operation;
import com.atlassian.sal.api.pluginsettings.PluginSettings;
Expand Down Expand Up @@ -308,33 +300,15 @@ private void doDeleteNotification(UUID uuid) {
}

private PrnfbSettings doGetPrnfbSettings() {
Object storedSettings = this.pluginSettings.get(STORAGE_KEY);
final Object storedSettings = this.pluginSettings.get(STORAGE_KEY);
if (storedSettings == null) {
this.logger.info("No settings found for " + STORAGE_KEY + ", looking for legacy settings.");
if (this.pluginSettings.get(se.bjurr.prnfb.settings.legacy.SettingsStorage.STORAGE_KEY)
!= null
|| this.pluginSettings.get(
se.bjurr.prnfb.settings.legacy.SettingsStorage.STORAGE_KEY_PRNFS)
!= null) {
try {
this.logger.info("Using legacy settings.");
final se.bjurr.prnfb.settings.legacy.PrnfbSettings legacySettings =
SettingsStorage.getPrnfbSettings(this.pluginSettings);
final PrnfbSettings fromLegacy = settingsFromLegacy(legacySettings);
doSetPrnfbSettings(fromLegacy);
storedSettings = this.pluginSettings.get(STORAGE_KEY);
} catch (final Exception e) {
this.logger.error("", e);
}
} else {
this.logger.info("Creating new default settings.");
return prnfbSettingsBuilder() //
.setPrnfbSettingsData( //
prnfbSettingsDataBuilder() //
.setAdminRestriction(USER_LEVEL.ADMIN) //
.build()) //
.build();
}
this.logger.info("Creating new default settings.");
return prnfbSettingsBuilder() //
.setPrnfbSettingsData( //
prnfbSettingsDataBuilder() //
.setAdminRestriction(USER_LEVEL.ADMIN) //
.build()) //
.build();
}
return gson.fromJson(storedSettings.toString(), PrnfbSettings.class);
}
Expand Down Expand Up @@ -372,97 +346,6 @@ public T perform() throws RuntimeException {
});
}

private PrnfbSettings settingsFromLegacy(
se.bjurr.prnfb.settings.legacy.PrnfbSettings oldSettings) {
final String ks = oldSettings.getKeyStore().orNull();
final String ksp = oldSettings.getKeyStorePassword().orNull();
final String kst = oldSettings.getKeyStoreType();
USER_LEVEL adminRestr = USER_LEVEL.SYSTEM_ADMIN;
if (oldSettings.isAdminsAllowed()) {
adminRestr = USER_LEVEL.ADMIN;
}
if (oldSettings.isUsersAllowed()) {
adminRestr = USER_LEVEL.EVERYONE;
}

final boolean shouldAcceptAnyCertificate = false;

final List<PrnfbButton> newButtons = newArrayList();
for (final se.bjurr.prnfb.settings.legacy.PrnfbButton oldButton : oldSettings.getButtons()) {
USER_LEVEL userLevel = USER_LEVEL.SYSTEM_ADMIN;
if (oldButton.getVisibility() == BUTTON_VISIBILITY.ADMIN) {
userLevel = USER_LEVEL.ADMIN;
}
if (oldButton.getVisibility() == BUTTON_VISIBILITY.EVERYONE) {
userLevel = USER_LEVEL.EVERYONE;
}
newButtons.add(
new PrnfbButton(
UUID.randomUUID(),
oldButton.getTitle(),
userLevel,
ON_OR_OFF.off,
null,
null,
"confirmationText",
null));
}

final List<PrnfbNotification> newNotifications = newArrayList();
for (final se.bjurr.prnfb.settings.legacy.PrnfbNotification oldNotification :
oldSettings.getNotifications()) {
try {
final PrnfbNotificationBuilder builder =
prnfbNotificationBuilder() //
.withFilterRegexp(oldNotification.getFilterRegexp().orNull()) //
.withFilterString(oldNotification.getFilterString().orNull()) //
.withInjectionUrl(oldNotification.getInjectionUrl().orNull()) //
.withInjectionUrlRegexp(oldNotification.getInjectionUrlRegexp().orNull()) //
.withMethod(oldNotification.getMethod()) //
.withName(oldNotification.getName()) //
.withPassword(oldNotification.getPassword().orNull()) //
.withPostContent(oldNotification.getPostContent().orNull()) //
.withProxyPassword(oldNotification.getProxyPassword().orNull()) //
.withProxyPort(oldNotification.getProxyPort()) //
.withProxyServer(oldNotification.getProxyServer().orNull()) //
.withProxyUser(oldNotification.getProxyUser().orNull()) //
.withTriggerIfCanMerge(
TRIGGER_IF_MERGE.valueOf(oldNotification.getTriggerIfCanMerge().name())) //
.withUrl(oldNotification.getUrl()) //
.withUser(oldNotification.getUser().orNull());

for (final Header h : oldNotification.getHeaders()) {
builder.withHeader(h.getName(), h.getValue());
}

for (final PullRequestState t : oldNotification.getTriggerIgnoreStateList()) {
builder.withTriggerIgnoreState(t);
}

for (final PrnfbPullRequestAction t : oldNotification.getTriggers()) {
builder.withTrigger(t);
}

newNotifications.add(builder.build());
} catch (final ValidationException e) {
this.logger.error("", e);
}
}

return prnfbSettingsBuilder() //
.setPrnfbSettingsData( //
prnfbSettingsDataBuilder() //
.setAdminRestriction(adminRestr) //
.setKeyStore(ks) //
.setKeyStorePassword(ksp) //
.setKeyStoreType(kst) //
.setShouldAcceptAnyCertificate(shouldAcceptAnyCertificate) //
.build()) //
.setButtons(newButtons) //
.setNotifications(newNotifications) //
.build();
}

private Predicate<HasUuid> withUuid(UUID uuid) {
return new Predicate<HasUuid>() {
@Override
Expand Down
72 changes: 0 additions & 72 deletions src/main/java/se/bjurr/prnfb/settings/legacy/AdminFormValues.java

This file was deleted.

25 changes: 0 additions & 25 deletions src/main/java/se/bjurr/prnfb/settings/legacy/Header.java

This file was deleted.

34 changes: 0 additions & 34 deletions src/main/java/se/bjurr/prnfb/settings/legacy/PrnfbButton.java

This file was deleted.

Loading

0 comments on commit 0a81203

Please sign in to comment.