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.
- Loading branch information
1 parent
085a7c1
commit d820353
Showing
9 changed files
with
115 additions
and
10 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
24 changes: 24 additions & 0 deletions
24
src/main/java/de/bund/digitalservice/a2j/config/FitConnectConfig.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.config; | ||
|
||
import dev.fitko.fitconnect.api.config.ApplicationConfig; | ||
import dev.fitko.fitconnect.client.bootstrap.ApplicationConfigLoader; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.ResourceLoader; | ||
|
||
@Configuration | ||
public class FitConnectConfig { | ||
private final ResourceLoader resourceLoader; | ||
|
||
public FitConnectConfig(ResourceLoader resourceLoader) { | ||
this.resourceLoader = resourceLoader; | ||
} | ||
|
||
@Bean | ||
public ApplicationConfig applicationConfig() throws IOException { | ||
return ApplicationConfigLoader.loadConfigFromPath( | ||
Path.of(resourceLoader.getResource("classpath:fitConnectConfig.yaml").getURI())); | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
src/main/java/de/bund/digitalservice/a2j/service/FitConnectSenderService.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,54 @@ | ||
package de.bund.digitalservice.a2j.service; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import dev.fitko.fitconnect.api.config.ApplicationConfig; | ||
import dev.fitko.fitconnect.api.domain.model.submission.SentSubmission; | ||
import dev.fitko.fitconnect.api.domain.sender.SendableSubmission; | ||
import dev.fitko.fitconnect.client.SenderClient; | ||
import dev.fitko.fitconnect.client.bootstrap.ClientFactory; | ||
import java.net.URI; | ||
import java.util.UUID; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class FitConnectSenderService implements SenderService { | ||
private final SenderClient client; | ||
|
||
public FitConnectSenderService(ApplicationConfig config) { | ||
this.client = ClientFactory.createSenderClient(config); | ||
} | ||
|
||
@Override | ||
public String sendMessage(String message) { | ||
|
||
SendableSubmission submission = | ||
SendableSubmission.Builder() | ||
.setDestination(UUID.fromString("89126fd7-1069-46f1-9cdc-152037db95a9")) | ||
.setServiceType("urn:de:fim:leika:leistung:99001001000000", "FIT Connect Demo") | ||
.setJsonData( | ||
buildJSON(message), | ||
URI.create("https://schema.fitko.de/fim/s00000096_1.0.schema.json")) | ||
.build(); | ||
|
||
SentSubmission sentSubmission = client.send(submission); | ||
|
||
System.out.println("helllooo" + sentSubmission.toString()); | ||
|
||
return "Tried to send " + message; | ||
} | ||
|
||
private String buildJSON(String message) { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
|
||
ObjectNode rootNode = mapper.createObjectNode(); | ||
rootNode.put("data", message); | ||
|
||
try { | ||
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(rootNode); | ||
} catch (JsonProcessingException e) { | ||
return "{\"error\":\"Failed to build JSON\"}"; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/de/bund/digitalservice/a2j/service/SenderService.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,5 @@ | ||
package de.bund.digitalservice.a2j.service; | ||
|
||
public interface SenderService { | ||
String sendMessage(String message); | ||
} |
File renamed without changes.
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,5 @@ | ||
senderConfig: | ||
clientId: "client" | ||
clientSecret: "s3cr3t" | ||
|
||
activeEnvironment: TEST |