-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/Onlineberatung/onlineBer…
…atung-userService into OB-8336-remove-invalid-rocketchat-sessions
- Loading branch information
Showing
52 changed files
with
813 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,8 @@ components: | |
example: "[email protected]" | ||
language: | ||
$ref: '#/components/schemas/LanguageCode' | ||
dialect: | ||
$ref: '#/components/schemas/Dialect' | ||
templateData: | ||
type: array | ||
items: | ||
|
@@ -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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/de/caritas/cob/userservice/api/PatchConsultantSaga.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package de.caritas.cob.userservice.api; | ||
|
||
import com.google.common.collect.Lists; | ||
import de.caritas.cob.userservice.api.admin.service.consultant.TransactionalStep; | ||
import de.caritas.cob.userservice.api.exception.httpresponses.DistributedTransactionException; | ||
import de.caritas.cob.userservice.api.exception.httpresponses.DistributedTransactionInfo; | ||
import de.caritas.cob.userservice.api.model.Consultant; | ||
import de.caritas.cob.userservice.api.port.out.ConsultantRepository; | ||
import de.caritas.cob.userservice.api.port.out.MessageClient; | ||
import de.caritas.cob.userservice.api.service.appointment.AppointmentService; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class PatchConsultantSaga { | ||
|
||
private final ConsultantRepository consultantRepository; | ||
|
||
private final UserServiceMapper userServiceMapper; | ||
|
||
private final MessageClient messageClient; | ||
|
||
private final AppointmentService appointmentService; | ||
|
||
private final PatchConsultantSagaRollbackHandler patchConsultantSagaRollbackHandler; | ||
|
||
@Transactional | ||
public Map<String, Object> executeTransactional( | ||
Consultant patchedConsultant, Map<String, Object> patchMap) { | ||
Consultant savedConsultant = saveConsultant(patchedConsultant); | ||
userServiceMapper | ||
.encodedDisplayNameOf(patchMap) | ||
.ifPresent( | ||
encodedUserName -> updateUserInRocketChatOrRollback(savedConsultant, encodedUserName)); | ||
|
||
userServiceMapper | ||
.displayNameOf(patchMap) | ||
.ifPresent( | ||
displayName -> | ||
patchConsultantInAppointmentServiceOrRollback(savedConsultant, displayName)); | ||
return userServiceMapper.mapOf(savedConsultant, patchMap); | ||
} | ||
|
||
private void patchConsultantInAppointmentServiceOrRollback( | ||
Consultant savedConsultant, String displayName) { | ||
|
||
try { | ||
appointmentService.patchConsultant(savedConsultant.getId(), displayName); | ||
} catch (Exception e) { | ||
log.error( | ||
"Error while patching consultant in appointment service. Will rollback patchConsultantSaga.", | ||
e); | ||
patchConsultantSagaRollbackHandler.rollbackUpdateUserInRocketchat(savedConsultant); | ||
// rollback on MariaDB will be handled automatically by spring due to @Transactional | ||
throw new DistributedTransactionException( | ||
e, | ||
DistributedTransactionInfo.builder() | ||
.completedTransactionalOperations( | ||
Lists.newArrayList( | ||
TransactionalStep.SAVE_CONSULTANT_IN_MARIADB, | ||
TransactionalStep.UPDATE_ROCKET_CHAT_USER_DISPLAY_NAME)) | ||
.name("patchConsultant") | ||
.failedStep(TransactionalStep.PATCH_APPOINTMENT_SERVICE_CONSULTANT) | ||
.build()); | ||
} | ||
} | ||
|
||
private void updateUserInRocketChatOrRollback(Consultant savedConsultant, String displayName) { | ||
try { | ||
if (savedConsultant.getRocketChatId() != null) { | ||
messageClient.updateUser(savedConsultant.getRocketChatId(), displayName); | ||
} | ||
} catch (Exception e) { | ||
log.error( | ||
"Error while updating consultant in rocketchat. Will rollback patchConsultantSaga.", e); | ||
// rollback will be handled automatically by spring due to @Transactional | ||
throw new DistributedTransactionException( | ||
e, | ||
DistributedTransactionInfo.builder() | ||
.completedTransactionalOperations( | ||
Lists.newArrayList(TransactionalStep.SAVE_CONSULTANT_IN_MARIADB)) | ||
.name("patchConsultant") | ||
.failedStep(TransactionalStep.UPDATE_ROCKET_CHAT_USER_DISPLAY_NAME) | ||
.build()); | ||
} | ||
} | ||
|
||
private Consultant saveConsultant(Consultant patchedConsultant) { | ||
return consultantRepository.save(patchedConsultant); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/de/caritas/cob/userservice/api/PatchConsultantSagaRollbackHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package de.caritas.cob.userservice.api; | ||
|
||
import com.google.common.collect.Lists; | ||
import de.caritas.cob.userservice.api.admin.service.consultant.TransactionalStep; | ||
import de.caritas.cob.userservice.api.exception.httpresponses.DistributedTransactionException; | ||
import de.caritas.cob.userservice.api.exception.httpresponses.DistributedTransactionInfo; | ||
import de.caritas.cob.userservice.api.model.Consultant; | ||
import de.caritas.cob.userservice.api.port.out.MessageClient; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class PatchConsultantSagaRollbackHandler { | ||
|
||
private final MessageClient messageClient; | ||
|
||
public void rollbackUpdateUserInRocketchat(Consultant savedConsultant) { | ||
try { | ||
var originalDisplayName = | ||
messageClient | ||
.findUser(savedConsultant.getRocketChatId()) | ||
.get() | ||
.get("displayName") | ||
.toString(); | ||
messageClient.updateUser(savedConsultant.getRocketChatId(), originalDisplayName); | ||
} catch (Exception e) { | ||
log.error("Error while rolling back consultant", e); | ||
throw new DistributedTransactionException( | ||
e, | ||
DistributedTransactionInfo.builder() | ||
.completedTransactionalOperations(Lists.newArrayList()) | ||
.name("patchConsultant") | ||
.failedStep(TransactionalStep.ROLLBACK_UPDATE_ROCKET_CHAT_USER_DISPLAY_NAME) | ||
.build()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/de/caritas/cob/userservice/api/admin/service/consultant/TransactionalStep.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package de.caritas.cob.userservice.api.admin.service.consultant; | ||
|
||
public enum TransactionalStep { | ||
CREATE_ACCOUNT_IN_KEYCLOAK, | ||
CREATE_CONSULTANT_IN_MARIADB, | ||
|
||
CREATE_ACCOUNT_IN_ROCKETCHAT, | ||
|
||
CREATE_ACCOUNT_IN_CALCOM_OR_APPOINTMENTSERVICE, | ||
|
||
SAVE_CONSULTANT_IN_MARIADB, | ||
ROLLBACK_CONSULTANT_IN_MARIADB, | ||
UPDATE_ROCKET_CHAT_USER_DISPLAY_NAME, | ||
|
||
ROLLBACK_UPDATE_ROCKET_CHAT_USER_DISPLAY_NAME, | ||
|
||
PATCH_APPOINTMENT_SERVICE_CONSULTANT; | ||
} |
Oops, something went wrong.