generated from digitalservicebund/java-application-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from digitalservicebund/send_static_test_message
Send static test message
- Loading branch information
Showing
28 changed files
with
373 additions
and
44 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
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
22 changes: 22 additions & 0 deletions
22
src/main/java/de/bund/digitalservice/a2j/repository/egvp/MessageInTransit.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,22 @@ | ||
package de.bund.digitalservice.a2j.repository.egvp; | ||
|
||
public record MessageInTransit(String userId, String customId, String bundIdMailbox) { | ||
|
||
public int hashCode() { | ||
|
||
return customId.hashCode(); | ||
} | ||
|
||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
|
||
if (obj.getClass() != this.getClass()) { | ||
return false; | ||
} | ||
|
||
return customId.equals(((MessageInTransit) obj).customId) | ||
&& userId.equals(((MessageInTransit) obj).userId); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
.../java/de/bund/digitalservice/a2j/repository/egvp/MessagesInTransitInMemoryRepository.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,24 @@ | ||
package de.bund.digitalservice.a2j.repository.egvp; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class MessagesInTransitInMemoryRepository implements MessagesInTransitRepository { | ||
public Set<MessageInTransit> messages = new HashSet<>(); | ||
|
||
public Set<MessageInTransit> getAll() { | ||
return messages; | ||
} | ||
|
||
@Override | ||
public void add(MessageInTransit message) { | ||
this.messages.add(message); | ||
} | ||
|
||
@Override | ||
public void removeAll(Set<MessageInTransit> messages) { | ||
this.messages.removeAll(messages); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/de/bund/digitalservice/a2j/repository/egvp/MessagesInTransitRepository.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,12 @@ | ||
package de.bund.digitalservice.a2j.repository.egvp; | ||
|
||
import java.util.Set; | ||
|
||
public interface MessagesInTransitRepository { | ||
|
||
public void add(MessageInTransit message); | ||
|
||
public void removeAll(Set<MessageInTransit> messages); | ||
|
||
public Set<MessageInTransit> getAll(); | ||
} |
3 changes: 0 additions & 3 deletions
3
src/main/java/de/bund/digitalservice/a2j/service/egvp/DTO/GetVersionResponse.java
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
src/main/java/de/bund/digitalservice/a2j/service/egvp/DTO/SendMessageResponse.java
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
src/main/java/de/bund/digitalservice/a2j/service/egvp/EgvpOutboxService.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,75 @@ | ||
package de.bund.digitalservice.a2j.service.egvp; | ||
|
||
import de.bund.digitalservice.a2j.repository.egvp.MessageInTransit; | ||
import de.bund.digitalservice.a2j.repository.egvp.MessagesInTransitRepository; | ||
import de.bund.digitalservice.a2j.service.egvp.client.EgvpClient; | ||
import de.bund.digitalservice.a2j.service.egvp.client.EgvpClientException; | ||
import de.bund.digitalservice.a2j.service.egvp.client.MessageDeliveryStatusResponse; | ||
import de.bund.digitalservice.a2j.service.egvp.client.SendMessageRequest; | ||
import de.bund.digitalservice.a2j.service.egvp.client.SendMessageResponse; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class EgvpOutboxService { | ||
|
||
private final EgvpClient client; | ||
|
||
private final MessagesInTransitRepository repository; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(EgvpOutboxService.class); | ||
|
||
EgvpOutboxService(EgvpClient client, MessagesInTransitRepository repository) { | ||
this.client = client; | ||
this.repository = repository; | ||
} | ||
|
||
public String sendMessage(SendMessageRequest request) throws EgvpClientException { | ||
|
||
SendMessageResponse response = this.client.sendMessage(request); | ||
repository.add( | ||
new MessageInTransit(request.userId(), response.customId(), request.bundIdMailbox())); | ||
return response.customId(); | ||
} | ||
|
||
@Scheduled(fixedRate = 5000) | ||
public void retrieveDeliveryStatus() { | ||
logger.info("POLLING MESSAGE DELIVERY"); | ||
Set<MessageInTransit> deliveredMessages = new HashSet<>(); | ||
Set<MessageInTransit> failedMessages = new HashSet<>(); | ||
|
||
Set<MessageInTransit> inTransit = repository.getAll(); | ||
|
||
inTransit.forEach( | ||
m -> { | ||
logger.info("checking status for message with customId {}", m.customId()); | ||
try { | ||
MessageDeliveryStatusResponse response = | ||
this.client.checkMessageStatus(m.userId(), m.customId()); | ||
if (response.delivered()) { | ||
deliveredMessages.add(m); | ||
// TODO send confirmation file to user | ||
} else { | ||
logger.info( | ||
"message {} with customId {} still in transit : {}", | ||
response.messageId(), | ||
m.customId(), | ||
response.pendingReason()); | ||
} | ||
} catch (EgvpClientException e) { | ||
failedMessages.add(m); | ||
// TODO send failure to user | ||
logger.error("Unable to deliver message :{}", e.getMessage()); | ||
} | ||
}); | ||
repository.removeAll( | ||
Stream.concat(deliveredMessages.stream(), failedMessages.stream()) | ||
.collect(Collectors.toSet())); | ||
} | ||
} |
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
6 changes: 5 additions & 1 deletion
6
...a2j/service/egvp/EgvpClientException.java → ...vice/egvp/client/EgvpClientException.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
3 changes: 3 additions & 0 deletions
3
src/main/java/de/bund/digitalservice/a2j/service/egvp/client/GetVersionResponse.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,3 @@ | ||
package de.bund.digitalservice.a2j.service.egvp.client; | ||
|
||
public record GetVersionResponse(String version) {} |
2 changes: 1 addition & 1 deletion
2
...vp/DTO/MessageDeliveryStatusResponse.java → ...client/MessageDeliveryStatusResponse.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package de.bund.digitalservice.a2j.service.egvp.DTO; | ||
package de.bund.digitalservice.a2j.service.egvp.client; | ||
|
||
public record MessageDeliveryStatusResponse( | ||
String messageId, Boolean delivered, String pendingReason, String path) {} |
2 changes: 1 addition & 1 deletion
2
...e/a2j/service/egvp/DTO/ResponseError.java → ...2j/service/egvp/client/ResponseError.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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package de.bund.digitalservice.a2j.service.egvp.DTO; | ||
package de.bund.digitalservice.a2j.service.egvp.client; | ||
|
||
public record ResponseError(String responseCode, String errorDetail, String errorDescription) {} |
3 changes: 2 additions & 1 deletion
3
.../service/egvp/DTO/SendMessageRequest.java → ...rvice/egvp/client/SendMessageRequest.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
3 changes: 3 additions & 0 deletions
3
src/main/java/de/bund/digitalservice/a2j/service/egvp/client/SendMessageResponse.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,3 @@ | ||
package de.bund.digitalservice.a2j.service.egvp.client; | ||
|
||
public record SendMessageResponse(String customId) {} |
24 changes: 22 additions & 2 deletions
24
src/main/java/de/bund/digitalservice/a2j/service/subscriber/FitConnectSubscriberService.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
3 changes: 2 additions & 1 deletion
3
src/main/java/de/bund/digitalservice/a2j/service/subscriber/SubscriberService.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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package de.bund.digitalservice.a2j.service.subscriber; | ||
|
||
import de.bund.digitalservice.a2j.service.egvp.client.EgvpClientException; | ||
import dev.fitko.fitconnect.api.domain.model.submission.SubmissionForPickup; | ||
|
||
public interface SubscriberService { | ||
|
||
void pickUpSubmission(SubmissionForPickup submissionForPickup); | ||
void pickUpSubmission(SubmissionForPickup submissionForPickup) throws EgvpClientException; | ||
} |
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 |
---|---|---|
|
@@ -18,3 +18,7 @@ management: | |
enabled: true | ||
server: | ||
port: 8081 | ||
egvp: | ||
client: | ||
testUserId: | ||
baseUri: |
Binary file not shown.
Oops, something went wrong.