company-service http://jira.mfd.msk:8088/browse/CLS-284 доделал кроме странной логики валидации
This commit is contained in:
parent
2829e50e7e
commit
a37fea5061
7 changed files with 588 additions and 17 deletions
|
|
@ -0,0 +1,134 @@
|
|||
package ru.spcex.clearing.company.config.validation;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.clearing.platform.dictionary.ClearingCategoryDictionary;
|
||||
import ru.clearing.platform.dictionary.WorkflowStatusDictionary;
|
||||
import ru.spcex.clearing.company.error.CompanyErrors;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.company.RelationNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.company.RelationUpdateRequest;
|
||||
import ru.spcex.clearing.validation.common.rules.DictionaryPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
import ru.spcex.platform.utils.validation.ValidatorImpl;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Configuration
|
||||
public class RelationValidationConfig {
|
||||
|
||||
@Bean("relationNewRequestValidation")
|
||||
public Function<RelationNewRequest, IValidator> relationNewRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return relationNewRequest -> {
|
||||
ImdgValidationContext<RelationNewRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(relationNewRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClearingCategoryDictionary);
|
||||
addImdg.accept(IMDGDistributedNames.Map_WorkflowStatusDictionary);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("companyId",
|
||||
RelationNewRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
Company.class,
|
||||
CompanyErrors.RequiredFieldEmpty,
|
||||
CompanyErrors.CompanyNotFound),
|
||||
DictionaryPresentRule.instance("documentType",
|
||||
RelationNewRequest::getClearingMemberCategory,
|
||||
IMDGDistributedNames.Map_ClearingCategoryDictionary,
|
||||
ClearingCategoryDictionary.class,
|
||||
CompanyErrors.RequiredFieldEmpty,
|
||||
CompanyErrors.WrongFieldValue),
|
||||
DictionaryPresentRule.instance("serviceStatus",
|
||||
RelationNewRequest::getServiceStatus,
|
||||
IMDGDistributedNames.Map_WorkflowStatusDictionary,
|
||||
WorkflowStatusDictionary.class,
|
||||
CompanyErrors.RequiredFieldEmpty,
|
||||
CompanyErrors.WrongFieldValue)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("relationUpdateRequestValidation")
|
||||
public Function<RelationUpdateRequest, IValidator> relationUpdateRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return relationUpdateRequest -> {
|
||||
ImdgValidationContext<RelationUpdateRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(relationUpdateRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Relation);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
// addImdg.accept(IMDGDistributedNames.Map_ClearingCategoryDictionary);
|
||||
addImdg.accept(IMDGDistributedNames.Map_WorkflowStatusDictionary);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("id",
|
||||
RelationUpdateRequest::getId,
|
||||
IMDGDistributedNames.Map_Relation,
|
||||
Relation.class,
|
||||
CompanyErrors.RequiredFieldEmpty,
|
||||
CompanyErrors.RelationNotFound,
|
||||
relation -> {
|
||||
if (relation.getConsumerId() == null) return null;
|
||||
Imdg<Company> companyImdg = context.obtainMap(IMDGDistributedNames.Map_Company, Company.class);
|
||||
Company company = companyImdg.getSingleObjectByID(relation.getConsumerId());
|
||||
if (company == null) {
|
||||
return CompanyErrors.CompanyNotFound;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}),
|
||||
// IdPresentRule.instance("companyId",
|
||||
// RelationUpdateRequest::getCompanyId,
|
||||
// IMDGDistributedNames.Map_Company,
|
||||
// Company.class,
|
||||
// CompanyErrors.RequiredFieldEmpty,
|
||||
// CompanyErrors.CompanyNotFound),
|
||||
// DictionaryPresentRule.instance("documentType",
|
||||
// RelationUpdateRequest::getClearingMemberCategory,
|
||||
// IMDGDistributedNames.Map_ClearingCategoryDictionary,
|
||||
// ClearingCategoryDictionary.class,
|
||||
// CompanyErrors.RequiredFieldEmpty,
|
||||
// CompanyErrors.WrongFieldValue),
|
||||
DictionaryPresentRule.instance("serviceStatus",
|
||||
RelationUpdateRequest::getServiceStatus,
|
||||
IMDGDistributedNames.Map_WorkflowStatusDictionary,
|
||||
WorkflowStatusDictionary.class,
|
||||
CompanyErrors.RequiredFieldEmpty,
|
||||
CompanyErrors.WrongFieldValue)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("relationDeleteRequestValidation")
|
||||
public Function<CommonDeleteRequest, IValidator> relationDeleteRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return relationDeleteRequest -> {
|
||||
ImdgValidationContext<CommonDeleteRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(relationDeleteRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Relation);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("id",
|
||||
CommonDeleteRequest::getId,
|
||||
IMDGDistributedNames.Map_Relation,
|
||||
Relation.class,
|
||||
CompanyErrors.RequiredFieldEmpty,
|
||||
CompanyErrors.RelationNotFound
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ import ru.clearing.classes.statics.data.account.ClientCode;
|
|||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.clearing.classes.statics.data.profile.Contact;
|
||||
import ru.clearing.classes.statics.data.profile.ProfileDocument;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
|
|
@ -37,6 +38,7 @@ public class ValidationConfig {
|
|||
addImdg.accept(IMDGDistributedNames.Map_DocumentTypeDictionary, DocumentTypeDictionary.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ContactTypeDictionary, ContactTypeDictionary.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Contact, Contact.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||
|
||||
addImdg.accept(IMDGDistributedNames.Map_WorkflowStatusDictionary, WorkflowStatusDictionary.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ public enum CompanyErrors implements IErrorEnumId {
|
|||
EditContactType(3021L), // Тип контакта компании %s не может быть изменен.
|
||||
TradingClearingRegistryNotFound(3022L), // ТКР с %s не найден
|
||||
AccountNotFound(3023L), // Счет %s не найден
|
||||
RelationNotFound(3026L), // Запись о договорных отношениях не найдена
|
||||
;
|
||||
private final Long id;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,28 +6,35 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
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.relation.Relation;
|
||||
import ru.clearing.classes.statics.data.profile.ProfileDocument;
|
||||
import ru.spcex.clearing.company.error.CompanyErrors;
|
||||
import ru.spcex.clearing.company.util.RequestHelper;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.company.ProfileDocumentNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.company.ProfileDocumentUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.company.*;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.enumeration.ServiceProduct;
|
||||
import ru.spcex.platform.enumeration.ServiceStatus;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgId;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||
import ru.spcex.platform.utils.error.ValidationException;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
public class RelationService extends QueueConsumer implements InitializingBean {
|
||||
|
|
@ -35,38 +42,203 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
|||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected ImdgProvider imdgProvider;
|
||||
protected ImdgId idSequence;
|
||||
protected Imdg<Relation> relationMap;
|
||||
protected Imdg<Company> companyMap;
|
||||
protected AccountNotificationHelper accountNotification;
|
||||
protected UserRoleVerification userRoleVerification;
|
||||
protected RequestHelper requestHelper;
|
||||
|
||||
protected ValidationHelper validationHelper;
|
||||
private Function<RelationNewRequest, IValidator> relationNewRequestValidator;
|
||||
private Function<RelationUpdateRequest, IValidator> relationUpdateRequestValidator;
|
||||
private Function<CommonDeleteRequest, IValidator> relationDeleteRequestValidator;
|
||||
|
||||
@Autowired
|
||||
public RelationService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaProducer,
|
||||
ImdgProvider imdgProvider,
|
||||
RequestHelper requestHelper,
|
||||
|
||||
UserRoleVerification userRoleVerification,
|
||||
ValidationHelper validationHelper,
|
||||
@Qualifier("relationNewRequestValidation") Function<RelationNewRequest, IValidator> relationNewRequestValidator,
|
||||
@Qualifier("relationUpdateRequestValidation") Function<RelationUpdateRequest, IValidator> relationUpdateRequestValidator,
|
||||
@Qualifier("relationDeleteRequestValidation") Function<CommonDeleteRequest, IValidator> relationDeleteRequestValidator,
|
||||
|
||||
AccountNotificationHelper accountNotification) {
|
||||
super(kafkaQueue, kafkaProducer);
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.idSequence = imdgProvider.getImdgIdGenerator();
|
||||
this.accountNotification = accountNotification;
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
|
||||
// this.requestHelper = requestHelper.setLogger(log);
|
||||
this.validationHelper = validationHelper;
|
||||
this.relationNewRequestValidator = relationNewRequestValidator;
|
||||
this.relationUpdateRequestValidator = relationUpdateRequestValidator;
|
||||
this.relationDeleteRequestValidator = relationDeleteRequestValidator;
|
||||
|
||||
relationMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||
companyMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
this.requestHelper = requestHelper.setLogger(log);
|
||||
}
|
||||
|
||||
// --- external API ---
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
// this.profileDocumentMap = imdgProvider.getImdg(IMDGDistributedNames.Map_ProfileDocument, ProfileDocument.class);
|
||||
// this.companyMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
//todo all CLS-284
|
||||
// callback(ProfileDocumentNewRequest.class)
|
||||
// .setFunction(this::profileDocumentNew)
|
||||
// .forDestination(Consts.DESTINATION_PROFILE_DOCUMENT_NEW, callbacks::put);
|
||||
// callback(ProfileDocumentUpdateRequest.class)
|
||||
// .setFunction(this::profileDocumentUpdate)
|
||||
// .forDestination(Consts.DESTINATION_PROFILE_DOCUMENT_UPDATE, callbacks::put);
|
||||
// callback(CommonDeleteRequest.class)
|
||||
// .setFunction(this::profileDocumentDelete)
|
||||
// .forDestination(Consts.DESTINATION_PROFILE_DOCUMENT_DELETE, callbacks::put);
|
||||
// init();
|
||||
|
||||
callback(RelationNewRequest.class)
|
||||
.setFunction(this::relationNew)
|
||||
.forDestination(Consts.DESTINATION_RELATION_NEW, callbacks::put);
|
||||
callback(RelationUpdateRequest.class)
|
||||
.setFunction(this::relationUpdate)
|
||||
.forDestination(Consts.DESTINATION_RELATION_UPDATE, callbacks::put);
|
||||
callback(CommonDeleteRequest.class)
|
||||
.setFunction(this::relationDelete)
|
||||
.forDestination(Consts.DESTINATION_RELATION_DELETE, callbacks::put);
|
||||
init();
|
||||
}
|
||||
|
||||
private synchronized RequestInfoUpdate relationNew(BaseRequest<RelationNewRequest> relationNewBaseRequest) {
|
||||
RelationNewRequest req = relationNewBaseRequest.getRequestPayload();
|
||||
log.debug("relation-new request received, BaseRequest.id = {}", relationNewBaseRequest.getId());
|
||||
{ // Валидация
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(relationNewBaseRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(relationNewBaseRequest, relationNewRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
}
|
||||
|
||||
|
||||
Company company = companyMap.getSingleObjectByID(req.getCompanyId());
|
||||
|
||||
// if (ClearingCategory.B.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.I.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.V.equalsByKey(req.getClearingMemberCategory())
|
||||
// ) {
|
||||
// /*
|
||||
// relation.consumerId (clearingMemberCategory.companyId=relation.companyId) и service=MKR,
|
||||
// если запись создана и serviceStatus=CLOS,
|
||||
// изменить запись в relation согласно описанию с тегом При возобнолвении
|
||||
// , иначе вернуть ошибку (3024)"Договорные отношения %s в секции МКР уже созданы."
|
||||
// */
|
||||
// }
|
||||
// if (ClearingCategory.C.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.F.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.V.equalsByKey(req.getClearingMemberCategory())
|
||||
// ) {
|
||||
// /*
|
||||
//проверить по relation.consumerId (clearingMemberCategory.companyId=relation.companyId) и service=FOND,
|
||||
//если запись создана и serviceStatus=CLOS, изменить запись в relation согласно описанию с тегом При возобнолвении,
|
||||
// иначе вернуть ошибку (3025)"Договорные отношения %s на фондовой секции уже созданы." */
|
||||
// }
|
||||
Relation relation = new Relation();
|
||||
relation.setId(idSequence.nextId());
|
||||
relation.setCreated(Instant.now());
|
||||
relation.setUpdated(relation.getCreated());
|
||||
|
||||
relation.setConsumerId(req.getCompanyId());
|
||||
relation.setSupplierId(SPVB_ID); // 1 СПВБ
|
||||
if (req.getServiceStatus() != null) {
|
||||
relation.setServiceStatus(req.getServiceStatus());
|
||||
} else {
|
||||
log.warn("Request has no status. Set status from company[{}].status={}", company.getId(), company.getWorkflowStatus());
|
||||
relation.setServiceStatus(company.getWorkflowStatus());
|
||||
}
|
||||
relation.setService(ru.spcex.platform.enumeration.Service.MKR.getKey()); // MKR
|
||||
relation.setServiceProduct(ServiceProduct.ZERO.getKey());
|
||||
relation.setComment(req.getComment());
|
||||
|
||||
relationMap.insert(relation);
|
||||
log.debug("New Relation[{}] created.", relation.getId());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private synchronized RequestInfoUpdate relationUpdate(BaseRequest<RelationUpdateRequest> relationUpdateBaseRequest) {
|
||||
RelationUpdateRequest req = relationUpdateBaseRequest.getRequestPayload();
|
||||
log.debug("relation-update request received, BaseRequest.id = {}", relationUpdateBaseRequest.getId());
|
||||
{ // Валидация
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(relationUpdateBaseRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(relationUpdateBaseRequest, relationUpdateRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
}
|
||||
|
||||
|
||||
//Company company = companyMap.getSingleObjectByID(req.getCompanyId());
|
||||
//
|
||||
// if (ClearingCategory.B.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.I.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.V.equalsByKey(req.getClearingMemberCategory())
|
||||
// ) {
|
||||
// /*
|
||||
// relation.consumerId (clearingMemberCategory.companyId=relation.companyId) и service=MKR,
|
||||
// если запись создана и serviceStatus=CLOS,
|
||||
// изменить запись в relation согласно описанию с тегом При возобнолвении
|
||||
// , иначе вернуть ошибку (3024)"Договорные отношения %s в секции МКР уже созданы."
|
||||
// */
|
||||
// }
|
||||
// if (ClearingCategory.C.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.F.equalsByKey(req.getClearingMemberCategory())
|
||||
// || ClearingCategory.V.equalsByKey(req.getClearingMemberCategory())
|
||||
// ) {
|
||||
// /*
|
||||
//проверить по relation.consumerId (clearingMemberCategory.companyId=relation.companyId) и service=FOND,
|
||||
//если запись создана и serviceStatus=CLOS, изменить запись в relation согласно описанию с тегом При возобнолвении,
|
||||
// иначе вернуть ошибку (3025)"Договорные отношения %s на фондовой секции уже созданы." */
|
||||
// }
|
||||
|
||||
Relation relation = relationMap.getSingleObjectByID(req.getId());
|
||||
relation.setUpdated(relation.getCreated());
|
||||
|
||||
if (req.getServiceStatus() != null) {
|
||||
relation.setServiceStatus(req.getServiceStatus());
|
||||
} else {
|
||||
// relation.setServiceStatus(company.getStatus());
|
||||
}
|
||||
relation.setComment(req.getComment());
|
||||
|
||||
relationMap.insert(relation);
|
||||
log.debug("Update Relation[{}] created.", relation.getId());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private synchronized RequestInfoUpdate relationDelete(BaseRequest<CommonDeleteRequest> relationDeleteBaseRequest) {
|
||||
CommonDeleteRequest req = relationDeleteBaseRequest.getRequestPayload();
|
||||
log.debug("relation-delete request received, BaseRequest.id = {}", relationDeleteBaseRequest.getId());
|
||||
{ // Валидация
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(relationDeleteBaseRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(relationDeleteBaseRequest, relationDeleteRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
}
|
||||
|
||||
|
||||
Relation relation = relationMap.getSingleObjectByID(req.getId());
|
||||
if (WorkflowStatus.Blocked.equalsByKey(relation.getServiceStatus())) {
|
||||
log.warn("Relation {} already blocked.", relation.getId());
|
||||
} else {
|
||||
relation.setUpdated(relation.getCreated());
|
||||
relation.setServiceStatus(WorkflowStatus.Blocked.getKey());
|
||||
|
||||
relationMap.insert(relation);
|
||||
log.debug("Relation[{}] block.", relation.getId());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// --- internal API ---
|
||||
|
||||
protected void createNewRelation(ImdgTransaction transaction, Company company) {
|
||||
Relation relation = new Relation();
|
||||
// relation.setId(idSequence.nextId());
|
||||
|
|
@ -79,7 +251,7 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
|||
relation.setService(ru.spcex.platform.enumeration.Service.MKR.getKey()); // MKR
|
||||
relation.setServiceProduct(ServiceProduct.ZERO.getKey());
|
||||
log.debug("New Relation[{}] created.", relation.getId());
|
||||
Imdg<Relation> relationMap = transaction.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||
Imdg<Relation> relationMap = transaction.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||
relationMap.insert(relation);
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +275,7 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
}
|
||||
|
||||
protected void onChangeWorkflowStatusOnlyRelationChange(ImdgTransaction transaction, Company company, String newStatus) throws ValidationException {
|
||||
protected synchronized void onChangeWorkflowStatusOnlyRelationChange(ImdgTransaction transaction, Company company, String newStatus) throws ValidationException {
|
||||
assert Objects.equals(newStatus, company.getWorkflowStatus());
|
||||
String query = String.format("consumerId=%s", company.getId());
|
||||
Imdg<Relation> relationMap = transaction.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,214 @@
|
|||
package ru.spcex.clearing.company.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.producer.MockProducer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.clearing.platform.dictionary.ClearingCategoryDictionary;
|
||||
import ru.clearing.platform.dictionary.WorkflowStatusDictionary;
|
||||
import ru.spcex.clearing.company.config.BeanConfiguration;
|
||||
import ru.spcex.clearing.company.config.validation.RelationValidationConfig;
|
||||
import ru.spcex.clearing.company.config.validation.ValidationConfig;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.company.RelationNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.company.RelationUpdateRequest;
|
||||
import ru.spcex.clearing.test.MatcherFactory;
|
||||
import ru.spcex.clearing.test.TestUtils;
|
||||
import ru.spcex.clearing.test.config.ImdgTestConfig;
|
||||
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||
import ru.spcex.platform.enumeration.ClearingCategory;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static ru.spcex.clearing.test.MatcherFactory.usingIgnoringFieldsComparator;
|
||||
import static ru.spcex.clearing.test.TestUtils.*;
|
||||
import static ru.spcex.clearing.test.config.ImdgTestConfig.currentID;
|
||||
import static ru.spcex.clearing.test.config.ImdgTestConfig.waitAvailableImdgProviderAndAddAdminWithDefaultId;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
BeanConfiguration.class,
|
||||
ValidationConfig.class,
|
||||
RelationService.class,
|
||||
AccountNotificationHelper.class,
|
||||
RelationValidationConfig.class,
|
||||
KafkaTestConfig.class,
|
||||
ImdgTestConfig.class})
|
||||
class RelationServiceTest {
|
||||
|
||||
public static final MatcherFactory.Matcher<Relation> RELATION_MATCHER = usingIgnoringFieldsComparator("created", "updated");
|
||||
private static final int PARTITION = 0;
|
||||
|
||||
private static final Long ID = currentID.getAndIncrement();
|
||||
@Autowired
|
||||
RelationService relationService;
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private ImdgProvider hazelcastServiceTest;
|
||||
private Imdg<Relation> relationMap;
|
||||
private Imdg<Company> companyMap;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<ProducerRecord> producerRecord;
|
||||
@SpyBean
|
||||
private MockProducer<String, Object> mockProducer;
|
||||
|
||||
private long COMPANY_ID;
|
||||
|
||||
private final long RELATION_ID = ID;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
waitAvailableImdgProviderAndAddAdminWithDefaultId();
|
||||
this.relationMap = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||
this.companyMap = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
|
||||
Company testCompany = new Company();
|
||||
testCompany.setWorkflowStatus(WorkflowStatus.Active.getKey());
|
||||
COMPANY_ID = companyMap.insert(testCompany);
|
||||
|
||||
Imdg<WorkflowStatusDictionary> workflowStatusDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_WorkflowStatusDictionary,
|
||||
WorkflowStatusDictionary.class
|
||||
);
|
||||
WorkflowStatusDictionary workflowStatusDictionary = new WorkflowStatusDictionary();
|
||||
workflowStatusDictionary.setId(1L);
|
||||
workflowStatusDictionary.setCode(WorkflowStatus.Active.getKey());
|
||||
workflowStatusDictionary.setName("active");
|
||||
workflowStatusDictionaryImdg.insert(workflowStatusDictionary);
|
||||
workflowStatusDictionary = new WorkflowStatusDictionary();
|
||||
workflowStatusDictionary.setId(2L);
|
||||
workflowStatusDictionary.setCode(WorkflowStatus.Blocked.getKey());
|
||||
workflowStatusDictionary.setName("not active");
|
||||
workflowStatusDictionaryImdg.insert(workflowStatusDictionary);
|
||||
|
||||
Imdg<ClearingCategoryDictionary> clearingCategoryDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingCategoryDictionary,
|
||||
ClearingCategoryDictionary.class
|
||||
);
|
||||
ClearingCategoryDictionary clearingCategoryDictionary = new ClearingCategoryDictionary();
|
||||
clearingCategoryDictionary.setId(1L);
|
||||
clearingCategoryDictionary.setCode(ClearingCategory.I.getKey());
|
||||
clearingCategoryDictionary.setName("I");
|
||||
clearingCategoryDictionaryImdg.insert(clearingCategoryDictionary);
|
||||
|
||||
TestUtils.FutureRecordMetadata future = spy(TestUtils.FutureRecordMetadata.class);
|
||||
doReturn(future).when(mockProducer).send(producerRecord.capture());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void newRelation() {
|
||||
//ARRANGE
|
||||
RelationNewRequest relationNewRequest = new RelationNewRequest();
|
||||
relationNewRequest.setCompanyId(COMPANY_ID);
|
||||
relationNewRequest.setServiceStatus("ACTV");
|
||||
relationNewRequest.setClearingMemberCategory("I");
|
||||
relationNewRequest.setComment(null);
|
||||
|
||||
Relation predictableRelation = new Relation();
|
||||
predictableRelation.setId(RELATION_ID);
|
||||
predictableRelation.setConsumerId(relationNewRequest.companyId);
|
||||
predictableRelation.setService("MKR");
|
||||
predictableRelation.setServiceProduct("ZERO");
|
||||
predictableRelation.setSupplierId(1L);
|
||||
predictableRelation.setServiceStatus("ACTV");
|
||||
|
||||
//ACT
|
||||
String jsonString = getJsonStringForNew(relationNewRequest, ID);
|
||||
|
||||
addRecordToKafka((MockConsumer) relationService.getConsumer(), Consts.DESTINATION_RELATION_NEW, PARTITION, 0, jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingWhenAddedRecordAndCheckIt(ID, mockProducer, producerRecord);
|
||||
Relation resultNew = relationMap.getSingleObjectBySQL("serviceStatus=ACTV"); // String.format("supplierId = %d", COMPANY_ID));
|
||||
predictableRelation.setId(resultNew.getId());
|
||||
RELATION_MATCHER.assertMatch(resultNew, predictableRelation);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateRelation() {
|
||||
//ARRANGE
|
||||
Relation existsRelation = new Relation();
|
||||
existsRelation.setId(ID);
|
||||
existsRelation.setConsumerId(COMPANY_ID);
|
||||
existsRelation.setSupplierId(1L);
|
||||
existsRelation.setComment("Test ONE");
|
||||
existsRelation.setServiceStatus("ACTV");
|
||||
existsRelation.setServiceProduct("PROD");
|
||||
existsRelation.setService("MKR");
|
||||
relationMap.insert(existsRelation);
|
||||
|
||||
Relation predictableRelation = new Relation();
|
||||
predictableRelation.setId(ID);
|
||||
predictableRelation.setConsumerId(COMPANY_ID);
|
||||
predictableRelation.setSupplierId(1L);
|
||||
predictableRelation.setComment("Another Me - ONE");
|
||||
predictableRelation.setServiceStatus("ACTV");
|
||||
predictableRelation.setServiceProduct("PROD");
|
||||
predictableRelation.setService("MKR");
|
||||
|
||||
RelationUpdateRequest relationUpdateRequest = new RelationUpdateRequest();
|
||||
relationUpdateRequest.setId(RELATION_ID);
|
||||
relationUpdateRequest.setComment("Another Me - ONE");
|
||||
relationUpdateRequest.setServiceStatus("ACTV");
|
||||
|
||||
//ACT
|
||||
String jsonString = getJsonStringForUpdate(relationUpdateRequest, ID);
|
||||
|
||||
addRecordToKafka((MockConsumer) relationService.getConsumer(), Consts.DESTINATION_RELATION_UPDATE, PARTITION, 0, jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingWhenAddedRecordAndCheckIt(ID, mockProducer, producerRecord);
|
||||
Relation resultUpdate = relationMap.getSingleObjectBySQL(String.format("id = %d", RELATION_ID));
|
||||
// predictableProfileDocument.setId(resultUpdate.getId());
|
||||
RELATION_MATCHER.assertMatch(resultUpdate, predictableRelation);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void deleteProfileDocument() {
|
||||
//ARRANGE
|
||||
Relation existsRelation = new Relation();
|
||||
existsRelation.setId(ID);
|
||||
existsRelation.setConsumerId(COMPANY_ID);
|
||||
existsRelation.setSupplierId(1L);
|
||||
existsRelation.setComment("Test ONE");
|
||||
existsRelation.setServiceStatus("ACTV");
|
||||
existsRelation.setServiceProduct("PROD");
|
||||
existsRelation.setService("MKR");
|
||||
relationMap.insert(existsRelation);
|
||||
|
||||
CommonDeleteRequest profileDocumentDeleteRequest = new CommonDeleteRequest();
|
||||
profileDocumentDeleteRequest.setId(RELATION_ID);
|
||||
|
||||
//ACT
|
||||
String jsonString = getJsonStringForUpdate(profileDocumentDeleteRequest, ID);
|
||||
|
||||
addRecordToKafka((MockConsumer) relationService.getConsumer(), Consts.DESTINATION_RELATION_DELETE, PARTITION, 0, jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingWhenAddedRecordAndCheckIt(ID, mockProducer, producerRecord);
|
||||
Relation resultUpdate = relationMap.getSingleObjectByID(RELATION_ID);
|
||||
// Assertions.assertNull(resultUpdate);
|
||||
assertEquals(WorkflowStatus.Blocked.getKey(), resultUpdate.getServiceStatus());
|
||||
}
|
||||
}
|
||||
|
|
@ -72,7 +72,9 @@ public interface Consts {
|
|||
@Deprecated
|
||||
String ACCOUNT_NEW_SDF01 = "account-new-sdf01";
|
||||
|
||||
String DESTINATION_RELATION_NEW = "relation-new";
|
||||
String DESTINATION_RELATION_UPDATE = "relation-update";
|
||||
String DESTINATION_RELATION_DELETE = "relation-delete";
|
||||
String DESTINATION_PROFILE_DOCUMENT_NEW = "profile-document-new";
|
||||
String DESTINATION_PROFILE_DOCUMENT_UPDATE = "profile-document-update";
|
||||
String DESTINATION_PROFILE_DOCUMENT_DELETE = "profile-document-delete";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
package ru.spcex.clearing.platform.messaging.domain.cud.company;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class RelationNewRequest {
|
||||
@JsonProperty
|
||||
public Long companyId;
|
||||
@JsonProperty
|
||||
private String serviceStatus;
|
||||
@JsonProperty
|
||||
private String clearingMemberCategory;
|
||||
@JsonProperty
|
||||
private String comment;
|
||||
|
||||
public Long getCompanyId() {
|
||||
return companyId;
|
||||
}
|
||||
|
||||
public void setCompanyId(Long companyId) {
|
||||
this.companyId = companyId;
|
||||
}
|
||||
|
||||
public String getServiceStatus() {
|
||||
return serviceStatus;
|
||||
}
|
||||
|
||||
public void setServiceStatus(String serviceStatus) {
|
||||
this.serviceStatus = serviceStatus;
|
||||
}
|
||||
|
||||
public String getClearingMemberCategory() {
|
||||
return clearingMemberCategory;
|
||||
}
|
||||
|
||||
public void setClearingMemberCategory(String clearingMemberCategory) {
|
||||
this.clearingMemberCategory = clearingMemberCategory;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue