-
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.
feat: fix rollback policy for the case where consultant cannot be cre…
…ated in appointment service
- Loading branch information
Showing
23 changed files
with
220 additions
and
48 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
10 changes: 10 additions & 0 deletions
10
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,10 @@ | ||
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 | ||
} |
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
40 changes: 40 additions & 0 deletions
40
.../caritas/cob/userservice/api/exception/httpresponses/DistributedTransactionException.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.exception.httpresponses; | ||
|
||
import de.caritas.cob.userservice.api.service.LogService; | ||
import org.springframework.http.HttpHeaders; | ||
|
||
public class DistributedTransactionException extends CustomHttpStatusException { | ||
|
||
private final HttpHeaders customHttpHeaders; | ||
|
||
public DistributedTransactionException( | ||
Exception e, DistributedTransactionInfo distributedTransactionInfo) { | ||
super( | ||
getFormattedMessageWithDistributedTransactionInfo(distributedTransactionInfo), | ||
e, | ||
LogService::logError); | ||
this.customHttpHeaders = | ||
buildCustomHeaders( | ||
"DISTRIBUTED_TRANSACTION_FAILED_ON_STEP_" | ||
+ distributedTransactionInfo.getFailedStep().name()); | ||
} | ||
|
||
private HttpHeaders buildCustomHeaders(String message) { | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add("X-Reason", message); | ||
return headers; | ||
} | ||
|
||
private static String getFormattedMessageWithDistributedTransactionInfo( | ||
DistributedTransactionInfo distributedTransactionInfo) { | ||
return String.format( | ||
"Distributed transaction %s failed. Completed transactional operations: %s. Failed step: %s", | ||
distributedTransactionInfo.getName(), | ||
distributedTransactionInfo.getCompletedTransactionalOperations(), | ||
distributedTransactionInfo.getFailedStep()); | ||
} | ||
|
||
public HttpHeaders getCustomHttpHeaders() { | ||
return customHttpHeaders; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...va/de/caritas/cob/userservice/api/exception/httpresponses/DistributedTransactionInfo.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,19 @@ | ||
package de.caritas.cob.userservice.api.exception.httpresponses; | ||
|
||
import de.caritas.cob.userservice.api.admin.service.consultant.TransactionalStep; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Data | ||
@Builder | ||
@AllArgsConstructor | ||
public class DistributedTransactionInfo { | ||
|
||
String name; | ||
List<TransactionalStep> completedTransactionalOperations; | ||
TransactionalStep failedStep; | ||
} |
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
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
Oops, something went wrong.