Skip to content

Commit

Permalink
fix(multiple database): hover the template name does not show the con…
Browse files Browse the repository at this point in the history
…tained database (#2542)

* Add database information to the template

* Modify the template's unit tests
  • Loading branch information
zijiacj authored May 29, 2024
1 parent 314a2a2 commit ba64230
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import com.oceanbase.odc.metadb.connection.DatabaseRepository;
import com.oceanbase.odc.metadb.databasechange.DatabaseChangeChangingOrderTemplateEntity;
import com.oceanbase.odc.metadb.databasechange.DatabaseChangeChangingOrderTemplateRepository;
import com.oceanbase.odc.service.connection.database.DatabaseService;
import com.oceanbase.odc.service.connection.database.model.Database;
import com.oceanbase.odc.service.databasechange.model.CreateDatabaseChangeChangingOrderTemplateReq;
import com.oceanbase.odc.service.databasechange.model.DatabaseChangeChangingOrderTemplateResp;
import com.oceanbase.odc.service.databasechange.model.DatabaseChangingOrderTemplateExists;
Expand Down Expand Up @@ -79,6 +81,8 @@ public class DatabaseChangeChangingOrderTemplateServiceTest extends ServiceTestE
private ProjectRepository projectRepository;
@MockBean
private ProjectPermissionValidator projectPermissionValidator;
@MockBean
private DatabaseService databaseService;

@Before
public void setUp() {
Expand Down Expand Up @@ -210,12 +214,14 @@ public void modifyDatabaseChangingOrderTemplate_projectNotExists_throwNotFoundEx

@Test
public void queryDatabaseChangingOrderTemplateById_findExistingTemplate_succeed() {
Database database = new Database();
when(databaseService.listDatabasesByIds(any())).thenReturn(Arrays.asList(database));
createDatabaseChangingOrderTemplate_saveEntity_succeed();
DatabaseChangeChangingOrderTemplateEntity byNameAndProjectId =
templateRepository.findByNameAndProjectId(TEMPLATE_NAME, PROJECT_ID).get();
DatabaseEntity database = new DatabaseEntity();
database.setProjectId(PROJECT_ID);
when(databaseRepository.findByIdIn(anyList())).thenReturn(Arrays.asList(database));
DatabaseEntity databaseEntity = new DatabaseEntity();
databaseEntity.setProjectId(PROJECT_ID);
when(databaseRepository.findByIdIn(anyList())).thenReturn(Arrays.asList(databaseEntity));
DatabaseChangeChangingOrderTemplateResp databaseChangeChangingOrderTemplateResp =
templateService.detail(
byNameAndProjectId.getId());
Expand All @@ -227,6 +233,8 @@ public void queryDatabaseChangingOrderTemplateById_findExistingTemplate_succeed(

@Test
public void listDatabaseChangingOrderTemplates_useQueryCondition_succeed() {
Database database = new Database();
when(databaseService.listDatabasesByIds(any())).thenReturn(Arrays.asList(database));
createDatabaseChangingOrderTemplate_saveEntity_succeed();
Pageable pageable = Pageable.unpaged();
QueryDatabaseChangeChangingOrderParams params = QueryDatabaseChangeChangingOrderParams.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.oceanbase.odc.metadb.databasechange.DatabaseChangeChangingOrderTemplateRepository;
import com.oceanbase.odc.metadb.databasechange.DatabaseChangeChangingOrderTemplateSpecs;
import com.oceanbase.odc.service.connection.database.DatabaseService;
import com.oceanbase.odc.service.connection.database.model.Database;
import com.oceanbase.odc.service.databasechange.model.CreateDatabaseChangeChangingOrderTemplateReq;
import com.oceanbase.odc.service.databasechange.model.DatabaseChangeChangingOrderTemplateResp;
import com.oceanbase.odc.service.databasechange.model.DatabaseChangeDatabase;
Expand Down Expand Up @@ -240,8 +241,14 @@ public DatabaseChangeChangingOrderTemplateResp detail(@NotNull Long id) {
templateResp.setProjectId(templateEntity.getProjectId());
templateResp
.setOrganizationId(templateEntity.getOrganizationId());
List<Long> databaseIds =
databaseSequences.stream().flatMap(Collection::stream).distinct().collect(Collectors.toList());
Map<Long, DatabaseChangeDatabase> id2DatabaseChangeDatabase =
databaseService.listDatabasesDetailsByIds(databaseIds).stream()
.collect(Collectors.toMap(Database::getId, DatabaseChangeDatabase::new));
List<List<DatabaseChangeDatabase>> databaseSequenceList = databaseSequences.stream()
.map(s -> s.stream().map(DatabaseChangeDatabase::new).collect(Collectors.toList()))
.map(s -> s.stream().map(id2DatabaseChangeDatabase::get)
.collect(Collectors.toList()))
.collect(Collectors.toList());
templateResp.setDatabaseSequenceList(databaseSequenceList);
Map<Long, Boolean> templateId2Status = getChangingOrderTemplateId2EnableStatus(
Expand All @@ -268,6 +275,13 @@ public Page<DatabaseChangeChangingOrderTemplateResp> listTemplates(@NotNull Page
Page<DatabaseChangeChangingOrderTemplateEntity> pageResult =
templateRepository.findAll(specification, pageable);
List<DatabaseChangeChangingOrderTemplateEntity> entityList = pageResult.getContent();
List<Long> databaseIds = entityList.stream()
.flatMap(entity -> entity.getDatabaseSequences().stream())
.flatMap(Collection::stream)
.distinct().collect(Collectors.toList());
Map<Long, DatabaseChangeDatabase> id2DatabaseChangeDatabase =
databaseService.listDatabasesDetailsByIds(databaseIds).stream()
.collect(Collectors.toMap(Database::getId, DatabaseChangeDatabase::new));
List<DatabaseChangeChangingOrderTemplateResp> templateRespList = entityList.stream().map(entity -> {
DatabaseChangeChangingOrderTemplateResp templateResp = new DatabaseChangeChangingOrderTemplateResp();
templateResp.setId(entity.getId());
Expand All @@ -276,6 +290,11 @@ public Page<DatabaseChangeChangingOrderTemplateResp> listTemplates(@NotNull Page
templateResp.setProjectId(entity.getProjectId());
templateResp.setOrganizationId(entity.getOrganizationId());
templateResp.setEnabled(entity.getEnabled());
List<List<DatabaseChangeDatabase>> databaseSequenceList = entity.getDatabaseSequences().stream()
.map(s -> s.stream().map(id2DatabaseChangeDatabase::get)
.collect(Collectors.toList()))
.collect(Collectors.toList());
templateResp.setDatabaseSequenceList(databaseSequenceList);
return templateResp;
}).collect(Collectors.toList());
return new PageImpl<>(templateRespList, pageable, pageResult.getTotalElements());
Expand Down

0 comments on commit ba64230

Please sign in to comment.