This commit is contained in:
parent
ebc2f4f684
commit
404ca8dcd8
8 changed files with 32 additions and 26 deletions
|
|
@ -100,7 +100,7 @@ public class AccountValidationConfig {
|
|||
AccountError.DictionaryNotFound,
|
||||
accountType -> {
|
||||
if (IEnumKey.contains(accountType.getCode(), AccountType.Corr, AccountType.Info)) return null;
|
||||
return AccountError.WrongFieldValue;
|
||||
return new EnumMessage(AccountError.WrongFieldValue, "accountType");
|
||||
}).withMessageDecorator((causeEmpty, errorCode, fieldName, fieldValue) -> {
|
||||
if (errorCode == AccountError.WrongFieldValue)
|
||||
return DictionaryPresentRule.FIELD_NOT_FOUND_DECORATOR_1.decorator(causeEmpty, errorCode, fieldName, fieldValue);
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ public class DictionaryPresentRule<R, D extends AbstractDictionary> implements I
|
|||
public final IErrorEnumId errorEmptyRequiredValue;
|
||||
public final IErrorEnumId errorWrongDictionaryValue;
|
||||
public final boolean required;
|
||||
public final Function<D, IErrorEnumId>[] additionalChecks;
|
||||
public final Function<D, EnumMessage>[] additionalChecks;
|
||||
protected IMessageDecorator decorator;
|
||||
|
||||
public DictionaryPresentRule(String fieldName, Function<R, String> getter, String dictionaryName, Class<D> dictionaryClass, IErrorEnumId errorEmptyRequiredValue, IErrorEnumId errorWrongDictionaryValue, boolean required, Function<D, IErrorEnumId>[] additionalChecks) {
|
||||
public DictionaryPresentRule(String fieldName, Function<R, String> getter, String dictionaryName, Class<D> dictionaryClass, IErrorEnumId errorEmptyRequiredValue, IErrorEnumId errorWrongDictionaryValue, boolean required, Function<D, EnumMessage>[] additionalChecks) {
|
||||
this.fieldName = fieldName;
|
||||
this.getter = getter;
|
||||
this.dictionaryName = dictionaryName;
|
||||
|
|
@ -67,7 +67,7 @@ public class DictionaryPresentRule<R, D extends AbstractDictionary> implements I
|
|||
IErrorEnumId errorEmptyRequiredValue,
|
||||
IErrorEnumId errorWrongDictionaryValue,
|
||||
boolean required,
|
||||
Function<D, IErrorEnumId>... additionalChecks) {
|
||||
Function<D, EnumMessage>... additionalChecks) {
|
||||
Objects.requireNonNull(errorWrongDictionaryValue, "errorWrongDictionaryValue");
|
||||
if (required)
|
||||
Objects.requireNonNull(errorEmptyRequiredValue, "errorEmptyRequiredValue");
|
||||
|
|
@ -99,7 +99,7 @@ public class DictionaryPresentRule<R, D extends AbstractDictionary> implements I
|
|||
Class<D> dictionaryClass,
|
||||
IErrorEnumId errorEmptyRequiredValue,
|
||||
IErrorEnumId errorWrongDictionaryValue,
|
||||
Function<D, IErrorEnumId>... additionalChecks) {
|
||||
Function<D, EnumMessage>... additionalChecks) {
|
||||
Objects.requireNonNull(errorWrongDictionaryValue, "errorWrongDictionaryValue");
|
||||
Objects.requireNonNull(errorEmptyRequiredValue, "errorEmptyRequiredValue");
|
||||
return new DictionaryPresentRule<>(fieldName,
|
||||
|
|
@ -131,10 +131,10 @@ public class DictionaryPresentRule<R, D extends AbstractDictionary> implements I
|
|||
if (dictionaryFromMap == null) { // never
|
||||
return decorator.of(false, errorWrongDictionaryValue, dictionaryClass.getSimpleName(), enumCode);
|
||||
}
|
||||
for (Function<D, IErrorEnumId> additionalCheck : additionalChecks) {
|
||||
IErrorEnumId validationError = additionalCheck.apply(dictionaryFromMap);
|
||||
for (Function<D, EnumMessage> additionalCheck : additionalChecks) {
|
||||
EnumMessage validationError = additionalCheck.apply(dictionaryFromMap);
|
||||
if (validationError != null)
|
||||
return of(validationError, fieldName);
|
||||
return Optional.of(validationError);
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ public class ClearingMemberCategoryValidationConfig {
|
|||
CompanyErrors.DictionaryNotFound,
|
||||
category -> {
|
||||
ClearingCategory enumVal = IEnumKey.getEnumByKey(ClearingCategory.class, category.getCode());
|
||||
return IEnumKey.contains(enumVal, T, K) ? CompanyErrors.CategoryIsNotSupported : null;
|
||||
return IEnumKey.contains(enumVal, T, K) ? new EnumMessage(CompanyErrors.CategoryIsNotSupported, category.getCode()) : null;
|
||||
}),
|
||||
ProviderMemberCategoryValidationRule.NEW
|
||||
);
|
||||
|
|
@ -101,7 +101,7 @@ public class ClearingMemberCategoryValidationConfig {
|
|||
false,
|
||||
category -> {
|
||||
ClearingCategory enumVal = IEnumKey.getEnumByKey(ClearingCategory.class, category.getCode());
|
||||
return IEnumKey.contains(enumVal, T, K) ? CompanyErrors.CategoryIsNotSupported : null;
|
||||
return IEnumKey.contains(enumVal, T, K) ? new EnumMessage(CompanyErrors.CategoryIsNotSupported, category.getCode()) : null;
|
||||
}),
|
||||
ProviderMemberCategoryValidationRule.UPDATE
|
||||
);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import static ru.spcex.platform.enumeration.ClearingCategory.K;
|
|||
import static ru.spcex.platform.enumeration.ClearingCategory.T;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
import ru.spcex.platform.utils.validation.ValidatorImpl;
|
||||
|
|
@ -58,7 +59,7 @@ public class RelationValidationConfig {
|
|||
false,
|
||||
category -> {
|
||||
ClearingCategory enumVal = IEnumKey.getEnumByKey(ClearingCategory.class, category.getCode());
|
||||
return IEnumKey.contains(enumVal, T, K) ? CompanyErrors.CategoryIsNotSupported : null;
|
||||
return IEnumKey.contains(enumVal, T, K) ? new EnumMessage(CompanyErrors.CategoryIsNotSupported, category.getCode()) : null;
|
||||
}),
|
||||
DictionaryPresentRule.instance("serviceStatus",
|
||||
RelationNewRequest::getServiceStatus,
|
||||
|
|
|
|||
|
|
@ -73,7 +73,10 @@ public enum ProviderMemberCategoryValidationRule implements IValidationRule<Imdg
|
|||
|
||||
if (ClearingCategory.P == categoryVal) {
|
||||
Collection<Long> categories = categoryImdg.getCollectionIdsByPredicate(predicateBuilder.and(
|
||||
predicateBuilder.equals("companyId", clearingMemberCategory.getCompanyId())
|
||||
predicateBuilder.equals("companyId", clearingMemberCategory.getCompanyId()),
|
||||
predicateBuilder.not(
|
||||
predicateBuilder.equals("id", clearingMemberCategory.getId())
|
||||
)
|
||||
));
|
||||
if (!categories.isEmpty()) {
|
||||
return Optional.of(new EnumMessage(
|
||||
|
|
|
|||
|
|
@ -144,6 +144,7 @@ public class ClearingMemberCategoryService extends QueueConsumer implements Init
|
|||
//todo сложный кейс с возможным изменением релейшена или пересозданием. Скоро ТЗ доделают.
|
||||
//companyService.relationService.updateExistRelation(transaction,clearingMemberCategory.getCompanyId(), oldClearingMemberCategory,
|
||||
// clearingMemberCategory.getClearingMemberCategory());
|
||||
companyService.relationService.cancelRelation(transaction, clearingMemberCategory.getCompanyId(), oldClearingMemberCategory, clearingMemberCategory.getId());
|
||||
companyService.relationService.createNewRelation(transaction, clearingMemberCategory.getCompanyId(), clearingMemberCategory);
|
||||
Imdg<ClearingMemberCategory> txClearingMemberCategoryMap = transaction.getImdg(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
|
||||
txClearingMemberCategoryMap.insert(clearingMemberCategory);
|
||||
|
|
@ -182,7 +183,7 @@ public class ClearingMemberCategoryService extends QueueConsumer implements Init
|
|||
if (clearingMemberCategory.getCompanyId() == null) { // never, только тестовые данные
|
||||
log.warn("Deleted clearingMemberCategory[{}] has not companyId", clearingMemberCategory.getId());
|
||||
} else {
|
||||
companyService.relationService.cancelRelation(transaction, clearingMemberCategory.getCompanyId(), clearingMemberCategory);
|
||||
companyService.relationService.cancelRelation(transaction, clearingMemberCategory.getCompanyId(), clearingMemberCategory.getClearingMemberCategory(), clearingMemberCategory.getId());
|
||||
}
|
||||
txOk = true;
|
||||
} finally {
|
||||
|
|
|
|||
|
|
@ -598,8 +598,8 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
|||
/**
|
||||
* Приходит от ClearingMemberCategory
|
||||
*/
|
||||
protected void cancelRelation(ImdgTransaction transaction, Long companyId, ClearingMemberCategory clearingMemberCategory) {
|
||||
log.debug("Cancelling relations for companyId={} and clearingMemberCategory {}", companyId, clearingMemberCategory == null ? null : clearingMemberCategory.getClearingMemberCategory());
|
||||
protected void cancelRelation(ImdgTransaction transaction, Long companyId, String clearingMemberCategory, Long categoryId) {
|
||||
log.debug("Cancelling relations for companyId={} and clearingMemberCategory {}", companyId, clearingMemberCategory == null ? null : clearingMemberCategory);
|
||||
Objects.requireNonNull(companyId, "companyId");
|
||||
Imdg<Relation> relationMap = transaction.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||
// String serviceStatus = null;
|
||||
|
|
@ -610,33 +610,33 @@ public class RelationService extends QueueConsumer implements InitializingBean {
|
|||
// serviceStatus = serviceForCMC(clearingCategory).getKey();
|
||||
// }
|
||||
|
||||
Collection<String> companyCMC = selectCompanyClearingMemberCategory(null, companyId, clearingMemberCategory.getId());
|
||||
if (companyCMC.contains(clearingMemberCategory.getClearingMemberCategory())) {
|
||||
Collection<String> companyCMC = selectCompanyClearingMemberCategory(null, companyId, categoryId);
|
||||
if (companyCMC.contains(clearingMemberCategory)) {
|
||||
// never
|
||||
log.warn("ClearingMemberCategory \"{}\" already exist in set for company {}.", clearingMemberCategory.getClearingMemberCategory(), companyId);
|
||||
log.warn("ClearingMemberCategory \"{}\" already exist in set for company {}.", clearingMemberCategory, companyId);
|
||||
}
|
||||
boolean companyCMCisBIV = companyCMC.contains(ClearingCategory.B.getKey()) || companyCMC.contains(ClearingCategory.I.getKey())
|
||||
|| companyCMC.contains(ClearingCategory.V.getKey());
|
||||
|| companyCMC.contains(ClearingCategory.V.getKey()) || companyCMC.contains(ClearingCategory.P.getKey());
|
||||
boolean companyCMCisCF = companyCMC.contains(ClearingCategory.C.getKey()) || companyCMC.contains(ClearingCategory.F.getKey());
|
||||
|
||||
|
||||
Relation relation = searchRelation(transaction, clearingMemberCategory.getClearingMemberCategory(), companyId);
|
||||
Relation relation = searchRelation(transaction, clearingMemberCategory, companyId);
|
||||
if (relation == null) {
|
||||
log.debug("Relation for clearingMemberCategory.id={} {} not found", clearingMemberCategory.getId(), clearingMemberCategory.getClearingMemberCategory());
|
||||
log.debug("Relation for clearingMemberCategory.id={} {} not found", categoryId, clearingMemberCategory);
|
||||
} else {
|
||||
if (companyCMCisBIV && MKR.equalsByKey(relation.getService())) {
|
||||
// relation не изменяем
|
||||
log.debug("Relation {} {} lost for ClearingMemberCategory \"{}\".", relation.getId(), relation.getService(), clearingMemberCategory.getClearingMemberCategory());
|
||||
log.debug("Relation {} {} lost for ClearingMemberCategory \"{}\".", relation.getId(), relation.getService(), clearingMemberCategory);
|
||||
} else if (companyCMCisCF && FOND.equalsByKey(relation.getService())) {
|
||||
// relation не изменяем
|
||||
log.debug("Relation {} {} lost for ClearingMemberCategory \"{}\".", relation.getId(), relation.getService(), clearingMemberCategory.getClearingMemberCategory());
|
||||
log.debug("Relation {} {} lost for ClearingMemberCategory \"{}\".", relation.getId(), relation.getService(), clearingMemberCategory);
|
||||
} else {
|
||||
// удалить.
|
||||
log.debug("Block exist relation.id={}", relation.getId());
|
||||
relation.setUpdated(Instant.now());
|
||||
relation.setServiceStatus(Closed.getKey());
|
||||
relationMap.update(relation);
|
||||
log.debug("Relation[{}] updated (closed) by clearingMemberCategory[{}].", relation.getId(), clearingMemberCategory.getId());
|
||||
log.debug("Relation[{}] updated (closed) by clearingMemberCategory[{}].", relation.getId(), categoryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
|||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||
import ru.spcex.platform.imdg.validation.rule.PresentById;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
import ru.spcex.platform.utils.validation.ValidatorImpl;
|
||||
|
||||
|
|
@ -539,7 +540,7 @@ public class ValidationProvider {
|
|||
InstrumentTypeDictionary.class,
|
||||
SecuritiesError.RequiredFieldIsEmpty,
|
||||
SecuritiesError.DictionaryNotFound,
|
||||
instrument -> !InstrumentType.DGCT.getKey().equalsIgnoreCase(instrument.getCode()) ? SecuritiesError.WrongFieldValue : null
|
||||
instrument -> !InstrumentType.DGCT.getKey().equalsIgnoreCase(instrument.getCode()) ? new EnumMessage(SecuritiesError.WrongFieldValue, "instrumentType") : null
|
||||
),
|
||||
DictionaryPresentRule.instance(
|
||||
"workflowStatus",
|
||||
|
|
@ -597,7 +598,7 @@ public class ValidationProvider {
|
|||
InstrumentTypeDictionary.class,
|
||||
SecuritiesError.RequiredFieldIsEmpty,
|
||||
SecuritiesError.DictionaryNotFound,
|
||||
instrument -> !InstrumentType.DGCT.getKey().equalsIgnoreCase(instrument.getCode()) ? SecuritiesError.WrongFieldValue : null
|
||||
instrument -> !InstrumentType.DGCT.getKey().equalsIgnoreCase(instrument.getCode()) ? new EnumMessage(SecuritiesError.WrongFieldValue, "instrumentType") : null
|
||||
),
|
||||
DictionaryPresentRule.instance(
|
||||
"workflowStatus",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue