Skip to content

Commit

Permalink
feat: add support for language formal and informal
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuzynow committed Jan 2, 2024
1 parent 02ed177 commit 163e4e4
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 61 deletions.
9 changes: 9 additions & 0 deletions services/mailservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ components:
example: "[email protected]"
language:
$ref: '#/components/schemas/LanguageCode'
dialect:
$ref: '#/components/schemas/Dialect'
templateData:
type: array
items:
Expand Down Expand Up @@ -116,3 +118,10 @@ components:
so, sq, sr, ss, st, su, sv, sw, ta, te, tg, th, ti, tk, tl, tn, to, tr, ts, tt, tw,
ty, ug, uk, ur, uz, ve, vi, vo, wa, wo, xh, yi, yo, za, zh, zu
]

Dialect:
type: string
default: formal
enum: [
formal, informal
]
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public void sendReassignRequestNotification(String rcGroupId, TenantData tenantD
.receiverEmailAddress(user.getEmail())
.receiverLanguageCode(user.getLanguageCode())
.receiverUsername(user.getUsername())
.receiverDialect(user.getDialect())
.tenantTemplateSupplier(tenantTemplateSupplier)
.applicationBaseUrl(applicationBaseUrl)
.multiTenancyEnabled(multiTenancyEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -42,6 +43,7 @@
import org.hibernate.search.annotations.TokenFilterDef;
import org.hibernate.search.annotations.TokenizerDef;
import org.springframework.lang.Nullable;
import de.caritas.cob.userservice.mailservice.generated.web.model.Dialect;

/** Represents a consultant */
@Entity
Expand Down Expand Up @@ -252,6 +254,12 @@ public boolean isInAgency(long agencyId) {
.contains(agencyId);
}

@JsonIgnore
@Transient
public Dialect getDialect() {
return isLanguageFormal() ? Dialect.FORMAL: Dialect.INFORMAL;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/de/caritas/cob/userservice/api/model/User.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.caritas.cob.userservice.api.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.neovisionaries.i18n.LanguageCode;
import java.time.LocalDateTime;
import java.util.Objects;
Expand All @@ -13,6 +14,7 @@
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -27,6 +29,7 @@
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import de.caritas.cob.userservice.mailservice.generated.web.model.Dialect;

/** Represents a user */
@Entity
Expand Down Expand Up @@ -150,4 +153,10 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(userId);
}

@JsonIgnore
@Transient
public Dialect getDialect() {
return isLanguageFormal() ? Dialect.FORMAL: Dialect.INFORMAL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ private MailDTO mailOf(Consultant consultant, String postCode) {
.template(TEMPLATE_NEW_DIRECT_ENQUIRY_NOTIFICATION)
.email(consultant.getEmail())
.language(fromValue(consultant.getLanguageCode().toString()))
.templateData(templateAttributes);
.templateData(templateAttributes)
.dialect(consultant.getDialect());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private MailDTO mailOf(Consultant consultant, String postCode, String agency) {
.template(TEMPLATE_NEW_ENQUIRY_NOTIFICATION)
.email(consultant.getEmail())
.language(language)
.dialect(consultant.getDialect())
.templateData(templateAttributes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public List<MailDTO> generateEmails() throws RocketChatGetGroupMembersException
return emptyList();
}

private List<MailDTO> buildFeedbackMessageMailsForExistingSession()
throws RocketChatGetGroupMembersException {
private List<MailDTO> buildFeedbackMessageMailsForExistingSession() {
if (nonNull(session.getConsultant())) {
return buildFeedbackMessageMailsForExistingConsultant();
}
Expand All @@ -69,8 +68,7 @@ private List<MailDTO> buildFeedbackMessageMailsForExistingSession()
return emptyList();
}

private List<MailDTO> buildFeedbackMessageMailsForExistingConsultant()
throws RocketChatGetGroupMembersException {
private List<MailDTO> buildFeedbackMessageMailsForExistingConsultant() {
Optional<Consultant> sendingConsultantOptional = consultantService.getConsultant(userId);
if (sendingConsultantOptional.isPresent()) {
Consultant sendingConsultant = sendingConsultantOptional.get();
Expand All @@ -81,15 +79,14 @@ private List<MailDTO> buildFeedbackMessageMailsForExistingConsultant()
return emptyList();
}

private List<MailDTO> buildMailsDependingOnAuthor(Consultant sendingConsultant)
throws RocketChatGetGroupMembersException {
private List<MailDTO> buildMailsDependingOnAuthor(Consultant sendingConsultant) {
var receivingConsultant = session.getConsultant();
if (areUsersEqual(userId, receivingConsultant)) {
return buildNotificationMailsForAllOtherConsultants(sendingConsultant);
}

if (receivingConsultant.getNotifyNewFeedbackMessageFromAdviceSeeker()
&& didAnotherConsultantWrite()
if (Boolean.TRUE.equals(receivingConsultant.getNotifyNewFeedbackMessageFromAdviceSeeker()
&& didAnotherConsultantWrite())
&& isLoggedOut(receivingConsultant)) {
var mail = buildMailForAssignedConsultant(sendingConsultant, receivingConsultant);

Expand Down Expand Up @@ -190,6 +187,7 @@ private MailDTO mailOf(Consultant recipient, String nameSender, String nameUser)
.template(TEMPLATE_NEW_FEEDBACK_MESSAGE_NOTIFICATION)
.email(recipient.getEmail())
.language(language)
.dialect(recipient.getDialect())
.templateData(
asList(
new TemplateDataDTO().key("name_sender").value(nameSender),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import de.caritas.cob.userservice.api.service.consultingtype.ReleaseToggle;
import de.caritas.cob.userservice.api.service.consultingtype.ReleaseToggleService;
import de.caritas.cob.userservice.consultingtypeservice.generated.web.model.NotificationsDTO;
import de.caritas.cob.userservice.mailservice.generated.web.model.Dialect;
import de.caritas.cob.userservice.mailservice.generated.web.model.MailDTO;
import de.caritas.cob.userservice.mailservice.generated.web.model.TemplateDataDTO;
import java.util.ArrayList;
Expand Down Expand Up @@ -188,6 +189,7 @@ private MailDTO buildMailDtoForNewMessageNotificationConsultant(
return new MailDTO()
.template(TEMPLATE_NEW_MESSAGE_NOTIFICATION_CONSULTANT)
.email(recipient.getEmail())
.dialect(recipient.getDialect())
.language(languageOf(recipient.getLanguageCode()))
.templateData(templateAttributes);
}
Expand Down Expand Up @@ -232,7 +234,7 @@ private List<MailDTO> buildMailForAskerList() {
asker.getEmail(),
asker.getLanguageCode(),
usernameTranscoder.decodeUsername(consultantUsername),
usernameTranscoder.decodeUsername(asker.getUsername()));
usernameTranscoder.decodeUsername(asker.getUsername()), asker.getDialect());

return singletonList(mailDTO);
}
Expand Down Expand Up @@ -262,7 +264,8 @@ private boolean isAdviceSeekerWithEmail() {
}

private MailDTO buildMailDtoForNewMessageNotificationAsker(
String email, LanguageCode languageCode, String consultantName, String askerName) {
String email, LanguageCode languageCode, String consultantName, String askerName,
Dialect askerDialect) {
var templateAttributes = new ArrayList<TemplateDataDTO>();
templateAttributes.add(new TemplateDataDTO().key("consultantName").value(consultantName));
templateAttributes.add(new TemplateDataDTO().key("askerName").value(askerName));
Expand All @@ -275,6 +278,7 @@ private MailDTO buildMailDtoForNewMessageNotificationAsker(

return new MailDTO()
.template(TEMPLATE_NEW_MESSAGE_NOTIFICATION_ASKER)
.dialect(askerDialect)
.email(email)
.language(languageOf(languageCode))
.templateData(templateAttributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private MailDTO buildMailDtoForReassignRequestNotification() {
.template(TEMPLATE_REASSIGN_CONFIRMATION_NOTIFICATION)
.email(receiverConsultant.getEmail())
.language(languageOf(receiverConsultant.getLanguageCode()))
.dialect(receiverConsultant.getDialect())
.templateData(templateAttributes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import java.util.List;
import javax.transaction.Transactional;
import lombok.Builder;
import de.caritas.cob.userservice.mailservice.generated.web.model.Dialect;

@Builder
public class ReassignmentRequestEmailSupplier implements EmailSupplier {

private final String receiverEmailAddress;
private final LanguageCode receiverLanguageCode;
private final String receiverUsername;

private final Dialect receiverDialect;
private final String applicationBaseUrl;
private final TenantTemplateSupplier tenantTemplateSupplier;
private final boolean multiTenancyEnabled;
Expand All @@ -40,6 +43,7 @@ private MailDTO buildMailDtoForReassignRequestNotification() {
return new MailDTO()
.template(TEMPLATE_REASSIGN_REQUEST_NOTIFICATION)
.email(receiverEmailAddress)
.dialect(receiverDialect)
.language(languageOf(receiverLanguageCode))
.templateData(templateAttributes);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import de.caritas.cob.userservice.api.port.out.ConsultantAgencyRepository;
import de.caritas.cob.userservice.api.service.consultingtype.ReleaseToggle;
import de.caritas.cob.userservice.api.service.consultingtype.ReleaseToggleService;
import de.caritas.cob.userservice.mailservice.generated.web.model.Dialect;
import de.caritas.cob.userservice.mailservice.generated.web.model.LanguageCode;
import de.caritas.cob.userservice.mailservice.generated.web.model.MailDTO;
import java.util.List;
Expand Down Expand Up @@ -91,6 +92,7 @@ public void generateEmails_Should_ReturnExpectedMailDTO_When_PresentConsultantHa
assertThat(generatedMail.getTemplate(), is(TEMPLATE_NEW_DIRECT_ENQUIRY_NOTIFICATION));
assertThat(generatedMail.getEmail(), is("[email protected]"));
assertThat(generatedMail.getLanguage(), is(LanguageCode.DE));
assertThat(generatedMail.getDialect(), is(MAIN_CONSULTANT.getDialect()));

var templateData = generatedMail.getTemplateData();
assertThat(templateData, hasSize(3));
Expand Down Expand Up @@ -143,11 +145,12 @@ public void generateEmails_Should_ReturnExpectedMailDTO_When_PresentConsultantHa
assertThat(generatedMail.getTemplate(), is(TEMPLATE_NEW_DIRECT_ENQUIRY_NOTIFICATION));
assertThat(generatedMail.getEmail(), is("[email protected]"));
assertThat(generatedMail.getLanguage(), is(LanguageCode.DE));

assertThat(generatedMail.getDialect(), is(MAIN_CONSULTANT.getDialect()));
var templateData = generatedMail.getTemplateData();
assertThat(templateData, hasSize(3));
assertThat(templateData.get(0).getKey(), is("name"));
assertThat(templateData.get(0).getValue(), is("first name last name"));

assertThat(templateData.get(1).getKey(), is("plz"));
assertThat(templateData.get(1).getValue(), is(POSTCODE));
assertThat(templateData.get(2).getKey(), is("url"));
Expand Down
Loading

0 comments on commit 163e4e4

Please sign in to comment.