Skip to content

Commit

Permalink
OLMIS-7989: Refactor currency unit in ProgramOrderableImportPersister…
Browse files Browse the repository at this point in the history
… to make it testable
  • Loading branch information
pwargulak committed Oct 17, 2024
1 parent 173431a commit ff14fcd
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class ProgramOrderableImportPersister
implements DataImportPersister<
ProgramOrderable, ProgramOrderableCsvModel, ProgramOrderableDto> {

private static final CurrencyUnit CURRENCY_UNIT = CurrencyUnit.of(System.getenv("CURRENCY_CODE"));
private final CurrencyUnit currencyUnit;

@Autowired private FileHelper fileHelper;
@Autowired private ProgramOrderableRepository programOrderableRepository;
Expand All @@ -67,6 +67,10 @@ public class ProgramOrderableImportPersister
@Qualifier("importExecutorService")
private ExecutorService importExecutorService;

public ProgramOrderableImportPersister() {
currencyUnit = CurrencyUnit.of(System.getenv("CURRENCY_CODE"));
}

@Override
public List<ProgramOrderableDto> processAndPersist(InputStream dataStream, Profiler profiler)
throws InterruptedException {
Expand Down Expand Up @@ -114,7 +118,7 @@ private List<ProgramOrderable> createOrUpdate(List<ProgramOrderableCsvModel> dto
dto.getDisplayOrder(),
dto.getDosesPerPatient(),
dto.getPricePerPack() != null
? Money.of(CURRENCY_UNIT, Double.parseDouble(dto.getPricePerPack()))
? Money.of(currencyUnit, Double.parseDouble(dto.getPricePerPack()))
: null,
null);

Expand All @@ -127,7 +131,7 @@ private List<ProgramOrderable> createOrUpdate(List<ProgramOrderableCsvModel> dto

if (programOrderable == null) {
programOrderable =
ProgramOrderable.createNew(program, orderableDisplayCategory, orderable, CURRENCY_UNIT);
ProgramOrderable.createNew(program, orderableDisplayCategory, orderable, currencyUnit);
}

programOrderable.updateFrom(programOrderableDto);
Expand Down

0 comments on commit ff14fcd

Please sign in to comment.