This commit is contained in:
parent
ed0fbdaaaf
commit
04a20c34db
2 changed files with 60 additions and 16 deletions
|
|
@ -1,18 +1,22 @@
|
|||
package ru.spcex.clearing.securities.service.builder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.securitites.DigitalCertificateSecurityGatewayRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.securitites.DigitalCertificateSecurityNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.securitites.DigitalCertificateSecurityUpdateRequest;
|
||||
import ru.spcex.platform.enumeration.InstrumentType;
|
||||
import ru.spcex.platform.enumeration.NominalTypeCode;
|
||||
|
||||
public class DigitalCertificateRequestBuilder {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private DigitalCertificateSecurityGatewayRequest gatewayRequest;
|
||||
private Long companyId;
|
||||
private Long digitalSecurityId;
|
||||
|
||||
private DigitalCertificateRequestBuilder() {
|
||||
}
|
||||
|
||||
|
|
@ -34,16 +38,15 @@ public class DigitalCertificateRequestBuilder {
|
|||
this.digitalSecurityId = digitalSecurityId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DigitalCertificateSecurityNewRequest buildNewRequest() {
|
||||
DigitalCertificateSecurityNewRequest newRequest = new DigitalCertificateSecurityNewRequest();
|
||||
|
||||
InstrumentType clrInstrumentType = Arrays.asList("DC", "D")
|
||||
.contains(gatewayRequest.getInstrumentType()) ? InstrumentType.DGCT : null;
|
||||
if (clrInstrumentType == null) {
|
||||
log.warn("Not defined instrumentType={}", gatewayRequest.getInstrumentType());
|
||||
return null;
|
||||
}
|
||||
newRequest.setInstrumentType(clrInstrumentType.getKey());
|
||||
Optional<InstrumentType> clrInstrumentType = resolveInstrumentType(gatewayRequest.getInstrumentType());
|
||||
Optional<NominalTypeCode> clrNominalTypeCode = resolveTypeCode(gatewayRequest.getTypeCode());
|
||||
clrInstrumentType.ifPresent(instrumentType -> newRequest.setInstrumentType(instrumentType.getKey()));
|
||||
clrNominalTypeCode.ifPresent(nominalTypeCode -> newRequest.setNominalTypeCode(nominalTypeCode.getKey()));
|
||||
|
||||
newRequest.setBaseCode(gatewayRequest.getDepoDcId());
|
||||
newRequest.setIssuerId(companyId);
|
||||
newRequest.setShortName(gatewayRequest.getShortName());
|
||||
|
|
@ -54,7 +57,6 @@ public class DigitalCertificateRequestBuilder {
|
|||
newRequest.setPriceVarianceLimit(gatewayRequest.getDeltaPrice());
|
||||
newRequest.setSecuritySymbol(gatewayRequest.getSecuritySymbol());
|
||||
newRequest.setWorkflowStatus(gatewayRequest.getWorkflowStatus());
|
||||
newRequest.setNominalTypeCode(gatewayRequest.getTypeCode());
|
||||
newRequest.setSettlementHouse(gatewayRequest.getSettlementOrganization());
|
||||
newRequest.setDepository(gatewayRequest.getSettlementDepository());
|
||||
newRequest.setNominalIndexationDate(gatewayRequest.getNominalIndexDate());
|
||||
|
|
@ -67,13 +69,11 @@ public class DigitalCertificateRequestBuilder {
|
|||
DigitalCertificateSecurityUpdateRequest updateRequest = new DigitalCertificateSecurityUpdateRequest();
|
||||
|
||||
updateRequest.setId(digitalSecurityId);
|
||||
InstrumentType clrInstrumentType = Arrays.asList("DC", "D")
|
||||
.contains(gatewayRequest.getInstrumentType()) ? InstrumentType.DGCT : null;
|
||||
if (clrInstrumentType == null) {
|
||||
log.warn("Not defined instrumentType={}", gatewayRequest.getInstrumentType());
|
||||
return null;
|
||||
}
|
||||
updateRequest.setInstrumentType(clrInstrumentType.getKey());
|
||||
Optional<InstrumentType> clrInstrumentType = resolveInstrumentType(gatewayRequest.getInstrumentType());
|
||||
Optional<NominalTypeCode> clrNominalTypeCode = resolveTypeCode(gatewayRequest.getTypeCode());
|
||||
clrInstrumentType.ifPresent(instrumentType -> updateRequest.setInstrumentType(instrumentType.getKey()));
|
||||
clrNominalTypeCode.ifPresent(nominalTypeCode -> updateRequest.setNominalTypeCode(nominalTypeCode.getKey()));
|
||||
|
||||
updateRequest.setBaseCode(gatewayRequest.getDepoDcId());
|
||||
updateRequest.setIssuerId(companyId);
|
||||
updateRequest.setShortName(gatewayRequest.getShortName());
|
||||
|
|
@ -84,7 +84,6 @@ public class DigitalCertificateRequestBuilder {
|
|||
updateRequest.setPriceVarianceLimit(gatewayRequest.getDeltaPrice());
|
||||
updateRequest.setSecuritySymbol(gatewayRequest.getSecuritySymbol());
|
||||
updateRequest.setWorkflowStatus(gatewayRequest.getWorkflowStatus());
|
||||
updateRequest.setNominalTypeCode(gatewayRequest.getTypeCode());
|
||||
updateRequest.setSettlementHouse(gatewayRequest.getSettlementOrganization());
|
||||
updateRequest.setDepository(gatewayRequest.getSettlementDepository());
|
||||
updateRequest.setNominalIndexationDate(gatewayRequest.getNominalIndexDate());
|
||||
|
|
@ -92,4 +91,28 @@ public class DigitalCertificateRequestBuilder {
|
|||
updateRequest.setNominalIndexationSign(gatewayRequest.getNominalIndexFact());
|
||||
return updateRequest;
|
||||
}
|
||||
|
||||
private Optional<InstrumentType> resolveInstrumentType(final String instrumentType) {
|
||||
InstrumentType clrInstrumentType = Arrays.asList("DC", "D")
|
||||
.contains(instrumentType) ? InstrumentType.DGCT : null;
|
||||
if (clrInstrumentType == null) {
|
||||
log.warn("Not defined instrumentType={}", instrumentType);
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(clrInstrumentType);
|
||||
}
|
||||
|
||||
private Optional<NominalTypeCode> resolveTypeCode(final String nominalTypeCode) {
|
||||
NominalTypeCode clrNominalTypeCode = null;
|
||||
if (StringUtils.hasLength(nominalTypeCode)) {
|
||||
clrNominalTypeCode =
|
||||
nominalTypeCode.equals("X") ? NominalTypeCode.INDX :
|
||||
nominalTypeCode.equals("U") ? NominalTypeCode.FIXD : null;
|
||||
}
|
||||
if (clrNominalTypeCode == null) {
|
||||
log.warn("Not defined NominalTypeCode={}", nominalTypeCode);
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(clrNominalTypeCode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package ru.spcex.platform.enumeration;
|
||||
|
||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||
|
||||
public enum NominalTypeCode implements IEnumKey {
|
||||
INDX("INDX"),
|
||||
FIXD("FIXD")
|
||||
;
|
||||
|
||||
private final String key;
|
||||
|
||||
NominalTypeCode(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue