Skip to content

Commit

Permalink
#112 | Use equals and null-safe checks
Browse files Browse the repository at this point in the history
  • Loading branch information
himeshr committed Nov 21, 2024
1 parent cd021dd commit 1672ee2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.Arrays;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;

import static org.avniproject.etl.repository.JdbcContextWrapper.runInOrgContext;
Expand Down Expand Up @@ -50,9 +51,9 @@ private void cleanUncancelledEncounters(TableMetadata tableMetadata, SchemaMetad

private String getPrimaryTableName(TableMetadata tableMetadata, SchemaMetadata currentSchemaMetadata) {
Optional<TableMetadata> primaryTableMetadata = currentSchemaMetadata.getAllIndividualAndProgramEncounterTables()
.stream().filter(tm -> tm.getEncounterTypeUuid() == tableMetadata.getEncounterTypeUuid()
&& tm.getProgramUuid() == tableMetadata.getProgramUuid()
&& tm.getSubjectTypeUuid() == tableMetadata.getSubjectTypeUuid()).findAny();
.stream().filter(tm -> tm.getEncounterTypeUuid().equals(tableMetadata.getEncounterTypeUuid())
&& (Objects.isNull(tm.getProgramUuid()) || (Objects.nonNull(tableMetadata.getProgramUuid()) && tableMetadata.getProgramUuid().equals(tm.getProgramUuid())))
&& tm.getSubjectTypeUuid().equals(tableMetadata.getSubjectTypeUuid())).findAny();

if (primaryTableMetadata.isPresent()) {
return primaryTableMetadata.get().getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ private void cleanInvalidExits(TableMetadata tableMetadata, SchemaMetadata curre

private String getPrimaryTableName(TableMetadata tableMetadata, SchemaMetadata currentSchemaMetadata) {
Optional<TableMetadata> primaryTableMetadata = currentSchemaMetadata.getAllProgramEnrolmentTables()
.stream().filter(tm -> tm.getProgramUuid() == tableMetadata.getProgramUuid()
&& tm.getSubjectTypeUuid() == tableMetadata.getSubjectTypeUuid()).findAny();
.stream().filter(tm -> tm.getProgramUuid().equals(tableMetadata.getProgramUuid())
&& tm.getSubjectTypeUuid().equals(tableMetadata.getSubjectTypeUuid())).findAny();

if (primaryTableMetadata.isPresent()) {
return primaryTableMetadata.get().getName();
Expand Down

0 comments on commit 1672ee2

Please sign in to comment.