Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multi-location association #1375

Merged
merged 14 commits into from
Jan 7, 2025
Merged
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package ca.bc.gov.app.dto.legacy;

import java.util.List;
import lombok.With;

@With
public record ForestClientContactDto(
String clientNumber,
String clientLocnCode,
List<String> locationCode,
String contactCode,
String contactName,
String businessPhone,
Expand Down
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
30 changes: 23 additions & 7 deletions backend/src/main/java/ca/bc/gov/app/util/ClientMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ClientMapper {

public static final String FIRST_NAME = "firstName";
public static final String LAST_NAME = "lastName";

/**
* Maps a {@link ClientBusinessInformationDto} object to a {@link SubmissionDetailEntity} object,
* using the specified submission ID.
Expand Down Expand Up @@ -160,6 +163,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 All @@ -168,13 +184,13 @@ public static Map<String, String> parseName(String displayName, String provider)

if ("IDIR".equalsIgnoreCase(provider) && nameParts.length >= 2) {

String firstName = nameParts[1].replaceAll("\\s+\\w+:\\w+$", StringUtils.EMPTY).trim();
String firstName = nameParts[1].replaceAll("\\s+[^\\s:]+:[^\\s:]+$", StringUtils.EMPTY).trim();
String lastName = nameParts[0].trim();

return
Map.of(
"firstName", firstName.split(" ")[0].trim(),
"lastName",
FIRST_NAME, firstName.split(" ")[0].trim(),
LAST_NAME,

Stream.concat(
Stream
Expand All @@ -187,14 +203,14 @@ public static Map<String, String> parseName(String displayName, String provider)

} else if (nameParts.length >= 2) {
return Map.of(
"firstName", nameParts[0].trim(),
"lastName", String.join(" ", Arrays.copyOfRange(nameParts, 1, nameParts.length))
FIRST_NAME, nameParts[0].trim(),
LAST_NAME, String.join(" ", Arrays.copyOfRange(nameParts, 1, nameParts.length))
);
}

return Map.of(
"firstName", nameParts[0],
"lastName", ""
FIRST_NAME, nameParts[0],
LAST_NAME, ""
);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/ClientDetailsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const formatLocations = (
const associatedLocationsRecord = computed(() => {
const result: Record<string, string> = {};
sortedContacts.value?.forEach((contact) => {
result[contact.contactCode] = formatLocations(contact.clientLocnCode);
result[contact.contactCode] = formatLocations(contact.locationCode);
});
return result;
});
Expand Down
6 changes: 3 additions & 3 deletions frontend/stub/__files/response-clients-details-G.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"wcbFirmNumber": "{{randomValue length=7 type='NUMERIC'}}",
"contacts": [
{
"clientLocnCode": ["00"],
"locationCode": ["00"],
"contactCode": "00",
"contactName": "Cheryl Bibby",
"contactTypeCode": "BL",
Expand All @@ -24,7 +24,7 @@
"emailAddress": "[email protected]"
},
{
"clientLocnCode": ["01", "02"],
"locationCode": ["01", "02"],
"contactCode": "01",
"contactName": "Edward Burns",
"contactTypeCode": "DI",
Expand All @@ -35,7 +35,7 @@
"emailAddress": "[email protected]"
},
{
"clientLocnCode": ["02"],
"locationCode": ["02"],
"contactCode": "02",
"contactName": "Christoffer Stewart",
"contactTypeCode": "BL",
Expand Down
2 changes: 1 addition & 1 deletion frontend/stub/__files/response-clients-details-S.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"clientComment": "Email from Michael Scott to request any letters for sec deposits be mailed to 3000, 28th St, Scranton",
"wcbFirmNumber": "{{randomValue length=7 type='NUMERIC'}}",
"contacts": [{
"clientLocnCode": ["00"],
"locationCode": ["00"],
"contactCode": "00",
"contactName": "Cheryl Bibby",
"contactTypeCode": "BL",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package ca.bc.gov.app.dto;

import java.util.List;
import lombok.With;

@With
public record ForestClientContactDto(
String clientNumber,
String clientLocnCode,
List<String> locationCode,
String contactCode,
String contactName,
String businessPhone,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.InheritInverseConfiguration;
Expand Down Expand Up @@ -49,4 +50,9 @@ default LocalDateTime toLocalDateTime(LocalDate date) {
return date == null ? null : date.atStartOfDay();
}

@Named("AddToListQualifier")
default List<String> addToList(String value) {
return value != null ? List.of(value) : List.of();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public interface ForestClientContactMapper extends
source = "cellPhone",
target = "secondaryPhone"
)
@Mapping(
source = "clientLocnCode",
target = "locationCode",
qualifiedByName = "AddToListQualifier"
)
ForestClientContactDto toDto(ForestClientContactEntity entity);

@Override
Expand Down
Loading
Loading