This commit is contained in:
parent
b81559002f
commit
142c534aa2
4 changed files with 133 additions and 229 deletions
|
|
@ -13,6 +13,7 @@ import ru.clearing.classes.statics.data.company.CompanySymbols;
|
|||
import ru.clearing.classes.statics.data.profile.CompanyInfo;
|
||||
import ru.spcex.clearing.company.error.CompanyErrors;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.ActionType;
|
||||
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountTerminationRequest;
|
||||
|
|
@ -20,6 +21,7 @@ import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteReques
|
|||
import ru.spcex.clearing.platform.messaging.domain.cud.company.CompanyNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.platform.messaging.service.Status;
|
||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||
import ru.spcex.clearing.util.services.RequestHelper;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
|
|
@ -37,6 +39,7 @@ import ru.spcex.platform.utils.validation.IValidator;
|
|||
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
|
|
@ -63,11 +66,11 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
ValidationHelper validationHelper,
|
||||
UserRoleVerification userRoleVerification,
|
||||
@Qualifier("companyNewRequestValidator")
|
||||
Function<CompanyNewRequest, IValidator> companyNewRequestValidator,
|
||||
Function<CompanyNewRequest, IValidator> companyNewRequestValidator,
|
||||
@Qualifier("companyUpdateRequestValidator")
|
||||
Function<CompanyNewRequest, IValidator> companyUpdateRequestValidator,
|
||||
Function<CompanyNewRequest, IValidator> companyUpdateRequestValidator,
|
||||
@Qualifier("CompanyDeleteRequestValidator")
|
||||
Function<CommonDeleteRequest, IValidator> companyDeleteRequestValidator,
|
||||
Function<CommonDeleteRequest, IValidator> companyDeleteRequestValidator,
|
||||
CompanySymbolService companySymbolService,
|
||||
AccountNotificationHelper accountNotification,
|
||||
RelationService relationService) {
|
||||
|
|
@ -98,10 +101,10 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
.setFunction(request -> requestHelper.requestFunction(this::blockCompanyAfterDocument, request))
|
||||
.forDestination(Consts.DESTINATION_COMPANY_BLOCK, callbacks::put);
|
||||
callback(CompanyNewRequest.class)
|
||||
.setFunction(request -> requestHelper.requestFunction(this::createCompany, request))
|
||||
.setFunction(request -> requestHelper.requestFunction(this::processBaseRequest, request))
|
||||
.forDestination(Consts.DESTINATION_COMPANY_NEW, callbacks::put);
|
||||
callback(CompanyNewRequest.class)
|
||||
.setFunction(request -> requestHelper.requestFunction(this::updateCompany, request))
|
||||
.setFunction(request -> requestHelper.requestFunction(this::processBaseRequest, request))
|
||||
.forDestination(Consts.DESTINATION_COMPANY_UPDATE, callbacks::put);
|
||||
callback(AccountTerminationRequest.class)
|
||||
.setFunction(request -> requestHelper.requestFunction(this::finishCompanyTermination, request))
|
||||
|
|
@ -109,41 +112,58 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
init();
|
||||
}
|
||||
|
||||
private synchronized RequestInfoUpdate createCompany(BaseRequest<CompanyNewRequest> companyNewRequestBaseRequest) throws ValidationException {
|
||||
CompanyNewRequest req = companyNewRequestBaseRequest.getRequestPayload();
|
||||
log.debug("company-new request received, BaseRequest.id = {}", companyNewRequestBaseRequest.getId());
|
||||
{ // Валидация
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(companyNewRequestBaseRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
private RequestInfoUpdate processBaseRequest(BaseRequest<?> request) {
|
||||
RequestInfoUpdate requestInfoUpdate = null;
|
||||
// Валидация
|
||||
requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(request);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(companyNewRequestBaseRequest, companyNewRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
try {
|
||||
ActionType actionType = request.getActionType();
|
||||
switch (actionType) {
|
||||
case NEW -> create((CompanyNewRequest) request.getRequestPayload());
|
||||
case UPDATE -> update((CompanyNewRequest) request.getRequestPayload());
|
||||
}
|
||||
} catch (ValidationException e) {
|
||||
requestInfoUpdate = new RequestInfoUpdate(request.getId(), Status.Error, e.getMessage());
|
||||
}
|
||||
return requestInfoUpdate;
|
||||
}
|
||||
|
||||
public synchronized Long create(CompanyNewRequest companyNewRequest) throws ValidationException {
|
||||
log.debug("creating new company");
|
||||
IValidator validator = companyNewRequestValidator.apply(companyNewRequest);
|
||||
Optional<EnumMessage> error = validator.tillFirstError();
|
||||
if (error.isPresent()) {
|
||||
throw new ValidationException(error.get());
|
||||
}
|
||||
|
||||
Instant now = Instant.now();
|
||||
Company company = new Company();
|
||||
company.setId(idSequence.nextId());
|
||||
Instant now = Instant.now();
|
||||
company.setCreated(now);
|
||||
company.setUpdated(now);
|
||||
|
||||
company.setShortName(req.getShortName());
|
||||
company.setFullName(req.getFullName());
|
||||
company.setShortName(companyNewRequest.getShortName());
|
||||
company.setFullName(companyNewRequest.getFullName());
|
||||
company.setTradingCode(companyNewRequest.getTradingCode());
|
||||
company.setClearingCode(companyNewRequest.getClearingCode());
|
||||
company.setRegistrationCode(companyNewRequest.getRegistrationCode());
|
||||
company.setWorkflowStatus(companyNewRequest.getWorkflowStatus());
|
||||
fillNewCompanyInfo(company, companyNewRequest);
|
||||
|
||||
ImdgTransaction transaction = imdgProvider.newTransaction();
|
||||
transaction.beginTransaction();
|
||||
boolean txOk = false;
|
||||
try {
|
||||
if (req.getCompanySymbol() != null) {
|
||||
CompanySymbols newSymbol = companySymbolService.createCompanySymbol(transaction, company.getId(), req.getCompanySymbol(), req.getCompanySymbolValue());
|
||||
updateCompanyBySymbol(company, newSymbol, false);
|
||||
if (companyNewRequest.getCompanySymbol() != null) {
|
||||
CompanySymbols companySymbols = companySymbolService.create(company.getId(), companyNewRequest.getCompanySymbol(),
|
||||
companyNewRequest.getCompanySymbolValue());
|
||||
log.debug("Creating companySymbols with id: {} by company.id: {} done", companySymbols.getId(), company.getId());
|
||||
}
|
||||
|
||||
company.setWorkflowStatus(req.getWorkflowStatus());
|
||||
fillNewCompanyInfo(company, req);
|
||||
|
||||
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
companyMap.insert(company);
|
||||
log.debug("company-new request processed, BaseRequest.id = {}, company.id={}",
|
||||
companyNewRequestBaseRequest.getId(), company.getId());
|
||||
companyNewRequest.getId(), company.getId());
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk)
|
||||
|
|
@ -152,48 +172,25 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
transaction.rollbackTransaction();
|
||||
}
|
||||
accountNotification.makeInfoAccount(company.getId());
|
||||
return null;
|
||||
return company.getId();
|
||||
}
|
||||
|
||||
void fillNewCompanyInfo(Company company, CompanyNewRequest req) {
|
||||
if (company.getProfile() == null)
|
||||
company.setProfile(new CompanyInfo());
|
||||
CompanyInfo ci = company.getProfile();
|
||||
ci.setId(company.getId());
|
||||
ci.setCompanyId(company.getId());
|
||||
//todo раскоментировать, когда в реквест добавят новые поля:
|
||||
// req.getWorkflowStatus()
|
||||
//ci.setCorporationSoleType(req.getCorporationSoleType());
|
||||
// ci.setCountryCode(req.getCountryCode());
|
||||
// ci.setDescription(req.getDescription());
|
||||
// ci.setProfessionalSign(req.getProfessionalSign());
|
||||
// ci.setLegalKind(req.getLegalKind());
|
||||
// ci.setOrganizationType(req.getOrganizationType());
|
||||
// ci.setResidence(req.getResidence());
|
||||
// ci.setShortNameEng(req.getShortNameEng());
|
||||
// ci.setFullNameEng(req.getFullNameEng());
|
||||
}
|
||||
|
||||
|
||||
private synchronized RequestInfoUpdate updateCompany(BaseRequest<CompanyNewRequest> companyUpdateRequestBaseRequest) throws ValidationException {
|
||||
CompanyNewRequest updateRequest = companyUpdateRequestBaseRequest.getRequestPayload();
|
||||
{ // Валидация,
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(companyUpdateRequestBaseRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(companyUpdateRequestBaseRequest, companyUpdateRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
public synchronized void update(CompanyNewRequest updateRequest) throws ValidationException {
|
||||
IValidator validator = companyUpdateRequestValidator.apply(updateRequest);
|
||||
Optional<EnumMessage> error = validator.tillFirstError();
|
||||
if (error.isPresent()) {
|
||||
throw new ValidationException(error.get());
|
||||
}
|
||||
|
||||
ImdgTransaction transaction = imdgProvider.newTransaction();
|
||||
transaction.beginTransaction();
|
||||
boolean txOk = false;
|
||||
try {
|
||||
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
|
||||
Company company = companyMap.getSingleObjectByID(updateRequest.getId());
|
||||
if (company == null) {
|
||||
log.trace("Company {} not found", updateRequest.getId());
|
||||
return requestHelper.makeErrorResponse(companyUpdateRequestBaseRequest, CompanyErrors.CompanyNotFound, updateRequest.getId());
|
||||
throw new ValidationException(new EnumMessage(CompanyErrors.CompanyNotFound));
|
||||
}
|
||||
// if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) {
|
||||
// log.trace("Company {} not active: {}", company.getId(), company.getWorkflowStatus());
|
||||
|
|
@ -207,8 +204,6 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
if (updateRequest.getCompanySymbol() != null || updateRequest.getCompanySymbolValue() != null) {
|
||||
log.trace("Request field CompanySymbol, CompanySymbolValue ignore for update company request.");
|
||||
}
|
||||
// CompanySymbols не обновляем
|
||||
|
||||
|
||||
String prevStatus = company.getWorkflowStatus();
|
||||
if (updateRequest.getWorkflowStatus() != null) {
|
||||
|
|
@ -229,7 +224,6 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
else
|
||||
transaction.rollbackTransaction();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void updateCompanyBySymbol(Company company, CompanySymbols companySymbol, boolean shouldBeDeleted) {
|
||||
|
|
@ -374,112 +368,6 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public synchronized Company createOrUpdateCompany(BaseRequest<CompanyNewRequest> companyNewRequestBaseRequest, Long existCompanyId) throws ValidationException {
|
||||
CompanyNewRequest req = companyNewRequestBaseRequest.getRequestPayload();
|
||||
log.debug("company new or update, request {}, existCOmpanyId={}", companyNewRequestBaseRequest.getId(), existCompanyId);
|
||||
{ // Валидация
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(companyNewRequestBaseRequest);
|
||||
if (requestInfoUpdate != null)
|
||||
throw new ValidationException(CompanyErrors.GeneralError, requestInfoUpdate.getMessage());
|
||||
// requestInfoUpdate = validationHelper.validateTillFirstError(companyNewRequestBaseRequest, companyNewRequestValidator);
|
||||
// if (requestInfoUpdate != null) throw new ValidationException(CompanyErrors.GeneralError, requestInfoUpdate.getMessage());
|
||||
}
|
||||
|
||||
Company company = null;
|
||||
if (existCompanyId != null) {
|
||||
company = companyIMap.getSingleObjectByID(existCompanyId);
|
||||
if (company == null) {
|
||||
throw new ValidationException(CompanyErrors.CompanyNotFound, String.valueOf(existCompanyId));
|
||||
}
|
||||
}
|
||||
|
||||
if (company == null) {
|
||||
// #createCompany
|
||||
company = new Company();
|
||||
company.setId(idSequence.nextId());
|
||||
Instant now = Instant.now();
|
||||
company.setCreated(now);
|
||||
company.setUpdated(now);
|
||||
log.debug("Create new company {}", company.getId());
|
||||
|
||||
company.setShortName(req.getShortName());
|
||||
company.setFullName(req.getFullName());
|
||||
company.setTradingCode(req.getTradingCode());
|
||||
company.setClearingCode(req.getClearingCode());
|
||||
company.setRegistrationCode(req.getRegistrationCode());
|
||||
// company.setInitiatorCode(req.getInitiatorCode());
|
||||
|
||||
ImdgTransaction transaction = imdgProvider.newTransaction();
|
||||
transaction.beginTransaction();
|
||||
boolean txOk = false;
|
||||
try {
|
||||
if (req.getCompanySymbol() != null) {
|
||||
CompanySymbols newSymbol = companySymbolService.createCompanySymbol(transaction, company.getId(), req.getCompanySymbol(), req.getCompanySymbolValue());
|
||||
updateCompanyBySymbol(company, newSymbol, false);
|
||||
}
|
||||
|
||||
company.setWorkflowStatus(req.getWorkflowStatus());
|
||||
fillNewCompanyInfo(company, req);
|
||||
|
||||
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
companyMap.insert(company);
|
||||
log.debug("company-new request processed, BaseRequest.id = {}, company.id={}",
|
||||
companyNewRequestBaseRequest.getId(), company.getId());
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk)
|
||||
transaction.commitTransaction();
|
||||
else
|
||||
transaction.rollbackTransaction();
|
||||
}
|
||||
accountNotification.makeInfoAccount(company.getId());
|
||||
} else {
|
||||
log.debug("Update exist company {}", company.getId());
|
||||
company.setUpdated(Instant.now());
|
||||
// #updateCompany
|
||||
|
||||
company.setUpdated(Instant.now());
|
||||
company.setShortName(req.getShortName());
|
||||
company.setFullName(req.getFullName());
|
||||
company.setTradingCode(req.getTradingCode());
|
||||
company.setClearingCode(req.getClearingCode());
|
||||
company.setRegistrationCode(req.getRegistrationCode());
|
||||
|
||||
if (req.getCompanySymbol() != null || req.getCompanySymbolValue() != null) {
|
||||
log.trace("Request field CompanySymbol, CompanySymbolValue ignore for update company request.");
|
||||
}
|
||||
// CompanySymbols не обновляем
|
||||
ImdgTransaction transaction = imdgProvider.newTransaction();
|
||||
transaction.beginTransaction();
|
||||
boolean txOk = false;
|
||||
try {
|
||||
String prevStatus = company.getWorkflowStatus();
|
||||
if (req.getWorkflowStatus() != null) {
|
||||
company.setWorkflowStatus(req.getWorkflowStatus());
|
||||
if (!Objects.equals(prevStatus, company.getWorkflowStatus())) {
|
||||
relationService.onChangeWorkflowStatus(transaction, company, prevStatus, company.getWorkflowStatus());
|
||||
} else {
|
||||
log.trace("Status was not changed");
|
||||
}
|
||||
} else {
|
||||
log.trace("Null new WorkflowStatus");
|
||||
}
|
||||
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
companyMap.update(company);
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk)
|
||||
transaction.commitTransaction();
|
||||
else
|
||||
transaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
return company;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Блокировка компании после блокировки счетов
|
||||
*
|
||||
|
|
@ -520,4 +408,12 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void fillNewCompanyInfo(Company company, CompanyNewRequest req) {
|
||||
if (company.getProfile() == null)
|
||||
company.setProfile(new CompanyInfo());
|
||||
CompanyInfo ci = company.getProfile();
|
||||
ci.setId(company.getId());
|
||||
ci.setCompanyId(company.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import org.springframework.beans.factory.InitializingBean;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||
import ru.spcex.clearing.company.error.CompanyErrors;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
|
@ -19,6 +20,7 @@ import ru.spcex.clearing.platform.messaging.domain.cud.company.CompanySymbolNewR
|
|||
import ru.spcex.clearing.platform.messaging.domain.cud.company.CompanySymbolUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.platform.messaging.service.Status;
|
||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||
import ru.spcex.clearing.util.services.RequestHelper;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
|
|
@ -29,9 +31,11 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
|||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.error.ClearingBaseException;
|
||||
import ru.spcex.platform.utils.error.ValidationException;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
|
|
@ -54,11 +58,11 @@ public class CompanySymbolService extends QueueConsumer implements InitializingB
|
|||
ValidationHelper validationHelper,
|
||||
UserRoleVerification userRoleVerification,
|
||||
@Qualifier("companySymbolNewRequestValidator")
|
||||
Function<CompanySymbolNewRequest, IValidator> companySymbolNewRequestValidator,
|
||||
Function<CompanySymbolNewRequest, IValidator> companySymbolNewRequestValidator,
|
||||
@Qualifier("companySymbolDeleteRequestValidator")
|
||||
Function<CommonDeleteRequest, IValidator> companySymbolDeleteRequestValidator,
|
||||
Function<CommonDeleteRequest, IValidator> companySymbolDeleteRequestValidator,
|
||||
@Qualifier("companySymbolUpdateRequestValidator")
|
||||
Function<CompanySymbolUpdateRequest, IValidator> companySymbolUpdateRequestValidator
|
||||
Function<CompanySymbolUpdateRequest, IValidator> companySymbolUpdateRequestValidator
|
||||
) {
|
||||
super(kafkaQueue, kafkaProducer);
|
||||
this.imdgProvider = imdgProvider;
|
||||
|
|
@ -76,7 +80,7 @@ public class CompanySymbolService extends QueueConsumer implements InitializingB
|
|||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
callback(CompanySymbolNewRequest.class)
|
||||
.setFunction(this::companySymbolNew)
|
||||
.setFunction(this::processBaseRequest)
|
||||
.forDestination(Consts.DESTINATION_COMPANY_SYMBOL_NEW, callbacks::put);
|
||||
callback(CompanySymbolUpdateRequest.class)
|
||||
.setFunction(this::companySymbolUpdate)
|
||||
|
|
@ -87,40 +91,60 @@ public class CompanySymbolService extends QueueConsumer implements InitializingB
|
|||
init();
|
||||
}
|
||||
|
||||
private RequestInfoUpdate processBaseRequest(BaseRequest<?> request) {
|
||||
RequestInfoUpdate requestInfoUpdate = null;
|
||||
// Валидация
|
||||
requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(request);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
try {
|
||||
create((CompanySymbolNewRequest) request.getRequestPayload());
|
||||
} catch (ValidationException e) {
|
||||
requestInfoUpdate = new RequestInfoUpdate(request.getId(), Status.Error, e.getMessage());
|
||||
}
|
||||
return requestInfoUpdate;
|
||||
}
|
||||
|
||||
public void setCompanyService(CompanyService companyService) {
|
||||
this.companyService = companyService;
|
||||
}
|
||||
|
||||
|
||||
public RequestInfoUpdate companySymbolNew(BaseRequest<CompanySymbolNewRequest> symbolRequest) {
|
||||
CompanySymbolNewRequest req = symbolRequest.getRequestPayload();
|
||||
log.debug("CompanySymbolNewRequest received, id={}", symbolRequest.getId());
|
||||
public Long create(CompanySymbolNewRequest symbolRequest) throws ValidationException {
|
||||
log.debug("CompanySymbolNewRequest received");
|
||||
{ // validate
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(symbolRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(symbolRequest, companySymbolNewRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
IValidator validator = companySymbolNewRequestValidator.apply(symbolRequest);
|
||||
Optional<EnumMessage> error = validator.tillFirstError();
|
||||
if (error.isPresent()) {
|
||||
throw new ValidationException(error.get());
|
||||
}
|
||||
}
|
||||
|
||||
CompanySymbols companySymbols = create(symbolRequest.companyId, symbolRequest.getCompanySymbol(),
|
||||
symbolRequest.getCompanySymbolValue());
|
||||
log.debug("successfully processed, id {}", companySymbols.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
CompanySymbols companySymbols = new CompanySymbols();
|
||||
companySymbols.setId(idSequence.nextId());
|
||||
companySymbols.setCompanyId(req.getCompanyId());
|
||||
companySymbols.setCompanySymbol(req.getCompanySymbol());
|
||||
companySymbols.setCompanySymbolValue(req.getCompanySymbolValue());
|
||||
|
||||
public CompanySymbols create(Long companyId, String companySymbol, String companySymbolValue) {
|
||||
Objects.requireNonNull(companyId);
|
||||
CompanySymbols newSymbol = new CompanySymbols();
|
||||
newSymbol.setId(idSequence.nextId());
|
||||
newSymbol.setCompanyId(companyId);
|
||||
newSymbol.setCompanySymbol(companySymbol);
|
||||
newSymbol.setCompanySymbolValue(companySymbolValue);
|
||||
log.debug("Created new companySymbols.id={} for company {}", newSymbol.getId(), companyId);
|
||||
ImdgTransaction transaction = imdgProvider.newTransaction();
|
||||
transaction.beginTransaction();
|
||||
boolean txOk = false;
|
||||
try {
|
||||
Imdg<CompanySymbols> companySymbolsTMap = transaction.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||
companySymbolsTMap.update(companySymbols);
|
||||
try {
|
||||
companyService.updateCompanyBySymbol(transaction, companySymbols, false);
|
||||
} catch (ClearingBaseException e) {
|
||||
return requestHelper.makeErrorResponse(symbolRequest, e.getEnumMsg());
|
||||
}
|
||||
companySymbolsTMap.update(newSymbol);
|
||||
|
||||
Imdg<Company> companyMap = transaction.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
Company company = companyMap.getSingleObjectByID(newSymbol.getCompanyId());
|
||||
companyService.updateCompanyBySymbol(company, newSymbol, false);
|
||||
companyMap.update(company);
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk)
|
||||
|
|
@ -128,9 +152,7 @@ public class CompanySymbolService extends QueueConsumer implements InitializingB
|
|||
else
|
||||
transaction.rollbackTransaction();
|
||||
}
|
||||
|
||||
log.debug("successfully processed, id {}", companySymbols.getId());
|
||||
return null;
|
||||
return newSymbol;
|
||||
}
|
||||
|
||||
public RequestInfoUpdate companySymbolUpdate(BaseRequest<CompanySymbolUpdateRequest> symbolRequest) {
|
||||
|
|
@ -210,22 +232,4 @@ public class CompanySymbolService extends QueueConsumer implements InitializingB
|
|||
log.debug("successfully processed, id {}", companySymbols.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
public CompanySymbols createCompanySymbol(ImdgTransaction transaction, Long companyId, String companySymbol, String companySymbolValue) {
|
||||
Objects.requireNonNull(companyId);
|
||||
CompanySymbols newSymbol = new CompanySymbols();
|
||||
newSymbol.setId(idSequence.nextId());
|
||||
newSymbol.setCompanyId(companyId);
|
||||
newSymbol.setCompanySymbol(companySymbol);
|
||||
newSymbol.setCompanySymbolValue(companySymbolValue);
|
||||
log.debug("Created new companySymbols.id={} for company {}", newSymbol.getId(), companyId);
|
||||
if (transaction == null) {
|
||||
Imdg<CompanySymbols> companySymbolsTMap = transaction.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||
companySymbolsTMap.insert(newSymbol);
|
||||
} else {
|
||||
Imdg<CompanySymbols> tMap = transaction.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||
tMap.insert(newSymbol);
|
||||
}
|
||||
return newSymbol;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,12 +117,14 @@ public class MultiCompanyService
|
|||
companyId = getCompanyIdForCompanySymbols(req.getUuid(), req.getCompany());
|
||||
log.debug("For request {} (uuid {}) company {}.", baseRequest.getId(), req.getUuid(), companyId == null ? "not found" : ("found, id=" + companyId));
|
||||
|
||||
RequestInfoUpdate replyI;
|
||||
Company company = companyService.createOrUpdateCompany(wrapRequest(baseRequest, req.getCompany(), null), companyId);
|
||||
companyId = company.getId();
|
||||
log.debug("The companyId={}", companyId);
|
||||
fillCompanyId(req, companyId);
|
||||
if (companyId == null) {
|
||||
companyId = companyService.create(req.getCompany());
|
||||
log.debug("The companyId={}", companyId);
|
||||
} else {
|
||||
companyService.update(req.getCompany());
|
||||
}
|
||||
|
||||
RequestInfoUpdate replyI;
|
||||
if (req.getCompanyInfo() != null) {
|
||||
log.trace("For company {} do update CompanyInfo", companyId);
|
||||
replyI = companyInfoService.companyInfoUpdate(wrapRequest(baseRequest, req.getCompanyInfo(), null));
|
||||
|
|
@ -141,19 +143,21 @@ public class MultiCompanyService
|
|||
validateReply(companyId, "profileDocumentUpdate", replyI);
|
||||
}
|
||||
}
|
||||
for (CompanySymbolNewRequest partRequest : req.getCompanySymbols()) {
|
||||
CompanySymbols existSymbol = findCompanySymbols(partRequest);
|
||||
if (existSymbol == null) {
|
||||
log.trace("For company[{}] do new companySymbol", companyId);
|
||||
replyI = companySymbolService.companySymbolNew(wrapRequest(baseRequest, partRequest, ActionType.NEW));
|
||||
validateReply(companyId, "companySymbolNew", replyI);
|
||||
} else {
|
||||
log.trace("For company[{}] do update companySymbol[{}]", companyId, existSymbol.getId());
|
||||
CompanySymbolUpdateRequest partUpdateRequest = createUpdateRequest(existSymbol, partRequest);
|
||||
replyI = companySymbolService.companySymbolUpdate(wrapRequest(baseRequest, partUpdateRequest, ActionType.UPDATE));
|
||||
validateReply(companyId, "companySymbolUpdate", replyI);
|
||||
}
|
||||
}
|
||||
|
||||
//todo по идее эта логика выполнена в companyService.create(req.getCompany())
|
||||
// for (CompanySymbolNewRequest partRequest : req.getCompanySymbols()) {
|
||||
// CompanySymbols existSymbol = findCompanySymbols(partRequest);
|
||||
// if (existSymbol == null) {
|
||||
// log.trace("For company[{}] do new companySymbol", companyId);
|
||||
// Long id = companySymbolService.create(partRequest);
|
||||
// validateReply(companyId, "companySymbolNew", replyI);
|
||||
// } else {
|
||||
// log.trace("For company[{}] do update companySymbol[{}]", companyId, existSymbol.getId());
|
||||
// CompanySymbolUpdateRequest partUpdateRequest = createUpdateRequest(existSymbol, partRequest);
|
||||
// replyI = companySymbolService.companySymbolUpdate(wrapRequest(baseRequest, partUpdateRequest, ActionType.UPDATE));
|
||||
// validateReply(companyId, "companySymbolUpdate", replyI);
|
||||
// }
|
||||
// }
|
||||
for (ContactNewRequest partRequest : req.getContacts()) {
|
||||
Contact existContact = findContact(partRequest);
|
||||
if (existContact == null) {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ public class RequestInfoUpdate {
|
|||
|
||||
public RequestInfoUpdate() {}
|
||||
|
||||
public RequestInfoUpdate(Long id, Status status, Long errorId, String message) {
|
||||
public RequestInfoUpdate(Long id, Status status, String message) {
|
||||
this.id = id;
|
||||
this.status = status;
|
||||
this.message = message;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue