Skip to content

Commit

Permalink
Simplify migration logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ncovercash committed Feb 6, 2024
1 parent 9303c16 commit 4fc3df0
Show file tree
Hide file tree
Showing 9 changed files with 342 additions and 491 deletions.
2 changes: 1 addition & 1 deletion folio-export-common
26 changes: 19 additions & 7 deletions src/main/java/org/folio/des/service/FolioTenantService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,21 @@ public class FolioTenantService extends TenantService {
private final PrepareSystemUserService prepareSystemUserService;
private final BursarMigrationService bursarMigrationService;

public FolioTenantService(JdbcTemplate jdbcTemplate, FolioExecutionContext context, FolioSpringLiquibase folioSpringLiquibase,
PrepareSystemUserService prepareSystemUserService, KafkaService kafka,
BulkEditConfigService bulkEditConfigService, EdifactScheduledJobInitializer edifactScheduledJobInitializer,
ScheduledJobsRemover scheduledJobsRemover, BursarScheduledJobInitializer bursarScheduledJobInitializer,
OldJobDeleteScheduler oldJobDeleteScheduler, BursarExportLegacyJobService bursarExportLegacyJobService,
JobService jobService, BursarMigrationService bursarMigrationService) {
public FolioTenantService(
JdbcTemplate jdbcTemplate,
FolioExecutionContext context,
FolioSpringLiquibase folioSpringLiquibase,
PrepareSystemUserService prepareSystemUserService,
KafkaService kafka,
BulkEditConfigService bulkEditConfigService,
EdifactScheduledJobInitializer edifactScheduledJobInitializer,
ScheduledJobsRemover scheduledJobsRemover,
BursarScheduledJobInitializer bursarScheduledJobInitializer,
OldJobDeleteScheduler oldJobDeleteScheduler,
BursarExportLegacyJobService bursarExportLegacyJobService,
JobService jobService,
BursarMigrationService bursarMigrationService
) {
super(jdbcTemplate, context, folioSpringLiquibase);
this.prepareSystemUserService = prepareSystemUserService;
this.kafka = kafka;
Expand All @@ -63,7 +72,10 @@ protected void afterTenantUpdate(TenantAttributes tenantAttributes) {
oldJobDeleteScheduler.scheduleOldJobDeletion(context.getTenantId());
kafka.createKafkaTopics();
kafka.restartEventListeners();
bursarMigrationService.recreateLegacyJobs(bursarExportLegacyJobService, jobService);
bursarMigrationService.updateLegacyBursarJobs(
bursarExportLegacyJobService,
jobService
);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw e;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.folio.des.service.bursarlegacy;

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.folio.de.entity.bursarlegacy.JobWithLegacyBursarParameters;
import org.folio.des.domain.dto.JobWithLegacyBursarParametersCollection;
import org.folio.des.repository.CQLService;
import org.folio.des.domain.dto.LegacyBursarFeeFines;
import org.folio.des.repository.bursarlegacy.BursarExportLegacyJobRepository;
import org.folio.des.service.util.JobMapperUtil;
import org.folio.spring.data.OffsetRequest;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -18,31 +15,24 @@ public class BursarExportLegacyJobService {

private final BursarExportLegacyJobRepository repository;

private final CQLService cqlService;

@Transactional(readOnly = true)
public JobWithLegacyBursarParametersCollection get(Integer offset, Integer limit, String query) {
var result = new JobWithLegacyBursarParametersCollection();
if (StringUtils.isBlank(query)) {
Page<JobWithLegacyBursarParameters> page = repository.findAll(
new OffsetRequest(offset, limit)
);
result.setJobRecords(page.map(this::entityToDto).getContent());
result.setTotalRecords((int) page.getTotalElements());
} else {
result.setJobRecords(
cqlService
.getByCQL(JobWithLegacyBursarParameters.class, query, offset, limit)
.stream()
.map(this::entityToDto)
.toList()
);
result.setTotalRecords(cqlService.countByCQL(JobWithLegacyBursarParameters.class, query));
}
return result;
public List<org.folio.des.domain.dto.JobWithLegacyBursarParameters> getAllLegacyJobs() {
return repository
.findAll()
.stream()
.filter(BursarExportLegacyJobService::hasLegacyBursarParameters)
.map(BursarExportLegacyJobService::entityToDto)
.toList();
}

public static boolean hasLegacyBursarParameters(JobWithLegacyBursarParameters job) {
// ensure legacy `bursarFeeFines` is present and actually contains values
LegacyBursarFeeFines legacyObject = job.getExportTypeSpecificParameters().getBursarFeeFines();

return (legacyObject != null && legacyObject.getDaysOutstanding() != null);
}

private org.folio.des.domain.dto.JobWithLegacyBursarParameters entityToDto(JobWithLegacyBursarParameters entity) {
public static org.folio.des.domain.dto.JobWithLegacyBursarParameters entityToDto(JobWithLegacyBursarParameters entity) {
return JobMapperUtil.entityToDto(entity);
}
}
Loading

0 comments on commit 4fc3df0

Please sign in to comment.