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()
|
repositoryLineEntries.stream()
|
||||||
.map(RepositoryLineEntry::getId)
|
|
||||||
.forEach(
|
.forEach(
|
||||||
id -> {
|
entry-> {
|
||||||
|
String id = entry.getId();
|
||||||
|
String originalName = entry.getOriginalName();
|
||||||
String strategy = req.getParameter("strategy-" + id);
|
String strategy = req.getParameter("strategy-" + id);
|
||||||
String namespace = req.getParameter("namespace-" + id);
|
String namespace = req.getParameter("namespace-" + id);
|
||||||
String name = req.getParameter("name-" + 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 static class RepositoryLineEntry {
|
||||||
private final String id;
|
private final String id;
|
||||||
|
private final String originalName;
|
||||||
private final String type;
|
private final String type;
|
||||||
private final String path;
|
private final String path;
|
||||||
private MigrationStrategy selectedStrategy;
|
private MigrationStrategy selectedStrategy;
|
||||||
@@ -160,6 +162,7 @@ class MigrationWizardServlet extends HttpServlet {
|
|||||||
|
|
||||||
public RepositoryLineEntry(V1Repository repository) {
|
public RepositoryLineEntry(V1Repository repository) {
|
||||||
this.id = repository.getId();
|
this.id = repository.getId();
|
||||||
|
this.originalName = repository.getName();
|
||||||
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.selectedStrategy = MigrationStrategy.COPY;
|
||||||
@@ -189,6 +192,10 @@ class MigrationWizardServlet extends HttpServlet {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getOriginalName() {
|
||||||
|
return originalName;
|
||||||
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ public class MigrationStrategyDao {
|
|||||||
return plan.get(id);
|
return plan.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String repositoryId, MigrationStrategy strategy, String newNamespace, String newName) {
|
public void set(String repositoryId, String originalName, MigrationStrategy strategy, String newNamespace, String newName) {
|
||||||
plan.set(repositoryId, strategy, newNamespace, newName);
|
plan.set(repositoryId, originalName, strategy, newNamespace, newName);
|
||||||
store.set(plan);
|
store.set(plan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,14 +29,14 @@ class RepositoryMigrationPlan {
|
|||||||
.findFirst();
|
.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);
|
Optional<RepositoryMigrationEntry> entry = get(repositoryId);
|
||||||
if (entry.isPresent()) {
|
if (entry.isPresent()) {
|
||||||
entry.get().setStrategy(strategy);
|
entry.get().setStrategy(strategy);
|
||||||
entry.get().setNewNamespace(newNamespace);
|
entry.get().setNewNamespace(newNamespace);
|
||||||
entry.get().setNewName(newName);
|
entry.get().setNewName(newName);
|
||||||
} else {
|
} 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 {
|
static class RepositoryMigrationEntry {
|
||||||
|
|
||||||
private String repositoryId;
|
private String repositoryId;
|
||||||
|
private String originalName;
|
||||||
private MigrationStrategy dataMigrationStrategy;
|
private MigrationStrategy dataMigrationStrategy;
|
||||||
private String newNamespace;
|
private String newNamespace;
|
||||||
private String newName;
|
private String newName;
|
||||||
@@ -52,13 +53,18 @@ class RepositoryMigrationPlan {
|
|||||||
RepositoryMigrationEntry() {
|
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.repositoryId = repositoryId;
|
||||||
|
this.originalName = originalName;
|
||||||
this.dataMigrationStrategy = dataMigrationStrategy;
|
this.dataMigrationStrategy = dataMigrationStrategy;
|
||||||
this.newNamespace = newNamespace;
|
this.newNamespace = newNamespace;
|
||||||
this.newName = newName;
|
this.newName = newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getOriginalName() {
|
||||||
|
return originalName;
|
||||||
|
}
|
||||||
|
|
||||||
public MigrationStrategy getDataMigrationStrategy() {
|
public MigrationStrategy getDataMigrationStrategy() {
|
||||||
return dataMigrationStrategy;
|
return dataMigrationStrategy;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,20 @@ class MigrationWizardServletTest {
|
|||||||
.contains("id");
|
.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
|
@Test
|
||||||
void shouldNotBeInvalidAtFirstRequest() {
|
void shouldNotBeInvalidAtFirstRequest() {
|
||||||
when(updateStep.getRepositoriesWithoutMigrationStrategies()).thenReturn(
|
when(updateStep.getRepositoriesWithoutMigrationStrategies()).thenReturn(
|
||||||
@@ -219,6 +233,6 @@ class MigrationWizardServletTest {
|
|||||||
|
|
||||||
servlet.doPost(request, response);
|
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() {
|
void shouldReturnNewValue() {
|
||||||
MigrationStrategyDao dao = new MigrationStrategyDao(storeFactory);
|
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");
|
Optional<RepositoryMigrationPlan.RepositoryMigrationEntry> entry = dao.get("id");
|
||||||
|
|
||||||
@@ -65,14 +65,14 @@ class MigrationStrategyDaoTest {
|
|||||||
@Nested
|
@Nested
|
||||||
class WithExistingDatabase {
|
class WithExistingDatabase {
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void initExistingDatabase() throws JAXBException {
|
void initExistingDatabase() {
|
||||||
MigrationStrategyDao dao = new MigrationStrategyDao(storeFactory);
|
MigrationStrategyDao dao = new MigrationStrategyDao(storeFactory);
|
||||||
|
|
||||||
dao.set("id", INLINE, "space", "name");
|
dao.set("id", "originalName", INLINE, "space", "name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldFindExistingValue() throws JAXBException {
|
void shouldFindExistingValue() {
|
||||||
MigrationStrategyDao dao = new MigrationStrategyDao(storeFactory);
|
MigrationStrategyDao dao = new MigrationStrategyDao(storeFactory);
|
||||||
|
|
||||||
Optional<RepositoryMigrationPlan.RepositoryMigrationEntry> entry = dao.get("id");
|
Optional<RepositoryMigrationPlan.RepositoryMigrationEntry> entry = dao.get("id");
|
||||||
@@ -86,6 +86,9 @@ class MigrationStrategyDaoTest {
|
|||||||
Assertions.assertThat(entry)
|
Assertions.assertThat(entry)
|
||||||
.map(RepositoryMigrationPlan.RepositoryMigrationEntry::getNewName)
|
.map(RepositoryMigrationPlan.RepositoryMigrationEntry::getNewName)
|
||||||
.contains("name");
|
.contains("name");
|
||||||
|
Assertions.assertThat(entry)
|
||||||
|
.map(RepositoryMigrationPlan.RepositoryMigrationEntry::getOriginalName)
|
||||||
|
.contains("originalName");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class XmlRepositoryV1UpdateStepTest {
|
|||||||
void createMigrationPlan() {
|
void createMigrationPlan() {
|
||||||
Answer<Object> planAnswer = invocation -> {
|
Answer<Object> planAnswer = invocation -> {
|
||||||
String id = invocation.getArgument(0).toString();
|
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);
|
lenient().when(migrationStrategyDao.get("3b91caa5-59c3-448f-920b-769aaa56b761")).thenAnswer(planAnswer);
|
||||||
|
|||||||
Reference in New Issue
Block a user