-
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
86c8de5
commit 23df414
Showing
26 changed files
with
338 additions
and
145 deletions.
There are no files selected for viewing
96 changes: 10 additions & 86 deletions
96
diga-epa-client/src/main/java/com/oviva/epa/client/KonnektorService.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,97 +1,21 @@ | ||
package com.oviva.epa.client; | ||
|
||
import com.oviva.epa.client.konn.KonnektorConnection; | ||
import com.oviva.epa.client.svc.CardServiceClient; | ||
import com.oviva.epa.client.svc.CertificateServiceClient; | ||
import com.oviva.epa.client.svc.EventServiceClient; | ||
import com.oviva.epa.client.svc.PhrManagementServiceClient; | ||
import com.oviva.epa.client.svc.model.KonnektorContext; | ||
import com.oviva.epa.client.svc.phr.PhrServiceClient; | ||
import com.oviva.epa.client.svc.phr.SmbInformationServiceClient; | ||
import com.oviva.epa.client.svc.phr.model.RecordIdentifier; | ||
import com.oviva.epa.client.svc.phr.model.RecordIdentifierAdapter; | ||
import de.gematik.epa.LibIheXdsMain; | ||
import com.oviva.epa.client.model.Card; | ||
import com.oviva.epa.client.model.PinStatus; | ||
import com.oviva.epa.client.model.RecordIdentifier; | ||
import com.oviva.epa.client.model.WriteDocumentResponse; | ||
import de.gematik.epa.ihe.model.document.Document; | ||
import de.gematik.epa.ihe.model.request.DocumentSubmissionRequest; | ||
import de.gematik.epa.ihe.model.simple.AuthorInstitution; | ||
import de.gematik.epa.ihe.model.simple.SubmissionSetMetadata; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType; | ||
import telematik.ws.conn.cardservice.xsd.v8_1.CardInfoType; | ||
import telematik.ws.conn.cardservice.xsd.v8_1.PinStatusEnum; | ||
|
||
public class KonnektorService { | ||
public interface KonnektorService { | ||
List<AuthorInstitution> getAuthorInstitutions(); | ||
|
||
private final EventServiceClient eventServiceClient; | ||
private final CardServiceClient cardServiceClient; | ||
private final PhrManagementServiceClient phrManagementServiceClient; | ||
private final PhrServiceClient phrServiceClient; | ||
List<Card> getCardsInfo(); | ||
|
||
private final SmbInformationServiceClient smbInformationServiceClient; | ||
PinStatus verifySmcPin(String cardHandle); | ||
|
||
public KonnektorService(KonnektorConnection connection, KonnektorContext konnektorContext) { | ||
WriteDocumentResponse writeDocument(RecordIdentifier recordIdentifier, Document document); | ||
|
||
eventServiceClient = new EventServiceClient(connection.eventService(), konnektorContext); | ||
|
||
cardServiceClient = | ||
new CardServiceClient(connection.cardService(), konnektorContext, eventServiceClient); | ||
|
||
phrServiceClient = new PhrServiceClient(connection.phrService(), konnektorContext); | ||
|
||
phrManagementServiceClient = | ||
new PhrManagementServiceClient(connection.phrManagementService(), konnektorContext); | ||
|
||
var certificateServiceClient = | ||
new CertificateServiceClient(connection.certificateService(), konnektorContext); | ||
|
||
smbInformationServiceClient = | ||
new SmbInformationServiceClient(eventServiceClient, certificateServiceClient); | ||
} | ||
|
||
public List<AuthorInstitution> getAuthorInstitutions() { | ||
return smbInformationServiceClient.getAuthorInstitutions(); | ||
} | ||
|
||
// TODO: map CardInfoType to a VO | ||
public List<CardInfoType> getCardsInfo() { | ||
// don't be fooled by the name, this returns a list of cards... | ||
return eventServiceClient.getSmbInfo().getCards().getCard(); | ||
} | ||
|
||
// TODO: map PinStatusEnum to a VO | ||
public PinStatusEnum verifyPin(String cardHandle) { | ||
var response = cardServiceClient.getPinStatusResponse(cardHandle, "PIN.SMC"); | ||
return response.getPinStatus(); | ||
} | ||
|
||
// TODO: map RegistryResponseType to a VO | ||
public RegistryResponseType writeDocument(RecordIdentifier recordIdentifier, Document document) { | ||
|
||
var docSubmissionRequest = | ||
new DocumentSubmissionRequest( | ||
new RecordIdentifierAdapter(recordIdentifier), | ||
List.of(document), | ||
getSubmissionSetMetadata(document)); | ||
|
||
var provideAndRegisterRequest = | ||
LibIheXdsMain.convertDocumentSubmissionRequest(docSubmissionRequest); | ||
|
||
return phrServiceClient.documentRepositoryProvideAndRegisterDocumentSetB( | ||
recordIdentifier, provideAndRegisterRequest); | ||
} | ||
|
||
public String getHomeCommunityID(String kvnr) { | ||
return phrManagementServiceClient.getHomeCommunityID(kvnr); | ||
} | ||
|
||
private SubmissionSetMetadata getSubmissionSetMetadata(Document document) { | ||
|
||
var author = | ||
document.documentMetadata().author().stream() | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("no author")); | ||
|
||
return new SubmissionSetMetadata(List.of(author), null, LocalDateTime.now(), null, null, null); | ||
} | ||
String getHomeCommunityID(String kvnr); | ||
} |
67 changes: 67 additions & 0 deletions
67
diga-epa-client/src/main/java/com/oviva/epa/client/KonnektorServiceBuilder.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,67 @@ | ||
package com.oviva.epa.client; | ||
|
||
import com.oviva.epa.client.internal.KonnektorServiceImpl; | ||
import com.oviva.epa.client.internal.svc.model.KonnektorContext; | ||
import com.oviva.epa.client.konn.KonnektorConnection; | ||
|
||
public class KonnektorServiceBuilder { | ||
|
||
private KonnektorConnection connection; | ||
private String workplaceId = "a"; | ||
private String mandantId = "m"; | ||
private String clientSystemId = "c"; | ||
private String userId = "admin"; | ||
|
||
private KonnektorServiceBuilder() {} | ||
|
||
public static KonnektorServiceBuilder newBuilder() { | ||
return new KonnektorServiceBuilder(); | ||
} | ||
|
||
public KonnektorServiceBuilder connection(KonnektorConnection connection) { | ||
this.connection = connection; | ||
return this; | ||
} | ||
|
||
public KonnektorServiceBuilder workplaceId(String workplace) { | ||
this.workplaceId = workplace; | ||
return this; | ||
} | ||
|
||
public KonnektorServiceBuilder mandantId(String mandantId) { | ||
this.mandantId = mandantId; | ||
return this; | ||
} | ||
|
||
public KonnektorServiceBuilder clientSystemId(String clientSystemId) { | ||
this.clientSystemId = clientSystemId; | ||
return this; | ||
} | ||
|
||
public KonnektorServiceBuilder userId(String userId) { | ||
this.userId = userId; | ||
return this; | ||
} | ||
|
||
public KonnektorService build() { | ||
|
||
if (connection == null) { | ||
throw new IllegalArgumentException("konnektor connection required"); | ||
} | ||
|
||
if (workplaceId == null) { | ||
throw new IllegalArgumentException("workplaceId required"); | ||
} | ||
|
||
if (mandantId == null) { | ||
throw new IllegalArgumentException("mandantId required"); | ||
} | ||
|
||
if (clientSystemId == null) { | ||
throw new IllegalArgumentException("clientSystemId required"); | ||
} | ||
|
||
var ctx = new KonnektorContext(mandantId, clientSystemId, workplaceId, userId); | ||
return new KonnektorServiceImpl(connection, ctx); | ||
} | ||
} |
145 changes: 145 additions & 0 deletions
145
diga-epa-client/src/main/java/com/oviva/epa/client/internal/KonnektorServiceImpl.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,145 @@ | ||
package com.oviva.epa.client.internal; | ||
|
||
import com.oviva.epa.client.*; | ||
import com.oviva.epa.client.internal.svc.CardServiceClient; | ||
import com.oviva.epa.client.internal.svc.CertificateServiceClient; | ||
import com.oviva.epa.client.internal.svc.EventServiceClient; | ||
import com.oviva.epa.client.internal.svc.PhrManagementServiceClient; | ||
import com.oviva.epa.client.internal.svc.model.KonnektorContext; | ||
import com.oviva.epa.client.internal.svc.phr.PhrServiceClient; | ||
import com.oviva.epa.client.internal.svc.phr.SmbInformationServiceClient; | ||
import com.oviva.epa.client.internal.svc.phr.model.RecordIdentifierAdapter; | ||
import com.oviva.epa.client.konn.KonnektorConnection; | ||
import com.oviva.epa.client.model.*; | ||
import de.gematik.epa.LibIheXdsMain; | ||
import de.gematik.epa.ihe.model.document.Document; | ||
import de.gematik.epa.ihe.model.request.DocumentSubmissionRequest; | ||
import de.gematik.epa.ihe.model.simple.AuthorInstitution; | ||
import de.gematik.epa.ihe.model.simple.SubmissionSetMetadata; | ||
import java.time.LocalDateTime; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryErrorList; | ||
import oasis.names.tc.ebxml_regrep.xsd.rs._3.RegistryResponseType; | ||
import telematik.ws.conn.cardservicecommon.xsd.v2_0.CardTypeType; | ||
|
||
public class KonnektorServiceImpl implements KonnektorService { | ||
|
||
private static final String STATUS_SUCCESS = | ||
"urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Success"; | ||
private final EventServiceClient eventServiceClient; | ||
private final CardServiceClient cardServiceClient; | ||
private final PhrManagementServiceClient phrManagementServiceClient; | ||
private final PhrServiceClient phrServiceClient; | ||
|
||
private final SmbInformationServiceClient smbInformationServiceClient; | ||
|
||
public KonnektorServiceImpl(KonnektorConnection connection, KonnektorContext konnektorContext) { | ||
|
||
eventServiceClient = new EventServiceClient(connection.eventService(), konnektorContext); | ||
|
||
cardServiceClient = | ||
new CardServiceClient(connection.cardService(), konnektorContext, eventServiceClient); | ||
|
||
phrServiceClient = new PhrServiceClient(connection.phrService(), konnektorContext); | ||
|
||
phrManagementServiceClient = | ||
new PhrManagementServiceClient(connection.phrManagementService(), konnektorContext); | ||
|
||
var certificateServiceClient = | ||
new CertificateServiceClient(connection.certificateService(), konnektorContext); | ||
|
||
smbInformationServiceClient = | ||
new SmbInformationServiceClient(eventServiceClient, certificateServiceClient); | ||
} | ||
|
||
@Override | ||
public List<AuthorInstitution> getAuthorInstitutions() { | ||
return smbInformationServiceClient.getAuthorInstitutions(); | ||
} | ||
|
||
@Override | ||
public List<Card> getCardsInfo() { | ||
// don't be fooled by the name, this returns a list of cards... | ||
return eventServiceClient.getSmbInfo().getCards().getCard().stream() | ||
.map(c -> new Card(c.getCardHandle(), c.getCardHolderName(), mapCardType(c.getCardType()))) | ||
.toList(); | ||
} | ||
|
||
private Card.CardType mapCardType(CardTypeType t) { | ||
return switch (t) { | ||
case SMC_B -> Card.CardType.SMC_B; | ||
case SMC_KT -> Card.CardType.SMC_KT; | ||
default -> Card.CardType.UNKNOWN; | ||
}; | ||
} | ||
|
||
@Override | ||
public PinStatus verifySmcPin(String cardHandle) { | ||
var response = cardServiceClient.getPinStatusResponse(cardHandle, "PIN.SMC"); | ||
return PinStatus.valueOf(response.getPinStatus().name()); | ||
} | ||
|
||
@Override | ||
public WriteDocumentResponse writeDocument(RecordIdentifier recordIdentifier, Document document) { | ||
|
||
var phrRecordIdentifier = | ||
new com.oviva.epa.client.internal.svc.phr.model.RecordIdentifier( | ||
recordIdentifier.kvnr(), recordIdentifier.homeCommunityId()); | ||
var docSubmissionRequest = | ||
new DocumentSubmissionRequest( | ||
new RecordIdentifierAdapter(phrRecordIdentifier), | ||
List.of(document), | ||
getSubmissionSetMetadata(document)); | ||
|
||
var provideAndRegisterRequest = | ||
LibIheXdsMain.convertDocumentSubmissionRequest(docSubmissionRequest); | ||
|
||
var res = | ||
phrServiceClient.documentRepositoryProvideAndRegisterDocumentSetB( | ||
phrRecordIdentifier, provideAndRegisterRequest); | ||
|
||
validateResponse(res); | ||
|
||
return new WriteDocumentResponse(res.getRequestId()); | ||
} | ||
|
||
private void validateResponse(RegistryResponseType res) { | ||
|
||
if (STATUS_SUCCESS.equals(res.getStatus())) { | ||
return; | ||
} | ||
var errors = | ||
Optional.ofNullable(res.getRegistryErrorList()) | ||
.map(RegistryErrorList::getRegistryError) | ||
.stream() | ||
.flatMap(Collection::stream) | ||
.map( | ||
e -> | ||
new WriteDocumentException.Error( | ||
e.getValue(), | ||
e.getCodeContext(), | ||
e.getErrorCode(), | ||
e.getSeverity(), | ||
e.getLocation())) | ||
.toList(); | ||
throw new WriteDocumentException( | ||
"writing document failed, status='%s'".formatted(res.getStatus()), errors); | ||
} | ||
|
||
@Override | ||
public String getHomeCommunityID(String kvnr) { | ||
return phrManagementServiceClient.getHomeCommunityID(kvnr); | ||
} | ||
|
||
private SubmissionSetMetadata getSubmissionSetMetadata(Document document) { | ||
|
||
var author = | ||
document.documentMetadata().author().stream() | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("no author")); | ||
|
||
return new SubmissionSetMetadata(List.of(author), null, LocalDateTime.now(), null, null, null); | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
...lient/svc/PhrManagementServiceClient.java → ...ernal/svc/PhrManagementServiceClient.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
2 changes: 1 addition & 1 deletion
2
...pa/client/svc/model/KonnektorContext.java → .../internal/svc/model/KonnektorContext.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
6 changes: 3 additions & 3 deletions
6
.../client/svc/phr/ContextHeaderBuilder.java → ...nternal/svc/phr/ContextHeaderBuilder.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
Oops, something went wrong.