Skip to content

Commit

Permalink
fix: fixing multiple location association
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj committed Jan 6, 2025
1 parent b64c0fc commit 171b35d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ private void cleanMatchers(SubmissionMatchDetailEntity entity) {
});
}

private Mono<SubmissionLocationContactEntity> saveAndAssociateContact(
private Flux<SubmissionLocationContactEntity> saveAndAssociateContact(
List<SubmissionLocationEntity> locations,
ClientContactDto contact,
Integer submissionId,
Expand All @@ -544,14 +544,18 @@ private Mono<SubmissionLocationContactEntity> saveAndAssociateContact(
.map(contactEntity -> contactEntity.withSubmissionId(submissionId))
.map(contactEntity -> contactEntity.withUserId(contact.index() == 0 ? userId : null))
.flatMap(submissionContactRepository::save)
.map(contactEntity ->
SubmissionLocationContactEntity
.builder()
.submissionLocationId(getLocationIdByName(locations, contact))
.submissionContactId(contactEntity.getSubmissionContactId())
.build()
)
.flatMap(submissionLocationContactRepository::save);
.flatMapMany(contactEntity ->
Flux
.fromIterable(contact.locationNames())
.map(locationName ->
SubmissionLocationContactEntity
.builder()
.submissionLocationId(getLocationIdByName(locations, locationName.text()))
.submissionContactId(contactEntity.getSubmissionContactId())
.build()
)
.flatMap(submissionLocationContactRepository::save)
);
}

private Mono<List<SubmissionLocationEntity>> saveAddresses(
Expand Down
13 changes: 13 additions & 0 deletions backend/src/main/java/ca/bc/gov/app/util/ClientMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,19 @@ public static Integer getLocationIdByName(
.orElse(0);
}

public static Integer getLocationIdByName(
List<SubmissionLocationEntity> locations,
String locationName
) {
return
locations
.stream()
.filter(location -> locationName.equalsIgnoreCase(location.getName()))
.map(SubmissionLocationEntity::getSubmissionLocationId)
.findFirst()
.orElse(0);
}

public static Map<String, String> parseName(String displayName, String provider) {
String[] nameParts =
displayName.contains(",")
Expand Down

0 comments on commit 171b35d

Please sign in to comment.