mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
Store original repository name in migration plan
This commit is contained in:
@@ -100,13 +100,14 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
repositoryLineEntries.stream()
|
||||
.map(RepositoryLineEntry::getId)
|
||||
.forEach(
|
||||
id -> {
|
||||
entry-> {
|
||||
String id = entry.getId();
|
||||
String originalName = entry.getOriginalName();
|
||||
String strategy = req.getParameter("strategy-" + id);
|
||||
String namespace = req.getParameter("namespace-" + id);
|
||||
String name = req.getParameter("name-" + id);
|
||||
migrationStrategyDao.set(id, MigrationStrategy.valueOf(strategy), namespace, name);
|
||||
migrationStrategyDao.set(id, originalName, MigrationStrategy.valueOf(strategy), namespace, name);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -150,6 +151,7 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
|
||||
private static class RepositoryLineEntry {
|
||||
private final String id;
|
||||
private final String originalName;
|
||||
private final String type;
|
||||
private final String path;
|
||||
private MigrationStrategy selectedStrategy;
|
||||
@@ -160,6 +162,7 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
|
||||
public RepositoryLineEntry(V1Repository repository) {
|
||||
this.id = repository.getId();
|
||||
this.originalName = repository.getName();
|
||||
this.type = repository.getType();
|
||||
this.path = repository.getType() + "/" + repository.getName();
|
||||
this.selectedStrategy = MigrationStrategy.COPY;
|
||||
@@ -189,6 +192,10 @@ class MigrationWizardServlet extends HttpServlet {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getOriginalName() {
|
||||
return originalName;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ public class MigrationStrategyDao {
|
||||
return plan.get(id);
|
||||
}
|
||||
|
||||
public void set(String repositoryId, MigrationStrategy strategy, String newNamespace, String newName) {
|
||||
plan.set(repositoryId, strategy, newNamespace, newName);
|
||||
public void set(String repositoryId, String originalName, MigrationStrategy strategy, String newNamespace, String newName) {
|
||||
plan.set(repositoryId, originalName, strategy, newNamespace, newName);
|
||||
store.set(plan);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,14 +29,14 @@ class RepositoryMigrationPlan {
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public void set(String repositoryId, MigrationStrategy strategy, String newNamespace, String newName) {
|
||||
public void set(String repositoryId, String originalName, MigrationStrategy strategy, String newNamespace, String newName) {
|
||||
Optional<RepositoryMigrationEntry> entry = get(repositoryId);
|
||||
if (entry.isPresent()) {
|
||||
entry.get().setStrategy(strategy);
|
||||
entry.get().setNewNamespace(newNamespace);
|
||||
entry.get().setNewName(newName);
|
||||
} else {
|
||||
entries.add(new RepositoryMigrationEntry(repositoryId, strategy, newNamespace, newName));
|
||||
entries.add(new RepositoryMigrationEntry(repositoryId, originalName, strategy, newNamespace, newName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ class RepositoryMigrationPlan {
|
||||
static class RepositoryMigrationEntry {
|
||||
|
||||
private String repositoryId;
|
||||
private String originalName;
|
||||
private MigrationStrategy dataMigrationStrategy;
|
||||
private String newNamespace;
|
||||
private String newName;
|
||||
@@ -52,13 +53,18 @@ class RepositoryMigrationPlan {
|
||||
RepositoryMigrationEntry() {
|
||||
}
|
||||
|
||||
RepositoryMigrationEntry(String repositoryId, MigrationStrategy dataMigrationStrategy, String newNamespace, String newName) {
|
||||
RepositoryMigrationEntry(String repositoryId, String originalName, MigrationStrategy dataMigrationStrategy, String newNamespace, String newName) {
|
||||
this.repositoryId = repositoryId;
|
||||
this.originalName = originalName;
|
||||
this.dataMigrationStrategy = dataMigrationStrategy;
|
||||
this.newNamespace = newNamespace;
|
||||
this.newName = newName;
|
||||
}
|
||||
|
||||
public String getOriginalName() {
|
||||
return originalName;
|
||||
}
|
||||
|
||||
public MigrationStrategy getDataMigrationStrategy() {
|
||||
return dataMigrationStrategy;
|
||||
}
|
||||
|
||||
@@ -131,6 +131,20 @@ class MigrationWizardServletTest {
|
||||
.contains("id");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldKeepOriginalName() {
|
||||
when(updateStep.getRepositoriesWithoutMigrationStrategies()).thenReturn(
|
||||
Collections.singletonList(new V1Repository("id", "git", "name"))
|
||||
);
|
||||
|
||||
servlet.doGet(request, response);
|
||||
|
||||
assertThat(renderedModel.get("repositories"))
|
||||
.asList()
|
||||
.extracting("originalName")
|
||||
.contains("name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotBeInvalidAtFirstRequest() {
|
||||
when(updateStep.getRepositoriesWithoutMigrationStrategies()).thenReturn(
|
||||
@@ -219,6 +233,6 @@ class MigrationWizardServletTest {
|
||||
|
||||
servlet.doPost(request, response);
|
||||
|
||||
verify(migrationStrategyDao).set("id", MigrationStrategy.COPY, "namespace", "name");
|
||||
verify(migrationStrategyDao).set("id", "name", MigrationStrategy.COPY, "namespace", "name");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class MigrationStrategyDaoTest {
|
||||
void shouldReturnNewValue() {
|
||||
MigrationStrategyDao dao = new MigrationStrategyDao(storeFactory);
|
||||
|
||||
dao.set("id", INLINE, "space", "name");
|
||||
dao.set("id", "originalName", INLINE, "space", "name");
|
||||
|
||||
Optional<RepositoryMigrationPlan.RepositoryMigrationEntry> entry = dao.get("id");
|
||||
|
||||
@@ -65,14 +65,14 @@ class MigrationStrategyDaoTest {
|
||||
@Nested
|
||||
class WithExistingDatabase {
|
||||
@BeforeEach
|
||||
void initExistingDatabase() throws JAXBException {
|
||||
void initExistingDatabase() {
|
||||
MigrationStrategyDao dao = new MigrationStrategyDao(storeFactory);
|
||||
|
||||
dao.set("id", INLINE, "space", "name");
|
||||
dao.set("id", "originalName", INLINE, "space", "name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindExistingValue() throws JAXBException {
|
||||
void shouldFindExistingValue() {
|
||||
MigrationStrategyDao dao = new MigrationStrategyDao(storeFactory);
|
||||
|
||||
Optional<RepositoryMigrationPlan.RepositoryMigrationEntry> entry = dao.get("id");
|
||||
@@ -86,6 +86,9 @@ class MigrationStrategyDaoTest {
|
||||
Assertions.assertThat(entry)
|
||||
.map(RepositoryMigrationPlan.RepositoryMigrationEntry::getNewName)
|
||||
.contains("name");
|
||||
Assertions.assertThat(entry)
|
||||
.map(RepositoryMigrationPlan.RepositoryMigrationEntry::getOriginalName)
|
||||
.contains("originalName");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
void createMigrationPlan() {
|
||||
Answer<Object> planAnswer = invocation -> {
|
||||
String id = invocation.getArgument(0).toString();
|
||||
return of(new RepositoryMigrationPlan.RepositoryMigrationEntry(id, MOVE, "namespace-" + id, "name-" + id));
|
||||
return of(new RepositoryMigrationPlan.RepositoryMigrationEntry(id, "originalName", MOVE, "namespace-" + id, "name-" + id));
|
||||
};
|
||||
|
||||
lenient().when(migrationStrategyDao.get("3b91caa5-59c3-448f-920b-769aaa56b761")).thenAnswer(planAnswer);
|
||||
|
||||
Reference in New Issue
Block a user