mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +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.Mustache;
|
||||||
import com.github.mustachejava.MustacheFactory;
|
import com.github.mustachejava.MustacheFactory;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import com.google.common.base.Strings;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import sonia.scm.boot.RestartEvent;
|
import sonia.scm.boot.RestartEvent;
|
||||||
@@ -71,9 +72,16 @@ class MigrationWizardServlet extends HttpServlet {
|
|||||||
boolean validationErrorFound = false;
|
boolean validationErrorFound = false;
|
||||||
for (RepositoryLineEntry repositoryLineEntry : repositoryLineEntries) {
|
for (RepositoryLineEntry repositoryLineEntry : repositoryLineEntries) {
|
||||||
String id = repositoryLineEntry.getId();
|
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 namespace = req.getParameter("namespace-" + id);
|
||||||
String name = req.getParameter("name-" + id);
|
|
||||||
repositoryLineEntry.setNamespace(namespace);
|
repositoryLineEntry.setNamespace(namespace);
|
||||||
|
|
||||||
|
String name = req.getParameter("name-" + id);
|
||||||
repositoryLineEntry.setName(name);
|
repositoryLineEntry.setName(name);
|
||||||
|
|
||||||
if (!ValidationUtil.isRepositoryNameValid(namespace)) {
|
if (!ValidationUtil.isRepositoryNameValid(namespace)) {
|
||||||
@@ -144,6 +152,7 @@ class MigrationWizardServlet extends HttpServlet {
|
|||||||
private final String id;
|
private final String id;
|
||||||
private final String type;
|
private final String type;
|
||||||
private final String path;
|
private final String path;
|
||||||
|
private MigrationStrategy selectedStrategy;
|
||||||
private String namespace;
|
private String namespace;
|
||||||
private String name;
|
private String name;
|
||||||
private boolean namespaceValid = true;
|
private boolean namespaceValid = true;
|
||||||
@@ -153,6 +162,7 @@ class MigrationWizardServlet extends HttpServlet {
|
|||||||
this.id = repository.getId();
|
this.id = repository.getId();
|
||||||
this.type = repository.getType();
|
this.type = repository.getType();
|
||||||
this.path = repository.getType() + "/" + repository.getName();
|
this.path = repository.getType() + "/" + repository.getName();
|
||||||
|
this.selectedStrategy = MigrationStrategy.COPY;
|
||||||
this.namespace = computeNewNamespace(repository);
|
this.namespace = computeNewNamespace(repository);
|
||||||
this.name = computeNewName(repository);
|
this.name = computeNewName(repository);
|
||||||
}
|
}
|
||||||
@@ -195,6 +205,17 @@ class MigrationWizardServlet extends HttpServlet {
|
|||||||
return name;
|
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) {
|
public void setNamespace(String namespace) {
|
||||||
this.namespace = namespace;
|
this.namespace = namespace;
|
||||||
}
|
}
|
||||||
@@ -211,6 +232,10 @@ class MigrationWizardServlet extends HttpServlet {
|
|||||||
this.nameValid = nameValid;
|
this.nameValid = nameValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSelectedStrategy(MigrationStrategy selectedStrategy) {
|
||||||
|
this.selectedStrategy = selectedStrategy;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isNamespaceInvalid() {
|
public boolean isNamespaceInvalid() {
|
||||||
return !namespaceValid;
|
return !namespaceValid;
|
||||||
}
|
}
|
||||||
@@ -219,4 +244,23 @@ class MigrationWizardServlet extends HttpServlet {
|
|||||||
return !nameValid;
|
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">
|
<div class="control select">
|
||||||
<select class="strategy-select" name="strategy-{{id}}">
|
<select class="strategy-select" name="strategy-{{id}}">
|
||||||
{{#strategies}}
|
{{#strategies}}
|
||||||
<option>{{name}}</option>
|
<option{{#selected}} selected{{/selected}}>{{name}}</option>
|
||||||
{{/strategies}}
|
{{/strategies}}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -157,6 +157,7 @@ class MigrationWizardServletTest {
|
|||||||
);
|
);
|
||||||
doReturn("invalid namespace").when(request).getParameter("namespace-id");
|
doReturn("invalid namespace").when(request).getParameter("namespace-id");
|
||||||
doReturn("invalid name").when(request).getParameter("name-id");
|
doReturn("invalid name").when(request).getParameter("name-id");
|
||||||
|
doReturn("COPY").when(request).getParameter("strategy-id");
|
||||||
|
|
||||||
servlet.doPost(request, response);
|
servlet.doPost(request, response);
|
||||||
|
|
||||||
@@ -171,6 +172,42 @@ class MigrationWizardServletTest {
|
|||||||
.contains(true);
|
.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
|
@Test
|
||||||
void shouldStoreValidMigration() {
|
void shouldStoreValidMigration() {
|
||||||
when(updateStep.getRepositoriesWithoutMigrationStrategies()).thenReturn(
|
when(updateStep.getRepositoriesWithoutMigrationStrategies()).thenReturn(
|
||||||
|
|||||||
Reference in New Issue
Block a user