Skip to content

Commit b5bb686

Browse files
committed
download for all test medic
1 parent 3ef63f9 commit b5bb686

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

src/test/java/dev/dsf/bpe/start/DownloadAllowListFromTtpViaMedic1ExampleStarter.java

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.hl7.fhir.r4.model.ResourceType;
1111
import org.hl7.fhir.r4.model.StringType;
1212
import org.hl7.fhir.r4.model.Task;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
1315

1416
import dev.dsf.bpe.AllowListProcessPluginDefinition;
1517
import dev.dsf.bpe.ConstantsAllowList;
@@ -19,25 +21,45 @@
1921

2022
public class DownloadAllowListFromTtpViaMedic1ExampleStarter
2123
{
22-
private static final String REQUESTER_FHIR_BASE_URL = ConstantsExampleStarters.MEDIC_1_FHIR_BASE_URL;
23-
private static final String REQUESTER_RECIPIENT = ConstantsExampleStarters.NAMINGSYSTEM_DSF_ORGANIZATION_IDENTIFIER_VALUE_MEDIC_1;
24+
private static final Logger logger = LoggerFactory.getLogger(DownloadAllowListFromTtpViaMedic1ExampleStarter.class);
25+
2426
private static final String ALLOW_LIST_FHIR_BASE_URL = ConstantsExampleStarters.TTP_FHIR_BASE_URL;
27+
private static final Map<String, String> REQUESTER_RECIPIENT = Map.of(
28+
ConstantsExampleStarters.NAMINGSYSTEM_DSF_ORGANIZATION_IDENTIFIER_VALUE_MEDIC_1,
29+
ConstantsExampleStarters.MEDIC_1_FHIR_BASE_URL,
30+
ConstantsExampleStarters.NAMINGSYSTEM_DSF_ORGANIZATION_IDENTIFIER_VALUE_MEDIC_2,
31+
ConstantsExampleStarters.MEDIC_2_FHIR_BASE_URL,
32+
ConstantsExampleStarters.NAMINGSYSTEM_DSF_ORGANIZATION_IDENTIFIER_VALUE_MEDIC_3,
33+
ConstantsExampleStarters.MEDIC_3_FHIR_BASE_URL);
2534

2635
// Environment variable "DSF_CLIENT_CERTIFICATE_PATH" or args[0]: the path to the client-certificate
2736
// dsf/dsf-tools/dsf-tools-test-data-generator/cert/Webbrowser_Test_User/Webbrowser_Test_User_certificate.p12
2837
// Environment variable "DSF_CLIENT_CERTIFICATE_PASSWORD" or args[1]: the password of the client-certificate
2938
// password
3039
public static void main(String[] args) throws Exception
3140
{
32-
ExampleStarter starter = ExampleStarter.forServer(args, REQUESTER_FHIR_BASE_URL);
41+
ExampleStarter starter = ExampleStarter.forServer(args,
42+
REQUESTER_RECIPIENT.entrySet().iterator().next().getValue());
43+
IdType allowList = allowList(starter);
3344

34-
Bundle allowList = allowList(starter);
35-
Task task = task(allowList);
45+
REQUESTER_RECIPIENT.forEach((identifier, url) -> start(args, allowList, identifier, url));
46+
}
3647

37-
starter.startWith(task);
48+
private static void start(String[] args, IdType allowList, String identifier, String url)
49+
{
50+
try
51+
{
52+
Task task = task(identifier, allowList);
53+
ExampleStarter.forServer(args, url).startWith(task);
54+
}
55+
catch (Exception exception)
56+
{
57+
logger.error("Could not start download allow-list with url '{}' in organization {} with base-url '{}' - {}",
58+
allowList.getValue(), identifier, url, exception.getMessage());
59+
}
3860
}
3961

40-
private static Task task(Bundle allowList)
62+
private static Task task(String requesterRecipientIdentifierValue, IdType allowList)
4163
{
4264
var def = new AllowListProcessPluginDefinition();
4365

@@ -50,22 +72,22 @@ private static Task task(Bundle allowList)
5072
task.setIntent(Task.TaskIntent.ORDER);
5173
task.setAuthoredOn(new Date());
5274
task.getRequester().setType(ResourceType.Organization.name())
53-
.setIdentifier(NamingSystems.OrganizationIdentifier.withValue(REQUESTER_RECIPIENT));
75+
.setIdentifier(NamingSystems.OrganizationIdentifier.withValue(requesterRecipientIdentifierValue));
5476
task.getRestriction().addRecipient().setType(ResourceType.Organization.name())
55-
.setIdentifier(NamingSystems.OrganizationIdentifier.withValue(REQUESTER_RECIPIENT));
77+
.setIdentifier(NamingSystems.OrganizationIdentifier.withValue(requesterRecipientIdentifierValue));
5678

5779
task.addInput().setValue(new StringType(ConstantsAllowList.PROFILE_DSF_TASK_DOWNLOAD_ALLOW_LIST_MESSAGE_NAME))
5880
.getType().addCoding(CodeSystems.BpmnMessage.messageName());
5981
task.addInput()
6082
.setValue(new Reference(new IdType(ALLOW_LIST_FHIR_BASE_URL, ResourceType.Bundle.name(),
61-
allowList.getIdElement().getIdPart(), allowList.getIdElement().getVersionIdPart())))
83+
allowList.getIdPart(), allowList.getVersionIdPart())))
6284
.getType().addCoding().setSystem(ConstantsAllowList.CODESYSTEM_DSF_ALLOW_LIST)
6385
.setCode(ConstantsAllowList.CODESYSTEM_DSF_ALLOW_LIST_VALUE_ALLOW_LIST);
6486

6587
return task;
6688
}
6789

68-
private static Bundle allowList(ExampleStarter starter) throws Exception
90+
private static IdType allowList(ExampleStarter starter) throws Exception
6991
{
7092
FhirWebserviceClient client = starter.createClient(ALLOW_LIST_FHIR_BASE_URL);
7193
Bundle searchResult = client.searchWithStrictHandling(Bundle.class, Map.of("identifier",
@@ -74,6 +96,6 @@ private static Bundle allowList(ExampleStarter starter) throws Exception
7496
if (searchResult.getTotal() != 1 && searchResult.getEntryFirstRep().getResource() instanceof Bundle)
7597
throw new IllegalStateException("Expected a single allow list Bundle");
7698

77-
return (Bundle) searchResult.getEntryFirstRep().getResource();
99+
return searchResult.getEntryFirstRep().getResource().getIdElement();
78100
}
79101
}

0 commit comments

Comments
 (0)