This commit is contained in:
parent
1c155e4804
commit
8d0f1faae8
4 changed files with 130 additions and 59 deletions
|
|
@ -11,7 +11,7 @@ import java.time.Instant;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class InboundRequest {
|
public class OutboundRequest {
|
||||||
@JsonProperty("id")
|
@JsonProperty("id")
|
||||||
@ApiModelProperty(
|
@ApiModelProperty(
|
||||||
value = """
|
value = """
|
||||||
|
|
@ -11,7 +11,7 @@ import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import ru.spcex.clearing.gatewayapi.config.GatewayApiSettings;
|
import ru.spcex.clearing.gatewayapi.config.GatewayApiSettings;
|
||||||
import ru.spcex.clearing.gatewayapi.config.InboundServerSettings;
|
import ru.spcex.clearing.gatewayapi.config.InboundServerSettings;
|
||||||
import ru.spcex.clearing.gatewayapi.request.InboundRequest;
|
import ru.spcex.clearing.gatewayapi.request.OutboundRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.clearing.AssetOperationRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.clearing.AssetOperationRequest;
|
||||||
|
|
@ -23,11 +23,8 @@ import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||||
import ru.spcex.platform.enumeration.Section;
|
import ru.spcex.platform.enumeration.Section;
|
||||||
import ru.spcex.platform.enumeration.Task;
|
import ru.spcex.platform.enumeration.Task;
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class GatewayService extends QueueConsumer implements InitializingBean {
|
public class GatewayService extends QueueConsumer implements InitializingBean {
|
||||||
|
|
@ -74,14 +71,11 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
||||||
logUnknownProperties(userRequest);
|
logUnknownProperties(userRequest);
|
||||||
|
|
||||||
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||||
HttpHeaders httpHeaders = new HttpHeaders();
|
|
||||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder()
|
||||||
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
.type(OutboundRequestType.MEMBER_ON_DEMAND)
|
||||||
InboundRequest inboundRequest = new InboundRequest();
|
.build();
|
||||||
inboundRequest.setId(UUID.randomUUID());
|
HttpEntity<OutboundRequest> request = makeDefaultRequest(outboundFondRequest);
|
||||||
inboundRequest.setType("MEMBER_ON_DEMAND");
|
|
||||||
inboundRequest.setDatetime(Instant.now());
|
|
||||||
HttpEntity<InboundRequest> request = new HttpEntity<>(inboundRequest, httpHeaders);
|
|
||||||
|
|
||||||
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
|
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
|
||||||
Map bodyResponse = response.getBody();
|
Map bodyResponse = response.getBody();
|
||||||
|
|
@ -91,20 +85,16 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
||||||
public void requestOnLimit(BaseRequest<LimExportedRequest> userRequest) {
|
public void requestOnLimit(BaseRequest<LimExportedRequest> userRequest) {
|
||||||
LimExportedRequest exportedRequest = userRequest.getRequestPayload();
|
LimExportedRequest exportedRequest = userRequest.getRequestPayload();
|
||||||
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||||
HttpHeaders httpHeaders = new HttpHeaders();
|
|
||||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
|
||||||
InboundRequest inboundRequest = new InboundRequest();
|
|
||||||
inboundRequest.setId(UUID.randomUUID());
|
|
||||||
inboundRequest.setType("FILL_LIMITS");
|
|
||||||
inboundRequest.setSection(exportedRequest.getSection());
|
|
||||||
inboundRequest.setDatetime(Instant.now());
|
|
||||||
|
|
||||||
Map<String, Object> content = new HashMap<>();
|
Map<String, Object> content = Map.of("file", exportedRequest.getLimFileName());
|
||||||
content.put("file", exportedRequest.getLimFileName());
|
|
||||||
inboundRequest.setContent(content);
|
|
||||||
HttpEntity<InboundRequest> request = new HttpEntity<>(inboundRequest, httpHeaders);
|
|
||||||
|
|
||||||
|
OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder()
|
||||||
|
.section(exportedRequest.getSection())
|
||||||
|
.type(OutboundRequestType.FILL_LIMITS)
|
||||||
|
.content(content)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpEntity<OutboundRequest> request = makeDefaultRequest(outboundFondRequest);
|
||||||
try {
|
try {
|
||||||
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
|
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
|
||||||
Map bodyResponse = response.getBody();
|
Map bodyResponse = response.getBody();
|
||||||
|
|
@ -124,49 +114,51 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
||||||
logUnknownProperties(userRequest);
|
logUnknownProperties(userRequest);
|
||||||
|
|
||||||
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||||
HttpHeaders httpHeaders = new HttpHeaders();
|
|
||||||
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
|
||||||
InboundRequest inboundRequest = new InboundRequest();
|
|
||||||
inboundRequest.setId(UUID.randomUUID());
|
|
||||||
inboundRequest.setType("ON_DEMAND");
|
|
||||||
inboundRequest.setSection(Section.FOND.getKey());
|
|
||||||
inboundRequest.setDatetime(Instant.now());
|
|
||||||
HttpEntity<InboundRequest> request = new HttpEntity<>(inboundRequest, httpHeaders);
|
|
||||||
|
|
||||||
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
|
OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder()
|
||||||
|
.section(Section.FOND.getKey())
|
||||||
|
.type(OutboundRequestType.ON_DEMAND)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
OutboundRequest outboundMkrRequest = OutboundRequestBuilder.builder()
|
||||||
|
.section(Section.MKR.getKey())
|
||||||
|
.type(OutboundRequestType.ON_DEMAND)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpEntity<OutboundRequest> requestFond = makeDefaultRequest(outboundFondRequest);
|
||||||
|
HttpEntity<OutboundRequest> requestMKR = makeDefaultRequest(outboundMkrRequest);
|
||||||
|
|
||||||
|
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, requestFond, Map.class);
|
||||||
Map bodyResponse = response.getBody();
|
Map bodyResponse = response.getBody();
|
||||||
log.debug("LOSC task 1/2 complete (FOND section), response: {}", bodyResponse);
|
log.debug("LOSC task 1/2 complete (FOND section), response: {}", bodyResponse);
|
||||||
|
response = restTemplate.exchange(url, HttpMethod.POST, requestMKR, Map.class);
|
||||||
inboundRequest.setId(UUID.randomUUID());
|
|
||||||
inboundRequest.setSection(Section.MKR.getKey());
|
|
||||||
request = new HttpEntity<>(inboundRequest, httpHeaders);
|
|
||||||
response = restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
|
|
||||||
bodyResponse = response.getBody();
|
bodyResponse = response.getBody();
|
||||||
log.debug("LOSC task 2/2 complete (MKR section), response: {}", bodyResponse);
|
log.debug("LOSC task 2/2 complete (MKR section), response: {}", bodyResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void requestOnAsset(BaseRequest<AssetOperationRequest> request) {
|
public void requestOnAsset(BaseRequest<AssetOperationRequest> request) {
|
||||||
log.debug("LOCM task received");
|
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(request);
|
||||||
|
if (requestInfoUpdate != null) return;
|
||||||
|
|
||||||
// RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
AssetOperationRequest assetOperationRequest = request.getRequestPayload();
|
||||||
// if (requestInfoUpdate != null) return;
|
Map<String, Object> content = Map.of("direction", "IN",
|
||||||
//
|
"amount", assetOperationRequest.getAmount(),
|
||||||
// logUnknownProperties(userRequest);
|
"quantity", assetOperationRequest.getQuantity(),
|
||||||
//
|
"code", assetOperationRequest.getCode(),
|
||||||
// String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
"asset", assetOperationRequest.getAsset(),
|
||||||
// HttpHeaders httpHeaders = new HttpHeaders();
|
"firm_id", assetOperationRequest.getFirmId());
|
||||||
// httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
|
||||||
// httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
OutboundRequest outboundRequest = OutboundRequestBuilder.builder()
|
||||||
// InboundRequest inboundRequest = new InboundRequest();
|
.section(Section.MKR.getKey())
|
||||||
// inboundRequest.setId(UUID.randomUUID());
|
.type(OutboundRequestType.ASSET_OPERATION)
|
||||||
// inboundRequest.setType("MEMBER_ON_DEMAND");
|
.content(content).build();
|
||||||
// inboundRequest.setDatetime(Instant.now());
|
|
||||||
// HttpEntity<InboundRequest> request = new HttpEntity<>(inboundRequest, httpHeaders);
|
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||||
//
|
|
||||||
// ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
|
HttpEntity<OutboundRequest> r = makeDefaultRequest(outboundRequest);
|
||||||
// Map bodyResponse = response.getBody();
|
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, r, Map.class);
|
||||||
// log.debug("LOCM task complete, response: {}", bodyResponse);
|
Map bodyResponse = response.getBody();
|
||||||
|
log.debug("Response from service: {}", bodyResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formingInboundUrl(String path) {
|
private String formingInboundUrl(String path) {
|
||||||
|
|
@ -189,4 +181,10 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HttpEntity<OutboundRequest> makeDefaultRequest(OutboundRequest outboundRequest) {
|
||||||
|
HttpHeaders httpHeaders = new HttpHeaders();
|
||||||
|
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
|
||||||
|
return new HttpEntity<>(outboundRequest, httpHeaders);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package ru.spcex.clearing.gatewayapi.service;
|
||||||
|
|
||||||
|
import ru.spcex.clearing.gatewayapi.request.OutboundRequest;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class OutboundRequestBuilder {
|
||||||
|
|
||||||
|
private String section;
|
||||||
|
private OutboundRequestType requestType;
|
||||||
|
private Map<String, Object> content;
|
||||||
|
|
||||||
|
private OutboundRequestBuilder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static OutboundRequestBuilder builder() {
|
||||||
|
return new OutboundRequestBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutboundRequestBuilder section(String section) {
|
||||||
|
this.section = section;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutboundRequestBuilder type(OutboundRequestType outboundRequestType) {
|
||||||
|
this.section = section;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutboundRequestBuilder content(Map<String, Object> content) {
|
||||||
|
this.content = content;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutboundRequest build() {
|
||||||
|
OutboundRequest outboundRequest = new OutboundRequest();
|
||||||
|
outboundRequest.setId(UUID.randomUUID());
|
||||||
|
outboundRequest.setDatetime(Instant.now());
|
||||||
|
outboundRequest.setSection(section);
|
||||||
|
outboundRequest.setType(requestType.getKey());
|
||||||
|
outboundRequest.setContent(content);
|
||||||
|
return outboundRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package ru.spcex.clearing.gatewayapi.service;
|
||||||
|
|
||||||
|
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||||
|
|
||||||
|
public enum OutboundRequestType implements IEnumKey {
|
||||||
|
ASSET_OPERATION("ASSET_OPERATION"),
|
||||||
|
ON_DEMAND("ON_DEMAND"),
|
||||||
|
FILL_LIMITS("FILL_LIMITS"),
|
||||||
|
MEMBER_ON_DEMAND("MEMBER_ON_DEMAND"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
OutboundRequestType(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKey() {
|
||||||
|
return this.key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equalsByKey(String key) {
|
||||||
|
return IEnumKey.super.equalsByKey(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue