mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
keep select migration strategy in case of an error
This commit is contained in:
@@ -4,6 +4,7 @@ import com.github.mustachejava.DefaultMustacheFactory;
|
||||
import com.github.mustachejava.Mustache;
|
||||
import com.github.mustachejava.MustacheFactory;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Strings;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import sonia.scm.boot.RestartEvent;
|
||||
@@ -71,9 +72,16 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
boolean validationErrorFound = false;
|
||||
for (RepositoryLineEntry repositoryLineEntry : repositoryLineEntries) {
|
||||
String id = repositoryLineEntry.getId();
|
||||
|
||||
String strategy = req.getParameter("strategy-" + id);
|
||||
if (!Strings.isNullOrEmpty(strategy)) {
|
||||
repositoryLineEntry.setSelectedStrategy(MigrationStrategy.valueOf(strategy));
|
||||
}
|
||||
|
||||
String namespace = req.getParameter("namespace-" + id);
|
||||
String name = req.getParameter("name-" + id);
|
||||
repositoryLineEntry.setNamespace(namespace);
|
||||
|
||||
String name = req.getParameter("name-" + id);
|
||||
repositoryLineEntry.setName(name);
|
||||
|
||||
if (!ValidationUtil.isRepositoryNameValid(namespace)) {
|
||||
@@ -144,6 +152,7 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
private final String id;
|
||||
private final String type;
|
||||
private final String path;
|
||||
private MigrationStrategy selectedStrategy;
|
||||
private String namespace;
|
||||
private String name;
|
||||
private boolean namespaceValid = true;
|
||||
@@ -153,6 +162,7 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
this.id = repository.getId();
|
||||
this.type = repository.getType();
|
||||
this.path = repository.getType() + "/" + repository.getName();
|
||||
this.selectedStrategy = MigrationStrategy.COPY;
|
||||
this.namespace = computeNewNamespace(repository);
|
||||
this.name = computeNewName(repository);
|
||||
}
|
||||
@@ -195,6 +205,17 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
return name;
|
||||
}
|
||||
|
||||
public MigrationStrategy getSelectedStrategy() {
|
||||
return selectedStrategy;
|
||||
}
|
||||
|
||||
public List<RepositoryLineMigrationStrategy> getStrategies() {
|
||||
return Arrays.asList(MigrationStrategy.values())
|
||||
.stream()
|
||||
.map(s -> new RepositoryLineMigrationStrategy(s.name(), selectedStrategy == s))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
@@ -211,6 +232,10 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
this.nameValid = nameValid;
|
||||
}
|
||||
|
||||
public void setSelectedStrategy(MigrationStrategy selectedStrategy) {
|
||||
this.selectedStrategy = selectedStrategy;
|
||||
}
|
||||
|
||||
public boolean isNamespaceInvalid() {
|
||||
return !namespaceValid;
|
||||
}
|
||||
@@ -219,4 +244,23 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
return !nameValid;
|
||||
}
|
||||
}
|
||||
|
||||
private static class RepositoryLineMigrationStrategy {
|
||||
|
||||
private final String name;
|
||||
private final boolean selected;
|
||||
|
||||
private RepositoryLineMigrationStrategy(String name, boolean selected) {
|
||||
this.name = name;
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
<div class="control select">
|
||||
<select class="strategy-select" name="strategy-{{id}}">
|
||||
{{#strategies}}
|
||||
<option>{{name}}</option>
|
||||
<option{{#selected}} selected{{/selected}}>{{name}}</option>
|
||||
{{/strategies}}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -157,6 +157,7 @@ class MigrationWizardServletTest {
|
||||
);
|
||||
doReturn("invalid namespace").when(request).getParameter("namespace-id");
|
||||
doReturn("invalid name").when(request).getParameter("name-id");
|
||||
doReturn("COPY").when(request).getParameter("strategy-id");
|
||||
|
||||
servlet.doPost(request, response);
|
||||
|
||||
@@ -171,6 +172,42 @@ class MigrationWizardServletTest {
|
||||
.contains(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldKeepSelectedMigrationStrategy() {
|
||||
when(updateStep.getRepositoriesWithoutMigrationStrategies()).thenReturn(
|
||||
Collections.singletonList(new V1Repository("id", "git", "name"))
|
||||
);
|
||||
|
||||
doReturn("we need an").when(request).getParameter("namespace-id");
|
||||
doReturn("error for this test").when(request).getParameter("name-id");
|
||||
doReturn("INLINE").when(request).getParameter("strategy-id");
|
||||
|
||||
servlet.doPost(request, response);
|
||||
|
||||
assertThat(renderedModel.get("repositories"))
|
||||
.asList()
|
||||
.extracting("selectedStrategy")
|
||||
.contains(MigrationStrategy.INLINE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseCopyWithoutMigrationStrategy() {
|
||||
when(updateStep.getRepositoriesWithoutMigrationStrategies()).thenReturn(
|
||||
Collections.singletonList(new V1Repository("id", "git", "name"))
|
||||
);
|
||||
|
||||
doReturn("we need an").when(request).getParameter("namespace-id");
|
||||
doReturn("error for this test").when(request).getParameter("name-id");
|
||||
doReturn("").when(request).getParameter("strategy-id");
|
||||
|
||||
servlet.doPost(request, response);
|
||||
|
||||
assertThat(renderedModel.get("repositories"))
|
||||
.asList()
|
||||
.extracting("selectedStrategy")
|
||||
.contains(MigrationStrategy.COPY);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldStoreValidMigration() {
|
||||
when(updateStep.getRepositoriesWithoutMigrationStrategies()).thenReturn(
|
||||
|
||||
Reference in New Issue
Block a user