diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/GatewayApiSettings.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/GatewayApiSettings.java index bfe34b603..c3aebf62c 100644 --- a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/GatewayApiSettings.java +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/GatewayApiSettings.java @@ -15,6 +15,7 @@ public class GatewayApiSettings { private KafkaProducerSettings kafkaProducer; private KafkaConsumerSettings kafkaConsumer; private InboundServerSettings inboundServer; + private InboundExternalServerSettings inboundExternalServer; public HazelcastClientParams getHazelcast() { return hazelcast; @@ -47,4 +48,12 @@ public class GatewayApiSettings { public void setInboundServer(InboundServerSettings inboundServer) { this.inboundServer = inboundServer; } + + public InboundExternalServerSettings getInboundExternalServer() { + return inboundExternalServer; + } + + public void setInboundExternalServer(InboundExternalServerSettings inboundExternalServer) { + this.inboundExternalServer = inboundExternalServer; + } } diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/InboundExternalServerSettings.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/InboundExternalServerSettings.java new file mode 100644 index 000000000..6a608e82e --- /dev/null +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/InboundExternalServerSettings.java @@ -0,0 +1,61 @@ +package ru.spcex.clearing.gatewayapi.config; + +import java.util.ArrayList; +import java.util.List; + +public class InboundExternalServerSettings { + private String host; + private String pathLOCM; + private String pathLOSC; + private Integer port; + private Boolean enableSsl; + private List allowedTypes = new ArrayList<>(); + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public Integer getPort() { + return port; + } + + public void setPort(Integer port) { + this.port = port; + } + + public Boolean getEnableSsl() { + return enableSsl; + } + + public void setEnableSsl(Boolean enableSsl) { + this.enableSsl = enableSsl; + } + + public String getPathLOCM() { + return pathLOCM; + } + + public void setPathLOCM(String pathLOCM) { + this.pathLOCM = pathLOCM; + } + + public String getPathLOSC() { + return pathLOSC; + } + + public void setPathLOSC(String pathLOSC) { + this.pathLOSC = pathLOSC; + } + + public List getAllowedTypes() { + return allowedTypes; + } + + public void setAllowedTypes(List allowedTypes) { + this.allowedTypes = allowedTypes; + } +} diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/InboundServerSettings.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/InboundServerSettings.java index ee103a3c5..8ce4b3b0a 100644 --- a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/InboundServerSettings.java +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/config/InboundServerSettings.java @@ -1,11 +1,15 @@ package ru.spcex.clearing.gatewayapi.config; +import java.util.ArrayList; +import java.util.List; + public class InboundServerSettings { private String host; private String pathLOCM; private String pathLOSC; private Integer port; private Boolean enableSsl; + private List allowedTypes = new ArrayList<>(); public String getHost() { return host; @@ -46,4 +50,12 @@ public class InboundServerSettings { public void setPathLOSC(String pathLOSC) { this.pathLOSC = pathLOSC; } + + public List getAllowedTypes() { + return allowedTypes; + } + + public void setAllowedTypes(List allowedTypes) { + this.allowedTypes = allowedTypes; + } } diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/GatewayController.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/GatewayController.java index 00a253ba4..93ce96bcb 100644 --- a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/GatewayController.java +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/GatewayController.java @@ -266,6 +266,8 @@ public class GatewayController { commonResponse.setType(request.getType()); commonResponse.setDatetime(request.getDatetime()); commonResponse.setSection(request.getSection()); + commonResponse.setSection(request.getSection()); + commonResponse.setClearingSystem(request.getClearingSystem()); if (success) { commonResponse.setCode(0L); commonResponse.setMessage("success"); diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/inbound/request/CommonRequest.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/inbound/request/CommonRequest.java index f48e95a1c..874cb6d65 100644 --- a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/inbound/request/CommonRequest.java +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/inbound/request/CommonRequest.java @@ -50,6 +50,9 @@ public class CommonRequest { @JsonProperty("section") @ApiModelProperty(value = "Секция (FOND или MKR)", example = "FOND") private String section; + @JsonProperty("clearing_system") + @ApiModelProperty(value = "Клиринговая система", example = "SPVB/LCC") + private String clearingSystem; public void validate(List typeValidValues, List
sectionValidValues) { if (!typeValidValues.isEmpty() && !typeValidValues.contains(type.toUpperCase())) { @@ -92,4 +95,12 @@ public class CommonRequest { public void setSection(String section) { this.section = section; } + + public String getClearingSystem() { + return clearingSystem; + } + + public void setClearingSystem(String clearingSystem) { + this.clearingSystem = clearingSystem; + } } diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/inbound/response/CommonResponse.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/inbound/response/CommonResponse.java index 612300408..5e315649c 100644 --- a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/inbound/response/CommonResponse.java +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/controller/inbound/response/CommonResponse.java @@ -45,6 +45,10 @@ public class CommonResponse { @JsonProperty("message") private String message; + @JsonProperty("clearing_system") + @ApiModelProperty(value = "Клиринговая система", example = "SPVB/LCC") + private String clearingSystem; + public UUID getId() { return id; } @@ -92,4 +96,12 @@ public class CommonResponse { public void setMessage(String message) { this.message = message; } + + public String getClearingSystem() { + return clearingSystem; + } + + public void setClearingSystem(String clearingSystem) { + this.clearingSystem = clearingSystem; + } } diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java index 9234f6239..516347aa8 100644 --- a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java @@ -25,6 +25,7 @@ import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import ru.clearing.classes.statics.data.register.GatewayResult; import ru.spcex.clearing.gatewayapi.config.GatewayApiSettings; +import ru.spcex.clearing.gatewayapi.config.InboundExternalServerSettings; import ru.spcex.clearing.gatewayapi.config.InboundServerSettings; import ru.spcex.clearing.gatewayapi.controller.inbound.request.operations.SentAsset; import ru.spcex.clearing.gatewayapi.controller.outbound.request.OutboundRequest; @@ -60,6 +61,7 @@ public class GatewayService extends QueueConsumer implements InitializingBean { private final UserRoleVerification userRoleVerification; private final RestTemplate restTemplate; private final InboundServerSettings inboundServerSettings; + private final InboundExternalServerSettings inboundExternalServerSettings; private final Map> sentAssets; private final Map outboundRequestByUuid; protected final Imdg gatewayResultImdg; @@ -77,6 +79,7 @@ public class GatewayService extends QueueConsumer implements InitializingBean { this.restTemplate = restTemplate; this.userRoleVerification = userRoleVerification; this.inboundServerSettings = gatewayApiSettings.getInboundServer(); + this.inboundExternalServerSettings = gatewayApiSettings.getInboundExternalServer(); this.sentAssets = sentAssets; this.outboundRequestByUuid = outboundRequestByUuid; this.gatewayResultImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_GatewayResult, GatewayResult.class); @@ -112,26 +115,16 @@ public class GatewayService extends QueueConsumer implements InitializingBean { if (requestInfoUpdate != null) return; logUnknownProperties(userRequest); - - String url = formingInboundUrl(inboundServerSettings.getPathLOCM()); - OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder() .type(OutboundRequestType.MEMBER_ON_DEMAND.getKey()) .build(); - HttpEntity request = makeDefaultRequest(outboundFondRequest); outboundRequestByUuid.put(outboundFondRequest.getId(), outboundFondRequest); - ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, request, SuccessResponse.class); - SuccessResponse bodyResponse = response.getBody(); - if (bodyResponse != null) { - log.debug("LOCM task complete, success response : {}", bodyResponse); - } + sendRequest(outboundFondRequest); } public void requestOnLimit(BaseRequest userRequest) { LimExportedRequest exportedRequest = userRequest.getRequestPayload(); - String url = formingInboundUrl(inboundServerSettings.getPathLOCM()); - Map content = Map.of("file", exportedRequest.getLimFileName()); OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder() @@ -140,14 +133,9 @@ public class GatewayService extends QueueConsumer implements InitializingBean { .content(content) .build(); - HttpEntity request = makeDefaultRequest(outboundFondRequest); outboundRequestByUuid.put(outboundFondRequest.getId(), outboundFondRequest); gatewayResultImdg.insert(GatewayResultBuilder.builder().outboundRequest(outboundFondRequest).build()); - ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, request, SuccessResponse.class); - SuccessResponse bodyResponse = response.getBody(); - if (bodyResponse != null) { - log.debug("Limit request complete, success response: {}", bodyResponse); - } + sendRequest(outboundFondRequest); } public void requestOnDemandSecurity(BaseRequest userRequest) { @@ -158,8 +146,6 @@ public class GatewayService extends QueueConsumer implements InitializingBean { logUnknownProperties(userRequest); - String url = formingInboundUrl(inboundServerSettings.getPathLOCM()); - OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder() .section(Section.FOND.getKey()) .type(OutboundRequestType.ON_DEMAND.getKey()) @@ -175,28 +161,16 @@ public class GatewayService extends QueueConsumer implements InitializingBean { .type(OutboundRequestType.ON_DEMAND.getKey()) .build(); - HttpEntity requestFond = makeDefaultRequest(outboundFondRequest); - HttpEntity requestMKR = makeDefaultRequest(outboundMkrRequest); - HttpEntity requestCURR = makeDefaultRequest(outboundCurrRequest); - outboundRequestByUuid.put(outboundFondRequest.getId(), outboundFondRequest); outboundRequestByUuid.put(outboundMkrRequest.getId(), outboundMkrRequest); outboundRequestByUuid.put(outboundCurrRequest.getId(), outboundCurrRequest); - ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, requestFond, SuccessResponse.class); - SuccessResponse bodyResponse = response.getBody(); - if (bodyResponse != null) { - log.debug("LOSC task 1/3 complete (FOND section), success response: {}", bodyResponse); - } - response = restTemplate.exchange(url, HttpMethod.POST, requestMKR, SuccessResponse.class); - bodyResponse = response.getBody(); - if (bodyResponse != null) { - log.debug("LOSC task 2/3 complete (MKR section), success response: {}", bodyResponse); - } - response = restTemplate.exchange(url, HttpMethod.POST, requestCURR, SuccessResponse.class); - bodyResponse = response.getBody(); - if (bodyResponse != null) { - log.debug("LOSC task 3/3 complete (CURR section), success response: {}", bodyResponse); - } + + sendRequest(outboundFondRequest); + log.debug("LOSC task 1/3 complete (FOND section)"); + sendRequest(outboundMkrRequest); + log.debug("LOSC task 2/3 complete (MKR section)"); + sendRequest(outboundCurrRequest); + log.debug("LOSC task 3/3 complete (CURR section)"); } public void requestOnAsset(BaseRequest request) { @@ -224,16 +198,10 @@ public class GatewayService extends QueueConsumer implements InitializingBean { .content(content).build(); gatewayBuilder.outboundRequest(outboundRequest); - String url = formingInboundUrl(inboundServerSettings.getPathLOCM()); - HttpEntity r = makeDefaultRequest(outboundRequest); try { outboundRequestByUuid.put(outboundRequest.getId(), outboundRequest); gatewayResultImdg.insert(gatewayBuilder.build()); - ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, r, SuccessResponse.class); - SuccessResponse bodyResponse = response.getBody(); - if (bodyResponse != null) { - log.debug("Response from service: {}", bodyResponse); - } + sendRequest(outboundRequest); } catch (Throwable err) { log.error("Exchange error: {}", ExceptionUtils.getStackTrace(err)); } finally { @@ -262,13 +230,7 @@ public class GatewayService extends QueueConsumer implements InitializingBean { .type(reportType.getKey()) .content(content).build(); - String url = formingInboundUrl(inboundServerSettings.getPathLOCM()); - HttpEntity r = makeDefaultRequest(outboundRequest); - ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, r, SuccessResponse.class); - SuccessResponse bodyResponse = response.getBody(); - if (bodyResponse != null) { - log.debug("Response from service: {}", bodyResponse); - } + sendRequest(outboundRequest); } public void requestOnTkr(BaseRequest request) { @@ -286,13 +248,7 @@ public class GatewayService extends QueueConsumer implements InitializingBean { .outboundRequest(outboundRequest) .build(); gatewayResultImdg.insert(gatewayResult); - String url = formingInboundUrl(inboundServerSettings.getPathLOCM()); - HttpEntity r = makeDefaultRequest(outboundRequest); - ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, r, SuccessResponse.class); - SuccessResponse bodyResponse = response.getBody(); - if (bodyResponse != null) { - log.debug("Response from service: {}", bodyResponse); - } + sendRequest(outboundRequest); } protected void makeContentByReportRequest(Map content, ReportPart reportPart) { @@ -324,6 +280,35 @@ public class GatewayService extends QueueConsumer implements InitializingBean { } } + private void sendRequest(OutboundRequest request) { + if (inboundServerSettings.getAllowedTypes().isEmpty() || + inboundServerSettings.getAllowedTypes().contains(request.getType())) { + String url = formingInboundUrl(inboundServerSettings.getEnableSsl(), + inboundServerSettings.getHost(), + inboundServerSettings.getPort(), + inboundServerSettings.getPathLOCM()); + exchange(request, url); + } + + if (inboundExternalServerSettings.getAllowedTypes().isEmpty() || + inboundExternalServerSettings.getAllowedTypes().contains(request.getType())) { + String url = formingInboundUrl(inboundExternalServerSettings.getEnableSsl(), + inboundExternalServerSettings.getHost(), + inboundExternalServerSettings.getPort(), + inboundExternalServerSettings.getPathLOCM()); + exchange(request, url); + } + } + + private void exchange(OutboundRequest request, String url){ + HttpEntity r = makeDefaultRequest(request); + ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, r, SuccessResponse.class); + SuccessResponse bodyResponse = response.getBody(); + if (bodyResponse != null) { + log.debug("Response from service: {}", bodyResponse); + } + } + public String formingInboundUrl(String path) { return "%s://%s:%s/%s".formatted( inboundServerSettings.getEnableSsl() ? "https" : "http", @@ -333,6 +318,15 @@ public class GatewayService extends QueueConsumer implements InitializingBean { ); } + public String formingInboundUrl(Boolean enableSsl, String host, Integer port, String path) { + return "%s://%s:%s/%s".formatted( + enableSsl ? "https" : "http", + host, + port, + path + ); + } + private void logUnknownProperties(BaseRequest request) { Map unknownProperties = request.getUnknownProperties(); for (Map.Entry unknownProperty : unknownProperties.entrySet()) { diff --git a/clearing-parent/gateway-api/src/main/resources/application.properties b/clearing-parent/gateway-api/src/main/resources/application.properties index d52efb390..f7041f34d 100644 --- a/clearing-parent/gateway-api/src/main/resources/application.properties +++ b/clearing-parent/gateway-api/src/main/resources/application.properties @@ -29,4 +29,11 @@ gateway-api.inbound-server.enable-ssl=false gateway-api.inbound-server.host=10.200.200.183 gateway-api.inbound-server.port=8084 gateway-api.inbound-server.pathLOCM=test_rest/inbound_request -gateway-api.inbound-server.pathLOSC=test_rest/inbound_request \ No newline at end of file +gateway-api.inbound-server.pathLOSC=test_rest/inbound_request +gateway-api.inbound-server.allowed-types=ASSET_OPERATION,ON_DEMAND + +gateway-api.inbound-external-server.enable-ssl=false +gateway-api.inbound-external-server.host=10.200.200.183 +gateway-api.inbound-external-server.port=8084 +gateway-api.inbound-external-server.pathLOCM=test_rest/inbound_request +gateway-api.inbound-external-server.allowed-types=FILL_LIMITS,MEMBER_ON_DEMAND \ No newline at end of file