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.UUID;
|
||||
|
||||
public class InboundRequest {
|
||||
public class OutboundRequest {
|
||||
@JsonProperty("id")
|
||||
@ApiModelProperty(
|
||||
value = """
|
||||
|
|
@ -11,7 +11,7 @@ import org.springframework.web.client.HttpClientErrorException;
|
|||
import org.springframework.web.client.RestTemplate;
|
||||
import ru.spcex.clearing.gatewayapi.config.GatewayApiSettings;
|
||||
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.Consts;
|
||||
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.Task;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class GatewayService extends QueueConsumer implements InitializingBean {
|
||||
|
|
@ -74,14 +71,11 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
logUnknownProperties(userRequest);
|
||||
|
||||
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("MEMBER_ON_DEMAND");
|
||||
inboundRequest.setDatetime(Instant.now());
|
||||
HttpEntity<InboundRequest> request = new HttpEntity<>(inboundRequest, httpHeaders);
|
||||
|
||||
OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder()
|
||||
.type(OutboundRequestType.MEMBER_ON_DEMAND)
|
||||
.build();
|
||||
HttpEntity<OutboundRequest> request = makeDefaultRequest(outboundFondRequest);
|
||||
|
||||
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
|
||||
Map bodyResponse = response.getBody();
|
||||
|
|
@ -91,20 +85,16 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
public void requestOnLimit(BaseRequest<LimExportedRequest> userRequest) {
|
||||
LimExportedRequest exportedRequest = userRequest.getRequestPayload();
|
||||
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<>();
|
||||
content.put("file", exportedRequest.getLimFileName());
|
||||
inboundRequest.setContent(content);
|
||||
HttpEntity<InboundRequest> request = new HttpEntity<>(inboundRequest, httpHeaders);
|
||||
Map<String, Object> content = Map.of("file", exportedRequest.getLimFileName());
|
||||
|
||||
OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder()
|
||||
.section(exportedRequest.getSection())
|
||||
.type(OutboundRequestType.FILL_LIMITS)
|
||||
.content(content)
|
||||
.build();
|
||||
|
||||
HttpEntity<OutboundRequest> request = makeDefaultRequest(outboundFondRequest);
|
||||
try {
|
||||
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
|
||||
Map bodyResponse = response.getBody();
|
||||
|
|
@ -124,49 +114,51 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
|
|||
logUnknownProperties(userRequest);
|
||||
|
||||
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();
|
||||
log.debug("LOSC task 1/2 complete (FOND section), response: {}", bodyResponse);
|
||||
|
||||
inboundRequest.setId(UUID.randomUUID());
|
||||
inboundRequest.setSection(Section.MKR.getKey());
|
||||
request = new HttpEntity<>(inboundRequest, httpHeaders);
|
||||
response = restTemplate.exchange(url, HttpMethod.POST, request, Map.class);
|
||||
response = restTemplate.exchange(url, HttpMethod.POST, requestMKR, Map.class);
|
||||
bodyResponse = response.getBody();
|
||||
log.debug("LOSC task 2/2 complete (MKR section), response: {}", bodyResponse);
|
||||
}
|
||||
|
||||
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);
|
||||
// if (requestInfoUpdate != null) return;
|
||||
//
|
||||
// logUnknownProperties(userRequest);
|
||||
//
|
||||
// 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("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);
|
||||
// Map bodyResponse = response.getBody();
|
||||
// log.debug("LOCM task complete, response: {}", bodyResponse);
|
||||
AssetOperationRequest assetOperationRequest = request.getRequestPayload();
|
||||
Map<String, Object> content = Map.of("direction", "IN",
|
||||
"amount", assetOperationRequest.getAmount(),
|
||||
"quantity", assetOperationRequest.getQuantity(),
|
||||
"code", assetOperationRequest.getCode(),
|
||||
"asset", assetOperationRequest.getAsset(),
|
||||
"firm_id", assetOperationRequest.getFirmId());
|
||||
|
||||
OutboundRequest outboundRequest = OutboundRequestBuilder.builder()
|
||||
.section(Section.MKR.getKey())
|
||||
.type(OutboundRequestType.ASSET_OPERATION)
|
||||
.content(content).build();
|
||||
|
||||
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||
|
||||
HttpEntity<OutboundRequest> r = makeDefaultRequest(outboundRequest);
|
||||
ResponseEntity<Map> response = restTemplate.exchange(url, HttpMethod.POST, r, Map.class);
|
||||
Map bodyResponse = response.getBody();
|
||||
log.debug("Response from service: {}", bodyResponse);
|
||||
}
|
||||
|
||||
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