Compare commits
1 commit
10_01_2024
...
refactor-i
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3107f02daf |
1990 changed files with 5614 additions and 222814 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,7 +1,3 @@
|
|||
target
|
||||
/.idea/
|
||||
*.iml
|
||||
logs
|
||||
tmp_notes.**
|
||||
tmp
|
||||
clearing-parent/backend-api/src/main/resources/meta.json
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
start mvn clean install -Dmaven.test.skip=true -P distributive
|
||||
pause
|
||||
|
|
@ -1,129 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>clearing-parent</artifactId>
|
||||
<groupId>ru.spcex.clearing</groupId>
|
||||
<version>SPCEX-1.0.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>account-service</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.platform</groupId>
|
||||
<artifactId>platform-messaging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.platform</groupId>
|
||||
<artifactId>platform-imdg-api-hazelcast-impl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.platform</groupId>
|
||||
<artifactId>platform-enum</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.clearing</groupId>
|
||||
<artifactId>classes</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.clearing</groupId>
|
||||
<artifactId>security-util</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.clearing</groupId>
|
||||
<artifactId>clearing-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<!-- TEST -->
|
||||
<dependency>
|
||||
<groupId>ru.spcex.clearing</groupId>
|
||||
<artifactId>test-clearing</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<excludes>
|
||||
<exclude>application.properties</exclude>
|
||||
</excludes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.21.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||
<version>1.2.0-M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.2.0-M1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package ru.spcex.clearing.account;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class AccountServiceApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication springApplication = new SpringApplication(AccountServiceApplication.class);
|
||||
springApplication.run(args);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
package ru.spcex.clearing.account.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import ru.spcex.clearing.account.config.settings.AccountServiceSettings;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
|
||||
@Configuration
|
||||
public class AccountServiceImdgConfig {
|
||||
private static ThreadPoolTaskExecutor createThreadPoolTaskExecutor(int maxPoolSz, boolean waitForCompletion) {
|
||||
ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
|
||||
if (maxPoolSz > 2) {
|
||||
pool.setKeepAliveSeconds(60);
|
||||
pool.setAllowCoreThreadTimeOut(true);
|
||||
}
|
||||
pool.setCorePoolSize(maxPoolSz);
|
||||
pool.setWaitForTasksToCompleteOnShutdown(waitForCompletion);
|
||||
return pool;
|
||||
}
|
||||
|
||||
@Bean(name = "taskExecutorHazelcastClientInitializer")
|
||||
public ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializer() {
|
||||
return createThreadPoolTaskExecutor(1, true);
|
||||
}
|
||||
|
||||
@Bean(name = "taskExecutorIdGeneratorAwaiter")
|
||||
public ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiter() {
|
||||
return createThreadPoolTaskExecutor(1, false);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Bean
|
||||
public ImdgProvider imdgProvider(
|
||||
@Qualifier("taskExecutorHazelcastClientInitializer") ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializer,
|
||||
@Qualifier("taskExecutorIdGeneratorAwaiter") ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiter,
|
||||
AccountServiceSettings settings
|
||||
) {
|
||||
return new HazelcastService(taskExecutorHazelcastClientInitializer,
|
||||
taskExecutorIdGeneratorAwaiter,
|
||||
settings.getHazelcast());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
package ru.spcex.clearing.account.config;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||
import ru.spcex.clearing.util.services.IMDGMessageResolver;
|
||||
import ru.spcex.clearing.util.services.RequestHelper;
|
||||
import ru.spcex.platform.enumeration.UserRole;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
|
||||
@Configuration
|
||||
public class BeanConfiguration {
|
||||
@Bean
|
||||
public IMessageResolver messageResolver(ImdgProvider imdgProvider) {
|
||||
return new IMDGMessageResolver(imdgProvider);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public RequestHelper requestHelper(IMessageResolver messageResolver) {
|
||||
return new RequestHelper(messageResolver, AccountError.GeneralError);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public UserRoleVerification userRoleVerification(ImdgProvider imdgProvider, IMessageResolver messageResolver) {
|
||||
return new UserRoleVerification(imdgProvider, messageResolver, UserRole.Admin, AccountError.UserVerifyDenial);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
package ru.spcex.clearing.account.config;
|
||||
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.kafka.core.ProducerFactory;
|
||||
import ru.spcex.clearing.account.config.settings.AccountServiceSettings;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.config.KafkaConsumerFactory;
|
||||
import ru.spcex.clearing.platform.messaging.config.KafkaProducerFactory;
|
||||
import ru.spcex.clearing.platform.messaging.config.element.KafkaProducerSettings;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfo;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgId;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class KafkaConfig {
|
||||
@Autowired
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
@Bean
|
||||
public Consumer<String, Object> createConsumer(AccountServiceSettings settings) {
|
||||
return KafkaConsumerFactory.consumer(settings.getKafkaConsumer());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Bean
|
||||
public Producer<String, Object> createProducer(AccountServiceSettings settings) {
|
||||
return KafkaProducerFactory.producer(settings.getKafkaProducer());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ProducerFactory<String, Object> pf(AccountServiceSettings settings) {
|
||||
KafkaProducerSettings kafkaSettings = settings.getKafkaProducer();
|
||||
return KafkaProducerFactory.producerFactory(kafkaSettings);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KafkaTemplate<String, Object> kafkaTemplate(ProducerFactory<String, Object> pf) {
|
||||
return new KafkaTemplate<>(pf);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Bean
|
||||
public KafkaSender kafkaSender(KafkaTemplate<String, Object> kafkaTemplate, ImdgProvider imdgProvider) {
|
||||
ImdgId imdgIdGenerator = imdgProvider.getImdgIdGenerator();
|
||||
return KafkaSender
|
||||
.setup()
|
||||
.setKafkaTemplate(kafkaTemplate)
|
||||
.idGenerator(imdgIdGenerator::nextId)
|
||||
.imdgProvider(s -> {
|
||||
Imdg<RequestInfo> imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_RequestInfo, RequestInfo.class);
|
||||
return imdg::insert;
|
||||
})
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
package ru.spcex.clearing.account.config.settings;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.spcex.clearing.platform.messaging.config.element.KafkaConsumerSettings;
|
||||
import ru.spcex.clearing.platform.messaging.config.element.KafkaProducerSettings;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.config.HazelcastClientParams;
|
||||
|
||||
@Component
|
||||
@PropertySource("file:${spring.config.location}/application.properties")
|
||||
@ConfigurationProperties("account-service")
|
||||
public class AccountServiceSettings {
|
||||
private HazelcastClientParams hazelcast;
|
||||
private KafkaConsumerSettings kafkaConsumer;
|
||||
private KafkaProducerSettings kafkaProducer;
|
||||
|
||||
public HazelcastClientParams getHazelcast() {
|
||||
return hazelcast;
|
||||
}
|
||||
|
||||
public void setHazelcast(HazelcastClientParams hazelcast) {
|
||||
this.hazelcast = hazelcast;
|
||||
}
|
||||
|
||||
public KafkaConsumerSettings getKafkaConsumer() {
|
||||
return kafkaConsumer;
|
||||
}
|
||||
|
||||
public void setKafkaConsumer(KafkaConsumerSettings kafkaConsumer) {
|
||||
this.kafkaConsumer = kafkaConsumer;
|
||||
}
|
||||
|
||||
public KafkaProducerSettings getKafkaProducer() {
|
||||
return kafkaProducer;
|
||||
}
|
||||
|
||||
public void setKafkaProducer(KafkaProducerSettings kafkaProducer) {
|
||||
this.kafkaProducer = kafkaProducer;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,101 +0,0 @@
|
|||
package ru.spcex.clearing.account.config.validation;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.AccountSymbols;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.AccountSymbolsNewRequest;
|
||||
import ru.spcex.clearing.validation.common.rules.FieldNotBlankRequiredRule;
|
||||
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.validation.IValidationRule;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
import ru.spcex.platform.utils.validation.ValidatorImpl;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Configuration
|
||||
public class AccountSymbolsValidationConfig {
|
||||
|
||||
@Bean("accountSymbolsDepoNewRequest")
|
||||
public Function<AccountSymbolsNewRequest, IValidator> accountSymbolsDepoNewRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return accountSymbolsNewRequest -> {
|
||||
ImdgValidationContext<AccountSymbolsNewRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(accountSymbolsNewRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_AccountSymbols);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("accountId",
|
||||
AccountSymbolsNewRequest::getAccountId,
|
||||
IMDGDistributedNames.Map_Account,
|
||||
Account.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.AccountNotFound,
|
||||
true,
|
||||
(Account account) -> {
|
||||
if (AccountType.Depo.equalsByKey(account.getAccountType())) {
|
||||
return null;
|
||||
} else {
|
||||
return AccountError.AccountDepoTypeRequired;
|
||||
}
|
||||
}
|
||||
),
|
||||
FieldNotBlankRequiredRule.instance("accountSymbolValue",
|
||||
AccountSymbolsNewRequest::getAccountSymbolValue,
|
||||
AccountError.RequiredFieldEmpty, true),
|
||||
new DuplicateAccountSymbolsRule()
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
static class DuplicateAccountSymbolsRule implements IValidationRule<ImdgValidationContext<AccountSymbolsNewRequest>> {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<AccountSymbolsNewRequest> context) {
|
||||
AccountSymbolsNewRequest validatedObject = context.getValidatedObject();
|
||||
Imdg<AccountSymbols> accountSymbolsImdg = context.obtainMap(IMDGDistributedNames.Map_AccountSymbols, AccountSymbols.class);
|
||||
|
||||
ImdgPredicateBuilder pb = accountSymbolsImdg.predicateBuilder();
|
||||
ImdgPredicate query = pb.or(
|
||||
pb.equals("accountId", validatedObject.getAccountId()),
|
||||
pb.equals("accountSymbolValue", validatedObject.getAccountSymbolValue())
|
||||
);
|
||||
Collection<AccountSymbols> existAccSymbols = accountSymbolsImdg.getCollectionObjectsByPredicate(query);
|
||||
|
||||
if (existAccSymbols.isEmpty()) {
|
||||
return empty();
|
||||
} else {
|
||||
AccountSymbols existAS = existAccSymbols.iterator().next();
|
||||
String duplicateMsg = "";
|
||||
if (validatedObject.getAccountId() != null && validatedObject.getAccountId().equals(existAS.getAccountId())) {
|
||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Account linkedAccount = accountImdg.getSingleObjectByID(existAS.getAccountId());
|
||||
if (linkedAccount != null) {
|
||||
duplicateMsg = linkedAccount.getAccount();
|
||||
} else {
|
||||
duplicateMsg = "" + existAS.getAccountId();
|
||||
}
|
||||
}
|
||||
if (validatedObject.getAccountSymbolValue() != null &&
|
||||
validatedObject.getAccountSymbolValue().equals(existAS.getAccountSymbolValue())) {
|
||||
if (!duplicateMsg.isEmpty())
|
||||
duplicateMsg += ", ";
|
||||
duplicateMsg += existAS.getAccountSymbolValue();
|
||||
}
|
||||
return of(AccountError.AccountAlreadyExist, duplicateMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,193 +0,0 @@
|
|||
package ru.spcex.clearing.account.config.validation;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.platform.dictionary.AccountTypeDictionary;
|
||||
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.CorrespondentAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.CorrespondentAccountUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonIdRequest;
|
||||
import ru.spcex.clearing.validation.common.rules.DictionaryPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.specific.FieldRequiredSpecificRule;
|
||||
import ru.spcex.clearing.validation.common.rules.specific.IdPresentSpecificRule;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.enumeration.AccountStatus;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
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;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Configuration
|
||||
public class AccountValidationConfig {
|
||||
|
||||
@Bean("correspondentAccountNewRequestValidator")
|
||||
public Function<CorrespondentAccountNewRequest, IValidator> correspondentAccountNewRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return correspondentAccountNewRequest -> {
|
||||
ImdgValidationContext<CorrespondentAccountNewRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(correspondentAccountNewRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
||||
addImdg.accept(IMDGDistributedNames.Map_AccountTypeDictionary);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("companyId",
|
||||
CorrespondentAccountNewRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound
|
||||
// company -> WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus()) ? null : AccountError.CompanyNotActive
|
||||
),
|
||||
FieldRequiredSpecificRule.instance("account",
|
||||
CorrespondentAccountNewRequest::getAccount,
|
||||
AccountError.AccountFieldNotSet,
|
||||
false,
|
||||
accountValue -> {
|
||||
if ((accountValue == null || accountValue.isBlank()) && AccountType.Info.equalsByKey(context.getValidatedObject().getAccountType())) {
|
||||
return null;
|
||||
}
|
||||
if (accountValue == null || accountValue.isBlank())
|
||||
return new EnumMessage(AccountError.AccountFieldNotSet, "account");
|
||||
Imdg<Account> accountImdg = context.obtainMap(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
ImdgPredicateBuilder pb = accountImdg.predicateBuilder();
|
||||
ImdgPredicate accountValuePredicate = pb.equals("account", accountValue);
|
||||
ImdgPredicate accountStatusPredicate = pb.equals("status", AccountStatus.ACTIVE.getKey());
|
||||
ImdgPredicate finalPredicate = pb.and(accountValuePredicate, accountStatusPredicate);
|
||||
Collection<Account> accounts = accountImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
if (accounts.isEmpty()) return null;
|
||||
return new EnumMessage(AccountError.AccountAlreadyExist, accounts.stream().findFirst().get().getAccount());
|
||||
}),
|
||||
DictionaryPresentRule.instance("status",
|
||||
CorrespondentAccountNewRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
ServiceStatusDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
false
|
||||
// , statusValue -> {
|
||||
// if (ServiceStatus.Active.equalsByKey(statusValue.getCode())) return null;
|
||||
// return AccountError.WrongFieldValue;
|
||||
// }
|
||||
),
|
||||
DictionaryPresentRule.instance("accountType",
|
||||
CorrespondentAccountNewRequest::getAccountType,
|
||||
IMDGDistributedNames.Map_AccountTypeDictionary,
|
||||
AccountTypeDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
accountType -> {
|
||||
if (IEnumKey.contains(accountType.getCode(), AccountType.Corr, AccountType.Info)) return null;
|
||||
return AccountError.WrongFieldValue;
|
||||
}).withMessageDecorator((causeEmpty, errorCode, fieldName, fieldValue) -> {
|
||||
if (errorCode == AccountError.WrongFieldValue)
|
||||
return DictionaryPresentRule.FIELD_NOT_FOUND_DECORATOR_1.decorator(causeEmpty, errorCode, fieldName, fieldValue);
|
||||
else
|
||||
return DictionaryPresentRule.DICTIONARY_NOT_FOUND_DECORATOR_2.decorator(causeEmpty, errorCode, fieldName, fieldValue);
|
||||
}
|
||||
),
|
||||
new SameAccountValidationRule<>(AccountType.Corr, CorrespondentAccountNewRequest::getAccount)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("correspondentAccountUpdateRequestValidator")
|
||||
public Function<CorrespondentAccountUpdateRequest, IValidator> correspondentAccountUpdateRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return correspondentAccountUpdateRequest -> {
|
||||
ImdgValidationContext<CorrespondentAccountUpdateRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(correspondentAccountUpdateRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
||||
addImdg.accept(IMDGDistributedNames.Map_AccountTypeDictionary);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("id",
|
||||
CorrespondentAccountUpdateRequest::getId,
|
||||
IMDGDistributedNames.Map_Account,
|
||||
Account.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.AccountNotFound),
|
||||
IdPresentRule.instance("companyId",
|
||||
CorrespondentAccountUpdateRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound,
|
||||
false,
|
||||
company -> {
|
||||
if (Objects.equals(company.getId(), correspondentAccountUpdateRequest.getCompanyId()))
|
||||
return null;
|
||||
return AccountError.WrongFieldValue;
|
||||
}),
|
||||
DictionaryPresentRule.instance("status",
|
||||
CorrespondentAccountUpdateRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
ServiceStatusDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
false),
|
||||
DictionaryPresentRule.instance("accountType",
|
||||
CorrespondentAccountUpdateRequest::getAccountType,
|
||||
IMDGDistributedNames.Map_AccountTypeDictionary,
|
||||
AccountTypeDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
false
|
||||
// accountType -> {
|
||||
// if (AccountType.Corr.equalsByKey(accountType.getCode())) return null;
|
||||
// return AccountError.WrongFieldValue;
|
||||
// }
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("correspondentAccountBlockRequestValidator")
|
||||
public Function<CommonIdRequest, IValidator> correspondentAccountBlockRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return correspondentAccountBlockRequest -> {
|
||||
ImdgValidationContext<CommonIdRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(correspondentAccountBlockRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentSpecificRule.instance("id",
|
||||
CommonIdRequest::getId,
|
||||
IMDGDistributedNames.Map_Account,
|
||||
Account.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.AccountNotFound,
|
||||
account -> {
|
||||
if (AccountStatus.BLOCKED.equalsByKey(account.getStatus()))
|
||||
return new EnumMessage(AccountError.AccountNotActive, account.getAccount());
|
||||
return null;
|
||||
})
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,160 +0,0 @@
|
|||
package ru.spcex.clearing.account.config.validation;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.BankAccount;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.platform.dictionary.CurrencyCodeDictionary;
|
||||
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonIdRequest;
|
||||
import ru.spcex.clearing.validation.common.rules.DictionaryPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.FieldNotBlankRequiredRule;
|
||||
import ru.spcex.clearing.validation.common.rules.FieldRequiredRule;
|
||||
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.specific.FieldRequiredSpecificRule;
|
||||
import ru.spcex.clearing.validation.common.rules.specific.IdPresentSpecificRule;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.enumeration.AccountStatus;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
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.validation.IValidator;
|
||||
import ru.spcex.platform.utils.validation.ValidatorImpl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Configuration
|
||||
public class BankAccountValidationConfig {
|
||||
|
||||
@Bean("bankAccountNewRequestValidator")
|
||||
public Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return bankAccountNewRequest -> {
|
||||
ImdgValidationContext<BankAccountNewRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(bankAccountNewRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_BankAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
||||
addImdg.accept(IMDGDistributedNames.Map_CurrencyCodeDictionary);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("companyId",
|
||||
BankAccountNewRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound,
|
||||
false),
|
||||
FieldNotBlankRequiredRule.instance("account",
|
||||
BankAccountNewRequest::getAccount,
|
||||
AccountError.RequiredFieldEmpty
|
||||
),
|
||||
new SameAccountValidationRule<>(AccountType.Bank, BankAccountNewRequest::getAccount),
|
||||
DictionaryPresentRule.instance("currency",
|
||||
BankAccountNewRequest::getCurrency,
|
||||
IMDGDistributedNames.Map_CurrencyCodeDictionary,
|
||||
CurrencyCodeDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound),
|
||||
FieldRequiredRule.instance("bankIdentificationCode",
|
||||
BankAccountNewRequest::getBankIdentificationCode,
|
||||
AccountError.RequiredFieldEmpty),
|
||||
FieldRequiredRule.instance("bankName",
|
||||
BankAccountNewRequest::getBankName,
|
||||
AccountError.RequiredFieldEmpty),
|
||||
DictionaryPresentRule.instance("status",
|
||||
BankAccountNewRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
ServiceStatusDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
false)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("bankAccountUpdateRequestValidator")
|
||||
public Function<BankAccountUpdateRequest, IValidator> bankAccountUpdateRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return bankAccountUpdateRequest -> {
|
||||
ImdgValidationContext<BankAccountUpdateRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(bankAccountUpdateRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_CurrencyCodeDictionary);
|
||||
addImdg.accept(IMDGDistributedNames.Map_BankAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("id",
|
||||
BankAccountUpdateRequest::getId,
|
||||
IMDGDistributedNames.Map_BankAccount,
|
||||
BankAccount.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.AccountNotFound,
|
||||
bankAccount -> {
|
||||
Long accountId = bankAccount.getAccountId();
|
||||
Imdg<Account> accountImdg = context.obtainMap(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
Account account = accountImdg.getSingleObjectByID(accountId);
|
||||
if (account == null) return AccountError.AccountNotFound;
|
||||
// if (!AccountStatus.ACTIVE.equalsByKey(account.getStatus())) return AccountError.AccountNotActive;
|
||||
return null;
|
||||
}),
|
||||
DictionaryPresentRule.instance("currency",
|
||||
BankAccountUpdateRequest::getCurrency,
|
||||
IMDGDistributedNames.Map_CurrencyCodeDictionary,
|
||||
CurrencyCodeDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
false)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("bankAccountBlockRequestValidator")
|
||||
public Function<CommonIdRequest, IValidator> bankAccountBlockRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return bankAccountBlockRequest -> {
|
||||
ImdgValidationContext<CommonIdRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(bankAccountBlockRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_BankAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentSpecificRule.instance("id",
|
||||
CommonIdRequest::getId,
|
||||
IMDGDistributedNames.Map_BankAccount,
|
||||
BankAccount.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.AccountNotFound,
|
||||
bankAccount -> {
|
||||
Long accountId = bankAccount.getAccountId();
|
||||
Imdg<Account> accountImdg = context.obtainMap(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
Account account = accountImdg.getSingleObjectByID(accountId);
|
||||
if (account == null)
|
||||
return new EnumMessage(AccountError.AccountNotFound, accountId);
|
||||
if (AccountStatus.BLOCKED.equalsByKey(account.getStatus()))
|
||||
return new EnumMessage(AccountError.AccountNotActive, account.getAccount());
|
||||
return null;
|
||||
})
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
package ru.spcex.clearing.account.config.validation;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.platform.dictionary.ClearingAccountTypeDictionary;
|
||||
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountUpdateRequest;
|
||||
import ru.spcex.clearing.validation.common.rules.DictionaryPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.FieldNotBlankRequiredRule;
|
||||
import ru.spcex.clearing.validation.common.rules.FieldRequiredRule;
|
||||
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.specific.FieldRequiredSpecificRule;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.ServiceStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
import ru.spcex.platform.utils.validation.ValidatorImpl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Configuration
|
||||
public class ClearingAccountValidationConfig {
|
||||
|
||||
@Bean("clearingAccountNewRequestValidator")
|
||||
public Function<ClearingAccountNewRequest, IValidator> clearingAccountNewRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return clearingAccountNewRequest -> {
|
||||
ImdgValidationContext<ClearingAccountNewRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(clearingAccountNewRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClearingAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClearingAccountTypeDictionary);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("companyId",
|
||||
ClearingAccountNewRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound
|
||||
// company -> !WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus()) ? AccountError.CompanyNotActive : null
|
||||
),
|
||||
FieldNotBlankRequiredRule.instance("account",
|
||||
ClearingAccountNewRequest::getAccount,
|
||||
AccountError.RequiredFieldEmpty),
|
||||
new SameAccountValidationRule<>(AccountType.Clrn, ClearingAccountNewRequest::getAccount),
|
||||
DictionaryPresentRule.instance("clearingAccountType",
|
||||
ClearingAccountNewRequest::getClearingAccountType,
|
||||
IMDGDistributedNames.Map_ClearingAccountTypeDictionary,
|
||||
ClearingAccountTypeDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound),
|
||||
DictionaryPresentRule.instance("status",
|
||||
ClearingAccountNewRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
ServiceStatusDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
false)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Bean("clearingAccountUpdateRequestValidator")
|
||||
public Function<ClearingAccountUpdateRequest, IValidator> clearingAccountUpdateRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return clearingAccountUpdateRequest -> {
|
||||
ImdgValidationContext<ClearingAccountUpdateRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(clearingAccountUpdateRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClearingAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClearingAccountTypeDictionary);
|
||||
return new ValidatorImpl<>(context,
|
||||
FieldRequiredRule.instance("account",
|
||||
ClearingAccountUpdateRequest::getAccount,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
accountValue -> {
|
||||
if (accountValue.isBlank())
|
||||
return AccountError.RequiredFieldEmpty;
|
||||
Imdg<Account> accountImdg = context.obtainMap(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
ImdgPredicateBuilder pb = accountImdg.predicateBuilder();
|
||||
ImdgPredicate accountValuePredicate = pb.equals("account", accountValue);
|
||||
ImdgPredicate accountStatusPredicate = pb.equals("status", ServiceStatus.Active.getKey());
|
||||
ImdgPredicate accountTypePredicate = pb.equals("accountType", AccountType.Clrn.getKey());
|
||||
ImdgPredicate finalPredicate = pb.and(accountValuePredicate,
|
||||
accountStatusPredicate,
|
||||
accountTypePredicate);
|
||||
Collection<Account> accounts = accountImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
if (accounts.isEmpty()) return AccountError.AccountNotFound;
|
||||
return null;
|
||||
}),
|
||||
FieldRequiredRule.instance("status",
|
||||
ClearingAccountUpdateRequest::getStatus,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
statusValue -> {
|
||||
if (statusValue == 0 || statusValue == 1 || statusValue == 2) return null;
|
||||
return AccountError.WrongFieldValue;
|
||||
}),
|
||||
FieldRequiredRule.instance("deal",
|
||||
ClearingAccountUpdateRequest::getDeal,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
dealValue -> {
|
||||
Imdg<Company> companyImdg = context.obtainMap(
|
||||
IMDGDistributedNames.Map_Company, Company.class
|
||||
);
|
||||
Company company = companyImdg.getFirstObjectByFieldValues(Map.of("tradingCode", dealValue));
|
||||
if (company == null) return AccountError.WrongFieldValue;
|
||||
return null;
|
||||
})
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,161 +0,0 @@
|
|||
package ru.spcex.clearing.account.config.validation;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.ClientCode;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
||||
import ru.spcex.clearing.validation.common.rules.DictionaryPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.FieldRequiredRule;
|
||||
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.Objects;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Configuration
|
||||
public class ClientCodeValidationConfig {
|
||||
|
||||
@Bean("clientCodeNewRequestValidator")
|
||||
public Function<ClientCodeNewRequest, IValidator> clientCodeNewRequestValidator(Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation) {
|
||||
return clientCodeUpdateRequest -> {
|
||||
ImdgValidationContext<ClientCodeNewRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(clientCodeUpdateRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
||||
return new ValidatorImpl<>(context,
|
||||
FieldRequiredRule.instance("companyId", ClientCodeNewRequest::getCompanyId, AccountError.RequiredFieldEmpty),
|
||||
IdPresentRule.instance("companyId",
|
||||
ClientCodeNewRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound),
|
||||
|
||||
IdPresentRule.instance("moneyAccountId",
|
||||
ClientCodeNewRequest::getMoneyAccountId,
|
||||
IMDGDistributedNames.Map_Account,
|
||||
Account.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.AccountNotFound,
|
||||
false,
|
||||
acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
|
||||
? null : AccountError.AccountNotFound
|
||||
),
|
||||
IdPresentRule.instance("depoAccountId",
|
||||
ClientCodeNewRequest::getDepoAccountId,
|
||||
IMDGDistributedNames.Map_Account,
|
||||
Account.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.AccountNotFound,
|
||||
false,
|
||||
acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
|
||||
? null : AccountError.AccountNotFound
|
||||
),
|
||||
|
||||
|
||||
DictionaryPresentRule.instance("stauts",
|
||||
ClientCodeNewRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
ServiceStatusDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
false)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("clientCodeUpdateRequestValidator")
|
||||
public Function<ClientCodeUpdateRequest, IValidator> clientCodeUpdateRequestValidator(Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation) {
|
||||
return clientCodeUpdateRequest -> {
|
||||
ImdgValidationContext<ClientCodeUpdateRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(clientCodeUpdateRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClientCode);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
||||
return new ValidatorImpl<ImdgValidationContext<ClientCodeUpdateRequest>>(context,
|
||||
IdPresentRule.instance("id",
|
||||
ClientCodeUpdateRequest::getId,
|
||||
IMDGDistributedNames.Map_ClientCode,
|
||||
ClientCode.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.RecordNotFound
|
||||
),
|
||||
|
||||
FieldRequiredRule.instance("companyId", ClientCodeUpdateRequest::getCompanyId, AccountError.RequiredFieldEmpty),
|
||||
IdPresentRule.instance("companyId",
|
||||
ClientCodeUpdateRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound),
|
||||
|
||||
IdPresentRule.instance("moneyAccountId",
|
||||
ClientCodeUpdateRequest::getMoneyAccountId,
|
||||
IMDGDistributedNames.Map_Account,
|
||||
Account.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.AccountNotFound,
|
||||
false,
|
||||
acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
|
||||
? null : AccountError.AccountNotFound
|
||||
),
|
||||
IdPresentRule.instance("depoAccountId",
|
||||
ClientCodeUpdateRequest::getDepoAccountId,
|
||||
IMDGDistributedNames.Map_Account,
|
||||
Account.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.AccountNotFound,
|
||||
false,
|
||||
acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
|
||||
? null : AccountError.AccountNotFound
|
||||
),
|
||||
|
||||
DictionaryPresentRule.instance("stauts",
|
||||
ClientCodeUpdateRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
ServiceStatusDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
false)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("clientCodeDeleteRequestValidator")
|
||||
public Function<CommonDeleteRequest, IValidator> clientCodeDeleteRequestValidator(Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation) {
|
||||
return companyDeleteRequest -> {
|
||||
ImdgValidationContext<CommonDeleteRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(companyDeleteRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClientCode);
|
||||
return new ValidatorImpl<>(context,
|
||||
// FieldRequiredRule.instance("id", CommonDeleteRequest::getId, CompanyErrors.RequiredFieldEmpty),
|
||||
IdPresentRule.instance("id",
|
||||
CommonDeleteRequest::getId,
|
||||
IMDGDistributedNames.Map_ClientCode,
|
||||
ClientCode.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.RecordNotFound)
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
package ru.spcex.clearing.account.config.validation;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.DepoAccountNewRequest;
|
||||
import ru.spcex.clearing.validation.common.rules.DictionaryPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.FieldNotBlankRequiredRule;
|
||||
import ru.spcex.clearing.validation.common.rules.FieldRequiredRule;
|
||||
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.specific.FieldRequiredSpecificRule;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
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.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Configuration
|
||||
public class DepoAccountValidationConfig {
|
||||
|
||||
@Bean("depoAccountNewRequestValidator")
|
||||
public Function<DepoAccountNewRequest, IValidator> depoAccountNewRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return depoAccountNewRequest -> {
|
||||
ImdgValidationContext<DepoAccountNewRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(depoAccountNewRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_DepoAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("companyId",
|
||||
DepoAccountNewRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound
|
||||
// company -> !WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus()) ? AccountError.CompanyNotActive : null
|
||||
),
|
||||
FieldNotBlankRequiredRule.instance("account",
|
||||
DepoAccountNewRequest::getAccount,
|
||||
AccountError.RequiredFieldEmpty),
|
||||
new SameAccountValidationRule<>(AccountType.Depo, DepoAccountNewRequest::getAccount),
|
||||
FieldRequiredRule.instance("depoAccountType",
|
||||
DepoAccountNewRequest::getDepoAccountType,
|
||||
AccountError.RequiredFieldEmpty),
|
||||
DictionaryPresentRule.instance("status",
|
||||
DepoAccountNewRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
ServiceStatusDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
false)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
package ru.spcex.clearing.account.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.platform.dictionary.AccountTypeDictionary;
|
||||
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.InformationAccountNewRequest;
|
||||
import ru.spcex.clearing.validation.common.rules.DictionaryPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.FieldNotBlankRequiredRule;
|
||||
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
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 InformationAccountValidationConfig {
|
||||
|
||||
@Bean("informationAccountNewRequestValidator")
|
||||
public Function<InformationAccountNewRequest, IValidator> informationAccountNewRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return informationAccountNewRequest -> {
|
||||
ImdgValidationContext<InformationAccountNewRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(informationAccountNewRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_InformationAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
||||
addImdg.accept(IMDGDistributedNames.Map_AccountTypeDictionary);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("companyId",
|
||||
InformationAccountNewRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound,
|
||||
company -> {
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus()))
|
||||
return AccountError.CompanyNotActive;
|
||||
return null;
|
||||
}),
|
||||
FieldNotBlankRequiredRule.instance("account", InformationAccountNewRequest::getAccount,
|
||||
AccountError.RequiredFieldEmpty),
|
||||
DictionaryPresentRule.instance("status", InformationAccountNewRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary, ServiceStatusDictionary.class,
|
||||
AccountError.RequiredFieldEmpty, AccountError.DictionaryNotFound, false),
|
||||
DictionaryPresentRule.instance("accountType", InformationAccountNewRequest::getAccountType,
|
||||
IMDGDistributedNames.Map_AccountTypeDictionary, AccountTypeDictionary.class,
|
||||
AccountError.RequiredFieldEmpty, AccountError.DictionaryNotFound, false),
|
||||
new SameAccountValidationRule<>(AccountType.Info, InformationAccountNewRequest::getAccount)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
package ru.spcex.clearing.account.config.validation;
|
||||
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.ServiceStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.validation.IValidationRule;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
class SameAccountValidationRule<R> implements IValidationRule<ImdgValidationContext<R>> {
|
||||
final String accountType;
|
||||
final Function<R, String> accountGetter;
|
||||
|
||||
public SameAccountValidationRule(AccountType accountType, Function<R, String> accountGetter) {
|
||||
this.accountType = accountType.getKey(); // or req.getAccountType()
|
||||
this.accountGetter = accountGetter;
|
||||
Objects.requireNonNull(accountGetter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<R> context) {
|
||||
R req = context.getValidatedObject();
|
||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||
ImdgPredicateBuilder pb = accountImdg.predicateBuilder();
|
||||
ImdgPredicate query = pb.and(
|
||||
pb.equals("account", accountGetter.apply(req)), // req.getAccount()
|
||||
// pb.equals("accountType", accountType), имена всех счетов уникальны, вне зависимости от типа
|
||||
pb.in("status", ServiceStatus.Active.getKey(), ServiceStatus.Reopened.getKey(), ServiceStatus.Appl.getKey())
|
||||
);
|
||||
Account existAccount = accountImdg.getFirstObjectByPredicate(query);
|
||||
if (existAccount != null) {
|
||||
return of(AccountError.AccountAlreadyExist, existAccount.getAccount());
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,217 +0,0 @@
|
|||
package ru.spcex.clearing.account.config.validation;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.DepoAccount;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonIdRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryUpdateRequest;
|
||||
import ru.spcex.clearing.validation.common.rules.DictionaryPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.FieldRequiredRule;
|
||||
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
||||
import ru.spcex.clearing.validation.common.rules.specific.IdPresentSpecificRule;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.CompanySymbol;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.validation.IValidationRule;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
import ru.spcex.platform.utils.validation.ValidatorImpl;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Configuration
|
||||
public class TradingClearingRegistryValidationConfig {
|
||||
|
||||
@Bean("tradingClearingRegistryNewRequest")
|
||||
public Function<TradingClearingRegistryNewRequest, IValidator> tradingClearingRegistryNewRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return tradingClearingRegistryNewRequest -> {
|
||||
ImdgValidationContext<TradingClearingRegistryNewRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(tradingClearingRegistryNewRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_CompanySymbols);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClearingAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_DepoAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_InformationAccount);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
||||
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentSpecificRule.instance("companyId",
|
||||
TradingClearingRegistryNewRequest::getCompanyId,
|
||||
IMDGDistributedNames.Map_Company,
|
||||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound,
|
||||
true,
|
||||
company -> {
|
||||
Imdg<CompanySymbols> companySymbolsImdg = context.obtainMap(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||
CompanySymbols symbol = companySymbolsImdg.getFirstObjectByFieldValues(Map.of(
|
||||
"companyId", company.getId(),
|
||||
"companySymbol", CompanySymbol.CLRC.getKey()
|
||||
));
|
||||
if (symbol == null)
|
||||
return new EnumMessage(AccountError.ClearingCompanySymbolNotFound, company.getShortName());
|
||||
return null;
|
||||
}),
|
||||
FieldRequiredRule.instance("moneyAccountId",
|
||||
TradingClearingRegistryNewRequest::getMoneyAccountId,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
moneyAccountId -> {
|
||||
Imdg<Account> accountImdg = context.obtainMap(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
Account account = accountImdg.getSingleObjectByID(moneyAccountId);
|
||||
if (account == null) {
|
||||
return AccountError.AccountNotFound;
|
||||
} else {
|
||||
if (AccountType.Clrn.equalsByKey(account.getAccountType()) || AccountType.Info.equalsByKey(account.getAccountType())) {
|
||||
// ok
|
||||
} else {
|
||||
// неправильный тип
|
||||
return AccountError.AccountNotFound;
|
||||
}
|
||||
}
|
||||
// Imdg<ClearingAccount> clearingAccountImdg = context.obtainMap(
|
||||
// IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class
|
||||
// );
|
||||
// ClearingAccount clearingAccount = clearingAccountImdg.getSingleObjectByFieldValues(
|
||||
// Map.of("accountId",moneyAccountId)
|
||||
// );
|
||||
// if (clearingAccount == null) {
|
||||
// Imdg<InformationAccount> informationAccountImdg = context.obtainMap(
|
||||
// IMDGDistributedNames.Map_InformationAccount, InformationAccount.class
|
||||
// );
|
||||
// InformationAccount infoAccount = informationAccountImdg.getSingleObjectByFieldValues(
|
||||
// Map.of("accountId",moneyAccountId));
|
||||
// if (infoAccount == null) return AccountError.AccountNotFound;
|
||||
// }
|
||||
return null;
|
||||
}),
|
||||
FieldRequiredRule.instance("depoAccountId",
|
||||
TradingClearingRegistryNewRequest::getDepoAccountId,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
false,
|
||||
depoAccountId -> {
|
||||
if (depoAccountId == null) return null;
|
||||
Imdg<DepoAccount> depoAccountImdg = context.obtainMap(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
|
||||
DepoAccount depoAccount = depoAccountImdg.getFirstObjectByFieldValues(
|
||||
Map.of("accountId", depoAccountId)
|
||||
);
|
||||
if (depoAccount == null) return AccountError.AccountNotFound;
|
||||
return null;
|
||||
}),
|
||||
DictionaryPresentRule.instance("status",
|
||||
TradingClearingRegistryNewRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
ServiceStatusDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
false),
|
||||
new newTCRDuplicateCheck()
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
static class newTCRDuplicateCheck implements IValidationRule<ImdgValidationContext<TradingClearingRegistryNewRequest>> {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TradingClearingRegistryNewRequest> context) {
|
||||
TradingClearingRegistryNewRequest validatedObject = context.getValidatedObject();
|
||||
Imdg<TradingClearingRegistry> tcrMap = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
|
||||
if (validatedObject.getMoneyAccountId() == null) {
|
||||
return of(AccountError.RequiredFieldEmpty, "MoneyAccountId");
|
||||
}
|
||||
//Map<String, Comparable<?>> query = new HashMap<>();
|
||||
// query.put("moneyAccountId", validatedObject.getMoneyAccountId());
|
||||
// if (validatedObject.getDepoAccountId() != null) {
|
||||
// query.put("depoAccountId", validatedObject.getDepoAccountId());
|
||||
// }
|
||||
ImdgPredicateBuilder pb = tcrMap.predicateBuilder();
|
||||
ImdgPredicate query = pb.equals("moneyAccountId", validatedObject.getMoneyAccountId());
|
||||
if (validatedObject.getDepoAccountId() != null) {
|
||||
query = pb.or(query, pb.equals("depoAccountId", validatedObject.getDepoAccountId()));
|
||||
}
|
||||
|
||||
Collection<TradingClearingRegistry> existTCR = tcrMap.getCollectionObjectsByPredicate(query);
|
||||
|
||||
if (existTCR.isEmpty()) {
|
||||
return empty();
|
||||
} else {
|
||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Account account = accountImdg.getSingleObjectByID(validatedObject.getMoneyAccountId());
|
||||
if (account == null && validatedObject.getDepoAccountId() != null) account = accountImdg.getSingleObjectByID(validatedObject.getDepoAccountId());
|
||||
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getAccount());
|
||||
// String tcrIds = existTCR.stream().map(tcr -> String.valueOf(tcr.getId())).collect(Collectors.joining(";"));
|
||||
// return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, tcrIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Bean("tradingClearingRegistryUpdateRequest")
|
||||
public Function<TradingClearingRegistryUpdateRequest, IValidator> tradingClearingRegistryUpdateRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return tradingClearingRegistryUpdateRequest -> {
|
||||
ImdgValidationContext<TradingClearingRegistryUpdateRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(tradingClearingRegistryUpdateRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
||||
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("id",
|
||||
TradingClearingRegistryUpdateRequest::getId,
|
||||
IMDGDistributedNames.Map_TradingClearingRegistry,
|
||||
TradingClearingRegistry.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.TradingClearingRegistryNotFound),
|
||||
DictionaryPresentRule.instance("status",
|
||||
TradingClearingRegistryUpdateRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
ServiceStatusDictionary.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.DictionaryNotFound,
|
||||
false)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("tradingClearingRegistryBlockRequest")
|
||||
public Function<CommonIdRequest, IValidator> tradingClearingRegistryBlockRequestValidator(
|
||||
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||
) {
|
||||
return tradingClearingRegistryBlockRequest -> {
|
||||
ImdgValidationContext<CommonIdRequest> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(tradingClearingRegistryBlockRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry);
|
||||
return new ValidatorImpl<>(context,
|
||||
IdPresentRule.instance("id",
|
||||
CommonIdRequest::getId,
|
||||
IMDGDistributedNames.Map_TradingClearingRegistry,
|
||||
TradingClearingRegistry.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.TradingClearingRegistryNotFound)
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
package ru.spcex.clearing.account.config.validation;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.clearing.classes.statics.data.account.*;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.clearing.platform.dictionary.*;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
@Configuration
|
||||
public class ValidationConfig {
|
||||
|
||||
@Bean("imdgForValidation")
|
||||
public Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation(ImdgProvider imdgProvider) {
|
||||
final Map<String, Imdg<? extends SpcexObjectBase>> imdg = new HashMap<>();
|
||||
BiConsumer<String, Class<? extends SpcexObjectBase>> addImdg = (s, aClass) -> imdg.put(s, imdgProvider.getImdg(s, aClass));
|
||||
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company, Company.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClearingAccountTypeDictionary, ClearingAccountTypeDictionary.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account, Account.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_AccountTypeDictionary, AccountTypeDictionary.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_CurrencyCodeDictionary, CurrencyCodeDictionary.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary, ServiceStatusDictionary.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
addImdg.accept(IMDGDistributedNames.Map_AccountSymbols, AccountSymbols.class);
|
||||
|
||||
//for ClientCodeValidationConfig
|
||||
addImdg.accept(IMDGDistributedNames.Map_ClientCode, ClientCode.class);
|
||||
|
||||
return imdg;
|
||||
}
|
||||
|
||||
@Bean("validationHelper")
|
||||
public ValidationHelper validationHelper(IMessageResolver messageResolver) {
|
||||
return new ValidationHelper(messageResolver);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package ru.spcex.clearing.account.errors;
|
||||
|
||||
import ru.spcex.platform.utils.enumeration.IErrorEnumId;
|
||||
|
||||
public enum AccountError implements IErrorEnumId {
|
||||
GeneralError(5000L),
|
||||
UserVerifyDenial(5001L),
|
||||
RequiredFieldEmpty(5002L),
|
||||
DictionaryNotFound(5003L),
|
||||
WrongFieldValue(5004L),
|
||||
RecordNotFound(5006L),
|
||||
AccountAlreadyExist(5010L),
|
||||
AccountNotFound(5011L),
|
||||
AccountNotActive(5012L),
|
||||
CompanyNotFound(5013L),
|
||||
CompanyNotActive(5014L),
|
||||
InfoAccountAlreadyExist(5015L),
|
||||
TradingClearingRegistryAlreadyExist(5016L),
|
||||
DepoAccountNotFound(5017L),
|
||||
MoneyAccountNotFound(5018L),
|
||||
ClearingCategoryNotFound(5019L),
|
||||
ClearingCompanySymbolNotFound(5022L), // Для компании %s отсутствует клиринговый код».
|
||||
AccountForTradingClearingRegistryAlreadyUsed(5023L),
|
||||
AccountFieldNotSet(5024L),
|
||||
AccountDepoTypeRequired(5025L),
|
||||
TradingClearingRegistryNotFound(3022L),
|
||||
;
|
||||
|
||||
private final Long id;
|
||||
|
||||
AccountError(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.platform.messaging.service.Status;
|
||||
import ru.spcex.platform.enumeration.*;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@Service
|
||||
public class AccountHelper {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final Imdg<ClearingMemberCategory> clearingMemberCategoryMap;
|
||||
private final Imdg<Relation> relationMap;
|
||||
private final IMessageResolver messageResolver;
|
||||
|
||||
@Autowired
|
||||
public AccountHelper(ImdgProvider imdgProvider,
|
||||
IMessageResolver messageResolver) {
|
||||
this.clearingMemberCategoryMap = imdgProvider.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class
|
||||
);
|
||||
this.relationMap = imdgProvider.getImdg(
|
||||
IMDGDistributedNames.Map_Relation, Relation.class
|
||||
);
|
||||
this.messageResolver = messageResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Заполняет поля relationId и companyId из соответствующей записи Relation
|
||||
*
|
||||
* @param requestId Идентификатор запроса для вывода лога
|
||||
*/
|
||||
public RequestInfoUpdate fillAccountFromRelation(Account account, Long requestId, boolean checkClearingMemberCategory) {
|
||||
Long companyId = account.getCompanyId();
|
||||
Collection<Relation> relations;
|
||||
ImdgPredicateBuilder relationPredicateBuilder = relationMap.predicateBuilder();
|
||||
ImdgPredicate finalRelationPredicate;
|
||||
if (checkClearingMemberCategory) {
|
||||
ImdgPredicateBuilder clearingMemberCategoryPredicateBuilder = clearingMemberCategoryMap.predicateBuilder();
|
||||
ImdgPredicate companyIdEquals = clearingMemberCategoryPredicateBuilder.equals("companyId", companyId);
|
||||
Collection<ClearingMemberCategory> clearingMemberCategories = clearingMemberCategoryMap.getCollectionObjectsByPredicate(companyIdEquals);
|
||||
|
||||
if (clearingMemberCategories.isEmpty())
|
||||
return makeError(requestId, AccountError.ClearingCategoryNotFound, companyId, "(any)");
|
||||
if (clearingMemberCategories.size() > 1)
|
||||
log.warn("ClearingMemberCategory for companyId {} contains multiply elements, use first", companyId);
|
||||
ClearingMemberCategory clearingMemberCategory = clearingMemberCategories.iterator().next();
|
||||
|
||||
ImdgPredicate consumerIdPredicate = relationPredicateBuilder.equals("consumerId", companyId);
|
||||
ImdgPredicate servicePredicate;
|
||||
String clearingCategoryValue = clearingMemberCategory.getClearingMemberCategory();
|
||||
if (IEnumKey.contains(clearingCategoryValue, ClearingCategory.B, ClearingCategory.I, ClearingCategory.V)) {
|
||||
servicePredicate = relationPredicateBuilder.equals("service", ru.spcex.platform.enumeration.Service.MKR.getKey());
|
||||
} else if (IEnumKey.contains(clearingCategoryValue, ClearingCategory.F, ClearingCategory.C)) {
|
||||
servicePredicate = relationPredicateBuilder.equals("service", ru.spcex.platform.enumeration.Service.FOND.getKey());
|
||||
} else {
|
||||
log.info("ClearingCategoryNotFound with clearingCategoryValue={} not implemented. Do not search Relation.", clearingCategoryValue);
|
||||
return null;
|
||||
//return makeError(requestId, AccountError.ClearingCategoryNotFound, companyId, clearingCategoryValue + " (case not implemented)");
|
||||
}
|
||||
finalRelationPredicate = relationPredicateBuilder.and(consumerIdPredicate, servicePredicate);
|
||||
relations = relationMap.getCollectionObjectsByPredicate(finalRelationPredicate);
|
||||
} else {
|
||||
finalRelationPredicate = relationPredicateBuilder.equals("consumerId", companyId);
|
||||
relations = relationMap.getCollectionObjectsByPredicate(finalRelationPredicate);
|
||||
}
|
||||
|
||||
if (relations.isEmpty()) {
|
||||
//return makeError(requestId, AccountError.WrongFieldValue, "companyId", finalRelationPredicate.toString());
|
||||
log.info("Relation not found: {}", finalRelationPredicate.toString());
|
||||
return null;
|
||||
}
|
||||
if (relations.size() > 1)
|
||||
log.warn("Relation for consumerId {} contains multiply elements, use first", companyId);
|
||||
Relation relation = relations.iterator().next();
|
||||
account.setRelationId(relation.getId());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public RequestInfoUpdate makeError(Long reqId, AccountError accountError, Object... args) {
|
||||
String errMsg = messageResolver.resolve(new EnumMessage(accountError, args));
|
||||
return new RequestInfoUpdate()
|
||||
.setId(reqId)
|
||||
.setStatus(Status.Error)
|
||||
.setMessage(errMsg);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,334 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
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.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.ClearingAccount;
|
||||
import ru.clearing.classes.statics.data.account.DepoAccount;
|
||||
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
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.account.CorrespondentAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.CorrespondentAccountUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountTerminationRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonIdRequest;
|
||||
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.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.enumeration.*;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
public class AccountService extends QueueConsumer implements InitializingBean {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final ImdgProvider imdgProvider;
|
||||
private final Imdg<Account> accountMap;
|
||||
private final Imdg<ClearingMemberCategory> clearingMemberCategoryMap;
|
||||
private final Imdg<Relation> relationMap;
|
||||
private final KafkaSender kafkaSender;
|
||||
private final IMessageResolver messageResolver;
|
||||
private final UserRoleVerification userRoleVerification;
|
||||
private final ValidationHelper validationHelper;
|
||||
private final AccountHelper accountHelper;
|
||||
private final InformationAccountService informationAccountService;
|
||||
private final Function<CorrespondentAccountNewRequest, IValidator> accountNewRequestValidator;
|
||||
private final Function<CorrespondentAccountUpdateRequest, IValidator> accountUpdateRequestValidator;
|
||||
private final Function<CommonIdRequest, IValidator> accountBlockRequestValidator;
|
||||
|
||||
@Autowired
|
||||
public AccountService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaProducer,
|
||||
ImdgProvider imdgProvider,
|
||||
KafkaSender kafkaSender,
|
||||
IMessageResolver messageResolver,
|
||||
UserRoleVerification userRoleVerification,
|
||||
ValidationHelper validationHelper,
|
||||
AccountHelper accountHelper,
|
||||
InformationAccountService informationAccountService,
|
||||
@Qualifier("correspondentAccountNewRequestValidator")
|
||||
Function<CorrespondentAccountNewRequest, IValidator> accountNewRequestValidator,
|
||||
@Qualifier("correspondentAccountUpdateRequestValidator")
|
||||
Function<CorrespondentAccountUpdateRequest, IValidator> accountUpdateRequestValidator,
|
||||
@Qualifier("correspondentAccountBlockRequestValidator")
|
||||
Function<CommonIdRequest, IValidator> accountBlockRequestValidator) {
|
||||
super(kafkaQueue, kafkaProducer);
|
||||
this.accountHelper = accountHelper;
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.accountMap = imdgProvider.getImdg(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
this.clearingMemberCategoryMap = imdgProvider.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class
|
||||
);
|
||||
this.relationMap = imdgProvider.getImdg(
|
||||
IMDGDistributedNames.Map_Relation, Relation.class
|
||||
);
|
||||
this.kafkaSender = kafkaSender;
|
||||
this.messageResolver = messageResolver;
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.validationHelper = validationHelper;
|
||||
this.informationAccountService = informationAccountService;
|
||||
this.accountNewRequestValidator = accountNewRequestValidator;
|
||||
this.accountUpdateRequestValidator = accountUpdateRequestValidator;
|
||||
this.accountBlockRequestValidator = accountBlockRequestValidator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
imdgProvider.waitAvailable();
|
||||
callback(CorrespondentAccountNewRequest.class)
|
||||
.setFunction(this::accountCorrespondentNew)
|
||||
.forDestination(Consts.DESTINATION_CORRESPONDENT_ACCOUNT_NEW, callbacks::put);
|
||||
callback(CorrespondentAccountUpdateRequest.class)
|
||||
.setFunction(this::correspondentAccountUpdate)
|
||||
.forDestination(Consts.DESTINATION_CORRESPONDENT_ACCOUNT_UPDATE, callbacks::put);
|
||||
callback(CommonIdRequest.class)
|
||||
.setFunction(this::correspondentAccountBlock)
|
||||
.forDestination(Consts.DESTINATION_CORRESPONDENT_ACCOUNT_BLOCK, callbacks::put);
|
||||
|
||||
callback(AccountTerminationRequest.class)
|
||||
.setFunction(this::accountTerminationForCompany)
|
||||
.forDestination(Consts.ACCOUNT_TERMINATION, callbacks::put);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
public RequestInfoUpdate accountCorrespondentNew(BaseRequest<CorrespondentAccountNewRequest> userRequest) {
|
||||
log.debug("CorrespondentAccountNewRequest received");
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, accountNewRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
CorrespondentAccountNewRequest req = userRequest.getRequestPayload();
|
||||
|
||||
Instant now = Instant.now();
|
||||
Account account = new Account();
|
||||
account.setCompanyId(req.getCompanyId());
|
||||
account.setAccount(req.getAccount());
|
||||
if (AccountType.Info.equalsByKey(req.getAccountType())) {
|
||||
Long infoSequenceId = informationAccountService.accountNextId();
|
||||
String accountValue = informationAccountService.generateInfoAccount(infoSequenceId);
|
||||
log.trace("New info-account SequenceId={} account={}", infoSequenceId, accountValue);
|
||||
account.setAccount(accountValue);
|
||||
}
|
||||
account.setAccountType(req.getAccountType());
|
||||
if (req.getStatus() == null) {
|
||||
account.setStatus(WorkflowStatus.Active.getKey());
|
||||
log.trace("Status not set in request. Use default: {}", account.getStatus());
|
||||
} else {
|
||||
account.setStatus(req.getStatus());
|
||||
}
|
||||
account.setCreated(now);
|
||||
account.setUpdated(now);
|
||||
|
||||
requestInfoUpdate = accountHelper.fillAccountFromRelation(account, userRequest.getId(), false);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
Long newId = null;
|
||||
if (AccountType.Corr.equalsByKey(account.getAccountType())) {
|
||||
// default, дополнительные таблицы не требуются
|
||||
newId = accountMap.insert(account);
|
||||
} else {
|
||||
// Транзакцией
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
imdgTransaction.beginTransaction();
|
||||
boolean txOk = false;
|
||||
try {
|
||||
Imdg<Account> accountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
newId = accountMap.insert(account);
|
||||
|
||||
if (AccountType.Corr.equalsByKey(account.getAccountType())) {
|
||||
// default, дополнительные таблицы не требуются
|
||||
} else if (AccountType.Info.equalsByKey(account.getAccountType()))
|
||||
makeInfoPart(imdgTransaction, account);
|
||||
else if (AccountType.Depo.equalsByKey(account.getAccountType()))
|
||||
makeDepoPart(imdgTransaction, account, req);
|
||||
else if (AccountType.Clrn.equalsByKey(account.getAccountType()))
|
||||
makeClrnPart(imdgTransaction, account);
|
||||
else {
|
||||
log.warn("Unexpected AccountType={}. Do not create additional record to other table's", account.getAccountType());
|
||||
}
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
} else {
|
||||
log.debug("failed insert, new account id {} rollback", newId);
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.debug("successfully processed, new account id {}", newId);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void makeInfoPart(ImdgTransaction imdgTransaction, Account account) {
|
||||
Imdg<InformationAccount> informationAccountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class);
|
||||
InformationAccount infoAcc = new InformationAccount();
|
||||
infoAcc.setAccountId(account.getId());
|
||||
Account firstAccountAntl = accountMap.getFirstObjectByFieldValues(Map.of(
|
||||
"companyId", Sender.One.getId(),
|
||||
"accountType", AccountType.Anlt.getKey()
|
||||
));
|
||||
if (firstAccountAntl == null) {
|
||||
log.warn("Can not find 1 ANTL account for fill information ClearingAccountId.");
|
||||
} else {
|
||||
infoAcc.setClearingAccountId(firstAccountAntl.getId());
|
||||
}
|
||||
infoAcc.setCompanyId(account.getCompanyId());
|
||||
Long infoId = informationAccountMap.insert(infoAcc);
|
||||
log.debug("For account id={} make InformationAccount id={}", account.getId(), infoId);
|
||||
}
|
||||
|
||||
protected void makeDepoPart(ImdgTransaction imdgTransaction, Account account, CorrespondentAccountNewRequest req) {
|
||||
Imdg<DepoAccount> depoAccountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
|
||||
DepoAccount depoAcc = new DepoAccount();
|
||||
depoAcc.setAccountId(account.getId());
|
||||
depoAcc.setCompanyId(account.getCompanyId());
|
||||
if (account.getAccount() != null && account.getAccount().contains("BC")) {
|
||||
depoAcc.setDepoAccountType(DepoAccountType.C.getKey());
|
||||
} else {
|
||||
//todo в реквесте нет поля depoAcc.setDepoAccountType(req.getDepoAccountType());
|
||||
}
|
||||
Long depoId = depoAccountMap.insert(depoAcc);
|
||||
log.debug("For account id={} make DepoAccount id={}", account.getId(), depoId);
|
||||
}
|
||||
|
||||
protected void makeClrnPart(ImdgTransaction imdgTransaction, Account account) {
|
||||
Imdg<ClearingAccount> clearingAccountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);
|
||||
ClearingAccount clnrAcc = new ClearingAccount();
|
||||
clnrAcc.setAccountId(account.getId());
|
||||
clnrAcc.setCompanyId(account.getCompanyId());
|
||||
Long clrnId = clearingAccountMap.insert(clnrAcc);
|
||||
log.debug("For account id={} make ClearingAccount id={}", account.getId(), clrnId);
|
||||
}
|
||||
|
||||
public RequestInfoUpdate correspondentAccountUpdate(BaseRequest<CorrespondentAccountUpdateRequest> userRequest) {
|
||||
log.debug("CorrespondentAccountUpdateRequest received");
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, accountUpdateRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
CorrespondentAccountUpdateRequest request = userRequest.getRequestPayload();
|
||||
|
||||
Account account = accountMap.getSingleObjectByID(request.getId());
|
||||
if (request.getAccountType() != null && !request.getAccountType().equals(account.getAccountType())) {
|
||||
requestInfoUpdate = makeError(userRequest.getId(), AccountError.WrongFieldValue, "accountType");
|
||||
return requestInfoUpdate;
|
||||
}
|
||||
|
||||
if (request.getStatus() != null) account.setStatus(request.getStatus());
|
||||
|
||||
account.setUpdated(Instant.now());
|
||||
|
||||
accountMap.update(account);
|
||||
|
||||
log.debug("successfully processed, update account id {}", account.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
public RequestInfoUpdate correspondentAccountBlock(BaseRequest<CommonIdRequest> userRequest) {
|
||||
log.debug("AccountBlockRequest received");
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, accountBlockRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
CommonIdRequest request = userRequest.getRequestPayload();
|
||||
|
||||
Account account = accountMap.getSingleObjectByID(request.getId());
|
||||
account.setStatus(ServiceStatus.Blocked.getKey());
|
||||
account.setUpdated(Instant.now());
|
||||
|
||||
accountMap.update(account);
|
||||
|
||||
log.debug("successfully processed, block account id {}", account.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public RequestInfoUpdate accountTerminationForCompany(BaseRequest<AccountTerminationRequest> userRequest) {
|
||||
log.debug("AccountTerminationRequest received, id={}", userRequest.getId());
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate; // never - system
|
||||
|
||||
AccountTerminationRequest req = userRequest.getRequestPayload();
|
||||
final Long companyId = req.getCompanyId();
|
||||
Collection<Account> accounts = accountMap.getCollectionObjectsBySQL("companyId=" + companyId);
|
||||
log.trace("Found {} accounts (will be terminated) by company {}", accounts.size(), companyId);
|
||||
int blockCount = 0;
|
||||
ImdgTransaction tx = imdgProvider.newTransaction();
|
||||
boolean txOk = false;
|
||||
try {
|
||||
tx.beginTransaction();
|
||||
for (Account account : accounts) {
|
||||
//Account account = accountMap.getSingleObjectByID(request.getId());
|
||||
if (!ServiceStatus.Blocked.equalsByKey(account.getStatus())) {
|
||||
account.setStatus(ServiceStatus.Blocked.getKey());
|
||||
account.setUpdated(Instant.now());
|
||||
accountMap.update(account);
|
||||
blockCount++;
|
||||
}
|
||||
}
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk)
|
||||
tx.commitTransaction();
|
||||
else
|
||||
tx.beginTransaction();
|
||||
}
|
||||
log.debug("For company {} block {} account (of {} account)", companyId, blockCount, accounts.size());
|
||||
|
||||
Long reqId = kafkaSender.sendRequestToQueue(Consts.ACCOUNT_TERMINATION_STEP2, req);
|
||||
log.info("On termination request id={} send to next step {} new request id={}",
|
||||
userRequest.getId(), Consts.ACCOUNT_TERMINATION_STEP2, reqId);
|
||||
|
||||
log.debug("successfully processed, account termination");
|
||||
return null;
|
||||
}
|
||||
|
||||
private RequestInfoUpdate makeError(Long reqId, AccountError accountError, Object... args) {
|
||||
String errMsg = messageResolver.resolve(new EnumMessage(accountError, args));
|
||||
return new RequestInfoUpdate()
|
||||
.setId(reqId)
|
||||
.setStatus(Status.Error)
|
||||
.setMessage(errMsg);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,122 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.account.*;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
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.account.AccountSymbolsNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonIdRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||
import ru.spcex.clearing.util.services.RequestHelper;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
public class AccountSymbolsService extends QueueConsumer implements InitializingBean {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private final ValidationHelper validationHelper;
|
||||
private final UserRoleVerification userRoleVerification;
|
||||
|
||||
private final ImdgProvider imdgProvider;
|
||||
private final Imdg<AccountSymbols> accountSymbolsImdg;
|
||||
|
||||
private final RequestHelper requestHelper;
|
||||
private final Function<AccountSymbolsNewRequest, IValidator> accountSymbolsNewRequestValidator;
|
||||
|
||||
private final IMessageResolver messageResolver;
|
||||
private final Producer<String, Object> kafkaProducer;
|
||||
private final KafkaSender kafkaSender;
|
||||
|
||||
public AccountSymbolsService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaProducer,
|
||||
KafkaSender kafkaSender,
|
||||
ImdgProvider imdgProvider,
|
||||
ValidationHelper validationHelper,
|
||||
UserRoleVerification userRoleVerification,
|
||||
IMessageResolver messageResolver,
|
||||
RequestHelper requestHelper,
|
||||
@Qualifier("accountSymbolsDepoNewRequest")
|
||||
Function<AccountSymbolsNewRequest, IValidator> accountSymbolsNewRequestValidator
|
||||
) {
|
||||
super(kafkaQueue, kafkaProducer);
|
||||
this.kafkaProducer = kafkaProducer;
|
||||
this.kafkaSender = kafkaSender;
|
||||
this.validationHelper = validationHelper;
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.requestHelper = requestHelper;
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.accountSymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_AccountSymbols, AccountSymbols.class);
|
||||
this.accountSymbolsNewRequestValidator = accountSymbolsNewRequestValidator;
|
||||
this.messageResolver = messageResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
imdgProvider.waitAvailable();
|
||||
callback(AccountSymbolsNewRequest.class)
|
||||
.setFunction(this::accountSymbolsNew)
|
||||
.forDestination(Consts.DESTINATION_DEPO_ACCOUNT_SYMBOLS_NEW, callbacks::put);
|
||||
callback(CommonIdRequest.class)
|
||||
.setFunction(this::accountSymbolsDelete)
|
||||
.forDestination(Consts.DESTINATION_DEPO_ACCOUNT_SYMBOLS_DELETE, callbacks::put);
|
||||
init();
|
||||
}
|
||||
|
||||
protected RequestInfoUpdate accountSymbolsNew(BaseRequest<AccountSymbolsNewRequest> userRequest) {
|
||||
log.debug("AccountSymbolsNewRequest received, id={}", userRequest.getId());
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, accountSymbolsNewRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
AccountSymbolsNewRequest req = userRequest.getRequestPayload();
|
||||
|
||||
Long id = accountSymbolsImdg.nextIDSequenceFor();
|
||||
AccountSymbols accountSymbols = new AccountSymbols();
|
||||
accountSymbols.setId(id);
|
||||
accountSymbols.setAccountId(req.getAccountId());
|
||||
accountSymbols.setAccountSymbolValue(req.getAccountSymbolValue());
|
||||
|
||||
accountSymbolsImdg.insert(accountSymbols);
|
||||
|
||||
log.debug("successfully processed, id {}. New accountSymbols.id={} was created", id, accountSymbols.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
protected RequestInfoUpdate accountSymbolsDelete(BaseRequest<CommonIdRequest> userRequest) {
|
||||
log.debug("AccountSymbolsDeleteRequest(CommonIdRequest) received, id={}", userRequest.getId());
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
CommonIdRequest req = userRequest.getRequestPayload();
|
||||
|
||||
AccountSymbols accountSymbols = accountSymbolsImdg.getSingleObjectByID(req.getId());
|
||||
if (accountSymbols == null) {
|
||||
return requestHelper.makeErrorResponse(userRequest, AccountError.AccountNotFound, req.getId());
|
||||
}
|
||||
|
||||
accountSymbolsImdg.delete(accountSymbols);
|
||||
|
||||
log.debug("successfully processed, id {}. New accountSymbols.id={} was deleted", userRequest.getId(), accountSymbols.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,230 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
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.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.BankAccount;
|
||||
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.account.BankAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonIdRequest;
|
||||
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.AccountType;
|
||||
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.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
public class BankAccountService extends QueueConsumer implements InitializingBean {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final Imdg<BankAccount> bankAccountMap;
|
||||
private final Imdg<Account> accountMap;
|
||||
private final ImdgProvider imdgProvider;
|
||||
|
||||
private final UserRoleVerification userRoleVerification;
|
||||
private final ValidationHelper validationHelper;
|
||||
|
||||
private final AccountHelper accountService;
|
||||
|
||||
private final Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator;
|
||||
private final Function<BankAccountUpdateRequest, IValidator> bankAccountUpdateRequestValidator;
|
||||
private final Function<CommonIdRequest, IValidator> bankAccountBlockRequestValidator;
|
||||
|
||||
@Autowired
|
||||
public BankAccountService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaProducer,
|
||||
ImdgProvider imdgProvider,
|
||||
UserRoleVerification userRoleVerification,
|
||||
ValidationHelper validationHelper,
|
||||
AccountHelper accountService,
|
||||
@Qualifier("bankAccountNewRequestValidator")
|
||||
Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator,
|
||||
@Qualifier("bankAccountUpdateRequestValidator")
|
||||
Function<BankAccountUpdateRequest, IValidator> bankAccountUpdateRequestValidator,
|
||||
@Qualifier("bankAccountBlockRequestValidator")
|
||||
Function<CommonIdRequest, IValidator> bankAccountBlockRequestValidator) {
|
||||
super(kafkaQueue, kafkaProducer);
|
||||
this.bankAccountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
this.accountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.validationHelper = validationHelper;
|
||||
this.accountService = accountService;
|
||||
this.bankAccountNewRequestValidator = bankAccountNewRequestValidator;
|
||||
this.bankAccountUpdateRequestValidator = bankAccountUpdateRequestValidator;
|
||||
this.bankAccountBlockRequestValidator = bankAccountBlockRequestValidator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
callback(BankAccountNewRequest.class)
|
||||
.setFunction(this::bankAccountNew)
|
||||
.forDestination(Consts.DESTINATION_BANK_ACCOUNT_NEW, callbacks::put);
|
||||
callback(BankAccountUpdateRequest.class)
|
||||
.setFunction(this::bankAccountUpdate)
|
||||
.forDestination(Consts.DESTINATION_BANK_ACCOUNT_UPDATE, callbacks::put);
|
||||
callback(CommonIdRequest.class)
|
||||
.setFunction(this::bankAccountBlock)
|
||||
.forDestination(Consts.DESTINATION_BANK_ACCOUNT_BLOCK, callbacks::put);
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
public RequestInfoUpdate bankAccountNew(BaseRequest<BankAccountNewRequest> userRequest) {
|
||||
log.debug("BankAccountNewRequest received");
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, bankAccountNewRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
BankAccountNewRequest req = userRequest.getRequestPayload();
|
||||
|
||||
Instant now = Instant.now();
|
||||
Account account = new Account();
|
||||
account.setAccount(req.getAccount());
|
||||
account.setAccountType(AccountType.Bank.getKey());
|
||||
if (req.getStatus() == null) {
|
||||
log.trace("Status not set in request. Use default: {}", account.getStatus());
|
||||
account.setStatus(WorkflowStatus.Active.getKey());
|
||||
} else {
|
||||
account.setStatus(req.getStatus());
|
||||
}
|
||||
account.setCompanyId(req.getCompanyId());
|
||||
account.setCreated(now);
|
||||
account.setUpdated(now);
|
||||
requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId(), false);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
Long bankAccountId = -1L;
|
||||
Long accountId = -1L;
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
boolean txOk = false;
|
||||
imdgTransaction.beginTransaction();
|
||||
try {
|
||||
Imdg<BankAccount> bankAccountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
Imdg<Account> accountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
accountId = accountMap.insert(account);
|
||||
|
||||
BankAccount bankAccount = new BankAccount();
|
||||
bankAccount.setBankIdentificationCode(req.getBankIdentificationCode());
|
||||
bankAccount.setBankName(req.getBankName());
|
||||
bankAccount.setCorrespondentAccount(req.getCorrespondentAccount());
|
||||
bankAccount.setCorrespondentAccountName(req.getCorrespondentAccountName());
|
||||
bankAccount.setCurrency(req.getCurrency());
|
||||
bankAccount.setDestination(req.getDestination());
|
||||
bankAccount.setTaxpayerIdentificationNumber(req.getTaxpayerIdentificationNumber());
|
||||
bankAccount.setTaxRegistrationReasonCode(req.getTaxRegistrationReasonCode());
|
||||
bankAccount.setAccount(req.getAccount());
|
||||
bankAccount.setCompanyId(req.getCompanyId());
|
||||
bankAccount.setAccountId(accountId);
|
||||
bankAccountId = bankAccountMap.insert(bankAccount);
|
||||
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
log.debug("successfully processed, new bank account id {}, account id {}", bankAccountId, accountId);
|
||||
} else {
|
||||
log.debug("failed insert, new bank account id {}, new account id {} (if id = -1 then insert is failed)",
|
||||
bankAccountId,
|
||||
accountId);
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private RequestInfoUpdate bankAccountUpdate(BaseRequest<BankAccountUpdateRequest> userRequest) {
|
||||
BankAccountUpdateRequest req = userRequest.getRequestPayload();
|
||||
log.debug("BankAccountUpdateRequest received id = {}", req.getId());
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, bankAccountUpdateRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
BankAccount bankAccount = bankAccountMap.getSingleObjectByID(req.getId());
|
||||
bankAccount.setBankIdentificationCode(req.getBankIdentificationCode());
|
||||
bankAccount.setBankName(req.getBankName());
|
||||
bankAccount.setCorrespondentAccount(req.getCorrespondentAccount());
|
||||
bankAccount.setCorrespondentAccountName(req.getCorrespondentAccountName());
|
||||
bankAccount.setCurrency(req.getCurrency());
|
||||
bankAccount.setDestination(req.getDestination());
|
||||
bankAccount.setTaxpayerIdentificationNumber(req.getTaxpayerIdentificationNumber());
|
||||
bankAccount.setTaxRegistrationReasonCode(req.getTaxRegistrationReasonCode());
|
||||
bankAccount.setAccount(req.getAccount());
|
||||
|
||||
Account account = accountMap.getSingleObjectByID(bankAccount.getAccountId());
|
||||
account.setAccount(req.account);
|
||||
account.setUpdated(Instant.now());
|
||||
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
boolean txOk = false;
|
||||
imdgTransaction.beginTransaction();
|
||||
try {
|
||||
Imdg<BankAccount> bankAccountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
Imdg<Account> accountMap = imdgTransaction.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
accountMap.update(account);
|
||||
bankAccountMap.update(bankAccount);
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
log.debug("successfully processed, new bank account id {}, account id {}",
|
||||
bankAccount.getId(),
|
||||
account.getId());
|
||||
} else {
|
||||
log.debug("failed update, bank account id {}, new account id {}",
|
||||
bankAccount.getId(),
|
||||
account.getId());
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
log.debug("successfully update, existing bankAccount with id {}", bankAccount.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
private RequestInfoUpdate bankAccountBlock(BaseRequest<CommonIdRequest> userRequest) {
|
||||
CommonIdRequest req = userRequest.getRequestPayload();
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, bankAccountBlockRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
log.debug("CommonIdRequest received id = {}", req.getId());
|
||||
BankAccount bankAccount = bankAccountMap.getSingleObjectByID(req.getId());
|
||||
|
||||
Account account = accountMap.getSingleObjectByID(bankAccount.getAccountId());
|
||||
account.setStatus(ServiceStatus.Blocked.getKey());
|
||||
account.setUpdated(Instant.now());
|
||||
|
||||
accountMap.update(account);
|
||||
//без изменений bankAccountMap.update(bankAccount);
|
||||
|
||||
log.debug("successfully block, existing bankAccount with id {}", bankAccount.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,617 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.commons.lang3.tuple.MutableTriple;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
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.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.ClearingAccount;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.clearing.classes.statics.data.misc.Notification;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.clearing.classes.statics.data.sdf.SDf52;
|
||||
import ru.clearing.platform.dictionary.ClearingCategoryDictionary;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
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.account.ClearingAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountSdf01Request;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountSdfRequestPart;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.AccountSdfToStatementRequestPart;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.StatementRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.utilities.NotificationFeedbackRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.utilities.NotificationNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.serialization.LogFormatter;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.clearing.util.services.RequestHelper;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.enumeration.*;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.utils.collection.Pair;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IErrorEnumId;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
@Service
|
||||
public class ClearingAccountService extends QueueConsumer implements InitializingBean {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final KafkaSender kafkaSender;
|
||||
private final AccountHelper accountService;
|
||||
private final SDFProcessService sdfProcessService;
|
||||
private final ValidationHelper validationHelper;
|
||||
private final ImdgProvider imdgProvider;
|
||||
private final IMessageResolver messageResolver;
|
||||
private final RequestHelper requestHelper;
|
||||
private final Function<ClearingAccountNewRequest, IValidator> clearingAccountNewRequestValidator;
|
||||
private final Function<ClearingAccountUpdateRequest, IValidator> clearingAccountUpdateRequestValidator;
|
||||
|
||||
private final Imdg<Account> accountImdg;
|
||||
private final Imdg<ClearingAccount> clearingAccountImdg;
|
||||
private final Imdg<Company> companyImdg;
|
||||
private final Imdg<Relation> relationImdg;
|
||||
private final Imdg<ClearingMemberCategory> clearingMemberCategoryImdg;
|
||||
private final Imdg<ClearingCategoryDictionary> clearingCategoryImdg;
|
||||
private final Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
|
||||
private final Imdg<Notification> notificationImdg;
|
||||
|
||||
@Autowired
|
||||
public ClearingAccountService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaResponseQueue,
|
||||
KafkaSender kafkaSender,
|
||||
AccountHelper accountService,
|
||||
SDFProcessService sdfProcessService,
|
||||
ValidationHelper validationHelper,
|
||||
ImdgProvider imdgProvider,
|
||||
IMessageResolver messageResolver,
|
||||
RequestHelper requestHelper,
|
||||
@Qualifier("clearingAccountNewRequestValidator")
|
||||
Function<ClearingAccountNewRequest, IValidator> clearingAccountNewRequestValidator,
|
||||
@Qualifier("clearingAccountUpdateRequestValidator")
|
||||
Function<ClearingAccountUpdateRequest, IValidator> clearingAccountUpdateRequestValidator) {
|
||||
super(kafkaQueue, kafkaResponseQueue);
|
||||
this.kafkaSender = kafkaSender;
|
||||
this.accountService = accountService;
|
||||
this.sdfProcessService = sdfProcessService;
|
||||
this.validationHelper = validationHelper;
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.messageResolver = messageResolver;
|
||||
this.requestHelper = requestHelper;
|
||||
this.clearingAccountNewRequestValidator = clearingAccountNewRequestValidator;
|
||||
this.clearingAccountUpdateRequestValidator = clearingAccountUpdateRequestValidator;
|
||||
|
||||
this.accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
this.clearingAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);
|
||||
this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
this.relationImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||
this.clearingMemberCategoryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
|
||||
this.clearingCategoryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ClearingCategoryDictionary, ClearingCategoryDictionary.class);
|
||||
this.tradingClearingRegistryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
this.notificationImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Notification, Notification.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
callback(ClearingAccountNewRequest.class)
|
||||
.setFunction(this::clearingAccountNew)
|
||||
.forDestination(Consts.DESTINATION_CLEARING_ACCOUNT_NEW, callbacks::put);
|
||||
callback(ClearingAccountUpdateRequest.class)
|
||||
.setFunction(this::clearingAccountUpdate)
|
||||
.forDestination(Consts.DESTINATION_CLEARING_ACCOUNT_UPDATE, callbacks::put);
|
||||
callback(AccountSdf01Request.class)
|
||||
.setFunction(this::accountNewSdf01)
|
||||
.forDestination(Consts.ACCOUNT_NEW_SDF01, callbacks::put);
|
||||
|
||||
callback(StatementRequest.class)
|
||||
.setFunction(this::accountUpdateSdf52)
|
||||
.forDestination(Consts.ACCOUNT_PROCESS_SDF52, callbacks::put);
|
||||
callback(NotificationFeedbackRequest.class)
|
||||
.setFunction(this::accountUpdateSdf52_part2Notification)
|
||||
.forDestination(Consts.ACCOUNT_NOTIFICATION_FEEDBACK, callbacks::put);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
public RequestInfoUpdate clearingAccountNew(BaseRequest<ClearingAccountNewRequest> userRequest) {
|
||||
RequestInfoUpdate requestInfoUpdate = validationHelper.validateTillFirstError(
|
||||
userRequest, clearingAccountNewRequestValidator
|
||||
);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
ClearingAccountNewRequest req = userRequest.getRequestPayload();
|
||||
|
||||
Instant now = Instant.now();
|
||||
Account account = new Account();
|
||||
account.setAccount(req.getAccount());
|
||||
account.setAccountType(AccountType.Clrn.getKey());
|
||||
if (req.getStatus() == null) {
|
||||
account.setStatus(WorkflowStatus.Active.getKey());
|
||||
log.trace("Status not set in request. Use default: {}", account.getStatus());
|
||||
} else {
|
||||
account.setStatus(req.getStatus());
|
||||
}
|
||||
account.setCompanyId(req.getCompanyId());
|
||||
account.setCreated(now);
|
||||
account.setUpdated(now);
|
||||
requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId(), true);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
Long clearingAccountId = -1L;
|
||||
Long accountId = -1L;
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
boolean txOk = false;
|
||||
imdgTransaction.beginTransaction();
|
||||
ClearingAccount clearingAccount = null;
|
||||
try {
|
||||
Imdg<Account> accountImdg = imdgTransaction.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Imdg<ClearingAccount> clearingAccountImdg = imdgTransaction.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);
|
||||
accountId = accountImdg.insert(account);
|
||||
|
||||
clearingAccount = new ClearingAccount();
|
||||
clearingAccount.setCompanyId(req.getCompanyId());
|
||||
clearingAccount.setAccountId(accountId);
|
||||
clearingAccount.setClearingAccountType(req.getClearingAccountType());
|
||||
clearingAccountId = clearingAccountImdg.insert(clearingAccount);
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
log.debug("successfully processed, new clearing account id {}, account id {}", clearingAccountId, accountId);
|
||||
} else {
|
||||
log.debug("failed insert, new clearing account id {}, new account id {} (if id = -1 then insert is failed)",
|
||||
clearingAccountId,
|
||||
accountId);
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public RequestInfoUpdate clearingAccountUpdate(BaseRequest<ClearingAccountUpdateRequest> userRequest) {
|
||||
RequestInfoUpdate requestInfoUpdate = validationHelper.validateTillFirstError(
|
||||
userRequest, clearingAccountUpdateRequestValidator
|
||||
);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
ClearingAccountUpdateRequest req = userRequest.getRequestPayload();
|
||||
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
boolean txOk = false;
|
||||
imdgTransaction.beginTransaction();
|
||||
try {
|
||||
Imdg<Account> accountImdg = imdgTransaction.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Imdg<ClearingAccount> clearingAccountImdg = imdgTransaction.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);
|
||||
|
||||
ImdgPredicateBuilder pb = accountImdg.predicateBuilder();
|
||||
ImdgPredicate accountValuePredicate = pb.equals("account", req.getAccount());
|
||||
ImdgPredicate accountStatusPredicate = pb.equals("status", ServiceStatus.Active.getKey());
|
||||
ImdgPredicate accountTypePredicate = pb.equals("accountType", AccountType.Clrn.getKey());
|
||||
ImdgPredicate finalPredicate = pb.and(accountValuePredicate,
|
||||
accountStatusPredicate,
|
||||
accountTypePredicate);
|
||||
|
||||
Account account = accountImdg.getCollectionObjectsByPredicate(finalPredicate).iterator().next();
|
||||
Long accountId = account.getId();
|
||||
|
||||
ClearingAccount clearingAccount = clearingAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", accountId));
|
||||
if (clearingAccount == null)
|
||||
return requestHelper.makeErrorResponse(userRequest, AccountError.AccountNotFound, account.getAccount());
|
||||
|
||||
Integer statusValue = req.getStatus();
|
||||
if (statusValue == 0) account.setStatus(ServiceStatus.Blocked.getKey());
|
||||
else if (statusValue == 1) account.setStatus(ServiceStatus.Active.getKey());
|
||||
else if (statusValue == 2) account.setStatus(ServiceStatus.Closed.getKey());
|
||||
account.setUpdated(Instant.now());
|
||||
|
||||
accountImdg.update(account);
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) imdgTransaction.commitTransaction();
|
||||
else imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public RequestInfoUpdate accountNewSdf01(BaseRequest<AccountSdf01Request> userRequest) {
|
||||
log.debug("AccountSdf01Request received, id={}", userRequest.getId());
|
||||
|
||||
AccountSdf01Request req = userRequest.getRequestPayload();
|
||||
List<AccountSdfToStatementRequestPart> accountToStatement = new ArrayList<>();
|
||||
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
boolean txOk = false;
|
||||
imdgTransaction.beginTransaction();
|
||||
try {
|
||||
Imdg<Account> accountImdg = imdgTransaction.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Imdg<ClearingAccount> clearingAccountImdg = imdgTransaction.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);
|
||||
|
||||
accountsLoop:
|
||||
for (AccountSdfRequestPart accountReq : req.getAccounts()) {
|
||||
Instant now = Instant.now();
|
||||
Account account = new Account();
|
||||
account.setAccount(accountReq.getAccount());
|
||||
account.setAccountType(AccountType.Clrn.getKey());
|
||||
account.setStatus(ServiceStatus.Active.getKey());
|
||||
account.setCompanyId(accountReq.getCompanyId());
|
||||
account.setCreated(now);
|
||||
account.setUpdated(now);
|
||||
RequestInfoUpdate requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId(), true);
|
||||
if (requestInfoUpdate != null) {
|
||||
log.warn("Error fill new account from relation. {}", /*account.getId(),*/ requestInfoUpdate.getMessage());
|
||||
{
|
||||
AccountSdfToStatementRequestPart responsePart = new AccountSdfToStatementRequestPart();
|
||||
responsePart.setSdfId(accountReq.getSdfId());
|
||||
responsePart.setErrorCode(AccountError.ClearingCategoryNotFound.getId()); // see accountService.fillAccountFromRelation
|
||||
responsePart.setErrorText(requestInfoUpdate.getMessage());
|
||||
accountToStatement.add(responsePart);
|
||||
continue accountsLoop;
|
||||
}
|
||||
}
|
||||
|
||||
if (accountImdg.getFirstObjectBySQL("account = '%s'".formatted(accountReq.getAccount())) != null) {
|
||||
log.debug("Account {} already exists", accountReq.getAccount());
|
||||
{
|
||||
AccountSdfToStatementRequestPart responsePart = new AccountSdfToStatementRequestPart();
|
||||
responsePart.setSdfId(accountReq.getSdfId());
|
||||
responsePart.setErrorCode(null);
|
||||
responsePart.setErrorText(null);
|
||||
accountToStatement.add(responsePart);
|
||||
continue accountsLoop;
|
||||
}
|
||||
}
|
||||
|
||||
Long clearingAccountId = -1L;
|
||||
Long accountId = -1L;
|
||||
ClearingAccount clearingAccount = null;
|
||||
accountId = accountImdg.insert(account);
|
||||
|
||||
clearingAccount = new ClearingAccount();
|
||||
clearingAccount.setCompanyId(accountReq.getCompanyId());
|
||||
clearingAccount.setAccountId(accountId);
|
||||
clearingAccount.setClearingAccountType(accountReq.getAccountType());
|
||||
clearingAccountId = clearingAccountImdg.insert(clearingAccount);
|
||||
log.debug("New account {}, clearingAccount {} was created.", accountId, clearingAccountId);
|
||||
|
||||
{
|
||||
AccountSdfToStatementRequestPart responsePart = new AccountSdfToStatementRequestPart();
|
||||
responsePart.setSdfId(accountReq.getSdfId());
|
||||
responsePart.setErrorCode(null);
|
||||
responsePart.setErrorText(null);
|
||||
accountToStatement.add(responsePart);
|
||||
}
|
||||
}
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
} else {
|
||||
log.debug("failed insert, new clearing accounts. Request id={}", userRequest.getId());
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sendStatementRequestBack(req.getGroupingSdf01Id(), req.getGroupingSdf02Id(), accountToStatement);
|
||||
log.debug("successfully processed, grouping id={}, processed number={}", req.getGroupingSdf01Id(), accountToStatement.size());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public RequestInfoUpdate accountUpdateSdf52(BaseRequest<StatementRequest> systemRequest) {
|
||||
log.debug("accountUpdateSdf52 StatementRequest received, id={}", systemRequest.getId());
|
||||
|
||||
StatementRequest req = systemRequest.getRequestPayload();
|
||||
Long groupId = req.getGroupId();
|
||||
if (SdfTable.SDF_52 != req.getTable()) {
|
||||
log.warn("Unsupported table {} received on accountUpdateSdf52. Expected only {}.",
|
||||
req.getTable(), SdfTable.SDF_52);
|
||||
}
|
||||
Collection<SDf52> sdfs = sdfProcessService.sdfsByGroupId(groupId);
|
||||
if (sdfs.isEmpty()) {
|
||||
log.info("Do not processing SDF52: S_DF52 not found by groupId={}", groupId);
|
||||
return null;
|
||||
}
|
||||
log.info("start processing {} SDF52: groupId={}", sdfs.size(), groupId);
|
||||
|
||||
List<Pair<SDf52, Account>> toUpdate = new ArrayList<>();
|
||||
List<Triple<SDf52, Account, String>> toProcessSDF53 = new ArrayList<>();
|
||||
{ // 1. Выборка данных
|
||||
for (SDf52 sDf52 : sdfs) {
|
||||
if (sdfProcessService.parseSdf52Status(sDf52.getStatus()) == null) {
|
||||
String msg = messageResolver.resolve(new EnumMessage(AccountError.WrongFieldValue, "status"));
|
||||
log.warn("By generationId={} s_df52[{}] error: {}", groupId, sDf52.getId(), msg);
|
||||
toProcessSDF53.add(new MutableTriple<>(sDf52, null,
|
||||
makeSdfErrorText(AccountError.WrongFieldValue, SDFProcessService.SDF_STATUS_ERROR)));
|
||||
continue;
|
||||
}
|
||||
Company company = sDf52.getDeal() == null ? null : companyImdg.getSingleObjectByFieldValues(Map.of("tradingCode", sDf52.getDeal()));
|
||||
if (company == null) {
|
||||
String msg = messageResolver.resolve(new EnumMessage(AccountError.CompanyNotFound, sDf52.getDeal()));
|
||||
log.warn("By generationId={} s_df52[{}] error: {}", groupId, sDf52.getId(), msg);
|
||||
toProcessSDF53.add(new MutableTriple<>(sDf52, null,
|
||||
makeSdfErrorText(AccountError.CompanyNotFound, SDFProcessService.SDF_STATUS_ERROR_COMPANY_NOT_FOUND)));
|
||||
continue;
|
||||
}
|
||||
Map<String, Comparable<?>> accountQuery = Map.of(
|
||||
"accountType", AccountType.Clrn.getKey(),
|
||||
"account", sDf52.getAccount(),
|
||||
"companyId", company.getId()
|
||||
);
|
||||
Account account = sDf52.getAccount() == null ? null : accountImdg.getFirstObjectByFieldValues(accountQuery);
|
||||
if (account == null) {
|
||||
if (SDFProcessService.SDF52_STATUS_3Open.equals(sDf52.getStatus())) {
|
||||
log.debug("By generationId={} s_df52[{}].status={}, but account not found (query: {}). COntinuse with result OK for status 3",
|
||||
groupId, sDf52.getId(), sDf52.getStatus(), accountQuery);
|
||||
} else {
|
||||
String msg = messageResolver.resolve(new EnumMessage(AccountError.AccountNotFound, sDf52.getAccount()));
|
||||
log.warn("By generationId={} s_df52[{}] (query: {}) error: {}", groupId, sDf52.getId(), accountQuery, msg);
|
||||
toProcessSDF53.add(new MutableTriple<>(sDf52, null,
|
||||
makeSdfErrorText(AccountError.AccountNotFound, SDFProcessService.SDF_STATUS_ERROR_COMPANY_NOT_FOUND)));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
toProcessSDF53.add(new MutableTriple<>(sDf52, account, SDFProcessService.SDF_STATUS_OK));
|
||||
toUpdate.add(new Pair<>(sDf52, account));
|
||||
}
|
||||
}
|
||||
log.debug("Selected to update {} account's", toUpdate.size());
|
||||
|
||||
// 4. to notification
|
||||
List<Long> notificationAccountIds = new ArrayList<>();
|
||||
for (Pair<SDf52, Account> item : toUpdate) {
|
||||
SDf52 sdf = item.getFirst();
|
||||
Account account = item.getSecond();
|
||||
AccountStatus newStatus = sdfProcessService.parseSdf52Status(sdf.getStatus());
|
||||
if (newStatus == null) { // never
|
||||
throw new IllegalArgumentException("Can not parse sdf status " + sdf.getStatus());
|
||||
}
|
||||
if (newStatus.equalsByKey(account.getStatus())) {
|
||||
// одинаковых обычно не бывает.
|
||||
continue;
|
||||
}
|
||||
if (AccountStatus.BLOCKED == newStatus || AccountStatus.CLOSE == newStatus) { // статус 0/2
|
||||
sendNotificationRequest(ObjectType.account_block, account, newStatus);
|
||||
notificationAccountIds.add(account.getId());
|
||||
putNotificationWaiting(systemRequest, item.getFirst(), item.getSecond());
|
||||
}
|
||||
if (AccountStatus.ACTIVE == newStatus) { // статус 1/3
|
||||
sendNotificationRequest(ObjectType.account_active, account, newStatus);
|
||||
notificationAccountIds.add(account.getId());
|
||||
putNotificationWaiting(systemRequest, item.getFirst(), item.getSecond());
|
||||
}
|
||||
}
|
||||
sdfProcessService.process(req, toProcessSDF53);
|
||||
|
||||
log.info("{} account's need wait accept over notification. GroupId={}", notificationAccountIds.size(), groupId);
|
||||
|
||||
log.debug("successfully processed, grouping id={} with {} accounts.",
|
||||
groupId, toUpdate.size());
|
||||
return null;
|
||||
}
|
||||
|
||||
protected RequestInfoUpdate accountUpdateSdf52_part2Notification(BaseRequest<NotificationFeedbackRequest> secondSystemRequest2) {
|
||||
log.debug("accountUpdateSdf52 NotificationFeedbackRequest received, id={}", secondSystemRequest2.getId());
|
||||
SDF52WaitingData trigger = onNotificationResponse(secondSystemRequest2.getRequestPayload());
|
||||
if (trigger == null) {
|
||||
log.trace("Not triggered, continue waiting");
|
||||
return null;
|
||||
} else {
|
||||
log.debug("Triggered, groupId={}, notification's status: {}, last notification user id={}",
|
||||
trigger.getGroupId(), trigger.globalStatus, secondSystemRequest2.getUserId());
|
||||
if (NotificationStatus.ACPT.equalsByKey(trigger.globalStatus)) {
|
||||
return accountUpdateSdf52_part2(trigger.systemRequest, trigger.sdf, trigger.account, secondSystemRequest2);
|
||||
} else if (NotificationStatus.CNCL.equalsByKey(trigger.globalStatus)) {
|
||||
log.debug("groupId={} rejected by user {}.", trigger.getGroupId(), secondSystemRequest2.getUserId());
|
||||
return null;
|
||||
} else {
|
||||
log.warn("Unknown waiting group status \"{}\"", trigger.globalStatus);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected RequestInfoUpdate accountUpdateSdf52_part2(BaseRequest<StatementRequest> systemRequest1,
|
||||
SDf52 sdf, Account account,
|
||||
BaseRequest<NotificationFeedbackRequest> secondSystemRequest2) {
|
||||
// 5. from notification:
|
||||
StatementRequest req = systemRequest1.getRequestPayload();
|
||||
Long groupId = req.getGroupId();
|
||||
log.info("Continue Sdf52 groupId={}, first request id={}, second request id={}",
|
||||
groupId, systemRequest1 == null ? null : systemRequest1.getId(), secondSystemRequest2 == null ? null : secondSystemRequest2.getId());
|
||||
|
||||
int countOfUpdated = 0;
|
||||
|
||||
// 2. обновление данных
|
||||
Instant now = Instant.now();
|
||||
AccountStatus newStatus = sdfProcessService.parseSdf52Status(sdf.getStatus());
|
||||
if (newStatus == null) {
|
||||
throw new IllegalArgumentException("Can not parse sdf status " + sdf.getStatus());
|
||||
}
|
||||
// За долгое время ожидания пользователя счёт мог быть обновлён, прочитать его ещё раз
|
||||
account = accountImdg.getSingleObjectByID(account.getId());
|
||||
if (!newStatus.equalsByKey(account.getStatus())) {
|
||||
// Обновление счёта
|
||||
String oldStatus = account.getStatus();
|
||||
account.setStatus(newStatus.getKey());
|
||||
account.setUpdated(now);
|
||||
accountImdg.update(account);
|
||||
log.trace("S_DF52[{}] do update status to {} for account[{}]",
|
||||
sdf.getId(), newStatus.getKey(), account.getId());
|
||||
if (AccountStatus.ACTIVE.equalsByKey(oldStatus) && AccountStatus.ACTIVE != newStatus) { // счёт заблокировали - значит блокируем ТКР, наоборот не надо.
|
||||
// Отправка в ТКР
|
||||
TradingClearingRegistryUpdateRequest tcrReq = new TradingClearingRegistryUpdateRequest();
|
||||
tcrReq.setMoneyAccountId(account.getId());
|
||||
tcrReq.setCompanyId(account.getCompanyId());
|
||||
tcrReq.setStatus(account.getStatus());
|
||||
Map<String, Long> queryTCR = new HashMap<>();
|
||||
queryTCR.put("moneyAccountId", tcrReq.getMoneyAccountId());
|
||||
if (tcrReq.getCompanyId() != null)
|
||||
queryTCR.put("companyId", tcrReq.getCompanyId());
|
||||
TradingClearingRegistry tcr = tradingClearingRegistryImdg.getFirstObjectByFieldValues(queryTCR);
|
||||
if (tcr == null) {
|
||||
log.warn("TradingClearingRegistry by {} not found, do not send update TCR.", queryTCR);
|
||||
} else {
|
||||
tcrReq.setId(tcr.getId());
|
||||
String destination = Consts.DESTINATION_TRADING_CLEARING_REGISTRY_UPDATE;
|
||||
log.debug("Send message to kafka \"{}\": {}", destination, LogFormatter.toStringWrapper(tcrReq));
|
||||
kafkaSender.sendRequestToQueue(destination, tcrReq);
|
||||
}
|
||||
}
|
||||
countOfUpdated++;
|
||||
} else {
|
||||
log.info("Account[{}] \"{}\" do not updated - same status \"{}\"", account.getId(), account.getAccount(), newStatus);
|
||||
}
|
||||
|
||||
log.debug("successfully processed, grouping id={}. Updated {} accounts.",
|
||||
groupId, countOfUpdated);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String makeSdfErrorText(IErrorEnumId clrError, String sdfCode) {
|
||||
if (clrError == null) return sdfCode;
|
||||
sdfCode = clrError.getId().toString();
|
||||
if (sdfCode.length() > 3)
|
||||
sdfCode = sdfCode.substring(sdfCode.length() - 3);
|
||||
return sdfCode;
|
||||
}
|
||||
|
||||
public void sendStatementRequestBack(Long groupingSdf01Id, Long groupSdf02Id, List<AccountSdfToStatementRequestPart> results) {
|
||||
final String destination = Consts.STATEMENT_PROCESS;
|
||||
StatementRequest request = new StatementRequest();
|
||||
request.setGroupId(groupingSdf01Id);
|
||||
request.setChildGenerationId(groupSdf02Id);
|
||||
request.setAccountCreationResults(results);
|
||||
request.setContinueSdf(true);
|
||||
request.setTable(SdfTable.SDF_01); // по нему запрос получили
|
||||
log.debug("Send message to kafka \"{}\": {}", destination, LogFormatter.toStringWrapper(request));
|
||||
kafkaSender.sendRequestToQueue(destination, request);
|
||||
}
|
||||
|
||||
public Long sendNotificationRequest(ObjectType objectType, Account account, AccountStatus requestToStatus) {
|
||||
String statusText = AccountStatus.BLOCKED == requestToStatus ? "Заблокирован"
|
||||
: AccountStatus.CLOSE == requestToStatus ? "Закрыт"
|
||||
: AccountStatus.ACTIVE == requestToStatus ? "Разблокирован" :
|
||||
requestToStatus.getKey();
|
||||
String message = String.format("Для счета %s будет изменен статус на «%s»", account.getAccount(), statusText);
|
||||
final String destination = Consts.NOTIFICATION_NEW;
|
||||
NotificationNewRequest request = new NotificationNewRequest();
|
||||
request.setObjectType(objectType.getKey());
|
||||
request.setObjectId(account.getId());
|
||||
request.setPriority(Priority.HIGH.getKey());
|
||||
request.setComment(message);
|
||||
log.debug("Send message to kafka \"{}\": {}", destination, LogFormatter.toStringWrapper(request));
|
||||
Long rKey = kafkaSender.sendRequestToQueue(destination, request);
|
||||
log.trace("About account.id={} send notification request id={}", account.getId(), rKey);
|
||||
return rKey;
|
||||
}
|
||||
|
||||
|
||||
// --------- notification apply system -----------
|
||||
public static class SDF52WaitingData {
|
||||
public BaseRequest<StatementRequest> systemRequest;
|
||||
public SDf52 sdf;
|
||||
public Account account;
|
||||
public Long notAnsweredAccountId;
|
||||
public String globalStatus;
|
||||
|
||||
public SDF52WaitingData(BaseRequest<StatementRequest> systemRequest, SDf52 sdf, Account account) {
|
||||
this.systemRequest = systemRequest;
|
||||
this.sdf = sdf;
|
||||
this.account = account;
|
||||
this.notAnsweredAccountId = account.getId();
|
||||
}
|
||||
|
||||
public Long getGroupId() {
|
||||
if (systemRequest != null && systemRequest.getRequestPayload() != null)
|
||||
return systemRequest.getRequestPayload().getGroupId();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected ConcurrentHashMap<Long, SDF52WaitingData> waitingList = new ConcurrentHashMap<>();
|
||||
|
||||
public boolean putNotificationWaiting(BaseRequest<StatementRequest> systemRequest, SDf52 sdf, Account account) {
|
||||
SDF52WaitingData data = new SDF52WaitingData(systemRequest, sdf, account);
|
||||
if (waitingList.contains(data.notAnsweredAccountId)) {
|
||||
log.warn("groupId={} accountId={} already waiting", data.getGroupId(), data.notAnsweredAccountId);
|
||||
}
|
||||
data.globalStatus = null;
|
||||
waitingList.put(data.notAnsweredAccountId, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return triggered SDF52WaitingData or null
|
||||
*/
|
||||
public SDF52WaitingData onNotificationResponse(NotificationFeedbackRequest onNotification) {
|
||||
if (onNotification.getNotificationId() == null) {
|
||||
log.trace("notificationId was empty");
|
||||
return null;
|
||||
}
|
||||
Notification notification = notificationImdg.getSingleObjectByID(onNotification.getNotificationId());
|
||||
if (notification == null) {
|
||||
log.warn("Notification with id={} not exist", onNotification.getNotificationId());
|
||||
return null;
|
||||
}
|
||||
if (!ObjectType.account_active.equalsByKey(notification.getObjectType()) && !ObjectType.account_block.equalsByKey(notification.getObjectType())) {
|
||||
log.warn("Notification[{}].objectType={} not supported", notification.getId(), notification.getObjectType());
|
||||
return null;
|
||||
}
|
||||
if (notification.getObjectId() == null) {
|
||||
log.warn("Notification[{}] with empty objectId", notification.getId());
|
||||
return null;
|
||||
}
|
||||
final Long accountId = notification.getObjectId();
|
||||
log.trace("Match accountId={} by notificationId={}", accountId, notification.getId());
|
||||
SDF52WaitingData inWaitingLst = waitingList.get(accountId);
|
||||
if (inWaitingLst == null) {
|
||||
log.debug("SDF52 waiting list (count {}) not found for accountId={}", waitingList.size(), accountId);
|
||||
return null;
|
||||
}
|
||||
boolean returnTrigger = false;
|
||||
if (NotificationStatus.ACPT.equalsByKey(onNotification.getNotificationStatus())) {
|
||||
log.trace("Triggered ACPT, by accountId={}", accountId);
|
||||
inWaitingLst.globalStatus = onNotification.getNotificationStatus();
|
||||
returnTrigger = true;
|
||||
} else if (NotificationStatus.CNCL.equalsByKey(onNotification.getNotificationStatus())) {
|
||||
log.trace("Triggered CNCL, by accountId={}", accountId);
|
||||
inWaitingLst.globalStatus = onNotification.getNotificationStatus();
|
||||
returnTrigger = true;
|
||||
} else {
|
||||
log.warn("Unknown notification[{}] status={}", onNotification.getNotificationId(), onNotification.getNotificationStatus());
|
||||
}
|
||||
if (returnTrigger) {
|
||||
log.debug("Remove from waiting list accountId={} (list groupId={})", accountId, inWaitingLst.getGroupId());
|
||||
waitingList.remove(inWaitingLst);
|
||||
}
|
||||
if (returnTrigger)
|
||||
return inWaitingLst;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,440 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.apache.kafka.clients.producer.RecordMetadata;
|
||||
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.account.ClientCode;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
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.ClientCodeNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.serialization.LogFormatter;
|
||||
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;
|
||||
import ru.spcex.platform.enumeration.TradingClearingRegistryType;
|
||||
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.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
public class ClientCodeService extends QueueConsumer implements InitializingBean {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final Producer<String, Object> kafkaProducer;
|
||||
private final ImdgId idGenerator;
|
||||
private final ImdgProvider imdgProvider;
|
||||
private final Imdg<ClientCode> clientCodeMap;
|
||||
private final Imdg<TradingClearingRegistry> tradingClearingRegistryMap;
|
||||
|
||||
|
||||
private final Function<ClientCodeNewRequest, IValidator> clientCodeNewRequestValidator;
|
||||
private final Function<ClientCodeUpdateRequest, IValidator> clientCodeUpdateRequestValidator;
|
||||
private final Function<CommonDeleteRequest, IValidator> clientCodeDeleteRequestValidator;
|
||||
private final ValidationHelper validationHelper;
|
||||
private final UserRoleVerification userRoleVerification;
|
||||
private final IMessageResolver messageResolver;
|
||||
private final RequestHelper requestHelper;
|
||||
|
||||
protected TradingClearingRegistryService tradingClearingRegistryService;
|
||||
|
||||
@Autowired
|
||||
public ClientCodeService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaProducer,
|
||||
ImdgProvider imdgProvider,
|
||||
ValidationHelper validationHelper,
|
||||
IMessageResolver messageResolver,
|
||||
RequestHelper requestHelper,
|
||||
TradingClearingRegistryService tradingClearingRegistryService,
|
||||
UserRoleVerification userRoleVerification,
|
||||
@Qualifier("clientCodeNewRequestValidator") Function<ClientCodeNewRequest, IValidator> clientCodeNewRequestValidator,
|
||||
@Qualifier("clientCodeUpdateRequestValidator") Function<ClientCodeUpdateRequest, IValidator> clientCodeUpdateRequestValidator,
|
||||
@Qualifier("clientCodeDeleteRequestValidator") Function<CommonDeleteRequest, IValidator> clientCodeDeleteRequestValidator) {
|
||||
super(kafkaQueue, kafkaProducer);
|
||||
this.kafkaProducer = kafkaProducer;
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.idGenerator = imdgProvider.getImdgIdGenerator();
|
||||
this.clientCodeMap = imdgProvider.getImdg(IMDGDistributedNames.Map_ClientCode, ClientCode.class);
|
||||
this.tradingClearingRegistryMap = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
this.clientCodeNewRequestValidator = clientCodeNewRequestValidator;
|
||||
this.clientCodeUpdateRequestValidator = clientCodeUpdateRequestValidator;
|
||||
this.clientCodeDeleteRequestValidator = clientCodeDeleteRequestValidator;
|
||||
this.validationHelper = validationHelper;
|
||||
this.requestHelper = requestHelper;
|
||||
this.messageResolver = messageResolver;
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.tradingClearingRegistryService = tradingClearingRegistryService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
imdgProvider.waitAvailable();
|
||||
|
||||
callback(ClientCodeNewRequest.class)
|
||||
.setFunction(this::clientCodeNew)
|
||||
.forDestination(Consts.DESTINATION_CLIENT_CODE_NEW, callbacks::put);
|
||||
callback(ClientCodeNewRequest.class)
|
||||
.setFunction(this::clientCodeNewFromApiUmCompany)
|
||||
.forDestination(Consts.DESTINATION_CLIENT_CODE_NEW_UM_COMPANY, callbacks::put);
|
||||
|
||||
callback(ClientCodeUpdateRequest.class)
|
||||
.setFunction(this::clientCodeUpdate)
|
||||
.forDestination(Consts.DESTINATION_CLIENT_CODE_UPDATE, callbacks::put);
|
||||
callback(CommonDeleteRequest.class)
|
||||
.setFunction(this::clientCodeDelete)
|
||||
.forDestination(Consts.DESTINATION_CLIENT_CODE_DELETE, callbacks::put);
|
||||
init();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверки
|
||||
* 3.5.1 если не была найдена запись в tradingClearingRegistry по companyId, moneyAccountId, depoAccountId и tradingClearingRegistryType=B (п 3.5.1)
|
||||
* 3.5.2 если не заполнены поля moneyAccountId ИЛИ moneyAccountId и depoAccountId
|
||||
* @param userRequest
|
||||
* @param moneyAccountId req.getMoneyAccountId()
|
||||
* @param depoAccountId req.getDepoAccountId()
|
||||
* @param companyId req.getCompanyId()
|
||||
* @return
|
||||
*/
|
||||
RequestInfoUpdate crossValidate(BaseRequest<?> userRequest, Long moneyAccountId, Long depoAccountId, Long companyId) {
|
||||
if (moneyAccountId == null) { // Если не заполнены moneyAccountId ИЛИ moneyAccountId и depoAccountId
|
||||
EnumMessage error = null;
|
||||
if (companyId == null) {
|
||||
error = new EnumMessage(AccountError.RequiredFieldEmpty, "companyId");
|
||||
} else {
|
||||
TradingClearingRegistry tcr = tradingClearingRegistryMap.getFirstObjectByFieldValues(Map.of("companyId", companyId));
|
||||
if (tcr==null) {
|
||||
error=new EnumMessage(AccountError.TradingClearingRegistryNotFound, companyId);
|
||||
}
|
||||
}
|
||||
if (error != null) {
|
||||
return requestHelper.makeErrorResponse(userRequest, error);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected RequestInfoUpdate clientCodeNew(BaseRequest<ClientCodeNewRequest> userRequest) {
|
||||
log.debug("ClientCodeNewRequest received {}", userRequest.getId());
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, clientCodeNewRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
ClientCodeNewRequest req = userRequest.getRequestPayload();
|
||||
// дополнительная проверка
|
||||
requestInfoUpdate = crossValidate(userRequest, req.getMoneyAccountId(), req.getDepoAccountId(), req.getCompanyId());
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
if (doCreateTCR) {
|
||||
try {
|
||||
requestInfoUpdate = createAndWaitTCR(userRequest.getId(), null,
|
||||
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
} catch (Exception e) {
|
||||
log.error("Can not wait creation of TCR. request id={};CompanyId={}, MoneyAccountId={}, DepoAccountId={}; {}",
|
||||
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
|
||||
e.toString());
|
||||
return makeErrorResponse(userRequest, AccountError.GeneralError, "Can not create TCR: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
ClientCode newClientCode = buildClientCode(req);
|
||||
clientCodeMap.insert(newClientCode);
|
||||
log.debug("successfully processed, new clientCode id {}", newClientCode.getId());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected RequestInfoUpdate clientCodeNewFromApiUmCompany(BaseRequest<ClientCodeNewRequest> userRequest) {
|
||||
log.debug("ClientCodeNewRequest (UM_COMPANY) received {}", userRequest.getId());
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, clientCodeNewRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
|
||||
ClientCodeNewRequest req = userRequest.getRequestPayload();
|
||||
// дополнительная проверка
|
||||
requestInfoUpdate = crossValidate(userRequest, req.getMoneyAccountId(), req.getDepoAccountId(), req.getCompanyId());
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
if (doCreateTCR) {
|
||||
try {
|
||||
requestInfoUpdate = createAndWaitTCR(userRequest.getId(), null,
|
||||
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
} catch (Exception e) {
|
||||
log.error("Can not wait creation of TCR. request id={};CompanyId={}, MoneyAccountId={}, DepoAccountId={}; {}",
|
||||
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
|
||||
e.toString());
|
||||
return makeErrorResponse(userRequest, AccountError.GeneralError, "Can not create TCR at this moment" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
ClientCode newClientCode = buildClientCode(req);
|
||||
clientCodeMap.insert(newClientCode);
|
||||
log.debug("successfully processed, new clientCode id {}", newClientCode.getId());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected RequestInfoUpdate clientCodeUpdate(BaseRequest<ClientCodeUpdateRequest> userRequest) {
|
||||
ClientCodeUpdateRequest req = userRequest.getRequestPayload();
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, clientCodeUpdateRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
// дополнительная проверка
|
||||
requestInfoUpdate = crossValidate(userRequest, req.getMoneyAccountId(), req.getDepoAccountId(), req.getCompanyId());
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
|
||||
log.debug("ClientCodeUpdateRequest received, id={}", req.getId());
|
||||
ClientCode clientCode = clientCodeMap.getSingleObjectByID(req.getId());
|
||||
if (clientCode == null) {
|
||||
return makeErrorResponse(userRequest, AccountError.RecordNotFound, req.getId());
|
||||
}
|
||||
|
||||
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
if (doCreateTCR) {
|
||||
try {
|
||||
requestInfoUpdate = createAndWaitTCR(userRequest.getId(), clientCode.getId(),
|
||||
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
} catch (Exception e) {
|
||||
log.error("Can not wait creation of TCR. request id={};CompanyId={}, MoneyAccountId={}, DepoAccountId={}; {}",
|
||||
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
|
||||
e.toString());
|
||||
return makeErrorResponse(userRequest, AccountError.GeneralError, "Can not create TCR: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
updateClientCode(clientCode, req);
|
||||
|
||||
clientCodeMap.update(clientCode);
|
||||
log.debug("successfully processed update, id {}", clientCode.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
private RequestInfoUpdate makeErrorResponse(BaseRequest<?> req, AccountError err, Object... arg) {
|
||||
return requestHelper.makeErrorResponse(req, err, arg);
|
||||
}
|
||||
|
||||
protected RequestInfoUpdate clientCodeDelete(BaseRequest<CommonDeleteRequest> userRequest) {
|
||||
log.debug("CommonDeleteRequest received id = {}", userRequest.getId());
|
||||
CommonDeleteRequest req = userRequest.getRequestPayload();
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, clientCodeDeleteRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
ClientCode clientCode = clientCodeMap.getSingleObjectByID(req.getId());
|
||||
if (clientCode.getMoneyAccountId() != null) {
|
||||
log.debug("Blocking clientCode.id = {}: send message to account-service", clientCode.getId());
|
||||
sendBlockTCR(clientCode.getTradingClearingRegistryId(), clientCode.getMoneyAccountId());
|
||||
}
|
||||
log.debug("Blocking clientCode.id={}", clientCode.getId());
|
||||
clientCode.setUpdated(Instant.now());
|
||||
clientCode.setStatus(WorkflowStatus.Blocked.getKey());
|
||||
clientCodeMap.update(clientCode);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
TradingClearingRegistry selectTradingClearingRegistry(Long companyId, Long moneyAccountId, Long depoAccountId) {
|
||||
Map<String, Comparable<?>> query = new HashMap<>();
|
||||
query.put("companyId", companyId);
|
||||
query.put("moneyAccountId", moneyAccountId);
|
||||
query.put("tradingClearingRegistryType", TradingClearingRegistryType.Client_B.getKey());
|
||||
if (depoAccountId != null) {
|
||||
query.put("depoAccountId", depoAccountId);
|
||||
}
|
||||
TradingClearingRegistry result = tradingClearingRegistryMap.getFirstObjectByFieldValues(query);
|
||||
log.trace("TradingClearingRegistry by: {}; {}found", query, result == null ? "not " : "");
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean checkNeedCreateTCR(Long companyId, Long moneyAccountId, Long depoAccountId) {
|
||||
// moneyAccountId обязателен, depoAccountId опционален
|
||||
if (moneyAccountId == null) {
|
||||
return false;
|
||||
}
|
||||
TradingClearingRegistry result = selectTradingClearingRegistry(companyId, moneyAccountId, depoAccountId);
|
||||
if (result == null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected RequestInfoUpdate createAndWaitTCR(Long reqId, Long clientCode,
|
||||
Long companyId, Long moneyAccountId, Long depoAccountId) {
|
||||
log.debug("For request {}, clientCode={} need create TCR: companyId={}, moneyAccountId={}, depoAccountId={}",
|
||||
reqId, clientCode == null ? "new" : clientCode,
|
||||
companyId, moneyAccountId, depoAccountId);
|
||||
BaseRequest<TradingClearingRegistryNewRequest> request = new BaseRequest<>();
|
||||
request.setId(idGenerator.nextId());
|
||||
request.setActionType(ActionType.NEW);
|
||||
TradingClearingRegistryNewRequest requestPayload = new TradingClearingRegistryNewRequest();
|
||||
requestPayload.setCompanyId(companyId);
|
||||
requestPayload.setMoneyAccountId(moneyAccountId);
|
||||
requestPayload.setDepoAccountId(depoAccountId);
|
||||
// requestPayload.setStatus(WorkflowStatus.Active.getKey());
|
||||
requestPayload.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey());
|
||||
request.setRequestPayload(requestPayload);
|
||||
|
||||
// Следующий вызываемый метод обязательно должен быть synchronized.
|
||||
RequestInfoUpdate reply = tradingClearingRegistryService.tradingClearingRegistryNew(request);
|
||||
if (reply != null && Status.Error.equals(reply.getStatus())) {
|
||||
log.warn("tradingClearingRegistryService return error: " + reply.getMessage());
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
|
||||
protected void sendBlockTCR(Long tradingClearingRegistryId, Long moneyAccountId) {
|
||||
if (tradingClearingRegistryId == null) {
|
||||
throw new IllegalArgumentException("tradingClearingRegistryId was null");
|
||||
}
|
||||
BaseRequest<TradingClearingRegistryUpdateRequest> request = new BaseRequest<>();
|
||||
request.setId(idGenerator.nextId());
|
||||
request.setActionType(ActionType.UPDATE);
|
||||
TradingClearingRegistryUpdateRequest requestPayload = new TradingClearingRegistryUpdateRequest();
|
||||
requestPayload.setId(tradingClearingRegistryId);
|
||||
requestPayload.setStatus(WorkflowStatus.Blocked.getKey());
|
||||
request.setRequestPayload(requestPayload);
|
||||
|
||||
log.debug("Send message to kafka \"{}\": {}", Consts.DESTINATION_TRADING_CLEARING_REGISTRY_UPDATE, LogFormatter.toStringWrapper(request));
|
||||
try {
|
||||
sendMessage(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_UPDATE, request);
|
||||
} catch (Exception e) {
|
||||
log.error("Can not send block TCR message, {}", e.toString());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param queue Consts.*
|
||||
* @param message BaseRequest
|
||||
* @return
|
||||
*/
|
||||
private Long sendMessage(String queue, BaseRequest<?> message) {
|
||||
Long sentRequestId = message.getId();
|
||||
if (sentRequestId == null) {
|
||||
throw new IllegalArgumentException("Message " + message.getClass().getSimpleName() + " required id.");
|
||||
}
|
||||
log.debug("Send to \"{}\" message {} id={}", queue, message.getActionType(), sentRequestId);
|
||||
try {
|
||||
Future<RecordMetadata> send = kafkaProducer.send(new ProducerRecord<>(queue, message));
|
||||
send.get();
|
||||
return sentRequestId;
|
||||
} catch (InterruptedException e) {
|
||||
log.error("Interrupt when send message, {}", ExceptionUtils.getStackTrace(e));
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException("Thread interrupted when send message to " + queue, e);
|
||||
} catch (ExecutionException e) {
|
||||
log.error("Error at send message, {} cause: {}", e.toString(), ExceptionUtils.getStackTrace(e.getCause()));
|
||||
throw new RuntimeException("Send message error", e.getCause());
|
||||
} catch (Exception e) {
|
||||
log.error("Unexpected exception when send message: {}", ExceptionUtils.getStackTrace(e));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param req требуется заполнить tradingClearingRegistryId по tradingClearingRegistry.code
|
||||
* @return
|
||||
*/
|
||||
private ClientCode buildClientCode(ClientCodeNewRequest req) {
|
||||
ClientCode clientCode = new ClientCode();
|
||||
// clientCode.setId(idSequence.newId()); add in insert
|
||||
clientCode.setCreated(Instant.now());
|
||||
clientCode.setUpdated(clientCode.getCreated());
|
||||
|
||||
clientCode.setCompanyId(req.getCompanyId());
|
||||
clientCode.setCode(req.getCode());
|
||||
|
||||
if (req.getMoneyAccountId() != null) {
|
||||
TradingClearingRegistry tradingClearingRegistry = selectTradingClearingRegistry(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
if (tradingClearingRegistry == null) {
|
||||
log.warn("TCR not found: CompanyId {}, MoneyAccountId {}, DepoAccountId {}",
|
||||
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
} else {
|
||||
clientCode.setTradingClearingRegistryId(tradingClearingRegistry.getId());
|
||||
}
|
||||
}
|
||||
|
||||
clientCode.setMoneyAccountId(req.getMoneyAccountId());
|
||||
clientCode.setDepoAccountId(req.getDepoAccountId());
|
||||
clientCode.setStatus(req.getStatus());
|
||||
|
||||
return clientCode;
|
||||
}
|
||||
|
||||
private void updateClientCode(ClientCode clientCode, ClientCodeUpdateRequest req) {
|
||||
assert clientCode.getId() != null && clientCode.getId().equals(req.getId());
|
||||
|
||||
clientCode.setCompanyId(req.getCompanyId());
|
||||
clientCode.setCode(req.getCode());
|
||||
|
||||
if (req.getMoneyAccountId() != null) {
|
||||
TradingClearingRegistry tradingClearingRegistry = selectTradingClearingRegistry(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
if (tradingClearingRegistry == null) {
|
||||
log.warn("TCR not found: CompanyId {}, MoneyAccountId {}, DepoAccountId {}",
|
||||
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
} else {
|
||||
clientCode.setTradingClearingRegistryId(tradingClearingRegistry.getId());
|
||||
}
|
||||
}
|
||||
|
||||
clientCode.setTradingClearingRegistryId(req.getTradingClearingRegistryId());
|
||||
clientCode.setMoneyAccountId(req.getMoneyAccountId());
|
||||
clientCode.setDepoAccountId(req.getDepoAccountId());
|
||||
clientCode.setStatus(req.getStatus());
|
||||
|
||||
clientCode.setUpdated(Instant.now());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,237 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.DepoAccount;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
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.account.DepoAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountSdf01Request;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountSdfRequestPart;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.AccountSdfToStatementRequestPart;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.StatementRequest;
|
||||
import ru.spcex.clearing.platform.messaging.serialization.LogFormatter;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.enumeration.*;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
public class DepoAccountService extends QueueConsumer implements InitializingBean {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private final KafkaSender kafkaSender;
|
||||
private final ValidationHelper validationHelper;
|
||||
private final ImdgProvider imdgProvider;
|
||||
private final AccountHelper accountService;
|
||||
private final Function<DepoAccountNewRequest, IValidator> depoAccountNewRequestValidator;
|
||||
|
||||
public DepoAccountService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaProducer,
|
||||
KafkaSender kafkaSender,
|
||||
ValidationHelper validationHelper,
|
||||
ImdgProvider imdgProvider,
|
||||
AccountHelper accountService,
|
||||
@Qualifier("depoAccountNewRequestValidator")
|
||||
Function<DepoAccountNewRequest, IValidator> depoAccountNewRequestValidator) {
|
||||
super(kafkaQueue, kafkaProducer);
|
||||
this.kafkaSender = kafkaSender;
|
||||
this.validationHelper = validationHelper;
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.accountService = accountService;
|
||||
this.depoAccountNewRequestValidator = depoAccountNewRequestValidator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
callback(DepoAccountNewRequest.class)
|
||||
.setFunction(this::depoAccountNew)
|
||||
.forDestination(Consts.DESTINATION_DEPO_ACCOUNT_NEW, callbacks::put);
|
||||
callback(AccountSdf01Request.class)
|
||||
.setFunction(this::accountNewSdf08)
|
||||
.forDestination(Consts.ACCOUNT_NEW_SDF08, callbacks::put);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
public RequestInfoUpdate depoAccountNew(BaseRequest<DepoAccountNewRequest> userRequest) {
|
||||
log.debug("DepoAccountNewRequest received");
|
||||
RequestInfoUpdate requestInfoUpdate = validationHelper.validateTillFirstError(
|
||||
userRequest, depoAccountNewRequestValidator
|
||||
);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
DepoAccountNewRequest req = userRequest.getRequestPayload();
|
||||
|
||||
Instant now = Instant.now();
|
||||
Account account = new Account();
|
||||
account.setAccount(req.getAccount());
|
||||
account.setAccountType(AccountType.Depo.getKey());
|
||||
if (req.getStatus() == null) {
|
||||
account.setStatus(WorkflowStatus.Active.getKey());
|
||||
log.trace("Status not set in request. Use default: {}", account.getStatus());
|
||||
} else {
|
||||
account.setStatus(req.getStatus());
|
||||
}
|
||||
account.setCompanyId(req.getCompanyId());
|
||||
account.setCreated(now);
|
||||
account.setUpdated(now);
|
||||
requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId(), true);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
Long depoAccountId = -1L;
|
||||
Long accountId = -1L;
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
boolean txOk = false;
|
||||
imdgTransaction.beginTransaction();
|
||||
DepoAccount depoAccount = null;
|
||||
try {
|
||||
Imdg<Account> accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Imdg<DepoAccount> depoAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
|
||||
accountId = accountImdg.insert(account);
|
||||
|
||||
depoAccount = new DepoAccount();
|
||||
depoAccount.setCompanyId(req.getCompanyId());
|
||||
depoAccount.setAccountId(accountId);
|
||||
if (account.getAccount() != null && account.getAccount().contains("BC")) {
|
||||
depoAccount.setDepoAccountType(DepoAccountType.C.getKey());
|
||||
} else {
|
||||
depoAccount.setDepoAccountType(req.getDepoAccountType());
|
||||
}
|
||||
depoAccountId = depoAccountImdg.insert(depoAccount);
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
log.debug("successfully processed, new depo account id {}, account id {}", depoAccountId, accountId);
|
||||
} else {
|
||||
log.debug("failed insert, new depo account id {}, new account id {} (if id = -1 then insert is failed)",
|
||||
depoAccountId,
|
||||
accountId);
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public RequestInfoUpdate accountNewSdf08(BaseRequest<AccountSdf01Request> userRequest) {
|
||||
log.debug("AccountSdf08Request received, id={}", userRequest.getId());
|
||||
|
||||
AccountSdf01Request req = userRequest.getRequestPayload();
|
||||
List<AccountSdfToStatementRequestPart> accountToStatement = new ArrayList<>();
|
||||
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
boolean txOk = false;
|
||||
imdgTransaction.beginTransaction();
|
||||
try {
|
||||
Imdg<Account> accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Imdg<DepoAccount> depoAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
|
||||
accountsLoop:
|
||||
for (AccountSdfRequestPart accountReq : req.getAccounts()) {
|
||||
|
||||
// DepoAccountNewRequest req = userRequest.getRequestPayload();
|
||||
|
||||
Instant now = Instant.now();
|
||||
Account account = new Account();
|
||||
account.setAccount(accountReq.getAccount());
|
||||
account.setAccountType(AccountType.Depo.getKey());
|
||||
account.setStatus(ServiceStatus.Active.getKey());
|
||||
account.setCompanyId(accountReq.getCompanyId());
|
||||
account.setCreated(now);
|
||||
account.setUpdated(now);
|
||||
RequestInfoUpdate requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId(), true);
|
||||
if (requestInfoUpdate != null) {
|
||||
log.warn("Error fill new account from relation. {}", /*account.getId(),*/ requestInfoUpdate.getMessage());
|
||||
{
|
||||
AccountSdfToStatementRequestPart responsePart = new AccountSdfToStatementRequestPart();
|
||||
responsePart.setSdfId(accountReq.getSdfId());
|
||||
responsePart.setErrorCode(AccountError.ClearingCategoryNotFound.getId()); // see accountService.fillAccountFromRelation
|
||||
responsePart.setErrorText(requestInfoUpdate.getMessage());
|
||||
accountToStatement.add(responsePart);
|
||||
continue accountsLoop;
|
||||
}
|
||||
}
|
||||
if (accountImdg.getFirstObjectBySQL("account = '%s'".formatted(accountReq.getAccount())) != null) {
|
||||
log.debug("Account {} already exists", accountReq.getAccount());
|
||||
{
|
||||
AccountSdfToStatementRequestPart responsePart = new AccountSdfToStatementRequestPart();
|
||||
responsePart.setSdfId(accountReq.getSdfId());
|
||||
responsePart.setErrorCode(null);
|
||||
responsePart.setErrorText(null);
|
||||
accountToStatement.add(responsePart);
|
||||
continue accountsLoop;
|
||||
}
|
||||
}
|
||||
|
||||
Long depoAccountId = -1L;
|
||||
Long accountId = -1L;
|
||||
|
||||
accountId = accountImdg.insert(account);
|
||||
|
||||
DepoAccount depoAccount = new DepoAccount();
|
||||
depoAccount.setCompanyId(accountReq.getCompanyId());
|
||||
depoAccount.setAccountId(accountId);
|
||||
if (account.getAccount() != null && account.getAccount().contains("BC")) {
|
||||
depoAccount.setDepoAccountType(DepoAccountType.C.getKey());
|
||||
} else {
|
||||
depoAccount.setDepoAccountType(accountReq.getAccountType());
|
||||
}
|
||||
depoAccountId = depoAccountImdg.insert(depoAccount);
|
||||
|
||||
|
||||
|
||||
log.debug("New account {}, depoAccount {} was created.", accountId, depoAccountId);
|
||||
|
||||
{
|
||||
AccountSdfToStatementRequestPart responsePart = new AccountSdfToStatementRequestPart();
|
||||
responsePart.setSdfId(accountReq.getSdfId());
|
||||
responsePart.setErrorCode(null);
|
||||
responsePart.setErrorText(null);
|
||||
accountToStatement.add(responsePart);
|
||||
}
|
||||
}
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
} else {
|
||||
log.debug("failed insert, new clearing accounts. Request id={}", userRequest.getId());
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
sendStatementRequestBack(req.getGroupingSdf01Id(), req.getGroupingSdf02Id(), accountToStatement);
|
||||
log.debug("successfully processed, grouping id={}, processed number={}", req.getGroupingSdf01Id(), accountToStatement.size());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void sendStatementRequestBack(Long groupingSdf01Id, Long groupingSdf02Id, List<AccountSdfToStatementRequestPart> results) {
|
||||
StatementRequest request = new StatementRequest();
|
||||
request.setGroupId(groupingSdf01Id);
|
||||
request.setChildGenerationId(groupingSdf02Id);
|
||||
request.setContinueSdf(true); //fixme????
|
||||
request.setAccountCreationResults(results);
|
||||
request.setTable(SdfTable.SDF_08); // по нему запрос получили
|
||||
log.debug("Send message to kafka \"{}\": {}", Consts.STATEMENT_PROCESS, LogFormatter.toStringWrapper(request));
|
||||
kafkaSender.sendRequestToQueue(Consts.STATEMENT_PROCESS, request);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,349 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
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.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
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.account.InformationAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.reports.NotificationRequest;
|
||||
import ru.spcex.clearing.platform.messaging.serialization.LogFormatter;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||
import ru.spcex.clearing.util.services.RequestHelper;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
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.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Service
|
||||
public class InformationAccountService extends QueueConsumer implements InitializingBean {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final KafkaSender kafkaSender;
|
||||
private final IMessageResolver messageResolver;
|
||||
private final UserRoleVerification userRoleVerification;
|
||||
private final ImdgProvider imdgProvider;
|
||||
private final ValidationHelper validationHelper;
|
||||
private final AccountHelper accountHelper;
|
||||
private final RequestHelper requestHelper;
|
||||
private final Function<InformationAccountNewRequest, IValidator> infoAccountNewRequestValidator;
|
||||
private final Imdg<InformationAccount> informationAccountImdg;
|
||||
private final Imdg<Account> accountImdg;
|
||||
/**
|
||||
* Кэш-счётчик сквозных номеров счетов.
|
||||
* См. accountNextId()
|
||||
*/
|
||||
protected AtomicLong infoCounter;
|
||||
|
||||
@Autowired
|
||||
public InformationAccountService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaResponseQueue,
|
||||
KafkaSender kafkaSender,
|
||||
IMessageResolver messageResolver,
|
||||
UserRoleVerification userRoleVerification,
|
||||
ImdgProvider imdgProvider,
|
||||
ValidationHelper validationHelper,
|
||||
AccountHelper accountHelper,
|
||||
RequestHelper requestHelper,
|
||||
@Qualifier("informationAccountNewRequestValidator")
|
||||
Function<InformationAccountNewRequest, IValidator> infoAccountNewRequestValidator) {
|
||||
super(kafkaQueue, kafkaResponseQueue);
|
||||
this.kafkaSender = kafkaSender;
|
||||
this.messageResolver = messageResolver;
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.validationHelper = validationHelper;
|
||||
this.accountHelper = accountHelper;
|
||||
this.requestHelper = requestHelper;
|
||||
this.infoAccountNewRequestValidator = infoAccountNewRequestValidator;
|
||||
this.informationAccountImdg = imdgProvider.getImdg(
|
||||
IMDGDistributedNames.Map_InformationAccount, InformationAccount.class
|
||||
);
|
||||
this.accountImdg = imdgProvider.getImdg(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
callback(InformationAccountNewRequest.class)
|
||||
.setFunction(this::informationAccountNew)
|
||||
.forDestination(Consts.DESTINATION_INFORMATION_ACCOUNT_NEW, callbacks::put);
|
||||
callback(InformationAccountNewRequest.class)
|
||||
.setFunction(this::informationAccountSystemNew)
|
||||
.forDestination(Consts.INFORMATION_ACCOUNT_SYSTEM_NEW, callbacks::put);
|
||||
init();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public RequestInfoUpdate informationAccountNew(BaseRequest<InformationAccountNewRequest> userRequest) {
|
||||
log.debug("InformationAccountNewRequest received");
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, infoAccountNewRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
InformationAccountNewRequest req = userRequest.getRequestPayload();
|
||||
|
||||
Long newId = informationAccountImdg.nextIDSequenceFor();
|
||||
Long infoSequenceId = accountNextId();
|
||||
String accountValue = generateInfoAccount(infoSequenceId);
|
||||
log.trace("New info-account id={}, sequenceId={}, account={}", newId, infoSequenceId, accountValue);
|
||||
|
||||
ImdgPredicateBuilder accountPredicateBuilder = accountImdg.predicateBuilder();
|
||||
ImdgPredicate companyIdPredicate = accountPredicateBuilder.equals("companyId", 1L);
|
||||
ImdgPredicate accountTypePredicate = accountPredicateBuilder.equals("accountType", AccountType.Anlt.getKey());
|
||||
ImdgPredicate andPredicate = accountPredicateBuilder.and(companyIdPredicate, accountTypePredicate);
|
||||
Collection<Account> accountsAnlt = accountImdg.getCollectionObjectsByPredicate(andPredicate);
|
||||
if (accountsAnlt.isEmpty()) {
|
||||
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "clearingAccountId");
|
||||
} else if (accountsAnlt.size() > 1) {
|
||||
log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first");
|
||||
}
|
||||
Account anltAccount = accountsAnlt.iterator().next();
|
||||
|
||||
Instant now = Instant.now();
|
||||
Account account = new Account();
|
||||
account.setAccount(req.getAccount());
|
||||
account.setAccountType(AccountType.Info.getKey());
|
||||
if (req.getStatus() == null) {
|
||||
account.setStatus(WorkflowStatus.Active.getKey());
|
||||
log.trace("Status not set in request. Use default: {}", account.getStatus());
|
||||
} else {
|
||||
account.setStatus(req.getStatus());
|
||||
}
|
||||
account.setCompanyId(req.getCompanyId());
|
||||
account.setCreated(now);
|
||||
account.setUpdated(now);
|
||||
|
||||
requestInfoUpdate = accountHelper.fillAccountFromRelation(account, userRequest.getId(), true);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
imdgTransaction.beginTransaction();
|
||||
boolean txOk = false;
|
||||
Long informationAccountId = -1L;
|
||||
Long accountId = -1L;
|
||||
InformationAccount informationAccount = null;
|
||||
try {
|
||||
Imdg<InformationAccount> informationAccountImdg = imdgTransaction.getImdg(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class);
|
||||
Imdg<Account> accountImdg = imdgTransaction.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
|
||||
accountId = accountImdg.insert(account);
|
||||
|
||||
informationAccount = new InformationAccount();
|
||||
informationAccount.setId(newId);
|
||||
informationAccount.setAccountId(accountId);
|
||||
informationAccount.setClearingAccountId(anltAccount.getId());
|
||||
informationAccount.setCompanyId(req.getCompanyId());
|
||||
informationAccountId = informationAccountImdg.insert(informationAccount);
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
log.debug("successfully processed, new information account id {}, new account id {}",
|
||||
informationAccountId,
|
||||
accountId);
|
||||
} else {
|
||||
log.debug("failed insert, new information account id {}, new account id {} (if id = -1 then insert is failed)",
|
||||
informationAccountId,
|
||||
accountId);
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public RequestInfoUpdate informationAccountSystemNew(BaseRequest<InformationAccountNewRequest> userRequest) {
|
||||
log.debug("InformationAccountNewRequest received (system), request id={}", userRequest.getId());
|
||||
|
||||
RequestInfoUpdate requestInfoUpdate;
|
||||
// RequestInfoUpdate requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, infoAccountNewRequestValidator);
|
||||
// if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
final Long forCompanyId = userRequest.getRequestPayload().getCompanyId();
|
||||
|
||||
ImdgPredicateBuilder pb = accountImdg.predicateBuilder();
|
||||
{ // Проверка существования счёта
|
||||
Collection<Account> accountsAnlt = accountImdg.getCollectionObjectsByFieldValues(Map.of(
|
||||
"companyId", forCompanyId,
|
||||
"accountType", AccountType.Info.getKey()
|
||||
));
|
||||
if (!accountsAnlt.isEmpty()) {
|
||||
String trueMessage = messageResolver.resolve(new EnumMessage(AccountError.InfoAccountAlreadyExist, forCompanyId));
|
||||
log.warn("{}", trueMessage);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Long newId = informationAccountImdg.nextIDSequenceFor();
|
||||
Long infoSequenceId = accountNextId(); // требуется последовательность n+1
|
||||
String accountValue = generateInfoAccount(infoSequenceId);
|
||||
log.trace("New info-account id={}, sequenceId={}, account={}", newId, infoSequenceId, accountValue);
|
||||
|
||||
Long anltAccountId = null;
|
||||
{
|
||||
ImdgPredicate andPredicate = pb.and(
|
||||
pb.equals("companyId", 1L),
|
||||
pb.equals("accountType", AccountType.Anlt.getKey())
|
||||
);
|
||||
Collection<Account> accountsAnlt = accountImdg.getCollectionObjectsByPredicate(andPredicate);
|
||||
if (accountsAnlt.isEmpty()) {
|
||||
log.error("Account with {} not exist.", andPredicate);
|
||||
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "clearingAccountId");
|
||||
} else if (accountsAnlt.size() > 1) {
|
||||
log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first");
|
||||
}
|
||||
Account anltAccount = accountsAnlt.iterator().next();
|
||||
anltAccountId = anltAccount.getId();
|
||||
}
|
||||
|
||||
Instant now = Instant.now();
|
||||
Account account = new Account();
|
||||
account.setAccount(accountValue);
|
||||
account.setAccountType(AccountType.Info.getKey());
|
||||
account.setStatus(ServiceStatus.Active.getKey());
|
||||
account.setCompanyId(forCompanyId);
|
||||
account.setCreated(now);
|
||||
account.setUpdated(now);
|
||||
requestInfoUpdate = accountHelper.fillAccountFromRelation(account, userRequest.getId(), false);
|
||||
if (requestInfoUpdate != null) {
|
||||
log.debug("Stop make new account, cause error: {}", requestInfoUpdate.getMessage());
|
||||
return requestInfoUpdate;
|
||||
}
|
||||
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
imdgTransaction.beginTransaction();
|
||||
boolean txOk = false;
|
||||
Long informationAccountId = -1L;
|
||||
Long accountId = -1L;
|
||||
InformationAccount informationAccount = null;
|
||||
try {
|
||||
Imdg<InformationAccount> informationAccountImdg = imdgTransaction.getImdg(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class);
|
||||
Imdg<Account> accountImdg = imdgTransaction.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
accountId = accountImdg.insert(account);
|
||||
|
||||
informationAccount = new InformationAccount();
|
||||
informationAccount.setId(newId);
|
||||
informationAccount.setAccountId(accountId);
|
||||
informationAccount.setClearingAccountId(anltAccountId);
|
||||
informationAccount.setCompanyId(userRequest.getRequestPayload().getCompanyId());
|
||||
informationAccountId = informationAccountImdg.insert(informationAccount);
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
log.debug("successfully processed, new information account id {}, new account id {}",
|
||||
informationAccountId,
|
||||
accountId);
|
||||
} else {
|
||||
log.debug("failed insert, new information account id {}, new account id {} (if id = -1 then insert is failed)",
|
||||
informationAccountId,
|
||||
accountId);
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
// send to kafka
|
||||
sendNotificationToReport(informationAccount, account);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Формирование уведолмения о регистрации УК
|
||||
*/
|
||||
protected void sendNotificationToReport(InformationAccount informationAccount, Account account) {
|
||||
NotificationRequest request = new NotificationRequest();
|
||||
request.setConsumerId(account.getCompanyId());
|
||||
log.debug("Send message to kafka \"{}\": {}", Consts.CREATE_NOTIFICATION_NTCR, LogFormatter.toStringWrapper(request));
|
||||
kafkaSender.sendRequestToQueue(Consts.CREATE_NOTIFICATION_NCMP, request);
|
||||
}
|
||||
|
||||
public String generateInfoAccount(Long id) {
|
||||
return "%d%d%08d%d".formatted(39911, 810, id, 7000);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Сквозной номер инфо-счетов
|
||||
*
|
||||
* @return infoCounter++
|
||||
*/
|
||||
public synchronized Long accountNextId() {
|
||||
if (infoCounter == null) synchronized (this) {
|
||||
if (infoCounter == null) {
|
||||
log.debug("Init account-information counter.");
|
||||
Collection<Account> allInfoAcc = accountImdg.getCollectionObjectsByFieldValues(Map.of("accountType", AccountType.Info.getKey()));
|
||||
if (allInfoAcc.isEmpty()) {
|
||||
infoCounter = new AtomicLong(1);
|
||||
log.debug("No account information on map. n={}", infoCounter.get());
|
||||
} else {
|
||||
Pattern accPattern = Pattern.compile("39911810([0-9]{8})7000");
|
||||
int maxN = 1;
|
||||
int parsedCount = 0;
|
||||
String lastAccount = null; // for debug
|
||||
for (Account acc : allInfoAcc) {
|
||||
try {
|
||||
String number = acc.getAccount();
|
||||
if (StringUtils.isEmpty(number)) continue;
|
||||
lastAccount = number;
|
||||
Matcher m = accPattern.matcher(number);
|
||||
if (m.find()) {
|
||||
String seqNumber = m.group(1);
|
||||
if (StringUtils.isNotEmpty(seqNumber)) {
|
||||
int accN = Integer.parseInt(seqNumber);
|
||||
if (accN > maxN) maxN = accN;
|
||||
}
|
||||
parsedCount++;
|
||||
}
|
||||
} catch (Exception errParse) {
|
||||
log.warn("Error parse account {}: {}", acc.getId(), ExceptionUtils.getStackTrace(errParse));
|
||||
}
|
||||
}
|
||||
infoCounter = new AtomicLong(maxN);
|
||||
log.debug("Parsed {} information accounts ({} pattern match) in map. n={}",
|
||||
allInfoAcc.size(), parsedCount, infoCounter.get());
|
||||
if (parsedCount == 0 && lastAccount != null)
|
||||
log.debug("Last unparseable account: {}", lastAccount);
|
||||
}
|
||||
}
|
||||
}
|
||||
return infoCounter.incrementAndGet();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,160 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.misc.Notification;
|
||||
import ru.clearing.classes.statics.data.sdf.SDf52;
|
||||
import ru.clearing.classes.statics.data.sdf.SDf53;
|
||||
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.balance.ExportToFileRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.StatementRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.utilities.NotificationFeedbackRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.platform.enumeration.AccountStatus;
|
||||
import ru.spcex.platform.enumeration.NotificationStatus;
|
||||
import ru.spcex.platform.enumeration.ObjectType;
|
||||
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.collection.Pair;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
@Service
|
||||
public class SDFProcessService {
|
||||
public static final String SDF_STATUS_OK = "OK"; // (Операция выполнена успешно) - если account обновлена по sDf52;
|
||||
public static final String SDF_STATUS_ERROR_REPEAT = "1"; // (Ошибка. Попытка повторно исполнить операцию)
|
||||
public static final String SDF_STATUS_ERROR_COMPANY_NOT_FOUND = "2"; // (Ошибка. Участник не найден) - если получена ошибка (5013) "Компания %s не найдена" (т.е. account НЕ обновлена по sDf52);
|
||||
public static final String SDF_STATUS_ERROR_LIMIT_SUMM = "3"; // (Ошибка. Сумма списания превышает сумму средств на торговом счете участника в ТС)
|
||||
public static final String SDF_STATUS_ERROR_NO_TRADE = "4"; // (Ошибка. Торги не идут)
|
||||
public static final String SDF_STATUS_ERROR = "9"; // (Другие ошибки, выявленные в КС) - если получены другие ошибки (т.е. account НЕ обновлена по sDf52).
|
||||
|
||||
protected static final Long SDF52_STATUS_0Blocked = 0L;
|
||||
protected static final Long SDF52_STATUS_1Unblocked = 1L;
|
||||
protected static final Long SDF52_STATUS_2Closed = 2L;
|
||||
protected static final Long SDF52_STATUS_3Open = 3L;
|
||||
|
||||
final protected Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected final Producer<String, Object> kafkaResponseQueue;
|
||||
protected final KafkaSender kafkaSender;
|
||||
|
||||
protected final ImdgProvider imdgProvider;
|
||||
protected final ImdgId idGenerator;
|
||||
|
||||
private final Imdg<SDf52> sdf52Imdg;
|
||||
|
||||
public SDFProcessService(
|
||||
Producer<String, Object> kafkaResponseQueue,
|
||||
KafkaSender kafkaSender,
|
||||
ImdgProvider imdgProvider) {
|
||||
this.kafkaResponseQueue = kafkaResponseQueue;
|
||||
this.kafkaSender = kafkaSender;
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.idGenerator = imdgProvider.getImdgIdGenerator();
|
||||
|
||||
this.sdf52Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf52, SDf52.class);
|
||||
}
|
||||
|
||||
public Collection<SDf52> sdfsByGroupId(Long generationId) {
|
||||
Collection<SDf52> sdfs = sdf52Imdg.getCollectionObjectsByFieldValues(Map.of(
|
||||
"generationId", generationId
|
||||
));
|
||||
return sdfs;
|
||||
}
|
||||
|
||||
public void process(StatementRequest req, List<Triple<SDf52, Account, String>> toProcessSDF53) {
|
||||
final Long generationId = req.getGroupId();
|
||||
log.info("Create S_DF53 generationId={} by {} S_DF_52",
|
||||
generationId, toProcessSDF53.size());
|
||||
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||
boolean txOk = false;
|
||||
imdgTransaction.beginTransaction();
|
||||
HashSet<String> fileNames = new HashSet<>();
|
||||
try { // 2. обновление данных, в транзакции
|
||||
Imdg<SDf53> sdf53Imdg = imdgTransaction.getImdg(IMDGDistributedNames.Map_SDf53, SDf53.class);
|
||||
|
||||
Instant now = Instant.now();
|
||||
for (Triple<SDf52, Account, String> item : toProcessSDF53) {
|
||||
SDf53 sDf53 = createBy(item.getLeft(), item.getRight(), now, generationId);
|
||||
sdf53Imdg.insert(sDf53);
|
||||
fileNames.add(item.getLeft().getFileName());
|
||||
}
|
||||
|
||||
txOk = true;
|
||||
} finally {
|
||||
if (txOk) {
|
||||
imdgTransaction.commitTransaction();
|
||||
} else {
|
||||
log.debug("failed create new SDF53, rollback transaction. sdf52 generationId={}", generationId);
|
||||
imdgTransaction.rollbackTransaction();
|
||||
}
|
||||
}
|
||||
|
||||
if (fileNames.size() > 1)
|
||||
log.warn("generationId={}, too many different file names in S_DF52: {}", generationId, fileNames);
|
||||
String fileNameSingle = fileNames.stream().filter(Objects::nonNull).findAny().orElse(null);
|
||||
log.info("Send export command for SDF53 generationId={} with source file name {}",
|
||||
generationId, (fileNameSingle == null ? null : "\"" + fileNameSingle + "\""));
|
||||
messageStatementToExport53(generationId, fileNameSingle);
|
||||
}
|
||||
|
||||
SDf53 createBy(SDf52 sdf52, String result, Instant now, Long newGenerationId) {
|
||||
SDf53 newSdf = new SDf53();
|
||||
newSdf.setId(idGenerator.nextId());
|
||||
newSdf.setAccName(sdf52.getAcc_name());
|
||||
newSdf.setAccount(sdf52.getAccount());
|
||||
newSdf.setDeal(sdf52.getDeal());
|
||||
newSdf.setDate(sdf52.getDate());
|
||||
newSdf.setStatus(sdf52.getStatus());
|
||||
newSdf.setResult(result);
|
||||
newSdf.setGenerationTime(now);
|
||||
newSdf.setGenerationId(sdf52.getGenerationId());
|
||||
if (!Objects.equals(newGenerationId, newSdf.getGenerationId())) { // never
|
||||
log.warn("Different GenerationId={} for sdf53[{}] and GenerationId={} for group of sdf52",
|
||||
newSdf.getGenerationId(), newSdf.getId(), newGenerationId
|
||||
);
|
||||
}
|
||||
newSdf.setInSDfId(sdf52.getId());
|
||||
return newSdf;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param status sdf.getStatus()
|
||||
* @return AccountStatus или null
|
||||
*/
|
||||
public AccountStatus parseSdf52Status(Long status) {
|
||||
if (SDF52_STATUS_1Unblocked.equals(status) || SDF52_STATUS_3Open.equals(status)) {
|
||||
return AccountStatus.ACTIVE;
|
||||
} else if (SDF52_STATUS_0Blocked.equals(status)) {
|
||||
return AccountStatus.BLOCKED;
|
||||
}
|
||||
if (SDF52_STATUS_2Closed.equals(status)) {
|
||||
return AccountStatus.CLOSE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
void messageStatementToExport53(Long groupId, String fileName) {
|
||||
final String destination = Consts.EXPORT_PROCESS; // dbf-exporter
|
||||
ExportToFileRequest request = new ExportToFileRequest();
|
||||
request.setNameOfTable("DF-53"); // SdfTable.SDF_53
|
||||
request.setSdfGroupId(groupId);
|
||||
request.setFileName(fileName);
|
||||
Long msgId = kafkaSender.sendRequestToQueue(destination, request);
|
||||
log.debug("Send ExportToFileRequest({}, {}) message id={} to kafka \"{}\"",
|
||||
groupId, request.getNameOfTable(), msgId, destination);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,498 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.ClearingAccount;
|
||||
import ru.clearing.classes.statics.data.account.DepoAccount;
|
||||
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
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.account.ClientCodeNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.clearing.CreateRegistryRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonIdRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.reports.NotificationRequest;
|
||||
import ru.spcex.clearing.platform.messaging.serialization.LogFormatter;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||
import ru.spcex.clearing.util.services.RequestHelper;
|
||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||
import ru.spcex.platform.enumeration.ServiceStatus;
|
||||
import ru.spcex.platform.enumeration.TradingClearingRegistryPurpose;
|
||||
import ru.spcex.platform.enumeration.TradingClearingRegistryType;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Service
|
||||
public class TradingClearingRegistryService extends QueueConsumer implements InitializingBean {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private final ValidationHelper validationHelper;
|
||||
private final UserRoleVerification userRoleVerification;
|
||||
|
||||
private final ImdgProvider imdgProvider;
|
||||
private final Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
|
||||
private final Imdg<DepoAccount> depoAccountImdg;
|
||||
private final Imdg<ClearingAccount> clearingAccountImdg;
|
||||
private final Imdg<InformationAccount> informationAccountImdg;
|
||||
private final Imdg<Account> accountImdg;
|
||||
private final Imdg<Company> companyImdg;
|
||||
private final Imdg<Relation> relationImdg;
|
||||
|
||||
private final Function<TradingClearingRegistryUpdateRequest, IValidator> tradingClearingRegistryUpdateRequestValidator;
|
||||
private final RequestHelper requestHelper;
|
||||
private final Function<TradingClearingRegistryNewRequest, IValidator> tradingClearingRegistryNewRequestValidator;
|
||||
private final Function<TradingClearingRegistryNewRequest, IValidator> tradingClearingRegistryAutoNewRequestValidator;
|
||||
private final Function<CommonIdRequest, IValidator> tradingClearingRegistryBlockRequestValidator;
|
||||
|
||||
private final IMessageResolver messageResolver;
|
||||
private final Producer<String, Object> kafkaProducer;
|
||||
private final KafkaSender kafkaSender;
|
||||
|
||||
public TradingClearingRegistryService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaProducer,
|
||||
KafkaSender kafkaSender,
|
||||
ImdgProvider imdgProvider,
|
||||
ValidationHelper validationHelper,
|
||||
UserRoleVerification userRoleVerification,
|
||||
IMessageResolver messageResolver,
|
||||
RequestHelper requestHelper,
|
||||
@Qualifier("tradingClearingRegistryNewRequest")
|
||||
Function<TradingClearingRegistryNewRequest, IValidator> tradingClearingRegistryNewRequestValidator,
|
||||
@Qualifier("tradingClearingRegistryUpdateRequest")
|
||||
Function<TradingClearingRegistryUpdateRequest, IValidator> tradingClearingRegistryUpdateRequestValidator,
|
||||
@Qualifier("tradingClearingRegistryBlockRequest")
|
||||
Function<CommonIdRequest, IValidator> tradingClearingRegistryBlockRequestValidator) {
|
||||
super(kafkaQueue, kafkaProducer);
|
||||
this.kafkaProducer = kafkaProducer;
|
||||
this.kafkaSender = kafkaSender;
|
||||
this.validationHelper = validationHelper;
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.requestHelper = requestHelper;
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.tradingClearingRegistryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
this.depoAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
|
||||
this.clearingAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);
|
||||
this.informationAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class);
|
||||
this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
this.accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
this.relationImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
||||
this.tradingClearingRegistryNewRequestValidator = tradingClearingRegistryNewRequestValidator;
|
||||
this.tradingClearingRegistryAutoNewRequestValidator = tradingClearingRegistryNewRequestValidator; // без relation.
|
||||
this.tradingClearingRegistryUpdateRequestValidator = tradingClearingRegistryUpdateRequestValidator;
|
||||
this.tradingClearingRegistryBlockRequestValidator = tradingClearingRegistryBlockRequestValidator;
|
||||
this.messageResolver = messageResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
imdgProvider.waitAvailable();
|
||||
callback(TradingClearingRegistryNewRequest.class) // todo deprecated - unused.
|
||||
.setFunction(this::tradingClearingRegistryAutoNew)
|
||||
.forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, callbacks::put);
|
||||
callback(TradingClearingRegistryNewRequest.class)
|
||||
.setFunction(this::tradingClearingRegistryNew)
|
||||
.forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_NEW, callbacks::put);
|
||||
callback(TradingClearingRegistryUpdateRequest.class)
|
||||
.setFunction(this::tradingClearingRegistryUpdate)
|
||||
.forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_UPDATE, callbacks::put);
|
||||
callback(CommonIdRequest.class)
|
||||
.setFunction(this::tradingClearingRegistryBlock)
|
||||
.forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_BLOCK, callbacks::put);
|
||||
init();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public RequestInfoUpdate tradingClearingRegistryAutoNew(BaseRequest<TradingClearingRegistryNewRequest> userRequest) {
|
||||
log.debug("TradingClearingRegistryNewRequest received");
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, tradingClearingRegistryAutoNewRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
TradingClearingRegistryNewRequest req = userRequest.getRequestPayload();
|
||||
|
||||
Long id = tradingClearingRegistryImdg.nextIDSequenceFor();
|
||||
TradingClearingRegistry tradingClearingRegistry = new TradingClearingRegistry();
|
||||
tradingClearingRegistry.setId(id);
|
||||
tradingClearingRegistry.setCompanyId(req.getCompanyId());
|
||||
tradingClearingRegistry.setMoneyAccountId(req.getMoneyAccountId());
|
||||
tradingClearingRegistry.setDepoAccountId(req.getDepoAccountId());
|
||||
|
||||
Account depoAccountMain = req.getDepoAccountId() != null ? accountImdg.getSingleObjectByID(req.getDepoAccountId()) : null;
|
||||
DepoAccount depoAccount = depoAccountMain != null ? depoAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", req.getDepoAccountId())) : null;
|
||||
|
||||
// InformationAccount infoAccount = null;
|
||||
ClearingAccount clearingAccount = null;
|
||||
Account accountMain = null;
|
||||
if (req.getMoneyAccountId() != null) {
|
||||
clearingAccount = clearingAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", req.getMoneyAccountId()));
|
||||
// if (clearingAccount == null) infoAccount = informationAccountImdg.getSingleObjectByFieldValues(Map.of("accountId", req.getMoneyAccountId()));
|
||||
Long accountId = req.getMoneyAccountId(); //clearingAccount != null ? clearingAccount.getAccountId() : infoAccount.getAccountId();
|
||||
accountMain = accountImdg.getSingleObjectByID(accountId);
|
||||
}
|
||||
|
||||
// кроссвалидация
|
||||
if (req.getMoneyAccountId() == null && (req.getMoneyAccountId() == null || req.getDepoAccountId() == null)) {
|
||||
TradingClearingRegistry registryByCompany = tradingClearingRegistryImdg.getFirstObjectByFieldValues(Map.of("companyId", req.getCompanyId()));
|
||||
if (registryByCompany == null) {
|
||||
log.trace("Not found registry with companyId={}",
|
||||
req.getCompanyId());
|
||||
return requestHelper.makeErrorResponse(userRequest,
|
||||
AccountError.TradingClearingRegistryNotFound,
|
||||
req.getCompanyId());
|
||||
}
|
||||
}
|
||||
|
||||
if (tradingClearingRegistry.getMoneyAccountId() == null && tradingClearingRegistry.getDepoAccountId() != null) {
|
||||
Collection<TradingClearingRegistry> registriesByCompany = tradingClearingRegistryImdg.getCollectionObjectsByFieldValues(Map.of("companyId", req.getCompanyId()));
|
||||
TradingClearingRegistry targetExistTradingClearingRegistry = null;
|
||||
for (TradingClearingRegistry existRegistry : registriesByCompany) {
|
||||
if (existRegistry.getMoneyAccountId() != null && existRegistry.getDepoAccountId() == null) {
|
||||
targetExistTradingClearingRegistry = existRegistry;
|
||||
}
|
||||
}
|
||||
if (targetExistTradingClearingRegistry == null) {
|
||||
log.warn("TradingClearingRegister with MoneyAccountId for companyId={} not found. Search exist accounts for company", req.getCompanyId());
|
||||
Long accountId;
|
||||
InformationAccount infoAccount = null;
|
||||
clearingAccount = clearingAccountImdg.getFirstObjectByFieldValues(Map.of("companyId", req.getCompanyId()));
|
||||
if (clearingAccount == null) {
|
||||
infoAccount = informationAccountImdg.getFirstObjectByFieldValues(Map.of("companyId", req.getCompanyId()));
|
||||
if (infoAccount == null) {
|
||||
log.warn("ClearingAccount and InfoAccount not exist for company {}.", req.getCompanyId());
|
||||
accountId = null;
|
||||
} else {
|
||||
accountId = infoAccount.getAccountId();
|
||||
log.debug("Found account.id={} and infoaccount.id={} by companyId={}", accountId, infoAccount.getId(), req.getCompanyId());
|
||||
}
|
||||
} else {
|
||||
accountId = clearingAccount.getAccountId();
|
||||
log.debug("Found account.id={} and clearingAccount.id={} by companyId={}", accountId, clearingAccount.getId(), req.getCompanyId());
|
||||
}
|
||||
if (accountId != null) {
|
||||
accountMain = accountImdg.getSingleObjectByID(accountId);
|
||||
if (accountMain == null) { // never, только с инконсистентными данными
|
||||
log.warn("Account {} not exist.", accountId);
|
||||
} else {
|
||||
tradingClearingRegistry.setMoneyAccountId(accountId);
|
||||
log.debug("Set tradingClearingRegistry[{}].MoneyAccountId={}", tradingClearingRegistry.getId(), accountId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.debug("Update exist TCR.id={}, set DepoAccountId={}", targetExistTradingClearingRegistry, req.getDepoAccountId());
|
||||
targetExistTradingClearingRegistry.setDepoAccountId(req.getDepoAccountId());
|
||||
targetExistTradingClearingRegistry.setUpdated(Instant.now());
|
||||
tradingClearingRegistryImdg.update(targetExistTradingClearingRegistry);
|
||||
log.debug("successfully processed, id {}. Updated exist TradingClearingRegistry.id={}", id, targetExistTradingClearingRegistry.getId());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
List<String> activeStatuses = Arrays.asList(ServiceStatus.Active.getKey(), ServiceStatus.Reopened.getKey());
|
||||
String status = null;
|
||||
if (depoAccountMain != null && depoAccountMain.getStatus() != null) {
|
||||
if (activeStatuses.contains(depoAccountMain.getStatus()) && activeStatuses.contains(accountMain.getStatus()))
|
||||
status = ServiceStatus.Active.getKey();
|
||||
if (depoAccountMain.getStatus().equals(ServiceStatus.Blocked.getKey()) || accountMain.getStatus().equals(ServiceStatus.Blocked.getKey()))
|
||||
status = ServiceStatus.Blocked.getKey();
|
||||
if (depoAccountMain.getStatus().equals(ServiceStatus.Suspended.getKey()) || accountMain.getStatus().equals(ServiceStatus.Suspended.getKey()))
|
||||
status = ServiceStatus.Suspended.getKey();
|
||||
if (depoAccountMain.getStatus().equals(ServiceStatus.Closed.getKey()) || accountMain.getStatus().equals(ServiceStatus.Closed.getKey()))
|
||||
status = ServiceStatus.Closed.getKey();
|
||||
} else if (accountMain.getStatus() != null) {
|
||||
if (activeStatuses.contains(accountMain.getStatus()))
|
||||
status = ServiceStatus.Active.getKey();
|
||||
if (accountMain.getStatus().equals(ServiceStatus.Blocked.getKey()))
|
||||
status = ServiceStatus.Blocked.getKey();
|
||||
if (accountMain.getStatus().equals(ServiceStatus.Suspended.getKey()))
|
||||
status = ServiceStatus.Suspended.getKey();
|
||||
if (accountMain.getStatus().equals(ServiceStatus.Closed.getKey()))
|
||||
status = ServiceStatus.Closed.getKey();
|
||||
}
|
||||
if (status == null)
|
||||
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, req.getMoneyAccountId());
|
||||
tradingClearingRegistry.setStatus(status);
|
||||
|
||||
String tradingRegistryType;
|
||||
if (depoAccount != null) {
|
||||
tradingRegistryType = depoAccount.getDepoAccountType();
|
||||
} else {
|
||||
if (clearingAccount != null) tradingRegistryType = clearingAccount.getClearingAccountType();
|
||||
else tradingRegistryType = TradingClearingRegistryType.Owner_A.getKey();
|
||||
}
|
||||
tradingClearingRegistry.setTradingClearingRegistryType(tradingRegistryType);
|
||||
|
||||
TradingClearingRegistryPurpose registryPurpose;
|
||||
if (req.getDepoAccountId() != null) registryPurpose = TradingClearingRegistryPurpose.C;
|
||||
else registryPurpose = TradingClearingRegistryPurpose.M;
|
||||
tradingClearingRegistry.setTradingClearingRegistryPurpose(registryPurpose.getKey());
|
||||
|
||||
Company company = companyImdg.getSingleObjectByID(req.getCompanyId());
|
||||
Long seqId = companySequenceNextId(req.getCompanyId(), registryPurpose, tradingRegistryType);
|
||||
String code = makeCode(company.getClearingCode(), registryPurpose, tradingRegistryType, seqId);
|
||||
log.debug("For new TCR.id={} of companyId={} next sequence={}; code={}", id, req.getCompanyId(), seqId, code);
|
||||
tradingClearingRegistry.setCode(code);
|
||||
|
||||
Instant now = Instant.now();
|
||||
tradingClearingRegistry.setCreated(now);
|
||||
tradingClearingRegistry.setUpdated(now);
|
||||
|
||||
tradingClearingRegistryImdg.insert(tradingClearingRegistry);
|
||||
log.debug("New TCR.id={} was created", tradingClearingRegistry.getId());
|
||||
|
||||
// sendNotificationToCompanySvc(tradingClearingRegistry); при автосоздании ТКР в company-service не отправлять.
|
||||
// sendNotificationToClearingSvc(tradingClearingRegistry);
|
||||
sendNotificationToReportSvc(tradingClearingRegistry);
|
||||
sendNotificationToClearingSvc(tradingClearingRegistry);
|
||||
|
||||
log.debug("successfully processed, id {}", id);
|
||||
return null;
|
||||
}
|
||||
|
||||
public synchronized RequestInfoUpdate tradingClearingRegistryNew(BaseRequest<TradingClearingRegistryNewRequest> userRequest) {
|
||||
log.debug("TradingClearingRegistryNewRequest received");
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) {
|
||||
return requestInfoUpdate;
|
||||
}
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, tradingClearingRegistryNewRequestValidator);
|
||||
if (requestInfoUpdate != null) {
|
||||
return requestInfoUpdate;
|
||||
}
|
||||
|
||||
TradingClearingRegistryNewRequest req = userRequest.getRequestPayload();
|
||||
// Дополнительная проверка
|
||||
if (req.getMoneyAccountId() == null && (req.getMoneyAccountId() == null || req.getDepoAccountId() == null)) {
|
||||
TradingClearingRegistry registryByCompany = tradingClearingRegistryImdg.getFirstObjectByFieldValues(Map.of("companyId", req.getCompanyId()));
|
||||
if (registryByCompany == null) {
|
||||
return requestHelper.makeErrorResponse(userRequest,
|
||||
AccountError.TradingClearingRegistryNotFound,
|
||||
"companyId=" + req.getCompanyId());
|
||||
}
|
||||
}
|
||||
|
||||
Long id = tradingClearingRegistryImdg.nextIDSequenceFor();
|
||||
TradingClearingRegistry tradingClearingRegistry = new TradingClearingRegistry();
|
||||
tradingClearingRegistry.setId(id);
|
||||
tradingClearingRegistry.setCompanyId(req.getCompanyId());
|
||||
tradingClearingRegistry.setMoneyAccountId(req.getMoneyAccountId());
|
||||
tradingClearingRegistry.setDepoAccountId(req.getDepoAccountId());
|
||||
|
||||
DepoAccount depoAccount = req.getDepoAccountId() != null ? depoAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", req.getDepoAccountId())) : null;
|
||||
ClearingAccount clearingAccount = req.getMoneyAccountId() != null ? clearingAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", req.getMoneyAccountId())) : null;
|
||||
|
||||
if (req.getStatus() == null) {
|
||||
tradingClearingRegistry.setStatus(ServiceStatus.Active.getKey());
|
||||
log.trace("TCR status in request not set. Use default: {}", tradingClearingRegistry.getStatus());
|
||||
} else {
|
||||
tradingClearingRegistry.setStatus(req.getStatus());
|
||||
log.trace("TCR status in request set: {}", tradingClearingRegistry.getStatus());
|
||||
}
|
||||
|
||||
String tradingRegistryType;
|
||||
if (req.getTradingClearingRegistryType() != null) {
|
||||
tradingRegistryType = req.getTradingClearingRegistryType();
|
||||
} else if (depoAccount != null) {
|
||||
tradingRegistryType = depoAccount.getDepoAccountType();
|
||||
} else {
|
||||
if (clearingAccount != null) tradingRegistryType = clearingAccount.getClearingAccountType();
|
||||
else tradingRegistryType = TradingClearingRegistryType.Owner_A.getKey();
|
||||
}
|
||||
tradingClearingRegistry.setTradingClearingRegistryType(tradingRegistryType);
|
||||
|
||||
TradingClearingRegistryPurpose registryPurpose;
|
||||
if (req.getDepoAccountId() != null) registryPurpose = TradingClearingRegistryPurpose.C;
|
||||
else registryPurpose = TradingClearingRegistryPurpose.M;
|
||||
tradingClearingRegistry.setTradingClearingRegistryPurpose(registryPurpose.getKey());
|
||||
|
||||
Company company = companyImdg.getSingleObjectByID(req.getCompanyId());
|
||||
Long seqId = companySequenceNextId(req.getCompanyId(), registryPurpose, tradingRegistryType);
|
||||
String code = makeCode(company.getClearingCode(), registryPurpose, tradingRegistryType, seqId);
|
||||
log.debug("For new TCR.id={} of companyId={} next sequence={}; code={}", id, req.getCompanyId(), seqId, code);
|
||||
tradingClearingRegistry.setCode(code);
|
||||
|
||||
Instant now = Instant.now();
|
||||
tradingClearingRegistry.setCreated(now);
|
||||
tradingClearingRegistry.setUpdated(now);
|
||||
|
||||
tradingClearingRegistryImdg.insert(tradingClearingRegistry);
|
||||
log.info("New TCR.id={} was created.", tradingClearingRegistry.getId());
|
||||
|
||||
sendNotificationToReportSvc(tradingClearingRegistry);
|
||||
sendNotificationToClearingSvc(tradingClearingRegistry);
|
||||
|
||||
log.debug("successfully processed, id {}", id);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Long companySequenceNextId(Long companyId, TradingClearingRegistryPurpose registryPurpose, String tradingRegistryType) {
|
||||
ImdgPredicateBuilder pb = tradingClearingRegistryImdg.predicateBuilder();
|
||||
Collection<TradingClearingRegistry> existTCR = tradingClearingRegistryImdg.getCollectionObjectsByPredicate(
|
||||
pb.and(
|
||||
pb.equals("companyId", companyId),
|
||||
pb.equals("tradingClearingRegistryPurpose", registryPurpose.getKey()),
|
||||
pb.equals("tradingClearingRegistryType", tradingRegistryType)
|
||||
)
|
||||
);
|
||||
if (existTCR.isEmpty()) {
|
||||
log.trace("For company id={} not found exist TCR.", companyId);
|
||||
return 1L;
|
||||
}
|
||||
log.trace("For company id={} found {} exist TCR.", companyId, existTCR.size());
|
||||
long maxN = 0;
|
||||
for (TradingClearingRegistry tcr : existTCR) {
|
||||
Long codeN = parseCodeSeqId(tcr.getCode());
|
||||
if (codeN != null) {
|
||||
if (maxN < codeN)
|
||||
maxN = codeN;
|
||||
}
|
||||
}
|
||||
return maxN + 1;
|
||||
}
|
||||
|
||||
protected Long parseCodeSeqId(String code) {
|
||||
if (code == null || code.isBlank())
|
||||
return null;
|
||||
try {
|
||||
String toParse = code.trim();
|
||||
if (toParse.length() > 5)
|
||||
toParse = toParse.substring(toParse.length() - 5);
|
||||
return Long.parseLong(toParse);
|
||||
} catch (NumberFormatException nan) {
|
||||
log.warn("Can not parse number from TCR code \"{}\": {}", code, nan.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected String makeCode(String companyClearingCode, TradingClearingRegistryPurpose registryPurpose, String tradingRegistryType, Long id) {
|
||||
String code;
|
||||
code = companyClearingCode;
|
||||
if (code.length() > 4)
|
||||
code = code.substring(code.length() - 4);
|
||||
code = "%4s".formatted(code).replace(' ', '0');
|
||||
code += registryPurpose.getKey(); // C / M / ...
|
||||
String trType = tradingRegistryType + "T"; // 2 символа
|
||||
code += trType;
|
||||
String sId = "%5s".formatted(id).replace(' ', '0');
|
||||
if (sId.length() > 5)
|
||||
sId = sId.substring(sId.length() - 5);
|
||||
code += sId;
|
||||
return code; // 12 имволов
|
||||
}
|
||||
|
||||
public RequestInfoUpdate tradingClearingRegistryUpdate(BaseRequest<TradingClearingRegistryUpdateRequest> userRequest) {
|
||||
log.debug("TradingClearingRegistryUpdateRequest received");
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, tradingClearingRegistryUpdateRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
TradingClearingRegistryUpdateRequest req = userRequest.getRequestPayload();
|
||||
TradingClearingRegistry tradingClearingRegistry = tradingClearingRegistryImdg.getSingleObjectByID(req.getId());
|
||||
|
||||
// кроссвалидация - нельзя менять эти поля:
|
||||
if (req.getMoneyAccountId() != null && !req.getMoneyAccountId().equals(tradingClearingRegistry.getMoneyAccountId())) {
|
||||
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "MoneyAccountId", req.getMoneyAccountId());
|
||||
}
|
||||
if (req.getDepoAccountId() != null && !req.getDepoAccountId().equals(tradingClearingRegistry.getDepoAccountId())) {
|
||||
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "DepoAccountId", req.getDepoAccountId());
|
||||
}
|
||||
// tradingClearingRegistry.setMoneyAccountId(req.getMoneyAccountId());
|
||||
// tradingClearingRegistry.setDepoAccountId(req.getDepoAccountId());
|
||||
|
||||
|
||||
if (req.getStatus() != null && !Objects.equals(req.getStatus(), tradingClearingRegistry.getStatus())) {
|
||||
Instant now = Instant.now();
|
||||
tradingClearingRegistry.setUpdated(now);
|
||||
tradingClearingRegistry.setStatus(req.getStatus());
|
||||
tradingClearingRegistryImdg.update(tradingClearingRegistry);
|
||||
log.debug("Update TCR.id={}.", tradingClearingRegistry.getId());
|
||||
} else {
|
||||
log.debug("Nothing to update TCR.id={}.", tradingClearingRegistry.getId());
|
||||
}
|
||||
|
||||
log.debug("successfully processed, id {}", tradingClearingRegistry.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
public RequestInfoUpdate tradingClearingRegistryBlock(BaseRequest<CommonIdRequest> userRequest) {
|
||||
log.debug("TradingClearingRegistryBlockRequest received");
|
||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, tradingClearingRegistryBlockRequestValidator);
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
|
||||
CommonIdRequest req = userRequest.getRequestPayload();
|
||||
TradingClearingRegistry tradingClearingRegistry = tradingClearingRegistryImdg.getSingleObjectByID(req.getId());
|
||||
|
||||
tradingClearingRegistry.setStatus(ServiceStatus.Blocked.getKey());
|
||||
tradingClearingRegistry.setUpdated(Instant.now());
|
||||
|
||||
tradingClearingRegistryImdg.update(tradingClearingRegistry);
|
||||
|
||||
log.debug("successfully processed, id {}", tradingClearingRegistry.getId());
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* company-service сообщение об успешном добавлении ТКР клиента с параметром tradingClearingRegistry.code
|
||||
*/
|
||||
protected void sendNotificationToCompanySvc(TradingClearingRegistry tradingClearingRegistry) {
|
||||
ClientCodeNewRequest request = new ClientCodeNewRequest();
|
||||
request.setTradingClearingRegistryId(tradingClearingRegistry.getId());
|
||||
request.setCompanyId(tradingClearingRegistry.getCompanyId());
|
||||
request.setCode(tradingClearingRegistry.getCode());
|
||||
request.setMoneyAccountId(tradingClearingRegistry.getMoneyAccountId());
|
||||
request.setDepoAccountId(tradingClearingRegistry.getDepoAccountId());
|
||||
log.debug("Send message to kafka \"{}\": {}", Consts.DESTINATION_CLIENT_CODE_NEW_UM_COMPANY, LogFormatter.toStringWrapper(request));
|
||||
kafkaSender.sendRequestToQueue(Consts.DESTINATION_CLIENT_CODE_NEW_UM_COMPANY, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* clearing-service сообщение на открытие клиринговых регистров;
|
||||
*/
|
||||
protected void sendNotificationToClearingSvc(TradingClearingRegistry tradingClearingRegistry) {
|
||||
CreateRegistryRequest request = new CreateRegistryRequest();
|
||||
request.setCompanyId(tradingClearingRegistry.getCompanyId());
|
||||
request.setTradingClearingRegistryId(tradingClearingRegistry.getId());
|
||||
log.debug("Send message to kafka \"{}\": {}", Consts.REGISTRY_NEW, LogFormatter.toStringWrapper(request));
|
||||
kafkaSender.sendRequestToQueue(Consts.REGISTRY_NEW, request);
|
||||
}
|
||||
|
||||
/**
|
||||
* report-service сообщение на формирование уведомления о создании нового ТКР
|
||||
*/
|
||||
protected void sendNotificationToReportSvc(TradingClearingRegistry tradingClearingRegistry) {
|
||||
NotificationRequest request = new NotificationRequest();
|
||||
request.setConsumerId(tradingClearingRegistry.getCompanyId());
|
||||
log.debug("Send message to kafka \"{}\": {}", Consts.CREATE_NOTIFICATION_NTCR, LogFormatter.toStringWrapper(request));
|
||||
kafkaSender.sendRequestToQueue(Consts.CREATE_NOTIFICATION_NTCR, request);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
package ru.spcex.clearing.account.validation;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountNewRequest;
|
||||
import ru.spcex.platform.enumeration.Status;
|
||||
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.validation.IValidationRule;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public enum AccountValidationRule implements IValidationRule<ImdgValidationContext<BankAccountNewRequest>> {
|
||||
|
||||
CompanyPresent() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<BankAccountNewRequest> context) {
|
||||
BankAccountNewRequest bankAccount = context.getValidatedObject();
|
||||
Imdg<Company> companyImdg = context.obtainMap(IMDGDistributedNames.Map_Company, Company.class);
|
||||
Company company = companyImdg.getSingleObjectByID(bankAccount.getCompanyId());
|
||||
if (company == null) {
|
||||
return of(AccountError.CompanyNotFound);
|
||||
}
|
||||
if (!Status.Active.equalsByKey(company.getWorkflowStatus())) {
|
||||
return of(AccountError.CompanyNotActive);
|
||||
}
|
||||
// context.storeObject(ValidationStored.Company, company);
|
||||
return empty();
|
||||
}
|
||||
},
|
||||
AccountIsNew() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<BankAccountNewRequest> context) {
|
||||
BankAccountNewRequest bankAccountRequest = context.getValidatedObject();
|
||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Account account = accountImdg.getFirstObjectByFieldValues(Map.of("account", bankAccountRequest.getAccount(),
|
||||
"accountStatus", Status.Active.getKey()));
|
||||
if (account != null) {
|
||||
return of(AccountError.AccountAlreadyExist);
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
},
|
||||
|
||||
RequiredFields() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<BankAccountNewRequest> context) {
|
||||
BankAccountNewRequest accountReq = context.getValidatedObject();
|
||||
if (StringUtils.isEmpty(accountReq.getCurrency())) {
|
||||
return of(AccountError.WrongFieldValue, "currency");
|
||||
}
|
||||
if (StringUtils.isEmpty(accountReq.getBankIdentificationCode())) {
|
||||
return of(AccountError.WrongFieldValue, "bankIdentificationCode");
|
||||
}
|
||||
if (StringUtils.isEmpty(accountReq.getBankName())) {
|
||||
return of(AccountError.WrongFieldValue, "bankName");
|
||||
}
|
||||
if (StringUtils.isEmpty(accountReq.getAccount())) {
|
||||
return of(AccountError.WrongFieldValue, "account");
|
||||
}
|
||||
if (StringUtils.isEmpty(accountReq.getDestination())) {
|
||||
return of(AccountError.WrongFieldValue, "destination");
|
||||
}
|
||||
if (StringUtils.isEmpty(accountReq.getCompanyId())) {
|
||||
return of(AccountError.WrongFieldValue, "companyId");
|
||||
}
|
||||
|
||||
return empty();
|
||||
}
|
||||
},
|
||||
|
||||
RubRequiredFields() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<BankAccountNewRequest> context) {
|
||||
BankAccountNewRequest accountReq = context.getValidatedObject();
|
||||
if ("RUB".equals(accountReq.getCurrency())) {
|
||||
if (StringUtils.isEmpty(accountReq.getCorrespondentAccount())) {
|
||||
return of(AccountError.WrongFieldValue, "correspondentAccount");
|
||||
}
|
||||
if (StringUtils.isEmpty(accountReq.getCorrespondentAccountName())) {
|
||||
return of(AccountError.WrongFieldValue, "correspondentAccountName");
|
||||
}
|
||||
if (StringUtils.isEmpty(accountReq.getTaxpayerIdentificationNumber())) {
|
||||
return of(AccountError.WrongFieldValue, "taxpayerIdentificationNumber");
|
||||
}
|
||||
if (StringUtils.isEmpty(accountReq.getTaxRegistrationReasonCode())) {
|
||||
return of(AccountError.WrongFieldValue, "taxRegistrationReasonCode");
|
||||
}
|
||||
}
|
||||
return empty();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public String ruleName() {
|
||||
return "AccountValidationRule." + name();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
spring.main.web-application-type=none
|
||||
account-service.hazelcast.cluster-members=127.0.0.1:5701
|
||||
account-service.hazelcast.login=dev
|
||||
account-service.hazelcast.password=dev-pass
|
||||
|
||||
account-service.kafka-consumer.bootstrap-servers=localhost:9092
|
||||
account-service.kafka-consumer.group-id=dev-group-account-service
|
||||
account-service.kafka-consumer.enable-auto-commit=true
|
||||
account-service.kafka-consumer.session-timeout-ms=30000
|
||||
account-service.kafka-consumer.auto-offset-reset=latest
|
||||
account-service.kafka-consumer.linger-ms=1
|
||||
account-service.kafka-consumer.buffer-memory=33554432
|
||||
|
||||
account-service.kafka-producer.bootstrap-servers=localhost:9092
|
||||
account-service.kafka-producer.acks=all
|
||||
account-service.kafka-producer.retries=0
|
||||
account-service.kafka-producer.batch-size=16384
|
||||
account-service.kafka-producer.linger-ms=1
|
||||
account-service.kafka-producer.buffer-memory=33554432
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<!-- |%X{ru.nbch.scoring.web.logging.mdc_key}-->
|
||||
<Pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %class{0}:%line - %message%n</Pattern>
|
||||
<charset>utf-8</charset>
|
||||
</encoder>
|
||||
</appender>
|
||||
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>./logs/account-service.log</file>
|
||||
<encoder>
|
||||
<!-- |%X{ru.nbch.scoring.web.logging.mdc_key}-->
|
||||
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %class{0}:%msg%n</Pattern>
|
||||
<charset>utf8</charset>
|
||||
</encoder>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
|
||||
<fileNamePattern>
|
||||
./logs/account-service.%i.log
|
||||
</fileNamePattern>
|
||||
<minIndex>1</minIndex>
|
||||
<maxIndex>10</maxIndex>
|
||||
</rollingPolicy>
|
||||
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
|
||||
<maxFileSize>500MB</maxFileSize>
|
||||
</triggeringPolicy>
|
||||
</appender>
|
||||
|
||||
<root level="warn">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
<appender-ref ref="FILE"/>
|
||||
</root>
|
||||
|
||||
<logger name="ru.spcex" level="debug" additivity="false">
|
||||
<appender-ref ref="FILE"/>
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</logger>
|
||||
</configuration>
|
||||
|
|
@ -1,246 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.producer.MockProducer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
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.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.clearing.platform.dictionary.AccountTypeDictionary;
|
||||
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
|
||||
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||
import ru.spcex.clearing.account.config.validation.AccountValidationConfig;
|
||||
import ru.spcex.clearing.account.config.validation.InformationAccountValidationConfig;
|
||||
import ru.spcex.clearing.account.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.account.CorrespondentAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.CorrespondentAccountUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfo;
|
||||
import ru.spcex.clearing.test.MatcherFactory;
|
||||
import ru.spcex.clearing.test.TestObjectCreator;
|
||||
import ru.spcex.clearing.test.config.ImdgTestConfig;
|
||||
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||
import ru.spcex.platform.enumeration.*;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import static ru.spcex.clearing.test.MatcherFactory.usingIgnoringFieldsComparator;
|
||||
import static ru.spcex.clearing.test.TestUtils.*;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
BeanConfiguration.class,
|
||||
ValidationConfig.class,
|
||||
AccountValidationConfig.class,
|
||||
AccountService.class,
|
||||
AccountHelper.class,
|
||||
InformationAccountService.class,
|
||||
InformationAccountValidationConfig.class,
|
||||
ImdgTestConfig.class,
|
||||
KafkaTestConfig.class})
|
||||
class AccountServiceTest {
|
||||
public static final MatcherFactory.Matcher<Account> ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||
public static final MatcherFactory.Matcher<RequestInfo> REQUEST_INFO_MATCHER_MATCHER = usingIgnoringFieldsComparator("created");
|
||||
private static final int PARTITION = 0;
|
||||
private static final String account = "123456789123";
|
||||
private static final Long companyId = 0L;
|
||||
private static final Long relationId = 0L;
|
||||
@Autowired
|
||||
AccountService accountService;
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private HazelcastService hazelcastServiceTest;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<ProducerRecord> producerRecord;
|
||||
@SpyBean
|
||||
private MockProducer<String, Object> producer;
|
||||
@Autowired
|
||||
@Qualifier("mockProducer")
|
||||
protected Producer<String, Object> mockProducer;
|
||||
|
||||
private Imdg<Account> accountImdg;
|
||||
private Imdg<Company> companyImdg;
|
||||
private Imdg<AccountTypeDictionary> accountTypeDictionaryImdg;
|
||||
private Imdg<ClearingMemberCategory> clearingMemberCategoryImdg;
|
||||
private Imdg<Relation> relationImdg;
|
||||
private Imdg<ServiceStatusDictionary> serviceStatusDictionaryImdg;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
hazelcastServiceTest.waitAvailable();
|
||||
accountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
companyImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Company, Company.class
|
||||
);
|
||||
accountTypeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_AccountTypeDictionary, AccountTypeDictionary.class
|
||||
);
|
||||
clearingMemberCategoryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class
|
||||
);
|
||||
relationImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Relation, Relation.class
|
||||
);
|
||||
serviceStatusDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary, ServiceStatusDictionary.class
|
||||
);
|
||||
ServiceStatusDictionary serviceStatusDictionary = new ServiceStatusDictionary();
|
||||
serviceStatusDictionary.setCode(ServiceStatus.Active.getKey());
|
||||
serviceStatusDictionary.setName(ServiceStatus.Active.getKey());
|
||||
serviceStatusDictionaryImdg.insert(serviceStatusDictionary);
|
||||
|
||||
Company company = new Company();
|
||||
company.setId(companyId);
|
||||
company.setWorkflowStatus(WorkflowStatus.Active.getKey());
|
||||
companyImdg.insert(company);
|
||||
|
||||
AccountTypeDictionary accountTypeDictionary = new AccountTypeDictionary();
|
||||
accountTypeDictionary.setCode(AccountType.Corr.getKey());
|
||||
accountTypeDictionary.setName(AccountType.Corr.getKey());
|
||||
accountTypeDictionaryImdg.insert(accountTypeDictionary);
|
||||
|
||||
ClearingMemberCategory clearingMemberCategory = new ClearingMemberCategory();
|
||||
clearingMemberCategory.setClearingMemberCategory(ClearingCategory.B.getKey());
|
||||
clearingMemberCategory.setCompanyId(companyId);
|
||||
clearingMemberCategoryImdg.insert(clearingMemberCategory);
|
||||
|
||||
Relation relation = new Relation();
|
||||
relation.setId(relationId);
|
||||
relation.setConsumerId(companyId);
|
||||
relation.setService(Service.MKR.getKey());
|
||||
relationImdg.insert(relation);
|
||||
|
||||
new TestObjectCreator(hazelcastServiceTest).createUserAdmin(1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountCorrespondentNew() {
|
||||
String uniqueAccount = account + UUID.randomUUID();
|
||||
|
||||
CorrespondentAccountNewRequest correspondentAccountNewRequest = new CorrespondentAccountNewRequest();
|
||||
correspondentAccountNewRequest.setAccount(uniqueAccount);
|
||||
correspondentAccountNewRequest.setAccountType(AccountType.Corr.getKey());
|
||||
correspondentAccountNewRequest.setCompanyId(companyId);
|
||||
correspondentAccountNewRequest.setStatus(ServiceStatus.Active.getKey());
|
||||
|
||||
Account predictableAccount = new Account();
|
||||
predictableAccount.setAccount(uniqueAccount);
|
||||
predictableAccount.setAccountType(AccountType.Corr.getKey());
|
||||
predictableAccount.setCompanyId(companyId);
|
||||
predictableAccount.setStatus(ServiceStatus.Active.getKey());
|
||||
predictableAccount.setRelationId(relationId);
|
||||
|
||||
String jsonString = getJsonStringForNew(correspondentAccountNewRequest, 0L);
|
||||
|
||||
addRecordToKafka((MockConsumer) accountService.getConsumer(),
|
||||
Consts.DESTINATION_CORRESPONDENT_ACCOUNT_NEW,
|
||||
PARTITION,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
Account resultNew = accountImdg.getCollectionObjectsByFieldValues(Map.of("account", uniqueAccount)).iterator().next();
|
||||
predictableAccount.setId(resultNew.getId());
|
||||
predictableAccount.setUpdated(resultNew.getUpdated());
|
||||
predictableAccount.setCreated(resultNew.getCreated());
|
||||
ACCOUNT_MATCHER.assertMatch(resultNew, predictableAccount);
|
||||
accountImdg.delete(resultNew);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountCorrespondentUpdate() {
|
||||
Account existAccount = new Account();
|
||||
existAccount.setAccount(account);
|
||||
existAccount.setAccountType(AccountType.Corr.getKey());
|
||||
existAccount.setStatus(ServiceStatus.Closed.getKey());
|
||||
existAccount.setCompanyId(companyId);
|
||||
Long accountId = accountImdg.insert(existAccount);
|
||||
|
||||
CorrespondentAccountUpdateRequest correspondentAccountUpdateRequest = new CorrespondentAccountUpdateRequest();
|
||||
correspondentAccountUpdateRequest.setAccount(account);
|
||||
correspondentAccountUpdateRequest.setAccountType(AccountType.Corr.getKey());
|
||||
correspondentAccountUpdateRequest.setStatus(ServiceStatus.Active.getKey());
|
||||
correspondentAccountUpdateRequest.setCompanyId(companyId);
|
||||
correspondentAccountUpdateRequest.setId(accountId);
|
||||
|
||||
|
||||
String jsonString = getJsonStringForUpdate(correspondentAccountUpdateRequest, 0);
|
||||
|
||||
//ACT
|
||||
addRecordToKafka((MockConsumer) accountService.getConsumer(),
|
||||
Consts.DESTINATION_CORRESPONDENT_ACCOUNT_UPDATE,
|
||||
PARTITION,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
Account resultUpdating = accountImdg.getSingleObjectByID(accountId);
|
||||
Account expectAccount = new Account();
|
||||
expectAccount.setId(existAccount.getId());
|
||||
expectAccount.setAccount(account);
|
||||
expectAccount.setAccountType(AccountType.Corr.getKey());
|
||||
expectAccount.setStatus(ServiceStatus.Closed.getKey());
|
||||
expectAccount.setCompanyId(companyId);
|
||||
expectAccount.setCreated(existAccount.getCreated());
|
||||
expectAccount.setUpdated(resultUpdating.getUpdated());
|
||||
expectAccount.setStatus(ServiceStatus.Active.getKey());
|
||||
ACCOUNT_MATCHER.assertMatch(resultUpdating, expectAccount);
|
||||
accountImdg.delete(resultUpdating);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountCorrespondentBlock() {
|
||||
Account existAccount = new Account();
|
||||
existAccount.setAccount(account);
|
||||
existAccount.setAccountType(AccountType.Corr.getKey());
|
||||
existAccount.setStatus(ServiceStatus.Active.getKey());
|
||||
existAccount.setCompanyId(companyId);
|
||||
Long accountId = accountImdg.insert(existAccount);
|
||||
|
||||
CommonDeleteRequest commonDeleteRequest = new CommonDeleteRequest();
|
||||
commonDeleteRequest.setId(accountId);
|
||||
|
||||
String jsonString = getJsonStringForDelete(commonDeleteRequest, 0);
|
||||
|
||||
//ACT
|
||||
addRecordToKafka((MockConsumer) accountService.getConsumer(),
|
||||
Consts.DESTINATION_CORRESPONDENT_ACCOUNT_BLOCK,
|
||||
PARTITION,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
Account resultBlock = accountImdg.getSingleObjectByID(accountId);
|
||||
existAccount.setStatus(ServiceStatus.Blocked.getKey());
|
||||
existAccount.setUpdated(resultBlock.getUpdated());
|
||||
|
||||
ACCOUNT_MATCHER.assertMatch(existAccount, resultBlock);
|
||||
accountImdg.delete(resultBlock);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import ru.clearing.classes.statics.data.account.*;
|
||||
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||
import ru.spcex.clearing.account.config.validation.AccountSymbolsValidationConfig;
|
||||
import ru.spcex.clearing.account.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.account.AccountSymbolsNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
||||
import ru.spcex.clearing.test.MatcherFactory;
|
||||
import ru.spcex.clearing.test.TestObjectCreator;
|
||||
import ru.spcex.clearing.test.config.ImdgTestConfig;
|
||||
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||
import ru.spcex.platform.enumeration.*;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import static ru.spcex.clearing.test.MatcherFactory.usingIgnoringFieldsComparator;
|
||||
import static ru.spcex.clearing.test.TestUtils.*;
|
||||
import static ru.spcex.clearing.test.config.KafkaTestConfig.setMockFuture;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
BeanConfiguration.class,
|
||||
ValidationConfig.class,
|
||||
AccountSymbolsValidationConfig.class,
|
||||
AccountSymbolsService.class,
|
||||
ImdgTestConfig.class,
|
||||
KafkaTestConfig.class})
|
||||
class AccountSymbolsServiceTest {
|
||||
public static final MatcherFactory.Matcher<AccountSymbols> ACCOUNT_SYMBOL_MATCHER = usingIgnoringFieldsComparator();
|
||||
private static final int PARTITION = 0;
|
||||
|
||||
@Autowired
|
||||
AccountSymbolsService accountSymbolsService;
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private ImdgProvider hazelcastServiceTest;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mockProducer")
|
||||
protected Producer<String, Object> mockProducer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("kafkaTestTemplate")
|
||||
protected KafkaTemplate<String, Object> kafkaTemplate;
|
||||
|
||||
private Imdg<AccountSymbols> accountSymbolsImdg;
|
||||
|
||||
private Imdg<Account> accountImdg;
|
||||
private Long accountId;
|
||||
private Imdg<ClearingAccount> clearingAccountImdg;
|
||||
private Long clearingAccountId;
|
||||
|
||||
static int newRequestCnt = 0;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
hazelcastServiceTest.waitAvailable();
|
||||
accountSymbolsImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_AccountSymbols, AccountSymbols.class
|
||||
);
|
||||
accountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
clearingAccountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class
|
||||
);
|
||||
|
||||
Account account = new Account();
|
||||
account.setStatus(ServiceStatus.Active.getKey());
|
||||
account.setAccountType(AccountType.Clrn.getKey());
|
||||
accountId = accountImdg.insert(account);
|
||||
|
||||
ClearingAccount clearingAccount = new ClearingAccount();
|
||||
clearingAccount.setAccountId(accountId);
|
||||
clearingAccount.setClearingAccountType("CAT");
|
||||
clearingAccountId = clearingAccountImdg.insert(clearingAccount);
|
||||
|
||||
new TestObjectCreator(hazelcastServiceTest).createUserAdmin(1000L);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
private void destroyTest() {
|
||||
//clean test data
|
||||
Account account = accountImdg.getSingleObjectByID(accountId);
|
||||
if (account != null)
|
||||
accountImdg.delete(account);
|
||||
ClearingAccount clearingAccount = clearingAccountImdg.getSingleObjectByID(clearingAccountId);
|
||||
if (clearingAccount != null)
|
||||
clearingAccountImdg.delete(clearingAccount);
|
||||
}
|
||||
|
||||
@Test
|
||||
void tradingClearingRegistryNew_moneyAccount_clearingAccount() {
|
||||
setMockFuture(kafkaTemplate);
|
||||
AccountSymbolsNewRequest accountSymbolsNewRequest = new AccountSymbolsNewRequest();
|
||||
accountSymbolsNewRequest.setAccountId(accountId);
|
||||
accountSymbolsNewRequest.setAccountSymbolValue("SYMBOL1");
|
||||
|
||||
AccountSymbols predictableAccountSymbols = new AccountSymbols();
|
||||
predictableAccountSymbols.setAccountId(accountId);
|
||||
predictableAccountSymbols.setAccountSymbolValue("SYMBOL1");
|
||||
|
||||
String jsonString = getJsonStringForNew(accountSymbolsNewRequest, 0L);
|
||||
|
||||
addRecordToKafka((MockConsumer) accountSymbolsService.getConsumer(),
|
||||
Consts.DESTINATION_DEPO_ACCOUNT_SYMBOLS_NEW,
|
||||
newRequestCnt,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
AccountSymbols resultNew = accountSymbolsImdg.getAllValues().iterator().next();
|
||||
predictableAccountSymbols.setId(resultNew.getId());
|
||||
|
||||
ACCOUNT_SYMBOL_MATCHER.assertMatch(resultNew, predictableAccountSymbols);
|
||||
accountSymbolsImdg.delete(resultNew); // cleanup test
|
||||
|
||||
newRequestCnt++;
|
||||
}
|
||||
|
||||
@Test
|
||||
void tradingClearingRegistryDelete() {
|
||||
AccountSymbols existAccountSymbols = new AccountSymbols();
|
||||
existAccountSymbols.setAccountId(accountId);
|
||||
existAccountSymbols.setAccountSymbolValue("SYMBOL 2");
|
||||
Long accountSymbolId = accountSymbolsImdg.insert(existAccountSymbols);
|
||||
|
||||
CommonDeleteRequest accountSymbolsDeleteRequest = new CommonDeleteRequest();
|
||||
accountSymbolsDeleteRequest.setId(accountSymbolId);
|
||||
|
||||
String jsonString = getJsonStringForDelete(accountSymbolsDeleteRequest, 0);
|
||||
|
||||
//ACT
|
||||
addRecordToKafka((MockConsumer) accountSymbolsService.getConsumer(),
|
||||
Consts.DESTINATION_DEPO_ACCOUNT_SYMBOLS_DELETE,
|
||||
PARTITION,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
AccountSymbols resultUpdating = accountSymbolsImdg.getSingleObjectByID(accountSymbolId);
|
||||
Assertions.assertNull(resultUpdating, "Должен был удалиться");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,436 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.BankAccount;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.clearing.platform.dictionary.CurrencyCodeDictionary;
|
||||
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||
import ru.spcex.clearing.account.config.validation.AccountValidationConfig;
|
||||
import ru.spcex.clearing.account.config.validation.BankAccountValidationConfig;
|
||||
import ru.spcex.clearing.account.config.validation.ValidationConfig;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
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.BankAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||
import ru.spcex.clearing.test.MatcherFactory.Matcher;
|
||||
import ru.spcex.clearing.test.TestObjectCreator;
|
||||
import ru.spcex.clearing.test.config.ImdgTestConfig;
|
||||
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||
import ru.spcex.platform.enumeration.*;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.timeout;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static ru.spcex.clearing.platform.messaging.service.Status.Error;
|
||||
import static ru.spcex.clearing.test.MatcherFactory.usingIgnoringFieldsComparator;
|
||||
import static ru.spcex.clearing.test.TestUtils.*;
|
||||
import static ru.spcex.clearing.test.config.KafkaTestConfig.getCaptor;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
AccountHelper.class,
|
||||
BankAccountService.class,
|
||||
ValidationConfig.class,
|
||||
BankAccountValidationConfig.class,
|
||||
AccountValidationConfig.class,
|
||||
BeanConfiguration.class,
|
||||
ImdgTestConfig.class,
|
||||
KafkaTestConfig.class})
|
||||
public class BankAccountServiceTest {
|
||||
public static final Matcher<BankAccount> BANK_ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||
public static final Matcher<Account> ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||
public static final Matcher<BaseRequest<Object>> BASE_REQUEST_MATCHER = usingIgnoringFieldsComparator();
|
||||
private static final int PARTITION = 0;
|
||||
private static final String TOPIC_ACCOUNT_NEW = Consts.DESTINATION_BANK_ACCOUNT_NEW;
|
||||
private static final String TOPIC_ACCOUNT_UPDATE = Consts.DESTINATION_BANK_ACCOUNT_UPDATE;
|
||||
private static final String TOPIC_ACCOUNT_DELETE = Consts.DESTINATION_BANK_ACCOUNT_BLOCK;
|
||||
private static final Long ID = 0L;
|
||||
private static final AtomicInteger countRun = new AtomicInteger(1);
|
||||
private static final Long accountId = 12L;
|
||||
private static final String currency = "RUB";
|
||||
private static final String bankIdentificationCode = "99999";
|
||||
private static final String bankName = "ooo tinkoff";
|
||||
private static final String destination = "OOO ROGA I KOPITA";
|
||||
private static final String correspondentAccount = "9294189285498598598";
|
||||
private static final String correspondentAccountName = "BIK OF TINKOFF";
|
||||
private static final String taxpayerIdentificationNumber = "848484848484";
|
||||
private static final String taxRegistrationReasonCode = "886886";
|
||||
protected final Long addresseeIdNew = 2L;
|
||||
protected final String deal = "111111111";
|
||||
private final String acc = "0123456789";
|
||||
protected Imdg<Company> companyImdg;
|
||||
private Imdg<BankAccount> bankAccountImdg;
|
||||
private Imdg<Account> accountImdg;
|
||||
private Imdg<CurrencyCodeDictionary> currencyCodeDictionaryImdg;
|
||||
private Imdg<ClearingMemberCategory> clearingMemberCategoryImdg;
|
||||
private Imdg<Relation> relationImdg;
|
||||
|
||||
@Autowired
|
||||
private IMessageResolver messageResolver;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private ImdgProvider hazelcastServiceTest;
|
||||
|
||||
@Autowired
|
||||
private BankAccountService bankAccountService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mockProducer")
|
||||
protected Producer<String, Object> mockProducer;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
hazelcastServiceTest.waitAvailable();
|
||||
companyImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
bankAccountImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
accountImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
currencyCodeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_CurrencyCodeDictionary, CurrencyCodeDictionary.class
|
||||
);
|
||||
clearingMemberCategoryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class
|
||||
);
|
||||
relationImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Relation, Relation.class
|
||||
);
|
||||
CurrencyCodeDictionary currencyCodeDictionary = new CurrencyCodeDictionary();
|
||||
currencyCodeDictionary.setCode("RUB");
|
||||
currencyCodeDictionary.setName("RUB");
|
||||
currencyCodeDictionaryImdg.insert(currencyCodeDictionary);
|
||||
|
||||
new TestObjectCreator(hazelcastServiceTest).createUserAdmin(1000L);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link BankAccountService#bankAccountNew(BaseRequest request)}<br>
|
||||
* Тест проверяет генерацию сущности {@link BankAccount} в Hazelcast при передаче из Apache Kafka.<br>
|
||||
* Входной запрос {@link BankAccountNewRequest}:<br>
|
||||
* {@link BankAccountNewRequest#bankIdentificationCode} - 99999<br>
|
||||
* {@link BankAccountNewRequest#bankName} - ооо тинькофф<br>
|
||||
* {@link BankAccountNewRequest#correspondentAccount} - 9294189285498598598<br>
|
||||
* {@link BankAccountNewRequest#correspondentAccountName} - BIK OF<br>
|
||||
* {@link BankAccountNewRequest#currency} - RUB<br>
|
||||
* {@link BankAccountNewRequest#destination} - OOO ROGA I KOPITA<br>
|
||||
* {@link BankAccountNewRequest#taxpayerIdentificationNumber} - 848484848484<br>
|
||||
* {@link BankAccountNewRequest#taxRegistrationReasonCode} - 886886<br>
|
||||
* {@link BankAccountNewRequest#account} - 123456789123<br>
|
||||
*/
|
||||
@Test
|
||||
public void bankAccountNew() {
|
||||
//ARRANGE
|
||||
BankAccount predictableBankAccount = getBankAccount();
|
||||
|
||||
Company company = getTestCompany();
|
||||
Long companyId = companyImdg.insert(company);
|
||||
Long relationId = 777L;
|
||||
Account predictableAccount = getTestAccount(accountId, acc);
|
||||
predictableAccount.setProcessingSign(null);
|
||||
predictableAccount.setCompanyId(companyId);
|
||||
predictableAccount.setRelationId(relationId);
|
||||
clearImdg(accountImdg);
|
||||
|
||||
ClearingMemberCategory clearingMemberCategory = new ClearingMemberCategory();
|
||||
clearingMemberCategory.setClearingMemberCategory(ClearingCategory.B.getKey());
|
||||
clearingMemberCategory.setCompanyId(companyId);
|
||||
clearingMemberCategoryImdg.insert(clearingMemberCategory);
|
||||
|
||||
Relation relation = new Relation();
|
||||
relation.setId(relationId);
|
||||
relation.setConsumerId(companyId);
|
||||
relation.setService(Service.MKR.getKey());
|
||||
relationImdg.insert(relation);
|
||||
|
||||
BankAccountNewRequest bankAccountNewRequest = getBankAccountNewRequest(predictableBankAccount);
|
||||
String jsonString = getJsonStringForNew(bankAccountNewRequest, ID);
|
||||
|
||||
//ACT
|
||||
addRecordToKafka((MockConsumer) bankAccountService.getConsumer(), TOPIC_ACCOUNT_NEW, PARTITION, 0, jsonString);
|
||||
waitingSendAndCheckRecord(ID, mockProducer);
|
||||
|
||||
Account accountResult = accountImdg.getFirstObjectBySQL(String.format("account = %s", acc));
|
||||
BankAccount bankAccountResult = bankAccountImdg.getFirstObjectBySQL(String.format("account = %s or companyId = %s", acc, addresseeIdNew));
|
||||
predictableBankAccount.setAccountId(accountResult.getId());
|
||||
predictableBankAccount.setId(bankAccountResult.getId());
|
||||
setSameValueToField(accountResult, predictableAccount);
|
||||
|
||||
//ASSERT
|
||||
BANK_ACCOUNT_MATCHER.assertMatch(bankAccountResult, predictableBankAccount);
|
||||
ACCOUNT_MATCHER.assertMatch(accountResult, predictableAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link BankAccountService#bankAccountNew(BaseRequest request)}<br>
|
||||
* Тест проверяет валидацию.<br>
|
||||
* Входной запрос {@link BankAccountNewRequest}:<br>
|
||||
* {@link BankAccountNewRequest#bankIdentificationCode} - 99999<br>
|
||||
* {@link BankAccountNewRequest#bankName} - ооо тинькофф<br>
|
||||
* {@link BankAccountNewRequest#correspondentAccount} - 9294189285498598598<br>
|
||||
* {@link BankAccountNewRequest#correspondentAccountName} - BIK OF<br>
|
||||
* {@link BankAccountNewRequest#currency} - RUB<br>
|
||||
* {@link BankAccountNewRequest#destination} - OOO ROGA I KOPITA<br>
|
||||
* {@link BankAccountNewRequest#taxpayerIdentificationNumber} - 848484848484<br>
|
||||
* {@link BankAccountNewRequest#taxRegistrationReasonCode} - 886886<br>
|
||||
* {@link BankAccountNewRequest#account} - 123456789123<br>
|
||||
*/
|
||||
@Test
|
||||
public void validatedBankAccountNew() {
|
||||
clearImdg(accountImdg);
|
||||
BankAccount predictableBankAccount = getBankAccount();
|
||||
Company company = getTestCompany();
|
||||
companyImdg.insert(company);
|
||||
BankAccountNewRequest bankAccountNewRequest = getBankAccountNewRequest(predictableBankAccount);
|
||||
|
||||
String errMsg;
|
||||
//AccountValidationRule.RequiredFields
|
||||
//WrongFieldValue
|
||||
bankAccountNewRequest.setCurrency(null);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "null, currency"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setCurrency("TT0");
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.DictionaryNotFound, "TT0, CurrencyCodeDictionary"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setCurrency(currency);
|
||||
bankAccountNewRequest.setBankIdentificationCode(null);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "bankIdentificationCode"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setBankIdentificationCode(bankIdentificationCode);
|
||||
bankAccountNewRequest.setBankName(null);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "bankName"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setBankName(bankName);
|
||||
bankAccountNewRequest.setAccount(null);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.RequiredFieldEmpty, "account"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setAccount(acc);
|
||||
|
||||
//AccountValidationRule.CompanyPresent
|
||||
//CompanyNotFound
|
||||
bankAccountNewRequest.setCompanyId(999924535239L);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.CompanyNotFound, bankAccountNewRequest.getCompanyId()+", companyId"));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
|
||||
bankAccountNewRequest.setCompanyId(company.getId());
|
||||
|
||||
//AccountValidationRule.AccountIsNew
|
||||
//AccountAlreadyExist
|
||||
Account existAccount = getTestAccount(accountId, acc);
|
||||
accountImdg.insert(existAccount);
|
||||
errMsg = messageResolver.resolve(new EnumMessage(AccountError.AccountAlreadyExist, existAccount.getAccount()));
|
||||
checkError(errMsg, bankAccountNewRequest);
|
||||
accountImdg.delete(existAccount);
|
||||
}
|
||||
|
||||
private void checkError(String errorMsg, BankAccountNewRequest bankAccountNewRequest) {
|
||||
//ARRANGE
|
||||
int currentTime = countRun.getAndIncrement();
|
||||
long currentOffset = currentTime;
|
||||
BaseRequest<Object> predictableBaseRequest = new BaseRequest<>();
|
||||
predictableBaseRequest.setId(ID);
|
||||
predictableBaseRequest.setActionType(ActionType.SYSTEM);
|
||||
RequestInfoUpdate requestInfoUpdate = new RequestInfoUpdate();
|
||||
requestInfoUpdate.setId(ID);
|
||||
requestInfoUpdate.setStatus(Error);
|
||||
requestInfoUpdate.setMessage(errorMsg);
|
||||
predictableBaseRequest.setRequestPayload(requestInfoUpdate);
|
||||
|
||||
String jsonString = getJsonStringForNew(bankAccountNewRequest, ID);
|
||||
|
||||
//ACT
|
||||
addRecordToKafka((MockConsumer) bankAccountService.getConsumer(), TOPIC_ACCOUNT_NEW, PARTITION, currentOffset, jsonString);
|
||||
|
||||
ArgumentCaptor<ProducerRecord> producerRecord = getCaptor(mockProducer);
|
||||
//waiting for kafka producer send message (finale event)
|
||||
verify(mockProducer, timeout(30_000L).times(currentTime))
|
||||
.send(producerRecord.capture());
|
||||
BaseRequest<Object> baseRequestResult = (BaseRequest<Object>) producerRecord.getValue().value();
|
||||
|
||||
//ASSERT
|
||||
assertEquals(Consts.REQUEST_INFO_UPDATE, producerRecord.getValue().topic());
|
||||
BASE_REQUEST_MATCHER.assertMatch(baseRequestResult, predictableBaseRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link BankAccountService#bankAccountUpdate(BaseRequest)}<br>
|
||||
* Тест проверяет обновление сущности {@link BankAccount} в Hazelcast при передаче из Apache Kafka.<br>
|
||||
* Входной запрос {@link BankAccountUpdateRequest}:<br>
|
||||
* {@link BankAccountUpdateRequest#bankIdentificationCode} - NEW BUNK NAME<br>
|
||||
* {@link BankAccountUpdateRequest#bankName} - 88888<br>
|
||||
* {@link BankAccountUpdateRequest#correspondentAccount} - 894984646541316<br>
|
||||
* {@link BankAccountUpdateRequest#correspondentAccountName} - BIK OF NEW BUNK<br>
|
||||
* {@link BankAccountUpdateRequest#currency} - EU<br>
|
||||
* {@link BankAccountUpdateRequest#destination} - OOO NEW BUNK<br>
|
||||
* {@link BankAccountUpdateRequest#taxpayerIdentificationNumber} - 65468461321<br>
|
||||
* {@link BankAccountUpdateRequest#taxRegistrationReasonCode} - 532137<br>
|
||||
* {@link BankAccountUpdateRequest#account} - 326984656514<br>
|
||||
*/
|
||||
@Test
|
||||
void bankAccountUpdate() {
|
||||
clearImdg(accountImdg);
|
||||
//ARRANGE
|
||||
// Company company = getTestCompany();
|
||||
// companyImdg.insert(company);
|
||||
Account predictableAccount = getTestAccount(accountId, acc);
|
||||
accountImdg.insert(predictableAccount);
|
||||
|
||||
BankAccount bankAccountExists = getBankAccount();
|
||||
bankAccountImdg.insert(bankAccountExists);
|
||||
BankAccount predictableUpdateBankAccount = new BankAccount();
|
||||
predictableUpdateBankAccount.setBankName("NEW BUNK NAME");
|
||||
predictableUpdateBankAccount.setBankIdentificationCode("88888");
|
||||
predictableUpdateBankAccount.setCorrespondentAccount("894984646541316");
|
||||
predictableUpdateBankAccount.setCorrespondentAccountName("BIK OF NEW BUNK");
|
||||
predictableUpdateBankAccount.setCurrency("RUB");
|
||||
predictableUpdateBankAccount.setDestination("OOO NEW BUNK");
|
||||
predictableUpdateBankAccount.setTaxpayerIdentificationNumber("65468461321");
|
||||
predictableUpdateBankAccount.setTaxRegistrationReasonCode("532137");
|
||||
predictableUpdateBankAccount.setAccount(acc);
|
||||
predictableUpdateBankAccount.setId(ID);
|
||||
|
||||
BankAccountUpdateRequest bankAccountUpdateRequest = new BankAccountUpdateRequest();
|
||||
bankAccountUpdateRequest.setId(predictableUpdateBankAccount.getId());
|
||||
bankAccountUpdateRequest.setBankName(predictableUpdateBankAccount.getBankName());
|
||||
bankAccountUpdateRequest.setBankIdentificationCode(predictableUpdateBankAccount.getBankIdentificationCode());
|
||||
bankAccountUpdateRequest.setCorrespondentAccount(predictableUpdateBankAccount.getCorrespondentAccount());
|
||||
bankAccountUpdateRequest.setCorrespondentAccountName(predictableUpdateBankAccount.getCorrespondentAccountName());
|
||||
bankAccountUpdateRequest.setCurrency(predictableUpdateBankAccount.getCurrency());
|
||||
bankAccountUpdateRequest.setDestination(predictableUpdateBankAccount.getDestination());
|
||||
bankAccountUpdateRequest.setTaxpayerIdentificationNumber(predictableUpdateBankAccount.getTaxpayerIdentificationNumber());
|
||||
bankAccountUpdateRequest.setTaxRegistrationReasonCode(predictableUpdateBankAccount.getTaxRegistrationReasonCode());
|
||||
bankAccountUpdateRequest.setAccount(predictableUpdateBankAccount.getAccount());
|
||||
|
||||
String jsonString = getJsonStringForUpdate(bankAccountUpdateRequest, ID);
|
||||
|
||||
//ACT
|
||||
addRecordToKafka((MockConsumer) bankAccountService.getConsumer(), TOPIC_ACCOUNT_UPDATE, PARTITION, 0, jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingSendAndCheckRecord(ID, mockProducer);
|
||||
|
||||
Account accountResult = accountImdg.getSingleObjectByID(predictableAccount.getId());
|
||||
BankAccount resultUpdating = bankAccountImdg.getSingleObjectByID(predictableUpdateBankAccount.getId());
|
||||
predictableAccount.setUpdated(accountResult.getUpdated());
|
||||
predictableUpdateBankAccount.setAccountId(resultUpdating.getAccountId());
|
||||
predictableUpdateBankAccount.setCompanyId(resultUpdating.getCompanyId());
|
||||
BANK_ACCOUNT_MATCHER.assertMatch(resultUpdating, predictableUpdateBankAccount);
|
||||
ACCOUNT_MATCHER.assertMatch(accountResult, predictableAccount);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link BankAccountService#bankAccountBlock(BaseRequest)}
|
||||
* Тест проверяет удаление сущности {@link BankAccount} в Hazelcast при передаче из Apache Kafka.
|
||||
* Входной запрос {@link CommonDeleteRequest}:
|
||||
* {@link CommonDeleteRequest#id} - Идентификатор записи
|
||||
*/
|
||||
@Test
|
||||
void bankAccountBlock() {
|
||||
//ARRANGE
|
||||
BankAccount bankAccountExists = getBankAccount();
|
||||
bankAccountImdg.insert(bankAccountExists);
|
||||
Account account = new Account();
|
||||
account.setId(accountId);
|
||||
account.setStatus(WorkflowStatus.Active.getKey());
|
||||
accountImdg.insert(account);
|
||||
|
||||
CommonDeleteRequest commonDeleteRequest = new CommonDeleteRequest();
|
||||
commonDeleteRequest.setId(ID);
|
||||
String jsonString = getJsonStringForDelete(commonDeleteRequest, ID);
|
||||
|
||||
//ACT
|
||||
addRecordToKafka((MockConsumer) bankAccountService.getConsumer(), TOPIC_ACCOUNT_DELETE, PARTITION, 0, jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingSendAndCheckRecord(ID, mockProducer);
|
||||
|
||||
Account bankAccount = accountImdg.getSingleObjectByID(accountId);
|
||||
assertEquals(bankAccount.getStatus(), WorkflowStatus.Blocked.getKey());
|
||||
}
|
||||
|
||||
private Company getTestCompany() {
|
||||
Company company = new Company();
|
||||
company.setId(addresseeIdNew);
|
||||
company.setWorkflowStatus(Status.Active.getKey());
|
||||
company.setTradingCode(deal);
|
||||
company.setShortName("ShortName");
|
||||
company.setFullName("FullName");
|
||||
return company;
|
||||
}
|
||||
|
||||
private Account getTestAccount(Long id, String acc) {
|
||||
Account account = new Account();
|
||||
account.setId(id);
|
||||
account.setAccount(acc);
|
||||
account.setAccountType(AccountType.Bank.getKey());
|
||||
account.setStatus(Status.Active.getKey());
|
||||
account.setProcessingSign(Allowed.ALLOWED.getKey());
|
||||
return account;
|
||||
}
|
||||
|
||||
private void setSameValueToField(Account from, Account to) {
|
||||
to.setCreated(from.getCreated());
|
||||
to.setUpdated(from.getUpdated());
|
||||
to.setId(from.getId());
|
||||
}
|
||||
|
||||
private BankAccount getBankAccount() {
|
||||
BankAccount bankAccount = new BankAccount();
|
||||
bankAccount.setAccountId(accountId);
|
||||
bankAccount.setAccount(acc);
|
||||
bankAccount.setCompanyId(addresseeIdNew);
|
||||
bankAccount.setId(ID);
|
||||
bankAccount.setBankName(bankName);
|
||||
bankAccount.setBankIdentificationCode(bankIdentificationCode);
|
||||
bankAccount.setCorrespondentAccount(correspondentAccount);
|
||||
bankAccount.setCorrespondentAccountName(correspondentAccountName);
|
||||
bankAccount.setCurrency(currency);
|
||||
bankAccount.setDestination(destination);
|
||||
bankAccount.setTaxpayerIdentificationNumber(taxpayerIdentificationNumber);
|
||||
bankAccount.setTaxRegistrationReasonCode(taxRegistrationReasonCode);
|
||||
return bankAccount;
|
||||
}
|
||||
|
||||
private BankAccountNewRequest getBankAccountNewRequest(BankAccount bankAccount) {
|
||||
BankAccountNewRequest bankAccountNewRequest = new BankAccountNewRequest();
|
||||
bankAccountNewRequest.setBankName(bankAccount.getBankName());
|
||||
bankAccountNewRequest.setBankIdentificationCode(bankAccount.getBankIdentificationCode());
|
||||
bankAccountNewRequest.setCorrespondentAccount(bankAccount.getCorrespondentAccount());
|
||||
bankAccountNewRequest.setCorrespondentAccountName(bankAccount.getCorrespondentAccountName());
|
||||
bankAccountNewRequest.setCurrency(bankAccount.getCurrency());
|
||||
bankAccountNewRequest.setDestination(bankAccount.getDestination());
|
||||
bankAccountNewRequest.setTaxpayerIdentificationNumber(bankAccount.getTaxpayerIdentificationNumber());
|
||||
bankAccountNewRequest.setTaxRegistrationReasonCode(bankAccount.getTaxRegistrationReasonCode());
|
||||
bankAccountNewRequest.setAccount(bankAccount.getAccount());
|
||||
bankAccountNewRequest.setCompanyId(bankAccount.getCompanyId());
|
||||
return bankAccountNewRequest;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,290 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.ClearingAccount;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.clearing.platform.dictionary.AccountTypeDictionary;
|
||||
import ru.clearing.platform.dictionary.ClearingAccountTypeDictionary;
|
||||
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||
import ru.spcex.clearing.account.config.validation.AccountValidationConfig;
|
||||
import ru.spcex.clearing.account.config.validation.ClearingAccountValidationConfig;
|
||||
import ru.spcex.clearing.account.config.validation.ValidationConfig;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
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.account.ClearingAccountNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountSdf01Request;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountSdfRequestPart;
|
||||
import ru.spcex.clearing.test.MatcherFactory;
|
||||
import ru.spcex.clearing.test.TestObjectCreator;
|
||||
import ru.spcex.clearing.test.config.ImdgTestConfig;
|
||||
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||
import ru.spcex.platform.enumeration.*;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgHazelcast;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
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.KafkaTestConfig.setMockFuture;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
BeanConfiguration.class,
|
||||
ValidationConfig.class,
|
||||
ClearingAccountValidationConfig.class,
|
||||
AccountValidationConfig.class,
|
||||
AccountHelper.class,
|
||||
ClearingAccountService.class,
|
||||
SDFProcessService.class,
|
||||
ImdgTestConfig.class,
|
||||
KafkaTestConfig.class})
|
||||
class ClearingAccountServiceTest {
|
||||
public static final MatcherFactory.Matcher<ClearingAccount> CLEARING_ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||
public static final MatcherFactory.Matcher<Account> ACCOUNT_MATCHER = usingIgnoringFieldsComparator("created", "updated");
|
||||
private static final int PARTITION = 0;
|
||||
private static final Long companyId = 0L;
|
||||
private static final Long relationId = 0L;
|
||||
private static final String CLEARING_ACCOUNT_TYPE_DICT = "A";
|
||||
private static final String ACCOUNT_VALUE = "account-value";
|
||||
private static final String TRADING_CODE = "trading-code";
|
||||
|
||||
@Autowired
|
||||
ClearingAccountService clearingAccountService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private ImdgProvider hazelcastServiceTest;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mockProducer")
|
||||
protected Producer<String, Object> mockProducer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("kafkaTestTemplate")
|
||||
protected KafkaTemplate<String, Object> kafkaTemplate;
|
||||
|
||||
private Imdg<ClearingAccount> clearingAccountImdg;
|
||||
private Imdg<Account> accountImdg;
|
||||
private Imdg<Company> companyImdg;
|
||||
private Imdg<ClearingAccountTypeDictionary> clearingAccountTypeDictionaryImdg;
|
||||
private Imdg<AccountTypeDictionary> accountTypeDictionaryImdg;
|
||||
private Imdg<ClearingMemberCategory> clearingMemberCategoryImdg;
|
||||
private Imdg<Relation> relationImdg;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
hazelcastServiceTest.waitAvailable();
|
||||
clearingAccountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class
|
||||
);
|
||||
accountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
|
||||
companyImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Company, Company.class
|
||||
);
|
||||
accountTypeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_AccountTypeDictionary, AccountTypeDictionary.class
|
||||
);
|
||||
clearingAccountTypeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingAccountTypeDictionary, ClearingAccountTypeDictionary.class
|
||||
);
|
||||
clearingMemberCategoryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class
|
||||
);
|
||||
relationImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Relation, Relation.class
|
||||
);
|
||||
|
||||
Company company = new Company();
|
||||
company.setId(companyId);
|
||||
company.setWorkflowStatus(WorkflowStatus.Active.getKey());
|
||||
company.setTradingCode(TRADING_CODE);
|
||||
companyImdg.insert(company);
|
||||
|
||||
AccountTypeDictionary accountTypeDictionary = new AccountTypeDictionary();
|
||||
accountTypeDictionary.setCode(AccountType.Clrn.getKey());
|
||||
accountTypeDictionary.setName(AccountType.Clrn.getKey());
|
||||
accountTypeDictionaryImdg.insert(accountTypeDictionary);
|
||||
|
||||
ClearingAccountTypeDictionary clearingAccountTypeDictionary = new ClearingAccountTypeDictionary();
|
||||
clearingAccountTypeDictionary.setName(CLEARING_ACCOUNT_TYPE_DICT);
|
||||
clearingAccountTypeDictionary.setCode(CLEARING_ACCOUNT_TYPE_DICT);
|
||||
clearingAccountTypeDictionaryImdg.insert(clearingAccountTypeDictionary);
|
||||
|
||||
ClearingMemberCategory clearingMemberCategory = new ClearingMemberCategory();
|
||||
clearingMemberCategory.setClearingMemberCategory(ClearingCategory.B.getKey());
|
||||
clearingMemberCategory.setCompanyId(companyId);
|
||||
clearingMemberCategoryImdg.insert(clearingMemberCategory);
|
||||
|
||||
Relation relation = new Relation();
|
||||
relation.setId(relationId);
|
||||
relation.setConsumerId(companyId);
|
||||
relation.setService(Service.MKR.getKey());
|
||||
relationImdg.insert(relation);
|
||||
|
||||
new TestObjectCreator(hazelcastServiceTest).createUserAdmin(1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearingAccountNew() {
|
||||
ClearingAccountNewRequest clearingAccountNewRequest = new ClearingAccountNewRequest();
|
||||
clearingAccountNewRequest.setAccount(ACCOUNT_VALUE);
|
||||
clearingAccountNewRequest.setCompanyId(companyId);
|
||||
clearingAccountNewRequest.setClearingAccountType(CLEARING_ACCOUNT_TYPE_DICT);
|
||||
|
||||
String jsonString = getJsonStringForNew(clearingAccountNewRequest, 0L);
|
||||
|
||||
addRecordToKafka((MockConsumer) clearingAccountService.getConsumer(),
|
||||
Consts.DESTINATION_CLEARING_ACCOUNT_NEW,
|
||||
PARTITION,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
Account predictableAccount = new Account();
|
||||
predictableAccount.setAccount(ACCOUNT_VALUE);
|
||||
predictableAccount.setAccountType(AccountType.Clrn.getKey());
|
||||
predictableAccount.setStatus(ServiceStatus.Active.getKey());
|
||||
predictableAccount.setRelationId(relationId);
|
||||
predictableAccount.setCompanyId(companyId);
|
||||
|
||||
ClearingAccount predictableClearingAccount = new ClearingAccount();
|
||||
predictableClearingAccount.setCompanyId(companyId);
|
||||
predictableClearingAccount.setClearingAccountType(CLEARING_ACCOUNT_TYPE_DICT);
|
||||
|
||||
Account resultAccountNew = accountImdg.getFirstObjectByFieldValues(Map.of("accountType", AccountType.Clrn.getKey()));
|
||||
ClearingAccount resultClearingAccountNew = clearingAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", resultAccountNew.getId()));
|
||||
|
||||
predictableAccount.setId(resultAccountNew.getId());
|
||||
predictableClearingAccount.setAccountId(resultAccountNew.getId());
|
||||
predictableClearingAccount.setId(resultClearingAccountNew.getId());
|
||||
|
||||
ACCOUNT_MATCHER.assertMatch(resultAccountNew, predictableAccount);
|
||||
CLEARING_ACCOUNT_MATCHER.assertMatch(resultClearingAccountNew, predictableClearingAccount);
|
||||
|
||||
clearingAccountImdg.delete(resultClearingAccountNew);
|
||||
accountImdg.delete(resultAccountNew);
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearingAccountUpdate() {
|
||||
Account existAccount = new Account();
|
||||
existAccount.setAccount(ACCOUNT_VALUE);
|
||||
existAccount.setStatus(ServiceStatus.Active.getKey());
|
||||
existAccount.setAccountType(AccountType.Clrn.getKey());
|
||||
Long accountId = accountImdg.insert(existAccount);
|
||||
|
||||
ClearingAccount existClearingAccount = new ClearingAccount();
|
||||
existClearingAccount.setAccountId(accountId);
|
||||
existClearingAccount.setClearingAccountType(CLEARING_ACCOUNT_TYPE_DICT);
|
||||
existClearingAccount.setCompanyId(companyId);
|
||||
|
||||
Account predictableAccount = new Account();
|
||||
predictableAccount.setAccount(ACCOUNT_VALUE);
|
||||
predictableAccount.setStatus(ServiceStatus.Blocked.getKey());
|
||||
predictableAccount.setAccountType(AccountType.Clrn.getKey());
|
||||
|
||||
clearingAccountImdg.insert(existClearingAccount);
|
||||
|
||||
ClearingAccountUpdateRequest clearingAccountUpdateRequest = new ClearingAccountUpdateRequest();
|
||||
clearingAccountUpdateRequest.setAccount(ACCOUNT_VALUE);
|
||||
clearingAccountUpdateRequest.setStatus(0);
|
||||
clearingAccountUpdateRequest.setDeal(TRADING_CODE);
|
||||
|
||||
String jsonString = getJsonStringForUpdate(clearingAccountUpdateRequest, 0L);
|
||||
|
||||
addRecordToKafka((MockConsumer) clearingAccountService.getConsumer(), Consts.DESTINATION_CLEARING_ACCOUNT_UPDATE, PARTITION, 0, jsonString);
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
Account accountResult = accountImdg.getSingleObjectByID(accountId);
|
||||
predictableAccount.setId(accountResult.getId());
|
||||
predictableAccount.setUpdated(accountResult.getUpdated());
|
||||
|
||||
ACCOUNT_MATCHER.assertMatch(accountResult, predictableAccount);
|
||||
}
|
||||
|
||||
@Test
|
||||
void makeSdfErrorText() {
|
||||
Assertions.assertEquals("013", clearingAccountService.makeSdfErrorText(AccountError.CompanyNotFound, SDFProcessService.SDF_STATUS_ERROR_COMPANY_NOT_FOUND));
|
||||
Assertions.assertEquals("2", clearingAccountService.makeSdfErrorText(null, SDFProcessService.SDF_STATUS_ERROR_COMPANY_NOT_FOUND));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ClearingAccountService#accountNewSdf01(BaseRequest)}<br>
|
||||
* Тест проверяет создание сущности {@link BaseRequest} в Hazelcast при передаче из Apache Kafka.<br>
|
||||
* Входной запрос {@link AccountSdf01Request}:<br>
|
||||
* {@link AccountSdfRequestPart#setSdfId} - текущий Id<br>
|
||||
* {@link AccountSdfRequestPart#setAccount} - 123456789123<br>
|
||||
* {@link AccountSdfRequestPart#setCompanyId} - текущий Id<br>
|
||||
* {@link AccountSdf01Request#setGroupingSdf01Id} - текущий Id<br>
|
||||
* {@link AccountSdf01Request#setAccounts} - Collections.singletonList(AccountSdfRequestPart)<br>
|
||||
*/
|
||||
@Test
|
||||
void accountSdf01New() throws InterruptedException {
|
||||
//ARRANGE
|
||||
clearImdg(accountImdg);
|
||||
setMockFuture(kafkaTemplate);
|
||||
Long firstID = currentID.getAndIncrement();
|
||||
Long secondID = currentID.getAndIncrement();
|
||||
AccountSdfRequestPart accountSdfRequestPart = new AccountSdfRequestPart();
|
||||
accountSdfRequestPart.setSdfId(firstID);
|
||||
accountSdfRequestPart.setAccount(ACCOUNT_VALUE);
|
||||
accountSdfRequestPart.setCompanyId(firstID);
|
||||
AccountSdf01Request accountSdf01Request = new AccountSdf01Request();
|
||||
accountSdf01Request.setGroupingSdf01Id(firstID);
|
||||
accountSdf01Request.setAccounts(Collections.singletonList(accountSdfRequestPart));
|
||||
|
||||
String jsonString = getJsonStringForNew(accountSdf01Request, 0L);
|
||||
|
||||
Account predictableAccount = new Account();
|
||||
predictableAccount.setAccount(ACCOUNT_VALUE);
|
||||
predictableAccount.setCompanyId(firstID);
|
||||
predictableAccount.setAccountType(AccountType.Clrn.getKey());
|
||||
predictableAccount.setStatus(ServiceStatus.Active.getKey());
|
||||
predictableAccount.setRelationId(relationId);
|
||||
ClearingAccount predictableClearingAccount = new ClearingAccount();
|
||||
predictableClearingAccount.setCompanyId(companyId);
|
||||
// predictableClearingAccount.setClearingAccountType(CLEARING_ACCOUNT_TYPE_DICT);
|
||||
|
||||
//KAFKA
|
||||
addRecordToKafka((MockConsumer) clearingAccountService.getConsumer(), Consts.ACCOUNT_NEW_SDF01, PARTITION, 0, jsonString);
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
ImdgHazelcast<Account> accountImdg = (ImdgHazelcast<Account>) hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
|
||||
//ASSERT
|
||||
Account accountResult = accountImdg.getSingleObjectBySQL(String.format("account = %s", ACCOUNT_VALUE));
|
||||
ClearingAccount resultClearingAccountNew = clearingAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", accountResult.getId()));
|
||||
predictableAccount.setId(accountResult.getId());
|
||||
predictableClearingAccount.setAccountId(accountResult.getId());
|
||||
predictableClearingAccount.setId(resultClearingAccountNew.getId());
|
||||
predictableAccount.setId(accountResult.getId());
|
||||
ACCOUNT_MATCHER.assertMatch(accountResult, predictableAccount);
|
||||
CLEARING_ACCOUNT_MATCHER.assertMatch(resultClearingAccountNew, predictableClearingAccount);
|
||||
accountImdg.delete(accountResult);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,420 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
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.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.ClearingAccount;
|
||||
import ru.clearing.classes.statics.data.account.ClientCode;
|
||||
import ru.clearing.classes.statics.data.account.DepoAccount;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.profile.CompanyInfo;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.clearing.platform.dictionary.*;
|
||||
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||
import ru.spcex.clearing.account.config.validation.ClientCodeValidationConfig;
|
||||
import ru.spcex.clearing.account.config.validation.TradingClearingRegistryValidationConfig;
|
||||
import ru.spcex.clearing.account.config.validation.ValidationConfig;
|
||||
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.account.ClientCodeNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeUpdateRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
||||
import ru.spcex.clearing.test.MatcherFactory;
|
||||
import ru.spcex.clearing.test.TestObjectCreator;
|
||||
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.TradingClearingRegistryType;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static ru.spcex.clearing.test.TestUtils.waitingSendAndCheckRecord;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
ClientCodeService.class,
|
||||
ClientCodeValidationConfig.class,
|
||||
|
||||
TradingClearingRegistryService.class,
|
||||
TradingClearingRegistryValidationConfig.class,
|
||||
|
||||
ValidationConfig.class,
|
||||
BeanConfiguration.class,
|
||||
|
||||
KafkaTestConfig.class,
|
||||
ImdgTestConfig.class})
|
||||
class ClientCodeServiceTest {
|
||||
|
||||
private static final int PARTITION = 0;
|
||||
private static final Long ID = 4L;
|
||||
public static final MatcherFactory.Matcher<ClientCode> CLIENT_CODE_MATCHER = MatcherFactory.usingIgnoringFieldsComparator("created", "updated");
|
||||
|
||||
private static final Long TCR_ID = 41L;
|
||||
private static final Long COMPANY_ID = 42L;
|
||||
|
||||
@Autowired
|
||||
ClientCodeService clientCodeService;
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private HazelcastService hazelcastServiceTest;
|
||||
@Captor
|
||||
private ArgumentCaptor<ProducerRecord> producerRecord;
|
||||
@Autowired
|
||||
@Qualifier("mockProducer")
|
||||
protected Producer<String, Object> mockProducer;
|
||||
|
||||
private Imdg<ClientCode> clientCodeImdg;
|
||||
|
||||
|
||||
// ****************************-*******************
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
hazelcastServiceTest.waitAvailable();
|
||||
clientCodeImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_ClientCode, ClientCode.class);
|
||||
|
||||
// Словари для теста, применяются в ValidationConfig
|
||||
putToDictionary(IMDGDistributedNames.Map_WorkflowStatusDictionary, new WorkflowStatusDictionary(), "ACTV");
|
||||
putToDictionary(IMDGDistributedNames.Map_CompanySymbolDictionary, new CompanySymbolDictionary(), "CLRC");
|
||||
putToDictionary(IMDGDistributedNames.Map_CorporationSoleTypeDictionary, new CorporationSoleTypeDictionary(), "GDIR");
|
||||
putToDictionary(IMDGDistributedNames.Map_CountryCodeDictionary, new CountryCodeDictionary(), "RUS");
|
||||
putToDictionary(IMDGDistributedNames.Map_AllowedDictionary, new AllowedDictionary(), "ALWD");
|
||||
putToDictionary(IMDGDistributedNames.Map_LegalKindDictionary, new LegalKindDictionary(), "JURD");
|
||||
putToDictionary(IMDGDistributedNames.Map_OrganizationTypeDictionary, new OrganizationTypeDictionary(), "NCRD");
|
||||
|
||||
|
||||
Imdg<Company> companyImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
Company company1 = new Company();
|
||||
company1.setId(COMPANY_ID);
|
||||
company1.setWorkflowStatus(WorkflowStatus.Active.getKey());
|
||||
company1.setFullName("Company prime");
|
||||
company1.setShortName("Seizwell");
|
||||
company1.setProfile(new CompanyInfo());
|
||||
company1.getProfile().setCompanyId(COMPANY_ID);
|
||||
company1.getProfile().setCountryCode("TLDI");
|
||||
company1.getProfile().setDescription("Big profit from TLD Company Prime.");
|
||||
company1.getProfile().setLegalKind("TLDI");
|
||||
company1.getProfile().setResidence("TLDI");
|
||||
companyImdg.insert(company1);
|
||||
|
||||
Imdg<TradingClearingRegistry> tcrImdg = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
TradingClearingRegistry registry1 = new TradingClearingRegistry();
|
||||
registry1.setId(TCR_ID);
|
||||
registry1.setCompanyId(COMPANY_ID);
|
||||
registry1.setCode("code-120-101");
|
||||
registry1.setMoneyAccountId(131L);
|
||||
registry1.setDepoAccountId(132L);
|
||||
registry1.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey());
|
||||
registry1.setStatus(WorkflowStatus.Active.getKey());
|
||||
tcrImdg.insert(registry1);
|
||||
|
||||
Imdg<Account> accounts = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Imdg<ClearingAccount> clsAccounts = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);
|
||||
Account moneyAccount = new Account();
|
||||
moneyAccount.setId(131L);
|
||||
moneyAccount.setAccount("AAAA-4444");
|
||||
moneyAccount.setStatus("ACTV");
|
||||
moneyAccount.setCompanyId(COMPANY_ID); // для валидации принадлежности счёта
|
||||
accounts.insert(moneyAccount);
|
||||
ClearingAccount clsAcc = new ClearingAccount();
|
||||
clsAcc.setId(moneyAccount.getId());
|
||||
clsAcc.setCompanyId(COMPANY_ID);
|
||||
clsAcc.setAccountId(moneyAccount.getId());
|
||||
clsAccounts.insert(clsAcc);
|
||||
Imdg<DepoAccount> depoAccounts = hazelcastServiceTest.getImdg(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
|
||||
Account depoAccount = new Account();
|
||||
depoAccount.setId(132L);
|
||||
depoAccount.setAccount("AAAB-44654");
|
||||
depoAccount.setStatus("ACTV");
|
||||
depoAccount.setCompanyId(COMPANY_ID); // для валидации принадлежности счёта
|
||||
accounts.insert(depoAccount);
|
||||
DepoAccount depoAcc = new DepoAccount();
|
||||
depoAcc.setId(depoAccount.getId());
|
||||
depoAcc.setCompanyId(COMPANY_ID);
|
||||
depoAcc.setAccountId(depoAccount.getId());
|
||||
depoAccounts.insert(depoAcc);
|
||||
|
||||
new TestObjectCreator(hazelcastServiceTest).createUserAdmin(1000L);
|
||||
}
|
||||
|
||||
private <D extends AbstractDictionary> void putToDictionary(String mapName, D object, String code) {
|
||||
Imdg<D> dMap = (Imdg) hazelcastServiceTest.getImdg(mapName, object.getClass());
|
||||
object.setId(2L);
|
||||
object.setCode(code);
|
||||
object.setName("name of " + code);
|
||||
dMap.insert(object);
|
||||
}
|
||||
|
||||
@Test
|
||||
void selectTradingClearingRegistry() {
|
||||
TradingClearingRegistry tcr = clientCodeService.selectTradingClearingRegistry(COMPANY_ID, 131L, 132L);
|
||||
assertNotNull(tcr);
|
||||
assertEquals(41L, tcr.getId());
|
||||
|
||||
tcr = clientCodeService.selectTradingClearingRegistry(COMPANY_ID, 131L, null);
|
||||
assertNotNull(tcr);
|
||||
assertEquals(41L, tcr.getId());
|
||||
|
||||
assertNull(clientCodeService.selectTradingClearingRegistry(0L, 131L, 132L));
|
||||
assertNull(clientCodeService.selectTradingClearingRegistry(COMPANY_ID, 0L, 132L));
|
||||
assertNull(clientCodeService.selectTradingClearingRegistry(COMPANY_ID, 131L, 0L));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link ClientCodeService#clientCodeUpdate(BaseRequest)}<br>
|
||||
* Тест проверяет создание {@link ClientCode} в IMDG при передаче из Apache Kafka (очередь 1).<br>
|
||||
* Входной запрос {@link ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeNewRequest}:<br>
|
||||
**/
|
||||
@Test
|
||||
void clientCodeNew1() {
|
||||
//ARRANGE
|
||||
final String ccCode = "Lucky planet";
|
||||
ClientCodeNewRequest clientCodeNewRequest = new ClientCodeNewRequest();
|
||||
clientCodeNewRequest.setCompanyId(COMPANY_ID);
|
||||
clientCodeNewRequest.setCode(ccCode);
|
||||
clientCodeNewRequest.setTradingClearingRegistryId(TCR_ID);
|
||||
clientCodeNewRequest.setDepoAccountId(null);
|
||||
clientCodeNewRequest.setMoneyAccountId(null);
|
||||
clientCodeNewRequest.setStatus("ACTV");
|
||||
|
||||
ClientCode predictableClientCode = new ClientCode();
|
||||
predictableClientCode.setCode(ccCode);
|
||||
predictableClientCode.setStatus("ACTV");
|
||||
predictableClientCode.setCompanyId(COMPANY_ID);
|
||||
// predictableClientCode.setMoneyAccountId(131L);
|
||||
// predictableClientCode.setDepoAccountId(132L);
|
||||
// predictableClientCode.setTradingClearingRegistryId(TCR_ID);
|
||||
|
||||
//ACT
|
||||
String jsonString = TestUtils.getJsonStringForNew(clientCodeNewRequest, ID);
|
||||
|
||||
TestUtils.addRecordToKafka((MockConsumer) clientCodeService.getConsumer(), Consts.DESTINATION_CLIENT_CODE_NEW, PARTITION, 0, jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingSendAndCheckRecord(ID, mockProducer);
|
||||
ClientCode resultNew = clientCodeImdg.getFirstObjectBySQL(String.format("code = '%s'", ccCode));
|
||||
predictableClientCode.setId(resultNew.getId());
|
||||
CLIENT_CODE_MATCHER.assertMatch(resultNew, predictableClientCode);
|
||||
assertNotNull(resultNew.getCreated());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ClientCodeService#clientCodeUpdate(BaseRequest)}<br>
|
||||
* Тест проверяет создание {@link ClientCode} в IMDG при передаче из Apache Kafka (очередь 2).<br>
|
||||
* Входной запрос {@link ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeNewRequest}:<br>
|
||||
**/
|
||||
@Test
|
||||
void clientCodeNew2() {
|
||||
//ARRANGE
|
||||
final String ccCode = "Lucky planet";
|
||||
ClientCodeNewRequest clientCodeNewRequest = new ClientCodeNewRequest();
|
||||
clientCodeNewRequest.setCompanyId(COMPANY_ID);
|
||||
clientCodeNewRequest.setCode(ccCode);
|
||||
clientCodeNewRequest.setTradingClearingRegistryId(TCR_ID);
|
||||
clientCodeNewRequest.setDepoAccountId(null);
|
||||
clientCodeNewRequest.setMoneyAccountId(null);
|
||||
clientCodeNewRequest.setStatus("ACTV");
|
||||
|
||||
ClientCode predictableClientCode = new ClientCode();
|
||||
predictableClientCode.setCode(ccCode);
|
||||
predictableClientCode.setStatus("ACTV");
|
||||
predictableClientCode.setCompanyId(COMPANY_ID);
|
||||
// predictableClientCode.setMoneyAccountId(131L);
|
||||
// predictableClientCode.setDepoAccountId(132L);
|
||||
// predictableClientCode.setTradingClearingRegistryId(TCR_ID);
|
||||
|
||||
//ACT
|
||||
String jsonString = TestUtils.getJsonStringForNew(clientCodeNewRequest, ID);
|
||||
|
||||
TestUtils.addRecordToKafka((MockConsumer) clientCodeService.getConsumer(), Consts.DESTINATION_CLIENT_CODE_NEW_UM_COMPANY, PARTITION, 0, jsonString);
|
||||
|
||||
//ASSERT
|
||||
TestUtils.waitingSendAndCheckRecord(ID, mockProducer, producerRecord);
|
||||
ClientCode resultNew = clientCodeImdg.getFirstObjectBySQL(String.format("code = '%s'", ccCode));
|
||||
predictableClientCode.setId(resultNew.getId());
|
||||
CLIENT_CODE_MATCHER.assertMatch(resultNew, predictableClientCode);
|
||||
assertNotNull(resultNew.getCreated());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link ClientCodeService#clientCodeUpdate(BaseRequest)}<br>
|
||||
* Тест проверяет создание {@link ClientCode} в IMDG при передаче из Apache Kafka (очередь 1).<br>
|
||||
* NEW с заполненными MoneyAccountId(131L), DepoAccountId(132L); - от этого будет создан ТКР.
|
||||
* Входной запрос {@link ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeNewRequest}:<br>
|
||||
**/
|
||||
@Test
|
||||
void clientCodeNew3() {
|
||||
//ARRANGE
|
||||
final String ccCode = "Lucky planet2";
|
||||
ClientCodeNewRequest clientCodeNewRequest = new ClientCodeNewRequest();
|
||||
clientCodeNewRequest.setCompanyId(COMPANY_ID);
|
||||
clientCodeNewRequest.setCode(ccCode);
|
||||
clientCodeNewRequest.setTradingClearingRegistryId(null);
|
||||
clientCodeNewRequest.setMoneyAccountId(131L);
|
||||
clientCodeNewRequest.setDepoAccountId(132L);
|
||||
clientCodeNewRequest.setStatus("ACTV");
|
||||
|
||||
ClientCode predictableClientCode = new ClientCode();
|
||||
predictableClientCode.setCode(ccCode);
|
||||
predictableClientCode.setStatus("ACTV");
|
||||
predictableClientCode.setCompanyId(COMPANY_ID);
|
||||
predictableClientCode.setMoneyAccountId(131L);
|
||||
predictableClientCode.setDepoAccountId(132L);
|
||||
predictableClientCode.setTradingClearingRegistryId(TCR_ID);
|
||||
|
||||
//ACT
|
||||
String jsonString = TestUtils.getJsonStringForNew(clientCodeNewRequest, ID);
|
||||
|
||||
TestUtils.addRecordToKafka((MockConsumer) clientCodeService.getConsumer(), Consts.DESTINATION_CLIENT_CODE_NEW, PARTITION, 0, jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingSendAndCheckRecord(ID, mockProducer);
|
||||
ClientCode resultNew = clientCodeImdg.getFirstObjectBySQL(String.format("code = '%s'", ccCode));
|
||||
predictableClientCode.setId(resultNew.getId());
|
||||
CLIENT_CODE_MATCHER.assertMatch(resultNew, predictableClientCode);
|
||||
assertNotNull(resultNew.getCreated());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ClientCodeService#clientCodeUpdate(BaseRequest)}<br>
|
||||
* Тест проверяет обновление сущности {@link ClientCode} в IMDG при передаче из Apache Kafka.<br>
|
||||
* Входной запрос {@link ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeUpdateRequest}:<br>
|
||||
**/
|
||||
@Test
|
||||
void clientCodeUpdate() {
|
||||
//ARRANGE
|
||||
ClientCode existsClientCode = new ClientCode();
|
||||
existsClientCode.setId(ID);
|
||||
existsClientCode.setCompanyId(COMPANY_ID);
|
||||
existsClientCode.setCode("0000");
|
||||
existsClientCode.setTradingClearingRegistryId(TCR_ID);
|
||||
existsClientCode.setMoneyAccountId(131L);
|
||||
existsClientCode.setDepoAccountId(132L);
|
||||
existsClientCode.setStatus("ACTV");
|
||||
clientCodeImdg.insert(existsClientCode);
|
||||
|
||||
ClientCodeUpdateRequest clientCodeUpdateRequest = new ClientCodeUpdateRequest();
|
||||
clientCodeUpdateRequest.setId(ID);
|
||||
clientCodeUpdateRequest.setCompanyId(COMPANY_ID);
|
||||
clientCodeUpdateRequest.setCode("1111");
|
||||
clientCodeUpdateRequest.setTradingClearingRegistryId(TCR_ID);
|
||||
clientCodeUpdateRequest.setMoneyAccountId(131L);
|
||||
clientCodeUpdateRequest.setDepoAccountId(132L);
|
||||
clientCodeUpdateRequest.setStatus("ACTV");
|
||||
|
||||
ClientCode predictableClientCode = new ClientCode();
|
||||
predictableClientCode.setId(ID);
|
||||
predictableClientCode.setCompanyId(COMPANY_ID);
|
||||
predictableClientCode.setCode("1111");
|
||||
predictableClientCode.setTradingClearingRegistryId(TCR_ID);
|
||||
predictableClientCode.setMoneyAccountId(131L);
|
||||
predictableClientCode.setDepoAccountId(132L);
|
||||
predictableClientCode.setStatus("ACTV");
|
||||
|
||||
//ACT
|
||||
String jsonString = TestUtils.getJsonStringForUpdate(clientCodeUpdateRequest, ID);
|
||||
|
||||
TestUtils.addRecordToKafka((MockConsumer) clientCodeService.getConsumer(), Consts.DESTINATION_CLIENT_CODE_UPDATE, PARTITION, 0, jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingSendAndCheckRecord(ID, mockProducer);
|
||||
|
||||
ClientCode resultUpdating = clientCodeImdg.getSingleObjectByID(ID);
|
||||
CLIENT_CODE_MATCHER.assertMatch(resultUpdating, predictableClientCode);
|
||||
assertNotNull(resultUpdating.getUpdated());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link ClientCodeService#clientCodeUpdate(BaseRequest)}<br>
|
||||
* Тест проверяет удаление {@link ClientCode} из IMDG при передаче из Apache Kafka.<br>
|
||||
* Входной запрос {@link ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest}:<br>
|
||||
**/
|
||||
@Test
|
||||
void clientCodeDelete1() {
|
||||
//ARRANGE
|
||||
ClientCode existsClientCode = new ClientCode();
|
||||
existsClientCode.setId(ID);
|
||||
existsClientCode.setCompanyId(COMPANY_ID);
|
||||
existsClientCode.setCode("0000");
|
||||
// Если следующие поля заполнить, то дополнительно отправит сообщение в trading-clearing-registry-update:
|
||||
existsClientCode.setTradingClearingRegistryId(null);
|
||||
existsClientCode.setMoneyAccountId(null);
|
||||
existsClientCode.setDepoAccountId(null);
|
||||
existsClientCode.setStatus("ACTV");
|
||||
|
||||
clientCodeImdg.insert(existsClientCode);
|
||||
|
||||
CommonDeleteRequest clientCodeDeleteRequest = new CommonDeleteRequest();
|
||||
clientCodeDeleteRequest.setId(ID);
|
||||
|
||||
Assertions.assertNotNull(clientCodeImdg.getSingleObjectByID(ID)); // verify test data
|
||||
|
||||
//ACT
|
||||
String jsonString = TestUtils.getJsonStringForUpdate(clientCodeDeleteRequest, ID);
|
||||
|
||||
TestUtils.addRecordToKafka((MockConsumer) clientCodeService.getConsumer(), Consts.DESTINATION_CLIENT_CODE_DELETE, PARTITION, 0, jsonString);
|
||||
|
||||
//ASSERT
|
||||
|
||||
waitingSendAndCheckRecord(ID, mockProducer);
|
||||
ClientCode resultUpdate = clientCodeImdg.getSingleObjectByID(ID);
|
||||
assertEquals(WorkflowStatus.Blocked.getKey(), resultUpdate.getStatus());
|
||||
}
|
||||
|
||||
// /**
|
||||
// * {@link ClientCodeService#clientCodeUpdate(BaseRequest)}<br>
|
||||
// * Тест проверяет удаление {@link ClientCode} из IMDG при передаче из Apache Kafka.<br>
|
||||
// * У ClientCode заполнены MoneyAccountId, DepoAccountId - по этому при удалении должно направиться дополнительное сообщение в очередь DESTINATION_TRADING_CLEARING_REGISTRY_UPDATE<br>
|
||||
// * Входной запрос {@link ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest}:<br>
|
||||
// **/
|
||||
// @Test
|
||||
// void clientCodeDelete2() {
|
||||
// //ARRANGE
|
||||
// ClientCode existsClientCode = new ClientCode();
|
||||
// existsClientCode.setId(ID);
|
||||
// existsClientCode.setCompanyId(COMPANY_ID);
|
||||
// existsClientCode.setCode("0000");
|
||||
// // Если следующие поля заполнить, то дополнительно отправит сообщение в trading-clearing-registry-update:
|
||||
// existsClientCode.setTradingClearingRegistryId(TCR_ID);
|
||||
// existsClientCode.setMoneyAccountId(131L);
|
||||
// existsClientCode.setDepoAccountId(132L);
|
||||
// existsClientCode.setStatus("ACTV");
|
||||
//
|
||||
// clientCodeImdg.insert(existsClientCode);
|
||||
//
|
||||
// CommonDeleteRequest clientCodeDeleteRequest = new CommonDeleteRequest();
|
||||
// clientCodeDeleteRequest.setId(ID);
|
||||
//
|
||||
// Assertions.assertNotNull(clientCodeImdg.getSingleObjectByID(ID)); // verify test data
|
||||
//
|
||||
// //ACT
|
||||
// String jsonString = getJsonStringForUpdate(clientCodeDeleteRequest, ID);
|
||||
//
|
||||
// addRecordToKafka((MockConsumer) clientCodeService.getConsumer(), Consts.DESTINATION_CLIENT_CODE_DELETE, PARTITION, 0, jsonString);
|
||||
//
|
||||
// //ASSERT
|
||||
//
|
||||
// waitingWhenAddedRecordAndCheckIt(ID, mockProducer, producerRecord);
|
||||
// ClientCode resultUpdate = clientCodeImdg.getSingleObjectByID(ID);
|
||||
// Assertions.assertNull(resultUpdate);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
@ -1,177 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.DepoAccount;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.clearing.platform.dictionary.AccountTypeDictionary;
|
||||
import ru.clearing.platform.dictionary.DepoAccountTypeDictionary;
|
||||
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||
import ru.spcex.clearing.account.config.validation.AccountValidationConfig;
|
||||
import ru.spcex.clearing.account.config.validation.DepoAccountValidationConfig;
|
||||
import ru.spcex.clearing.account.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.account.DepoAccountNewRequest;
|
||||
import ru.spcex.clearing.test.MatcherFactory;
|
||||
import ru.spcex.clearing.test.TestObjectCreator;
|
||||
import ru.spcex.clearing.test.config.ImdgTestConfig;
|
||||
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||
import ru.spcex.platform.enumeration.*;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Map;
|
||||
|
||||
import static ru.spcex.clearing.test.MatcherFactory.usingIgnoringFieldsComparator;
|
||||
import static ru.spcex.clearing.test.TestUtils.*;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
BeanConfiguration.class,
|
||||
ValidationConfig.class,
|
||||
DepoAccountValidationConfig.class,
|
||||
AccountValidationConfig.class,
|
||||
AccountHelper.class,
|
||||
DepoAccountService.class,
|
||||
ImdgTestConfig.class,
|
||||
KafkaTestConfig.class})
|
||||
class DepoAccountServiceTest {
|
||||
public static final MatcherFactory.Matcher<DepoAccount> CLEARING_ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||
public static final MatcherFactory.Matcher<Account> ACCOUNT_MATCHER = usingIgnoringFieldsComparator("created", "updated");
|
||||
private static final int PARTITION = 0;
|
||||
private static final Long companyId = 0L;
|
||||
private static final Long relationId = 0L;
|
||||
private static final String DEPO_ACCOUNT_TYPE_DICT = "A";
|
||||
private static final String ACCOUNT_VALUE = "account-value";
|
||||
private static final String TRADING_CODE = "trading-code";
|
||||
|
||||
@Autowired
|
||||
DepoAccountService depoAccountService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private ImdgProvider hazelcastServiceTest;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mockProducer")
|
||||
protected Producer<String, Object> mockProducer;
|
||||
|
||||
private Imdg<DepoAccount> depoAccountImdg;
|
||||
private Imdg<Account> accountImdg;
|
||||
private Imdg<Company> companyImdg;
|
||||
private Imdg<DepoAccountTypeDictionary> depoAccountTypeDictionaryImdg;
|
||||
private Imdg<AccountTypeDictionary> accountTypeDictionaryImdg;
|
||||
private Imdg<ClearingMemberCategory> clearingMemberCategoryImdg;
|
||||
private Imdg<Relation> relationImdg;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
hazelcastServiceTest.waitAvailable();
|
||||
depoAccountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_DepoAccount, DepoAccount.class
|
||||
);
|
||||
accountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
|
||||
companyImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Company, Company.class
|
||||
);
|
||||
accountTypeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_AccountTypeDictionary, AccountTypeDictionary.class
|
||||
);
|
||||
depoAccountTypeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_DepoAccountTypeDictionary, DepoAccountTypeDictionary.class
|
||||
);
|
||||
clearingMemberCategoryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class
|
||||
);
|
||||
relationImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Relation, Relation.class
|
||||
);
|
||||
|
||||
Company company = new Company();
|
||||
company.setId(companyId);
|
||||
company.setWorkflowStatus(WorkflowStatus.Active.getKey());
|
||||
company.setTradingCode(TRADING_CODE);
|
||||
companyImdg.insert(company);
|
||||
|
||||
AccountTypeDictionary accountTypeDictionary = new AccountTypeDictionary();
|
||||
accountTypeDictionary.setCode(AccountType.Depo.getKey());
|
||||
accountTypeDictionary.setName(AccountType.Depo.getKey());
|
||||
accountTypeDictionaryImdg.insert(accountTypeDictionary);
|
||||
|
||||
DepoAccountTypeDictionary depoAccountTypeDictionary = new DepoAccountTypeDictionary();
|
||||
depoAccountTypeDictionary.setName(DEPO_ACCOUNT_TYPE_DICT);
|
||||
depoAccountTypeDictionary.setCode(DEPO_ACCOUNT_TYPE_DICT);
|
||||
depoAccountTypeDictionaryImdg.insert(depoAccountTypeDictionary);
|
||||
|
||||
ClearingMemberCategory clearingMemberCategory = new ClearingMemberCategory();
|
||||
clearingMemberCategory.setClearingMemberCategory(ClearingCategory.B.getKey());
|
||||
clearingMemberCategory.setCompanyId(companyId);
|
||||
clearingMemberCategoryImdg.insert(clearingMemberCategory);
|
||||
|
||||
Relation relation = new Relation();
|
||||
relation.setId(relationId);
|
||||
relation.setConsumerId(companyId);
|
||||
relation.setService(Service.MKR.getKey());
|
||||
relationImdg.insert(relation);
|
||||
|
||||
new TestObjectCreator(hazelcastServiceTest).createUserAdmin(1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void depoAccountNew() {
|
||||
DepoAccountNewRequest depoAccountNewRequest = new DepoAccountNewRequest();
|
||||
depoAccountNewRequest.setAccount(ACCOUNT_VALUE);
|
||||
depoAccountNewRequest.setCompanyId(companyId);
|
||||
depoAccountNewRequest.setDepoAccountType(DEPO_ACCOUNT_TYPE_DICT);
|
||||
|
||||
String jsonString = getJsonStringForNew(depoAccountNewRequest, 0L);
|
||||
|
||||
addRecordToKafka((MockConsumer) depoAccountService.getConsumer(),
|
||||
Consts.DESTINATION_DEPO_ACCOUNT_NEW,
|
||||
PARTITION,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
Account predictableAccount = new Account();
|
||||
predictableAccount.setAccount(ACCOUNT_VALUE);
|
||||
predictableAccount.setAccountType(AccountType.Depo.getKey());
|
||||
predictableAccount.setStatus(ServiceStatus.Active.getKey());
|
||||
predictableAccount.setRelationId(relationId);
|
||||
predictableAccount.setCompanyId(companyId);
|
||||
|
||||
DepoAccount predictableDepoAccount = new DepoAccount();
|
||||
predictableDepoAccount.setCompanyId(companyId);
|
||||
predictableDepoAccount.setDepoAccountType(DEPO_ACCOUNT_TYPE_DICT);
|
||||
|
||||
Account resultAccountNew = accountImdg.getFirstObjectByFieldValues(Map.of("accountType", AccountType.Depo.getKey()));
|
||||
DepoAccount resultDepoAccountNew = depoAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", resultAccountNew.getId()));
|
||||
|
||||
predictableAccount.setId(resultAccountNew.getId());
|
||||
predictableDepoAccount.setAccountId(resultAccountNew.getId());
|
||||
predictableDepoAccount.setId(resultDepoAccountNew.getId());
|
||||
|
||||
ACCOUNT_MATCHER.assertMatch(resultAccountNew, predictableAccount);
|
||||
CLEARING_ACCOUNT_MATCHER.assertMatch(resultDepoAccountNew, predictableDepoAccount);
|
||||
|
||||
depoAccountImdg.delete(resultDepoAccountNew);
|
||||
accountImdg.delete(resultAccountNew);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,198 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.clearing.platform.dictionary.AccountTypeDictionary;
|
||||
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||
import ru.spcex.clearing.account.config.validation.AccountValidationConfig;
|
||||
import ru.spcex.clearing.account.config.validation.InformationAccountValidationConfig;
|
||||
import ru.spcex.clearing.account.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.account.InformationAccountNewRequest;
|
||||
import ru.spcex.clearing.test.MatcherFactory;
|
||||
import ru.spcex.clearing.test.TestObjectCreator;
|
||||
import ru.spcex.clearing.test.config.ImdgTestConfig;
|
||||
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||
import ru.spcex.platform.enumeration.*;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Map;
|
||||
|
||||
import static ru.spcex.clearing.test.MatcherFactory.usingIgnoringFieldsComparator;
|
||||
import static ru.spcex.clearing.test.TestUtils.*;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
BeanConfiguration.class,
|
||||
ValidationConfig.class,
|
||||
InformationAccountValidationConfig.class,
|
||||
AccountValidationConfig.class,
|
||||
AccountHelper.class,
|
||||
InformationAccountService.class,
|
||||
ImdgTestConfig.class,
|
||||
KafkaTestConfig.class})
|
||||
class InformationAccountServiceTest {
|
||||
public static final MatcherFactory.Matcher<InformationAccount> INFORMATION_ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||
public static final MatcherFactory.Matcher<Account> ACCOUNT_MATCHER = usingIgnoringFieldsComparator("created", "updated");
|
||||
private static final int PARTITION = 0;
|
||||
private static final String account = "123456789123";
|
||||
private static final Long companyId = 0L;
|
||||
private static final Long relationId = 0L;
|
||||
private Long anltAccountId;
|
||||
|
||||
@Autowired
|
||||
InformationAccountService informationAccountService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private ImdgProvider hazelcastServiceTest;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mockProducer")
|
||||
protected Producer<String, Object> mockProducer;
|
||||
|
||||
private Imdg<InformationAccount> informationAccountImdg;
|
||||
private Imdg<Account> accountImdg;
|
||||
private Imdg<Company> companyImdg;
|
||||
private Imdg<AccountTypeDictionary> accountTypeDictionaryImdg;
|
||||
private Imdg<ClearingMemberCategory> clearingMemberCategoryImdg;
|
||||
private Imdg<Relation> relationImdg;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
hazelcastServiceTest.waitAvailable();
|
||||
informationAccountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_InformationAccount, InformationAccount.class
|
||||
);
|
||||
accountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
clearImdg(accountImdg);
|
||||
|
||||
companyImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Company, Company.class
|
||||
);
|
||||
accountTypeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_AccountTypeDictionary, AccountTypeDictionary.class
|
||||
);
|
||||
clearingMemberCategoryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class
|
||||
);
|
||||
relationImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Relation, Relation.class
|
||||
);
|
||||
|
||||
Company company = new Company();
|
||||
company.setId(companyId);
|
||||
company.setWorkflowStatus(WorkflowStatus.Active.getKey());
|
||||
companyImdg.insert(company);
|
||||
|
||||
AccountTypeDictionary accountTypeDictionary = new AccountTypeDictionary();
|
||||
accountTypeDictionary.setCode(AccountType.Info.getKey());
|
||||
accountTypeDictionary.setName(AccountType.Info.getKey());
|
||||
accountTypeDictionaryImdg.insert(accountTypeDictionary);
|
||||
|
||||
ClearingMemberCategory clearingMemberCategory = new ClearingMemberCategory();
|
||||
clearingMemberCategory.setClearingMemberCategory(ClearingCategory.B.getKey());
|
||||
clearingMemberCategory.setCompanyId(companyId);
|
||||
clearingMemberCategoryImdg.insert(clearingMemberCategory);
|
||||
|
||||
Relation relation = new Relation();
|
||||
relation.setId(relationId);
|
||||
relation.setConsumerId(companyId);
|
||||
relation.setService(Service.MKR.getKey());
|
||||
relationImdg.insert(relation);
|
||||
|
||||
Account accountAnlt = new Account();
|
||||
accountAnlt.setAccountType(AccountType.Anlt.getKey());
|
||||
accountAnlt.setCompanyId(1L);
|
||||
anltAccountId = accountImdg.insert(accountAnlt);
|
||||
|
||||
new TestObjectCreator(hazelcastServiceTest).createUserAdmin(1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountInformationNew() {
|
||||
InformationAccountNewRequest InformationAccountNewRequest = new InformationAccountNewRequest();
|
||||
InformationAccountNewRequest.setCompanyId(companyId);
|
||||
InformationAccountNewRequest.setAccount(account);
|
||||
|
||||
String jsonString = getJsonStringForNew(InformationAccountNewRequest, 0L);
|
||||
|
||||
addRecordToKafka((MockConsumer) informationAccountService.getConsumer(),
|
||||
Consts.DESTINATION_INFORMATION_ACCOUNT_NEW,
|
||||
PARTITION,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
Account predictableAccount = new Account();
|
||||
predictableAccount.setAccountType(AccountType.Info.getKey());
|
||||
predictableAccount.setStatus(ServiceStatus.Active.getKey());
|
||||
predictableAccount.setRelationId(relationId);
|
||||
predictableAccount.setCompanyId(companyId);
|
||||
|
||||
InformationAccount predictableInfoAccount = new InformationAccount();
|
||||
predictableInfoAccount.setCompanyId(companyId);
|
||||
predictableInfoAccount.setClearingAccountId(anltAccountId);
|
||||
|
||||
Account resultAccountNew = accountImdg.getFirstObjectByFieldValues(Map.of("accountType", AccountType.Info.getKey()));
|
||||
InformationAccount resultInfoAccountNew = informationAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", resultAccountNew.getId()));
|
||||
|
||||
predictableAccount.setId(resultAccountNew.getId());
|
||||
predictableAccount.setAccount(account);
|
||||
predictableInfoAccount.setAccountId(resultAccountNew.getId());
|
||||
predictableInfoAccount.setId(resultInfoAccountNew.getId());
|
||||
|
||||
ACCOUNT_MATCHER.assertMatch(resultAccountNew, predictableAccount);
|
||||
INFORMATION_ACCOUNT_MATCHER.assertMatch(resultInfoAccountNew, predictableInfoAccount);
|
||||
|
||||
informationAccountImdg.delete(resultInfoAccountNew);
|
||||
accountImdg.delete(resultAccountNew);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountIncrementSequence() {
|
||||
Imdg<InformationAccount> accountInfoImdg = hazelcastServiceTest.getImdg( IMDGDistributedNames.Map_InformationAccount, InformationAccount.class );
|
||||
|
||||
{
|
||||
Account account = new Account();
|
||||
account.setId(120L);
|
||||
account.setAccountType(AccountType.Info.getKey());
|
||||
account.setCompanyId(10L);
|
||||
account.setAccount("39911810000000127000");
|
||||
accountImdg.insert(account);
|
||||
InformationAccount accountInfo = new InformationAccount();
|
||||
accountInfo.setId(121L);
|
||||
accountInfo.setAccountId(account.getId());
|
||||
accountInfo.setCompanyId(account.getCompanyId());
|
||||
accountInfoImdg.insert(accountInfo);
|
||||
}
|
||||
UserRoleVerification userRoleVerification = Mockito.mock(UserRoleVerification.class);
|
||||
InformationAccountService infoAccSvc=new InformationAccountService(null,null,null,
|
||||
null, userRoleVerification, hazelcastServiceTest, null, null, null, null);
|
||||
Long n = infoAccSvc.accountNextId();
|
||||
Assertions.assertEquals(13L, n);
|
||||
n = infoAccSvc.accountNextId();
|
||||
Assertions.assertEquals(14L, n);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.producer.MockProducer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
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.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.ClearingAccount;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.clearing.platform.dictionary.AccountTypeDictionary;
|
||||
import ru.clearing.platform.dictionary.ClearingAccountTypeDictionary;
|
||||
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||
import ru.spcex.clearing.account.config.validation.ValidationConfig;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.test.TestObjectCreator;
|
||||
import ru.spcex.clearing.test.config.ImdgTestConfig;
|
||||
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||
import ru.spcex.platform.enumeration.AccountStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
BeanConfiguration.class,
|
||||
ValidationConfig.class,
|
||||
SDFProcessService.class,
|
||||
ImdgTestConfig.class,
|
||||
KafkaTestConfig.class})
|
||||
class SDFProcessServiceTest {
|
||||
@Autowired
|
||||
SDFProcessService sdfProcessService;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private ImdgProvider hazelcastServiceTest;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<ProducerRecord> producerRecord;
|
||||
@SpyBean
|
||||
private MockProducer<String, Object> producer;
|
||||
@Autowired
|
||||
@Qualifier("mockProducer")
|
||||
protected Producer<String, Object> mockProducer;
|
||||
|
||||
private Imdg<ClearingAccount> clearingAccountImdg;
|
||||
private Imdg<Account> accountImdg;
|
||||
private Imdg<Company> companyImdg;
|
||||
private Imdg<ClearingAccountTypeDictionary> clearingAccountTypeDictionaryImdg;
|
||||
private Imdg<AccountTypeDictionary> accountTypeDictionaryImdg;
|
||||
private Imdg<ClearingMemberCategory> clearingMemberCategoryImdg;
|
||||
private Imdg<Relation> relationImdg;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
hazelcastServiceTest.waitAvailable();
|
||||
clearingAccountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class
|
||||
);
|
||||
accountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
|
||||
companyImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Company, Company.class
|
||||
);
|
||||
accountTypeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_AccountTypeDictionary, AccountTypeDictionary.class
|
||||
);
|
||||
clearingAccountTypeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingAccountTypeDictionary, ClearingAccountTypeDictionary.class
|
||||
);
|
||||
clearingMemberCategoryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class
|
||||
);
|
||||
relationImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Relation, Relation.class
|
||||
);
|
||||
|
||||
|
||||
new TestObjectCreator(hazelcastServiceTest).createUserAdmin(1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseSdf52Status() {
|
||||
Assertions.assertEquals(AccountStatus.BLOCKED, sdfProcessService.parseSdf52Status(0L));
|
||||
Assertions.assertEquals(AccountStatus.ACTIVE, sdfProcessService.parseSdf52Status(1L));
|
||||
Assertions.assertEquals(AccountStatus.ACTIVE, sdfProcessService.parseSdf52Status(3L));
|
||||
Assertions.assertEquals(AccountStatus.CLOSE, sdfProcessService.parseSdf52Status(2L));
|
||||
Assertions.assertEquals(null, sdfProcessService.parseSdf52Status(4705211956118233163L));
|
||||
Assertions.assertEquals(null, sdfProcessService.parseSdf52Status(null));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,357 +0,0 @@
|
|||
package ru.spcex.clearing.account.service;
|
||||
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.ClearingAccount;
|
||||
import ru.clearing.classes.statics.data.account.DepoAccount;
|
||||
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
|
||||
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||
import ru.spcex.clearing.account.config.validation.TradingClearingRegistryValidationConfig;
|
||||
import ru.spcex.clearing.account.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.registry.TradingClearingRegistryNewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryUpdateRequest;
|
||||
import ru.spcex.clearing.test.MatcherFactory;
|
||||
import ru.spcex.clearing.test.TestObjectCreator;
|
||||
import ru.spcex.clearing.test.config.ImdgTestConfig;
|
||||
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||
import ru.spcex.platform.enumeration.*;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import static ru.spcex.clearing.test.MatcherFactory.usingIgnoringFieldsComparator;
|
||||
import static ru.spcex.clearing.test.TestUtils.*;
|
||||
import static ru.spcex.clearing.test.config.KafkaTestConfig.setMockFuture;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {
|
||||
BeanConfiguration.class,
|
||||
ValidationConfig.class,
|
||||
TradingClearingRegistryValidationConfig.class,
|
||||
TradingClearingRegistryService.class,
|
||||
ImdgTestConfig.class,
|
||||
KafkaTestConfig.class})
|
||||
class TradingClearingRegistryServiceTest {
|
||||
public static final MatcherFactory.Matcher<TradingClearingRegistry> TRADING_CLEARING_REGISTRY_MATCHER = usingIgnoringFieldsComparator();
|
||||
private static final int PARTITION = 0;
|
||||
private static final String TOPIC_ACCOUNT_NEW = Consts.ACCOUNT_NEW_SDF01;
|
||||
private static final String account = "123456789123";
|
||||
private static final Long companyId = 0L;
|
||||
private static final Long relationId = 0L;
|
||||
@Autowired
|
||||
TradingClearingRegistryService tradingClearingRegistryService;
|
||||
@Autowired
|
||||
@Qualifier("hazelcastServiceTest")
|
||||
private ImdgProvider hazelcastServiceTest;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("mockProducer")
|
||||
protected Producer<String, Object> mockProducer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("kafkaTestTemplate")
|
||||
protected KafkaTemplate<String, Object> kafkaTemplate;
|
||||
|
||||
private Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
|
||||
private Imdg<Company> companyImdg;
|
||||
private Imdg<CompanySymbols> companySymbolsImdg;
|
||||
private Imdg<ServiceStatusDictionary> serviceStatusDictionaryImdg;
|
||||
|
||||
private Imdg<ClearingAccount> clearingAccountImdg;
|
||||
private Long clearingAccountId;
|
||||
|
||||
private Imdg<DepoAccount> depoAccountImdg;
|
||||
private Long depoAccountId;
|
||||
|
||||
private Imdg<InformationAccount> informationAccountImdg;
|
||||
private Long infoAccountId;
|
||||
|
||||
private Imdg<Account> accountImdg;
|
||||
private Long accountId;
|
||||
|
||||
private Long account2Id;
|
||||
|
||||
static int newRequestCnt = 0;
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
hazelcastServiceTest.waitAvailable();
|
||||
tradingClearingRegistryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class
|
||||
);
|
||||
companyImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Company, Company.class
|
||||
);
|
||||
companySymbolsImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class
|
||||
);
|
||||
serviceStatusDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary, ServiceStatusDictionary.class
|
||||
);
|
||||
accountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_Account, Account.class
|
||||
);
|
||||
clearingAccountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class
|
||||
);
|
||||
depoAccountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_DepoAccount, DepoAccount.class
|
||||
);
|
||||
informationAccountImdg = hazelcastServiceTest.getImdg(
|
||||
IMDGDistributedNames.Map_InformationAccount, InformationAccount.class
|
||||
);
|
||||
ServiceStatusDictionary serviceStatusDictionary = new ServiceStatusDictionary();
|
||||
serviceStatusDictionary.setCode(ServiceStatus.Active.getKey());
|
||||
serviceStatusDictionary.setName(ServiceStatus.Active.getKey());
|
||||
serviceStatusDictionaryImdg.insert(serviceStatusDictionary);
|
||||
|
||||
Company company = new Company();
|
||||
company.setId(companyId);
|
||||
company.setWorkflowStatus(WorkflowStatus.Active.getKey());
|
||||
company.setClearingCode("77");
|
||||
companyImdg.insert(company);
|
||||
|
||||
CompanySymbols companySymbols = new CompanySymbols();
|
||||
companySymbols.setCompanyId(companyId);
|
||||
companySymbols.setCompanySymbol(CompanySymbol.CLRC.getKey());
|
||||
companySymbolsImdg.insert(companySymbols);
|
||||
|
||||
Account account = new Account();
|
||||
account.setStatus(ServiceStatus.Active.getKey());
|
||||
account.setAccountType(AccountType.Clrn.getKey());
|
||||
accountId = accountImdg.insert(account);
|
||||
|
||||
account2Id = accountImdg.insert(account);
|
||||
|
||||
DepoAccount depoAccount = new DepoAccount();
|
||||
depoAccount.setAccountId(accountId);
|
||||
depoAccount.setDepoAccountType("DAT");
|
||||
depoAccountId = depoAccountImdg.insert(depoAccount);
|
||||
|
||||
ClearingAccount clearingAccount = new ClearingAccount();
|
||||
clearingAccount.setAccountId(accountId);
|
||||
clearingAccount.setClearingAccountType("CAT");
|
||||
clearingAccountId = clearingAccountImdg.insert(clearingAccount);
|
||||
|
||||
InformationAccount informationAccount = new InformationAccount();
|
||||
informationAccount.setAccountId(account2Id);
|
||||
infoAccountId = informationAccountImdg.insert(informationAccount);
|
||||
|
||||
new TestObjectCreator(hazelcastServiceTest).createUserAdmin(1000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void tradingClearingRegistryNew_moneyAccount_clearingAccount() {
|
||||
setMockFuture(kafkaTemplate);
|
||||
TradingClearingRegistryNewRequest tradingClearingRegistryNewRequest = new TradingClearingRegistryNewRequest();
|
||||
tradingClearingRegistryNewRequest.setCompanyId(companyId);
|
||||
tradingClearingRegistryNewRequest.setMoneyAccountId(accountId);
|
||||
tradingClearingRegistryNewRequest.setTradingClearingRegistryType(TradingClearingRegistryType.Owner_A.getKey());
|
||||
|
||||
TradingClearingRegistry predictableTradingClearingRegistry = new TradingClearingRegistry();
|
||||
predictableTradingClearingRegistry.setCompanyId(companyId);
|
||||
predictableTradingClearingRegistry.setCode("0077MAT00001");
|
||||
predictableTradingClearingRegistry.setMoneyAccountId(accountId);
|
||||
predictableTradingClearingRegistry.setTradingClearingRegistryType(TradingClearingRegistryType.Owner_A.getKey());
|
||||
predictableTradingClearingRegistry.setTradingClearingRegistryPurpose(TradingClearingRegistryPurpose.M.getKey());
|
||||
predictableTradingClearingRegistry.setStatus(ServiceStatus.Active.getKey());
|
||||
|
||||
String jsonString = getJsonStringForNew(tradingClearingRegistryNewRequest, 0L);
|
||||
|
||||
addRecordToKafka((MockConsumer) tradingClearingRegistryService.getConsumer(),
|
||||
Consts.DESTINATION_TRADING_CLEARING_REGISTRY_NEW,
|
||||
newRequestCnt,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
TradingClearingRegistry resultNew = tradingClearingRegistryImdg.getAllValues().iterator().next();
|
||||
predictableTradingClearingRegistry.setId(resultNew.getId());
|
||||
predictableTradingClearingRegistry.setUpdated(resultNew.getUpdated());
|
||||
predictableTradingClearingRegistry.setCreated(resultNew.getCreated());
|
||||
|
||||
TRADING_CLEARING_REGISTRY_MATCHER.assertMatch(resultNew, predictableTradingClearingRegistry);
|
||||
tradingClearingRegistryImdg.delete(resultNew);
|
||||
|
||||
newRequestCnt++;
|
||||
}
|
||||
|
||||
@Test
|
||||
void tradingClearingRegistryNew_moneyAccount_informationAccount() {
|
||||
setMockFuture(kafkaTemplate);
|
||||
clearImdg(tradingClearingRegistryImdg);
|
||||
TradingClearingRegistryNewRequest tradingClearingRegistryNewRequest = new TradingClearingRegistryNewRequest();
|
||||
tradingClearingRegistryNewRequest.setCompanyId(companyId);
|
||||
tradingClearingRegistryNewRequest.setMoneyAccountId(account2Id);
|
||||
tradingClearingRegistryNewRequest.setTradingClearingRegistryType(TradingClearingRegistryType.Owner_A.getKey());
|
||||
|
||||
TradingClearingRegistry predictableTradingClearingRegistry = new TradingClearingRegistry();
|
||||
predictableTradingClearingRegistry.setCompanyId(companyId);
|
||||
predictableTradingClearingRegistry.setCode("0077MAT00001");
|
||||
predictableTradingClearingRegistry.setMoneyAccountId(account2Id);
|
||||
predictableTradingClearingRegistry.setTradingClearingRegistryType(TradingClearingRegistryType.Owner_A.getKey());
|
||||
predictableTradingClearingRegistry.setTradingClearingRegistryPurpose(TradingClearingRegistryPurpose.M.getKey());
|
||||
predictableTradingClearingRegistry.setStatus(ServiceStatus.Active.getKey());
|
||||
|
||||
String jsonString = getJsonStringForNew(tradingClearingRegistryNewRequest, 0L);
|
||||
|
||||
addRecordToKafka((MockConsumer) tradingClearingRegistryService.getConsumer(),
|
||||
Consts.DESTINATION_TRADING_CLEARING_REGISTRY_NEW,
|
||||
newRequestCnt,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
TradingClearingRegistry resultNew = tradingClearingRegistryImdg.getAllValues().iterator().next();
|
||||
predictableTradingClearingRegistry.setId(resultNew.getId());
|
||||
predictableTradingClearingRegistry.setUpdated(resultNew.getUpdated());
|
||||
predictableTradingClearingRegistry.setCreated(resultNew.getCreated());
|
||||
|
||||
TRADING_CLEARING_REGISTRY_MATCHER.assertMatch(resultNew, predictableTradingClearingRegistry);
|
||||
tradingClearingRegistryImdg.delete(resultNew);
|
||||
|
||||
newRequestCnt++;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void tradingClearingRegistryNew_depoAccount() {
|
||||
setMockFuture(kafkaTemplate);
|
||||
clearImdg(tradingClearingRegistryImdg);
|
||||
TradingClearingRegistryNewRequest tradingClearingRegistryNewRequest = new TradingClearingRegistryNewRequest();
|
||||
tradingClearingRegistryNewRequest.setCompanyId(companyId);
|
||||
tradingClearingRegistryNewRequest.setMoneyAccountId(accountId);
|
||||
tradingClearingRegistryNewRequest.setDepoAccountId(account2Id);
|
||||
|
||||
TradingClearingRegistry predictableTradingClearingRegistry = new TradingClearingRegistry();
|
||||
predictableTradingClearingRegistry.setCompanyId(companyId);
|
||||
predictableTradingClearingRegistry.setCode("0077CDATT00001");
|
||||
predictableTradingClearingRegistry.setMoneyAccountId(accountId);
|
||||
predictableTradingClearingRegistry.setDepoAccountId(account2Id);
|
||||
predictableTradingClearingRegistry.setTradingClearingRegistryType("DAT");
|
||||
predictableTradingClearingRegistry.setTradingClearingRegistryPurpose(TradingClearingRegistryPurpose.C.getKey());
|
||||
predictableTradingClearingRegistry.setStatus(ServiceStatus.Active.getKey());
|
||||
|
||||
String jsonString = getJsonStringForNew(tradingClearingRegistryNewRequest, 0L);
|
||||
|
||||
addRecordToKafka((MockConsumer) tradingClearingRegistryService.getConsumer(),
|
||||
Consts.DESTINATION_TRADING_CLEARING_REGISTRY_NEW,
|
||||
newRequestCnt,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
TradingClearingRegistry resultNew = tradingClearingRegistryImdg.getAllValues().iterator().next();
|
||||
predictableTradingClearingRegistry.setId(resultNew.getId());
|
||||
predictableTradingClearingRegistry.setUpdated(resultNew.getUpdated());
|
||||
predictableTradingClearingRegistry.setCreated(resultNew.getCreated());
|
||||
|
||||
TRADING_CLEARING_REGISTRY_MATCHER.assertMatch(resultNew, predictableTradingClearingRegistry);
|
||||
tradingClearingRegistryImdg.delete(resultNew);
|
||||
|
||||
newRequestCnt++;
|
||||
}
|
||||
|
||||
@Test
|
||||
void tradingClearingRegistryUpdate() {
|
||||
TradingClearingRegistry existTradingClearingRegistry = new TradingClearingRegistry();
|
||||
existTradingClearingRegistry.setStatus(ServiceStatus.Closed.getKey());
|
||||
Long registryId = tradingClearingRegistryImdg.insert(existTradingClearingRegistry);
|
||||
|
||||
TradingClearingRegistryUpdateRequest tradingClearingRegistryUpdateRequest = new TradingClearingRegistryUpdateRequest();
|
||||
tradingClearingRegistryUpdateRequest.setStatus(ServiceStatus.Active.getKey());
|
||||
tradingClearingRegistryUpdateRequest.setId(registryId);
|
||||
|
||||
String jsonString = getJsonStringForUpdate(tradingClearingRegistryUpdateRequest, 0);
|
||||
|
||||
//ACT
|
||||
addRecordToKafka((MockConsumer) tradingClearingRegistryService.getConsumer(),
|
||||
Consts.DESTINATION_TRADING_CLEARING_REGISTRY_UPDATE,
|
||||
PARTITION,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
TradingClearingRegistry resultUpdating = tradingClearingRegistryImdg.getSingleObjectByID(registryId);
|
||||
existTradingClearingRegistry.setUpdated(resultUpdating.getUpdated());
|
||||
existTradingClearingRegistry.setStatus(ServiceStatus.Active.getKey());
|
||||
TRADING_CLEARING_REGISTRY_MATCHER.assertMatch(resultUpdating, existTradingClearingRegistry);
|
||||
tradingClearingRegistryImdg.delete(resultUpdating);
|
||||
}
|
||||
|
||||
@Test
|
||||
void tradingClearingRegistryBlock() {
|
||||
TradingClearingRegistry existTradingClearingRegistry = new TradingClearingRegistry();
|
||||
existTradingClearingRegistry.setStatus(ServiceStatus.Closed.getKey());
|
||||
Long registryId = tradingClearingRegistryImdg.insert(existTradingClearingRegistry);
|
||||
|
||||
CommonDeleteRequest tradingClearingRegistryDeleteRequest = new CommonDeleteRequest();
|
||||
tradingClearingRegistryDeleteRequest.setId(registryId);
|
||||
|
||||
String jsonString = getJsonStringForDelete(tradingClearingRegistryDeleteRequest, 0);
|
||||
|
||||
//ACT
|
||||
addRecordToKafka((MockConsumer) tradingClearingRegistryService.getConsumer(),
|
||||
Consts.DESTINATION_TRADING_CLEARING_REGISTRY_BLOCK,
|
||||
PARTITION,
|
||||
0,
|
||||
jsonString);
|
||||
|
||||
//ASSERT
|
||||
waitingSendAndCheckRecord(0L, mockProducer);
|
||||
|
||||
TradingClearingRegistry resultUpdating = tradingClearingRegistryImdg.getSingleObjectByID(registryId);
|
||||
existTradingClearingRegistry.setUpdated(resultUpdating.getUpdated());
|
||||
existTradingClearingRegistry.setStatus(ServiceStatus.Blocked.getKey());
|
||||
TRADING_CLEARING_REGISTRY_MATCHER.assertMatch(resultUpdating, existTradingClearingRegistry);
|
||||
tradingClearingRegistryImdg.delete(resultUpdating);
|
||||
}
|
||||
|
||||
@Test
|
||||
void makeCode() {
|
||||
Assertions.assertEquals("0005CAT00001", tradingClearingRegistryService.makeCode(
|
||||
"5", TradingClearingRegistryPurpose.C, TradingClearingRegistryType.Owner_A.getKey(), 1L
|
||||
));
|
||||
Assertions.assertEquals("0005CET00012", tradingClearingRegistryService.makeCode(
|
||||
"005", TradingClearingRegistryPurpose.C, "E", 12L
|
||||
));
|
||||
Assertions.assertEquals("0105CERT00012", tradingClearingRegistryService.makeCode(
|
||||
"000000105", TradingClearingRegistryPurpose.C, "ER", 100012L
|
||||
));
|
||||
|
||||
Assertions.assertEquals("0105MAT00012", tradingClearingRegistryService.makeCode(
|
||||
"000000105", TradingClearingRegistryPurpose.M, "A", 100012L
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseCodeSeqId() {
|
||||
Assertions.assertEquals(Long.valueOf(1L), tradingClearingRegistryService.parseCodeSeqId("0005CAT00001"));
|
||||
Assertions.assertEquals(Long.valueOf(5001), tradingClearingRegistryService.parseCodeSeqId("0005CAT05001"));
|
||||
Assertions.assertEquals(null, tradingClearingRegistryService.parseCodeSeqId("0005CAT"));
|
||||
Assertions.assertEquals(null, tradingClearingRegistryService.parseCodeSeqId(""));
|
||||
Assertions.assertEquals(null, tradingClearingRegistryService.parseCodeSeqId(null));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>backend-api</artifactId>
|
||||
|
|
@ -8,12 +8,12 @@
|
|||
<description>Clearing backend API module</description>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<artifactId>clearing-parent</artifactId>
|
||||
<parent>
|
||||
<artifactId>clearing-parent</artifactId>
|
||||
<groupId>ru.spcex.clearing</groupId>
|
||||
<version>SPCEX-1.0.0.0</version>
|
||||
</parent>
|
||||
|
||||
|
||||
|
||||
<properties>
|
||||
<keycloak-spring-boot-starter.version>17.0.1</keycloak-spring-boot-starter.version>
|
||||
|
|
@ -25,93 +25,25 @@
|
|||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.keycloak</groupId>
|
||||
<artifactId>keycloak-spring-boot-starter</artifactId>
|
||||
<version>${keycloak-spring-boot-starter.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.platform</groupId>
|
||||
<artifactId>platform-imdg-api-hazelcast-impl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.platform</groupId>
|
||||
<artifactId>platform-messaging</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.clearing</groupId>
|
||||
<artifactId>classes</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.clearing</groupId>
|
||||
<artifactId>dictionary</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.platform</groupId>
|
||||
<artifactId>platform-enum</artifactId>
|
||||
</dependency>
|
||||
<!-- TEST -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.spcex.clearing</groupId>
|
||||
<artifactId>test-clearing</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.skyscreamer</groupId>
|
||||
<artifactId>jsonassert</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.11</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test-autoconfigure</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.keycloak.bom</groupId>
|
||||
<artifactId>keycloak-adapter-bom</artifactId>
|
||||
<version>${keycloak-spring-boot-starter.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<groupId>org.keycloak.bom</groupId>
|
||||
<artifactId>keycloak-adapter-bom</artifactId>
|
||||
<version>${keycloak-spring-boot-starter.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
|
@ -122,7 +54,6 @@
|
|||
<excludes>
|
||||
<exclude>application.properties</exclude>
|
||||
<exclude>keycloak.json</exclude>
|
||||
<exclude>meta/**</exclude>
|
||||
</excludes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
|
|
@ -143,268 +74,6 @@
|
|||
<finalName>${project.artifactId}</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>xml-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<!--all doc generation: mvn clean xml:transform@ddl xml:transform@data xml:transform@db xml:transform@json xml:transform@core xml:transform@report xml:transform@web -->
|
||||
<execution>
|
||||
<!-- Generate DDL.sql from META file
|
||||
command: mvn xml:transform@ddl -->
|
||||
<id>ddl</id>
|
||||
<goals>
|
||||
<goal>transform</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformationSets>
|
||||
<transformationSet>
|
||||
<dir>src/main/resources/meta</dir>
|
||||
<includes>
|
||||
<include>meta.xml</include>
|
||||
</includes>
|
||||
<stylesheet>src/main/resources/meta/xsl/ddl.xsl</stylesheet>
|
||||
<fileMappers>
|
||||
<fileMapper
|
||||
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
|
||||
<targetExtension>ddl.sql</targetExtension>
|
||||
</fileMapper>
|
||||
</fileMappers>
|
||||
</transformationSet>
|
||||
</transformationSets>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<!-- Generate Data.sql from META and DATA file
|
||||
command: mvn xml:transform@data -->
|
||||
<id>data</id>
|
||||
<goals>
|
||||
<goal>transform</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformationSets>
|
||||
<transformationSet>
|
||||
<dir>src/main/resources/meta</dir>
|
||||
<includes>
|
||||
<include>data.xml</include>
|
||||
</includes>
|
||||
<stylesheet>src/main/resources/meta/xsl/data.xsl</stylesheet>
|
||||
<fileMappers>
|
||||
<fileMapper
|
||||
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
|
||||
<targetExtension>data.sql</targetExtension>
|
||||
</fileMapper>
|
||||
</fileMappers>
|
||||
</transformationSet>
|
||||
<transformationSet>
|
||||
<dir>src/main/resources/meta</dir>
|
||||
<includes>
|
||||
<include>data_initial.xml</include>
|
||||
</includes>
|
||||
<stylesheet>src/main/resources/meta/xsl/data.xsl</stylesheet>
|
||||
<fileMappers>
|
||||
<fileMapper
|
||||
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
|
||||
<targetExtension>data_initial.sql</targetExtension>
|
||||
</fileMapper>
|
||||
</fileMappers>
|
||||
</transformationSet>
|
||||
</transformationSets>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<!-- Generate db.html - description from META and dATA file
|
||||
command: mvn xml:transform@db -->
|
||||
<id>db</id>
|
||||
<goals>
|
||||
<goal>transform</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformationSets>
|
||||
<transformationSet>
|
||||
<dir>src/main/resources/meta</dir>
|
||||
<includes>
|
||||
<include>meta.xml</include>
|
||||
</includes>
|
||||
<stylesheet>src/main/resources/meta/xsl/db.xsl</stylesheet>
|
||||
<fileMappers>
|
||||
<fileMapper
|
||||
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
|
||||
<targetExtension>db.html</targetExtension>
|
||||
</fileMapper>
|
||||
</fileMappers>
|
||||
</transformationSet>
|
||||
</transformationSets>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<!-- Generate meta.json - description from META file
|
||||
command: mvn xml:transform@json -->
|
||||
<id>json</id>
|
||||
<goals>
|
||||
<goal>transform</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformationSets>
|
||||
<transformationSet>
|
||||
<dir>src/main/resources/meta</dir>
|
||||
<includes>
|
||||
<include>meta.xml</include>
|
||||
</includes>
|
||||
<stylesheet>src/main/resources/meta/xsl/json.xsl</stylesheet>
|
||||
<fileMappers>
|
||||
<fileMapper
|
||||
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
|
||||
<targetExtension>meta.json</targetExtension>
|
||||
</fileMapper>
|
||||
</fileMappers>
|
||||
</transformationSet>
|
||||
</transformationSets>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<!-- Generate core.html - description from META* files
|
||||
command: mvn xml:transform@core -->
|
||||
<id>core</id>
|
||||
<goals>
|
||||
<goal>transform</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformationSets>
|
||||
<transformationSet>
|
||||
<dir>src/main/resources/meta</dir>
|
||||
<includes>
|
||||
<include>meta.xml</include>
|
||||
</includes>
|
||||
<stylesheet>src/main/resources/meta/xsl/core.xsl</stylesheet>
|
||||
<fileMappers>
|
||||
<fileMapper
|
||||
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
|
||||
<targetExtension>core.html</targetExtension>
|
||||
</fileMapper>
|
||||
</fileMappers>
|
||||
</transformationSet>
|
||||
</transformationSets>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<!-- Generate report.html - report description from META* files
|
||||
command: mvn xml:transform@report -->
|
||||
<id>report</id>
|
||||
<goals>
|
||||
<goal>transform</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformationSets>
|
||||
<transformationSet>
|
||||
<dir>src/main/resources/meta</dir>
|
||||
<includes>
|
||||
<include>meta.xml</include>
|
||||
</includes>
|
||||
<stylesheet>src/main/resources/meta/xsl/report.xsl</stylesheet>
|
||||
<fileMappers>
|
||||
<fileMapper
|
||||
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
|
||||
<targetExtension>report.html</targetExtension>
|
||||
</fileMapper>
|
||||
</fileMappers>
|
||||
</transformationSet>
|
||||
</transformationSets>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<!-- Generate web.html - description from META* files
|
||||
command: mvn xml:transform@web -->
|
||||
<id>web</id>
|
||||
<goals>
|
||||
<goal>transform</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformationSets>
|
||||
<transformationSet>
|
||||
<dir>src/main/resources/meta</dir>
|
||||
<includes>
|
||||
<include>meta.xml</include>
|
||||
</includes>
|
||||
<stylesheet>src/main/resources/meta/xsl/web.xsl</stylesheet>
|
||||
<fileMappers>
|
||||
<fileMapper
|
||||
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
|
||||
<targetExtension>web.html</targetExtension>
|
||||
</fileMapper>
|
||||
</fileMappers>
|
||||
</transformationSet>
|
||||
</transformationSets>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<!-- Generate java_classes.java from META file
|
||||
command: mvn xml:transform@java -->
|
||||
<id>java</id>
|
||||
<goals>
|
||||
<goal>transform</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformationSets>
|
||||
<transformationSet>
|
||||
<dir>src/main/resources/meta</dir>
|
||||
<includes>
|
||||
<include>meta.xml</include>
|
||||
</includes>
|
||||
<stylesheet>src/main/resources/meta/xsl/java.xsl</stylesheet>
|
||||
<fileMappers>
|
||||
<fileMapper
|
||||
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
|
||||
<targetExtension>java_classes.java</targetExtension>
|
||||
</fileMapper>
|
||||
</fileMappers>
|
||||
</transformationSet>
|
||||
</transformationSets>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-meta</id>
|
||||
<phase>process-classes</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${basedir}/src/main/resources</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${basedir}/target/generated-resources/xml/xslt</directory>
|
||||
<includes>
|
||||
<include>meta.json</include>
|
||||
</includes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.21.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||
<version>1.2.0-M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>5.2.0-M1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import ru.spcex.clearing.backendapi.config.element.BackendApiSettings;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
|
||||
@Configuration
|
||||
public class BackEndApiImdgConfig {
|
||||
Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Bean(name = "taskExecutorHazelcastClientInitializer")
|
||||
public ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializer() {
|
||||
return createThreadPoolTaskExecutor(1, true);
|
||||
}
|
||||
|
||||
@Bean(name = "taskExecutorIdGeneratorAwaiter")
|
||||
public ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiter() {
|
||||
return createThreadPoolTaskExecutor(1, false);
|
||||
}
|
||||
|
||||
@Bean(name = "taskExecutorHazelcastClientInitializerHist")
|
||||
public ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializerHist() {
|
||||
return createThreadPoolTaskExecutor(1, true);
|
||||
}
|
||||
|
||||
@Bean(name = "taskExecutorIdGeneratorAwaiterHist")
|
||||
public ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiterHist() {
|
||||
return createThreadPoolTaskExecutor(1, false);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Bean
|
||||
public ImdgProvider imdgProvider(
|
||||
@Qualifier("taskExecutorHazelcastClientInitializer") ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializer,
|
||||
@Qualifier("taskExecutorIdGeneratorAwaiter") ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiter,
|
||||
BackendApiSettings clientSetting
|
||||
) {
|
||||
if (clientSetting.getHazelcast() == null || clientSetting.getHazelcast().getClusterMembers() == null) {
|
||||
log.warn("Property \"backend-api.hazelcast.cluster-members\" not set!");
|
||||
throw new IllegalArgumentException("Property \"backend-api.hazelcast.cluster-members\" not set");
|
||||
}
|
||||
ImdgProvider imdg = new HazelcastService(taskExecutorHazelcastClientInitializer,
|
||||
taskExecutorIdGeneratorAwaiter,
|
||||
clientSetting.getHazelcast());
|
||||
// todo корректное ожидание готовности imdg.waitAvailable();
|
||||
return imdg;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Bean
|
||||
public ImdgProvider imdgProviderHist(
|
||||
@Qualifier("taskExecutorHazelcastClientInitializerHist") ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializer,
|
||||
@Qualifier("taskExecutorIdGeneratorAwaiterHist") ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiter,
|
||||
BackendApiSettings clientSetting
|
||||
) {
|
||||
if (clientSetting.getHazelcastSearch() == null || clientSetting.getHazelcastSearch().getClusterMembers() == null) {
|
||||
log.warn("Property \"backend-api.hazelcast-search.cluster-members\" not set!");
|
||||
// может работать без history, но history будет недоступна
|
||||
}
|
||||
ImdgProvider imdg = new HazelcastService(taskExecutorHazelcastClientInitializer,
|
||||
taskExecutorIdGeneratorAwaiter,
|
||||
clientSetting.getHazelcastSearch());
|
||||
// todo корректное ожидание готовности imdg.waitAvailable();
|
||||
return imdg;
|
||||
}
|
||||
|
||||
|
||||
private static ThreadPoolTaskExecutor createThreadPoolTaskExecutor(int maxPoolSz, boolean waitForCompletion) {
|
||||
ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
|
||||
if (maxPoolSz > 2) {
|
||||
pool.setKeepAliveSeconds(60);
|
||||
pool.setAllowCoreThreadTimeOut(true);
|
||||
}
|
||||
pool.setCorePoolSize(maxPoolSz);
|
||||
pool.setWaitForTasksToCompleteOnShutdown(waitForCompletion);
|
||||
return pool;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@PropertySource("file:${spring.config.location}/application.properties")
|
||||
@ConfigurationProperties("backend-api")
|
||||
public class BackendApiSettings {
|
||||
public String getExampleSetting() {
|
||||
return exampleSetting;
|
||||
}
|
||||
|
||||
public void setExampleSetting(String exampleSetting) {
|
||||
this.exampleSetting = exampleSetting;
|
||||
}
|
||||
|
||||
private String exampleSetting;
|
||||
}
|
||||
|
|
@ -1,177 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.history.condition.HistorySubscription;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.history.condition.specific.*;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class HistoryConfig {
|
||||
|
||||
private final ImdgPredicateBuilder pb;
|
||||
|
||||
@Autowired
|
||||
public HistoryConfig(ImdgProvider imdgProvider) {
|
||||
this.pb = imdgProvider.getImdg(
|
||||
IMDGDistributedNames.Map_SearchMoneyBalanceRegister,
|
||||
SpcexObjectBase.class
|
||||
).predicateBuilder();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public List<HistorySubscription> histSubscriptions() {
|
||||
List<HistorySubscription> hst = new LinkedList<>();
|
||||
hst.add(executionDeposit());
|
||||
hst.add(executionFond());
|
||||
hst.add(depoBalanceRegister());
|
||||
hst.add(moneyBalanceRegister());
|
||||
hst.add(admittedLiabilitiesRegister());
|
||||
hst.add(coveredLiabilitiesRegister());
|
||||
hst.add(moneyPaymentInstructionRegister());
|
||||
hst.add(depoPaymentInstructionRegister());
|
||||
hst.add(excludeLiabilitiesRegister());
|
||||
hst.add(liabilitiesRegister());
|
||||
hst.add(executionRegister());
|
||||
return hst;
|
||||
}
|
||||
|
||||
private HistorySubscription moneyBalanceRegister() {
|
||||
HistorySubscription sbscr = new HistorySubscription();
|
||||
sbscr.setDestination("money-balance-registers");
|
||||
sbscr.setSearchProxyMapName(IMDGDistributedNames.Map_SearchMoneyBalanceRegister);
|
||||
sbscr.setFullHistoryMapName(IMDGDistributedNames.Map_MoneyBalanceRegister);
|
||||
sbscr.setConditions(List.of(
|
||||
new CreatedFromCondition(pb),
|
||||
new CreatedToCondition(pb)
|
||||
));
|
||||
return sbscr;
|
||||
}
|
||||
|
||||
private HistorySubscription depoBalanceRegister() {
|
||||
HistorySubscription sbscr = new HistorySubscription();
|
||||
sbscr.setDestination("depo-balance-registers");
|
||||
sbscr.setSearchProxyMapName(IMDGDistributedNames.Map_SearchDepoBalanceRegister);
|
||||
sbscr.setFullHistoryMapName(IMDGDistributedNames.Map_DepoBalanceRegister);
|
||||
sbscr.setConditions(List.of(
|
||||
new CreatedFromCondition(pb),
|
||||
new CreatedToCondition(pb)
|
||||
));
|
||||
return sbscr;
|
||||
}
|
||||
|
||||
private HistorySubscription depoPaymentInstructionRegister() {
|
||||
HistorySubscription sbscr = new HistorySubscription();
|
||||
sbscr.setDestination("depo-payment-instruction-registers");
|
||||
sbscr.setSearchProxyMapName(IMDGDistributedNames.Map_SearchDepoPaymentInstructionRegister);
|
||||
sbscr.setFullHistoryMapName(IMDGDistributedNames.Map_DepoPaymentInstructionRegister);
|
||||
sbscr.setConditions(List.of(
|
||||
new CreatedFromCondition(pb),
|
||||
new CreatedToCondition(pb)
|
||||
));
|
||||
return sbscr;
|
||||
}
|
||||
|
||||
private HistorySubscription excludeLiabilitiesRegister() {
|
||||
HistorySubscription sbscr = new HistorySubscription();
|
||||
sbscr.setDestination("exclude-liabilities-registers");
|
||||
sbscr.setSearchProxyMapName(IMDGDistributedNames.Map_SearchExcludeLiabilitiesRegister);
|
||||
sbscr.setFullHistoryMapName(IMDGDistributedNames.Map_ExcludeLiabilitiesRegister);
|
||||
sbscr.setConditions(List.of(
|
||||
new CreatedFromCondition(pb),
|
||||
new CreatedToCondition(pb)
|
||||
));
|
||||
return sbscr;
|
||||
}
|
||||
|
||||
private HistorySubscription liabilitiesRegister() {
|
||||
HistorySubscription sbscr = new HistorySubscription();
|
||||
sbscr.setDestination("liabilities-registers");
|
||||
sbscr.setSearchProxyMapName(IMDGDistributedNames.Map_SearchLiabilitiesRegister);
|
||||
sbscr.setFullHistoryMapName(IMDGDistributedNames.Map_LiabilitiesRegister);
|
||||
sbscr.setConditions(List.of(
|
||||
new CreatedFromCondition(pb),
|
||||
new CreatedToCondition(pb)
|
||||
));
|
||||
return sbscr;
|
||||
}
|
||||
|
||||
private HistorySubscription admittedLiabilitiesRegister() {
|
||||
HistorySubscription sbscr = new HistorySubscription();
|
||||
sbscr.setDestination("admitted-liabilities-registers");
|
||||
sbscr.setSearchProxyMapName(IMDGDistributedNames.Map_SearchAdmittedLiabilitiesRegister);
|
||||
sbscr.setFullHistoryMapName(IMDGDistributedNames.Map_AdmittedLiabilitiesRegister);
|
||||
sbscr.setConditions(List.of(
|
||||
new ClearingDateFromCondition(pb),
|
||||
new ClearingDateToCondition(pb)
|
||||
));
|
||||
return sbscr;
|
||||
}
|
||||
|
||||
private HistorySubscription executionRegister() {
|
||||
HistorySubscription sbscr = new HistorySubscription();
|
||||
sbscr.setDestination("execution-registers");
|
||||
sbscr.setSearchProxyMapName(IMDGDistributedNames.Map_SearchExecutionRegister);
|
||||
sbscr.setFullHistoryMapName(IMDGDistributedNames.Map_ExecutionRegister);
|
||||
sbscr.setConditions(List.of(
|
||||
new ClearingDateFromCondition(pb),
|
||||
new ClearingDateToCondition(pb)
|
||||
));
|
||||
return sbscr;
|
||||
}
|
||||
|
||||
private HistorySubscription moneyPaymentInstructionRegister() {
|
||||
HistorySubscription sbscr = new HistorySubscription();
|
||||
sbscr.setDestination("money-payment-instruction-registers");
|
||||
sbscr.setSearchProxyMapName(IMDGDistributedNames.Map_SearchMoneyPaymentInstructionRegister);
|
||||
sbscr.setFullHistoryMapName(IMDGDistributedNames.Map_MoneyPaymentInstructionRegister);
|
||||
sbscr.setConditions(List.of(
|
||||
new ClearingDateFromCondition(pb),
|
||||
new ClearingDateToCondition(pb)
|
||||
));
|
||||
return sbscr;
|
||||
}
|
||||
|
||||
private HistorySubscription coveredLiabilitiesRegister() {
|
||||
HistorySubscription sbscr = new HistorySubscription();
|
||||
sbscr.setDestination("covered-liabilities-registers");
|
||||
sbscr.setSearchProxyMapName(IMDGDistributedNames.Map_SearchCoveredLiabilitiesRegister);
|
||||
sbscr.setFullHistoryMapName(IMDGDistributedNames.Map_CoveredLiabilitiesRegister);
|
||||
sbscr.setConditions(List.of(
|
||||
new ClearingDateFromCondition(pb),
|
||||
new ClearingDateToCondition(pb)
|
||||
));
|
||||
return sbscr;
|
||||
}
|
||||
|
||||
private HistorySubscription executionDeposit() {
|
||||
HistorySubscription sbscr = new HistorySubscription();
|
||||
sbscr.setDestination("execution-deposits");
|
||||
sbscr.setSearchProxyMapName(IMDGDistributedNames.Map_SearchExecutionDeposit);
|
||||
sbscr.setFullHistoryMapName(IMDGDistributedNames.Map_ExecutionDeposit);
|
||||
sbscr.setConditions(List.of(
|
||||
new TradingDateFromCondition(pb),
|
||||
new TradingDateToCondition(pb)
|
||||
));
|
||||
return sbscr;
|
||||
}
|
||||
|
||||
private HistorySubscription executionFond() {
|
||||
HistorySubscription sbscr = new HistorySubscription();
|
||||
sbscr.setDestination("execution-fonds");
|
||||
sbscr.setSearchProxyMapName(IMDGDistributedNames.Map_SearchExecutionFond);
|
||||
sbscr.setFullHistoryMapName(IMDGDistributedNames.Map_ExecutionFond);
|
||||
sbscr.setConditions(List.of(
|
||||
new TradingDateFromCondition(pb),
|
||||
new TradingDateToCondition(pb)
|
||||
));
|
||||
return sbscr;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
||||
@Configuration
|
||||
public class JacksonHttpConverterConfig {
|
||||
@Bean("customJsonHttpConverter")
|
||||
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
|
||||
return new MappingJackson2HttpMessageConverter(mapper);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||
import org.apache.kafka.clients.consumer.OffsetResetStrategy;
|
||||
import org.apache.kafka.clients.producer.MockProducer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.kafka.core.ProducerFactory;
|
||||
import ru.spcex.clearing.backendapi.config.element.BackendApiSettings;
|
||||
import ru.spcex.clearing.platform.messaging.config.KafkaConsumerFactory;
|
||||
import ru.spcex.clearing.platform.messaging.config.KafkaProducerFactory;
|
||||
import ru.spcex.clearing.platform.messaging.config.element.KafkaProducerSettings;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.platform.imdg.api.ImdgId;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
@Configuration
|
||||
public class KafkaConfig {
|
||||
|
||||
@Profile("!kafkaDisabled")
|
||||
@Autowired
|
||||
@Bean
|
||||
public Producer<String, Object> createProducer(BackendApiSettings settings) {
|
||||
return KafkaProducerFactory.producer(settings.getKafkaProducer());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ProducerFactory<String, Object> pf(BackendApiSettings settings) {
|
||||
KafkaProducerSettings kafkaSettings = settings.getKafkaProducer();
|
||||
return KafkaProducerFactory.producerFactory(kafkaSettings);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public KafkaTemplate<String, Object> kafkaTemplateS(ProducerFactory<String, Object> pf) {
|
||||
return new KafkaTemplate<>(pf);
|
||||
}
|
||||
|
||||
@Profile("!kafkaDisabled")
|
||||
@Autowired
|
||||
@Bean
|
||||
public KafkaSender kafkaSender(KafkaTemplate<String, Object> kafkaTemplate, ImdgProvider imdgProvider) {
|
||||
ImdgId imdgIdGenerator = imdgProvider.getImdgIdGenerator();
|
||||
return KafkaSender.setup()
|
||||
.saveRequestInfo(false)
|
||||
.setKafkaTemplate(kafkaTemplate)
|
||||
.idGenerator(imdgIdGenerator::nextId)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Profile("kafkaDisabled")
|
||||
@Bean
|
||||
public MockProducer<String, Object> createMockProducer() {
|
||||
return new MockProducer<>(true, (topic, data) -> data != null ? data.getBytes() : new byte[0], (topic, data) -> data.toString().getBytes());
|
||||
}
|
||||
|
||||
@Profile("!kafkaDisabled")
|
||||
@Autowired
|
||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
@Bean
|
||||
public Consumer<String, Object> createConsumer(BackendApiSettings settings) {
|
||||
return KafkaConsumerFactory.consumer(settings.getKafkaConsumer());
|
||||
}
|
||||
|
||||
@Profile("kafkaDisabled")
|
||||
@Bean
|
||||
public Consumer<String, Object> createConsumerMock() {
|
||||
return new MockConsumer<>(OffsetResetStrategy.NONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.ResourceBundleMessageSource;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.enumeration.SpringPropertiesMessageResolver;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@Configuration
|
||||
public class MessagesConfig {
|
||||
@Bean("validation-error-messages")
|
||||
public ResourceBundleMessageSource messages() {
|
||||
ResourceBundleMessageSource source = new ResourceBundleMessageSource();
|
||||
source.setBasenames("messages/error");
|
||||
source.setUseCodeAsDefaultMessage(true);
|
||||
source.setDefaultEncoding("utf8");
|
||||
source.setDefaultLocale(Locale.ROOT);
|
||||
return source;
|
||||
}
|
||||
|
||||
@Bean("errorResolver")
|
||||
public IMessageResolver errorResolver(@Qualifier("validation-error-messages") ResourceBundleMessageSource messageBundle) {
|
||||
return new SpringPropertiesMessageResolver(messageBundle);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
import ru.spcex.clearing.backendapi.meta.MetaServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
@Configuration
|
||||
public class MetaConfiguration {
|
||||
@Value("file:${spring.config.location}/meta.json")
|
||||
private Resource meta;
|
||||
|
||||
@Bean("metaJson")
|
||||
public String metaJsonConfiguration() throws IOException {
|
||||
if (!meta.isReadable()) throw new IllegalStateException("cannot read meta.json from spring.config.location");
|
||||
return Files.readString(meta.getFile().toPath());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Bean
|
||||
public MetaServer metaServer(@Qualifier("metaJson") String metaJson) throws JsonProcessingException {
|
||||
ObjectMapper jsonObjectMapper = new ObjectMapper();
|
||||
jsonObjectMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
|
||||
jsonObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
MetaServer metaServer = jsonObjectMapper.readValue(metaJson, MetaServer.class);
|
||||
metaServer.initAndValidate();
|
||||
return metaServer;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package ru.spcex.clearing.backendapi.security;
|
||||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
@SuppressWarnings("Guava")
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public class SwaggerConfig {
|
||||
|
||||
@Bean
|
||||
public Docket api() {
|
||||
return new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("clearing-backend-api")
|
||||
.apiInfo(metadata())
|
||||
.select()
|
||||
.apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot")))
|
||||
.paths(PathSelectors.any())
|
||||
.build()
|
||||
.useDefaultResponseMessages(false);
|
||||
}
|
||||
|
||||
private ApiInfo metadata() {
|
||||
return new ApiInfoBuilder()
|
||||
.title("Spcex Clearing service")
|
||||
.description("Сервис клиринга")
|
||||
.version("0.0.1")
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.web.server.Cookie;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
|
||||
import org.springframework.boot.web.servlet.server.CookieSameSiteSupplier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.context.request.RequestContextListener;
|
||||
import org.springframework.web.servlet.config.annotation.*;
|
||||
import ru.spcex.clearing.backendapi.config.element.BackendApiSettings;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@SuppressWarnings("Duplicates")
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
//todo remove? see ClearingCorsFilter
|
||||
@CrossOrigin
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
private final MappingJackson2HttpMessageConverter customJsonHttpConverter;
|
||||
private final String sameSite;
|
||||
|
||||
@Autowired
|
||||
public WebConfig(@Qualifier("customJsonHttpConverter") MappingJackson2HttpMessageConverter customJsonHttpConverter,
|
||||
BackendApiSettings backendSettings
|
||||
) {
|
||||
this.customJsonHttpConverter = customJsonHttpConverter;
|
||||
this.sameSite = backendSettings.getSecurity().getSameSite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
|
||||
configurer.enable();
|
||||
}
|
||||
|
||||
@Autowired
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
|
||||
Consumer<HttpMessageConverter<?>> addConverter = httpMessageConverter -> {
|
||||
messageConverters.removeIf(registeredConverter -> registeredConverter.getClass().equals(httpMessageConverter.getClass()));
|
||||
messageConverters.add(httpMessageConverter);
|
||||
};
|
||||
addConverter.accept(new StringHttpMessageConverter());
|
||||
addConverter.accept(customJsonHttpConverter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addViewControllers(ViewControllerRegistry registry) {
|
||||
registry.addRedirectViewController("/v2/api-docs", "/v2/api-docs?group=api");
|
||||
registry.addRedirectViewController("/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui");
|
||||
registry.addRedirectViewController("/swagger-resources/configuration/security", "/swagger-resources/configuration/security");
|
||||
registry.addRedirectViewController("/swagger-resources", "/swagger-resources");
|
||||
registry.addRedirectViewController("", "/swagger-ui.html");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry
|
||||
.addResourceHandler("/swagger-ui.html**")
|
||||
.addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> enableDefaultServlet() {
|
||||
return (factory) -> factory.setRegisterDefaultServlet(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**").allowedMethods("*");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RequestContextListener requestContextListener() {
|
||||
return new RequestContextListener();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CookieSameSiteSupplier applicationCookieSameSiteSupplier() {
|
||||
if (sameSite == null) {
|
||||
return null;
|
||||
} else if (sameSite.equalsIgnoreCase(Cookie.SameSite.NONE.attributeValue())) {
|
||||
return CookieSameSiteSupplier.ofNone();
|
||||
} else if (sameSite.equalsIgnoreCase(Cookie.SameSite.LAX.attributeValue())) {
|
||||
return CookieSameSiteSupplier.ofLax();
|
||||
} else if (sameSite.equalsIgnoreCase(Cookie.SameSite.STRICT.attributeValue())) {
|
||||
return CookieSameSiteSupplier.ofStrict();
|
||||
} else {
|
||||
throw new IllegalStateException("unknown SameSite setting");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.config.element;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.spcex.clearing.backendapi.security.element.SecuritySettings;
|
||||
import ru.spcex.clearing.platform.messaging.config.element.KafkaConsumerSettings;
|
||||
import ru.spcex.clearing.platform.messaging.config.element.KafkaProducerSettings;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.config.HazelcastClientParams;
|
||||
|
||||
@Component
|
||||
@PropertySource("file:${spring.config.location}/application.properties")
|
||||
@ConfigurationProperties("backend-api")
|
||||
public class BackendApiSettings {
|
||||
private HazelcastClientParams hazelcast;
|
||||
private HazelcastClientParams hazelcastSearch;
|
||||
private KafkaProducerSettings kafkaProducer;
|
||||
private KafkaConsumerSettings kafkaConsumer;
|
||||
private SecuritySettings security;
|
||||
private String exampleSetting;
|
||||
|
||||
public HazelcastClientParams getHazelcast() {
|
||||
return hazelcast;
|
||||
}
|
||||
|
||||
public void setHazelcast(HazelcastClientParams hazelcast) {
|
||||
this.hazelcast = hazelcast;
|
||||
}
|
||||
|
||||
public KafkaProducerSettings getKafkaProducer() {
|
||||
return kafkaProducer;
|
||||
}
|
||||
|
||||
public void setKafkaProducer(KafkaProducerSettings kafkaProducer) {
|
||||
this.kafkaProducer = kafkaProducer;
|
||||
}
|
||||
|
||||
public KafkaConsumerSettings getKafkaConsumer() {
|
||||
return kafkaConsumer;
|
||||
}
|
||||
|
||||
public void setKafkaConsumer(KafkaConsumerSettings kafkaConsumer) {
|
||||
this.kafkaConsumer = kafkaConsumer;
|
||||
}
|
||||
|
||||
public String getExampleSetting() {
|
||||
return exampleSetting;
|
||||
}
|
||||
|
||||
public void setExampleSetting(String exampleSetting) {
|
||||
this.exampleSetting = exampleSetting;
|
||||
}
|
||||
|
||||
public SecuritySettings getSecurity() {
|
||||
return security;
|
||||
}
|
||||
|
||||
public void setSecurity(SecuritySettings security) {
|
||||
this.security = security;
|
||||
}
|
||||
|
||||
public HazelcastClientParams getHazelcastSearch() {
|
||||
return hazelcastSearch;
|
||||
}
|
||||
|
||||
public void setHazelcastSearch(HazelcastClientParams hazelcastSearch) {
|
||||
this.hazelcastSearch = hazelcastSearch;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package ru.spcex.clearing.backendapi.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.spcex.clearing.backendapi.config.BackendApiSettings;
|
||||
|
||||
@Controller("/")
|
||||
public class DefaultController implements InitializingBean {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, path = "/anonymous/method1", produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@ResponseBody
|
||||
public String processGet() {
|
||||
log.info("Call test method for backend-api controller");
|
||||
return "backend-api controller test method";
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, path = "/users/method2", produces = MediaType.TEXT_PLAIN_VALUE)
|
||||
@ResponseBody
|
||||
public String processProtectedGet() {
|
||||
log.info("controller method2");
|
||||
return "use post";
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private BackendApiSettings settings;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
log.info("controller started");
|
||||
log.info("settings example {}", settings.getExampleSetting());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package ru.spcex.clearing.backendapi.controller;
|
||||
|
||||
import org.keycloak.KeycloakSecurityContext;
|
||||
import org.keycloak.adapters.RefreshableKeycloakSecurityContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import ru.spcex.clearing.backendapi.security.TokenRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/backend-api-login")
|
||||
public class LoginController {
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
@Autowired
|
||||
public LoginController(@Qualifier("clearing-rest") RestTemplate restTemplate) {
|
||||
this.restTemplate = restTemplate;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/perform-login", method = RequestMethod.POST)
|
||||
public ResponseEntity<Map<String, Object>> refreshToken(HttpServletRequest httpServletRequest,
|
||||
HttpServletResponse httpServletResponse) {
|
||||
RefreshableKeycloakSecurityContext session = (RefreshableKeycloakSecurityContext) httpServletRequest.getSession().getAttribute(KeycloakSecurityContext.class.getName());
|
||||
String login = httpServletRequest.getHeader("clearing-login");
|
||||
String password = httpServletRequest.getHeader("clearing-password");
|
||||
HttpEntity<MultiValueMap<String, String>> request =
|
||||
new TokenRequest.Builder()
|
||||
.username(login)
|
||||
.password(password)
|
||||
.build();
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(
|
||||
"http://10.200.200.147:8080/realms/master/protocol/openid-connect/token",
|
||||
request, String.class);
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue;
|
||||
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.domain.actions.IAction;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public abstract class AbstractQueueController {
|
||||
private final IOperator operator;
|
||||
|
||||
public AbstractQueueController(IOperator operator) {
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
protected <T> CudResponse processRequest(String destination, IAction<T> iAction) throws ExecutionException, InterruptedException {
|
||||
CudResponse responseToClient = new CudResponse();
|
||||
responseToClient.setPayload(operator.sendRequestToQueue(destination, iAction, true));
|
||||
responseToClient.setCode(0);
|
||||
responseToClient.setMessage("success");
|
||||
return responseToClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Для оптимизации передачи userId
|
||||
*/
|
||||
protected <T> CudResponse processRequest(String destination, IAction<T> iAction, Long userId) throws ExecutionException, InterruptedException {
|
||||
CudResponse responseToClient = new CudResponse();
|
||||
responseToClient.setPayload(operator.sendRequestToQueue(destination, iAction, userId));
|
||||
responseToClient.setCode(0);
|
||||
responseToClient.setMessage("success");
|
||||
return responseToClient;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue;
|
||||
|
||||
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.errors.ActionValidationException;
|
||||
import ru.spcex.clearing.backendapi.errors.BackEndError;
|
||||
import ru.spcex.clearing.backendapi.errors.NotFound404Exception;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
||||
|
||||
@ControllerAdvice("ru.spcex.clearing.backendapi.controller.queue")
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
public class QueueExceptionHandler extends ResponseEntityExceptionHandler {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final IMessageResolver errorResolver;
|
||||
|
||||
@Autowired
|
||||
public QueueExceptionHandler(@Qualifier("errorResolver") IMessageResolver errorResolver) {
|
||||
this.errorResolver = errorResolver;
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = ActionValidationException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ResponseBody
|
||||
public BasicSpcexResponse handleValidationException(ActionValidationException e) {
|
||||
log.error("Default exception handler: {}", ExceptionUtils.getStackTrace(e));
|
||||
EnumMessage firstError = e.getErrors().iterator().next();
|
||||
BasicSpcexResponse errorResponse = new BasicSpcexResponse();
|
||||
errorResponse.setCode(firstError.getSubject().getId());
|
||||
errorResponse.setMessage(errorResolver.resolve(firstError));
|
||||
return errorResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ResponseEntity<Object> handleHttpMessageNotReadable(HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
|
||||
BasicSpcexResponse errorResponse = new BasicSpcexResponse();
|
||||
EnumMessage message;
|
||||
try {
|
||||
UnrecognizedPropertyException jacksonException = (UnrecognizedPropertyException) ex.getCause();
|
||||
message = new EnumMessage(BackEndError.UnknownJsonProperty, jacksonException.getPropertyName());
|
||||
} catch (ClassCastException e) {
|
||||
log.error(ExceptionUtils.getStackTrace(ex));
|
||||
message = new EnumMessage(BackEndError.FailedToReadHttpMessage);
|
||||
}
|
||||
errorResponse.setCode(message.getSubject().getId());
|
||||
errorResponse.setMessage(errorResolver.resolve(message));
|
||||
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
@ExceptionHandler(NotFound404Exception.class)
|
||||
@ResponseStatus(value = HttpStatus.NOT_FOUND)
|
||||
@ResponseBody
|
||||
public BasicSpcexResponse notFoundEx(NotFound404Exception ex) {
|
||||
BasicSpcexResponse response = new BasicSpcexResponse();
|
||||
EnumMessage message = ex.getError();
|
||||
response.setCode(message.getSubject().getId());
|
||||
response.setMessage(errorResolver.resolve(message));
|
||||
return response;
|
||||
}
|
||||
|
||||
@ExceptionHandler(value = Throwable.class)
|
||||
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@ResponseBody
|
||||
public BasicSpcexResponse handleDefault(Throwable e) {
|
||||
log.error("Default exception handler: {}", ExceptionUtils.getStackTrace(e));
|
||||
BasicSpcexResponse errorResponse = new BasicSpcexResponse();
|
||||
errorResponse.setCode(-1);
|
||||
errorResponse.setMessage("internal server error");
|
||||
return errorResponse;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.account;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.AccountNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.AccountUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/accounting/accounts")
|
||||
public class AccountController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public AccountController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all accounts.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_Account, Account.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "create account.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse add(
|
||||
@ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
||||
@RequestBody AccountNewAction accountNewAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.DESTINATION_CORRESPONDENT_ACCOUNT_NEW, accountNewAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "update account.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse update(
|
||||
@ApiParam(value = "Идентификатор изменяемого объекта.", required = true, example = "1234")
|
||||
@PathVariable("id") Long id,
|
||||
@ApiParam(value = "Новые значения полей объекта.", required = true)
|
||||
@RequestBody AccountUpdateAction accountUpdateAction) throws ExecutionException, InterruptedException {
|
||||
accountUpdateAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_CORRESPONDENT_ACCOUNT_UPDATE, accountUpdateAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "delete account.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public CudResponse delete(@ApiParam(value = "Идентификатор удаляемого объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_CORRESPONDENT_ACCOUNT_BLOCK, deleteAction);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.account;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.account.AccountSymbols;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.AccountSymbolsNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/accounting/depo-accounts-symbols")
|
||||
public class AccountSymbolsController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public AccountSymbolsController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all accounts-symbols.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_AccountSymbols, AccountSymbols.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "create AccountSymbols.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse add(
|
||||
@ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
||||
@RequestBody AccountSymbolsNewAction accountNewAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.DESTINATION_DEPO_ACCOUNT_SYMBOLS_NEW, accountNewAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "delete AccountSymbols.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public CudResponse delete(@ApiParam(value = "Идентификатор удаляемого объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_DEPO_ACCOUNT_SYMBOLS_DELETE, deleteAction);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.account;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.account.BankAccount;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.BankAccountNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.BankAccountUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetByIdResponse;
|
||||
import ru.spcex.clearing.backendapi.meta.GetResponseFactory;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/accounting/bank-accounts")
|
||||
public class BankAccountController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
private final GetResponseFactory responseMetaFactory;
|
||||
|
||||
@Autowired
|
||||
public BankAccountController(GetResponseFactory responseMetaFactory, IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
this.responseMetaFactory = responseMetaFactory;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "create bank account.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse add(
|
||||
@ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
||||
@RequestBody BankAccountNewAction bankAccountNewAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.DESTINATION_BANK_ACCOUNT_NEW, bankAccountNewAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "update bank account.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse update(
|
||||
@ApiParam(value = "Идентификатор изменяемого объекта.", required = true, example = "1234")
|
||||
@PathVariable("id") Long id,
|
||||
@ApiParam(value = "Новые значения полей объекта.", required = true)
|
||||
@RequestBody BankAccountUpdateAction bankAccountUpdateAction) throws ExecutionException, InterruptedException {
|
||||
bankAccountUpdateAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_BANK_ACCOUNT_UPDATE, bankAccountUpdateAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "delete bank account.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public CudResponse delete(@ApiParam(value = "Идентификатор удаляемого объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_BANK_ACCOUNT_BLOCK, deleteAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get bank account.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetByIdResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetByIdResponse getById(@ApiParam(value = "Идентификатор объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) {
|
||||
Optional<BankAccount> bankAccount = stateLoader.getById(id, IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
CommonGetByIdResponse response = new CommonGetByIdResponse();
|
||||
bankAccount.ifPresentOrElse( r -> {
|
||||
Map<String, Object> extractedByMeta = responseMetaFactory.responseFromObject(r);
|
||||
response.fromEntity(extractedByMeta);
|
||||
}, () -> response.setCode(404));
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all bank accounts.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.account;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.account.ClearingAccount;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/accounting/clearing-accounts")
|
||||
public class ClearingAccountController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public ClearingAccountController(IStateLoader stateLoader) {
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all clearing account.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.account;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.account.ClientCode;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.ClientCodeNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.ClientCodeUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/client-codes")
|
||||
public class ClientCodeController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public ClientCodeController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "create client code.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse add(
|
||||
@ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
||||
@RequestBody ClientCodeNewAction clientCodeNewAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.DESTINATION_CLIENT_CODE_NEW, clientCodeNewAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "update client-code.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse update(
|
||||
@ApiParam(value = "Идентификатор изменяемого объекта.", required = true, example = "1234")
|
||||
@PathVariable("id") Long id,
|
||||
@ApiParam(value = "Новые значения полей объекта.", required = true)
|
||||
@RequestBody ClientCodeUpdateAction clientCodeUpdateAction) throws ExecutionException, InterruptedException {
|
||||
clientCodeUpdateAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_CLIENT_CODE_UPDATE, clientCodeUpdateAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "delete client code.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public CudResponse delete(@ApiParam(value = "Идентификатор удаляемого объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_CLIENT_CODE_DELETE, deleteAction);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "get all client codes.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_ClientCode, ClientCode.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.account;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.account.DepoAccount;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/accounting/depo-accounts")
|
||||
public class DepoAccountController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public DepoAccountController(IStateLoader stateLoader) {
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all depo account.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.account;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.AccountInformationNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.account.BankAccountNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/accounting/information-accounts")
|
||||
public class InformationAccountController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public InformationAccountController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all information accounts.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_InformationAccount,
|
||||
InformationAccount.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
// @ApiOperation(value = "Добавление информационного счета.")
|
||||
// @ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
// @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
// @ResponseBody
|
||||
// public CudResponse add(
|
||||
// @ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
||||
// @RequestBody AccountInformationNewAction accountNewInformationAction) throws ExecutionException, InterruptedException {
|
||||
// return processRequest(Consts.DESTINATION_INFORMATION_ACCOUNT_NEW, accountNewInformationAction);
|
||||
// }
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.clearing;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.clearing.VerificationResult;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/verification-results")
|
||||
public class VerificationResultController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public VerificationResultController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all VerificationResult's.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_VerificationResult, VerificationResult.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.company;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.ClearingMemberCategoryNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.ClearingMemberCategoryUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/clearing-member-categories")
|
||||
public class ClearingMemberCategoryController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public ClearingMemberCategoryController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "new clearing category.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse add(
|
||||
@ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
||||
@RequestBody ClearingMemberCategoryNewAction clearingMemberCategoryNewAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.DESTINATION_CLEARING_MEMBER_CATEGORY_NEW, clearingMemberCategoryNewAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "update clearing member category.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse update(
|
||||
@ApiParam(value = "Идентификатор изменяемого объекта.", required = true, example = "1234")
|
||||
@PathVariable("id") Long id,
|
||||
@ApiParam(value = "Новые значения полей объекта.", required = true)
|
||||
@RequestBody ClearingMemberCategoryUpdateAction clearingMemberCategoryUpdateAction) throws ExecutionException, InterruptedException {
|
||||
clearingMemberCategoryUpdateAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_CLEARING_MEMBER_CATEGORY_UPDATE, clearingMemberCategoryUpdateAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "delete clearing member category.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public CudResponse delete(@ApiParam(value = "Идентификатор удаляемого объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_CLEARING_MEMBER_CATEGORY_DELETE, deleteAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all ClearingMemberCategories.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.company;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.CompanyNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/companies")
|
||||
public class CompanyController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public CompanyController(IOperator operator,
|
||||
IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "delete company.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public CudResponse delete(@ApiParam(value = "Идентификатор удаляемого объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_COMPANY_DELETE, deleteAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all Company's.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_Company, Company.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "new company.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse add(
|
||||
@ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
||||
@RequestBody CompanyNewAction companyNewAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.DESTINATION_COMPANY_NEW, companyNewAction);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.company;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.CompanyInfoUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.company.CompanyInfoBackendGetAll;
|
||||
import ru.spcex.clearing.backendapi.meta.GetResponseFactory;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/company-infos")
|
||||
public class CompanyInfoController extends AbstractQueueController {
|
||||
private final Imdg<Company> companyImdg;
|
||||
private final GetResponseFactory responseFactory;
|
||||
|
||||
@Autowired
|
||||
public CompanyInfoController(IOperator operator, ImdgProvider imdgProvider, GetResponseFactory responseFactory) {
|
||||
super(operator);
|
||||
this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
this.responseFactory = responseFactory;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "update company info.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse update(
|
||||
@ApiParam(value = "Идентификатор изменяемого объекта.", required = true, example = "1234")
|
||||
@PathVariable("id") Long id,
|
||||
@ApiParam(value = "Новые значения полей объекта.", required = true)
|
||||
@RequestBody CompanyInfoUpdateAction companyInfoUpdateAction) throws ExecutionException, InterruptedException {
|
||||
companyInfoUpdateAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_COMPANY_INFO_UPDATE, companyInfoUpdateAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all CompanyInfo's.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CompanyInfoBackendGetAll.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CompanyInfoBackendGetAll getAll() {
|
||||
Collection<Map<String, Object>> all = new ArrayList<>();
|
||||
Collection<Company> companies = companyImdg.getAllValues();
|
||||
CompanyInfoBackendGetAll response = new CompanyInfoBackendGetAll();
|
||||
response.fromEntity(companies);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.company;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.company.CompanyRoleSet;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.CompanyRoleSetNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/company-role-sets")
|
||||
public class CompanyRoleSetController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public CompanyRoleSetController(IOperator operator,
|
||||
IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all CompanyRoleSet's.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_CompanyRoleSet,
|
||||
CompanyRoleSet.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "create CompanyRoleSet.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse create(
|
||||
@ApiParam(value = "Значения полей нового объекта.", required = true)
|
||||
@RequestBody CompanyRoleSetNewAction companyRoleSetNewAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.DESTINATION_COMPANY_ROLE_SET_NEW, companyRoleSetNewAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "delete CompanyRoleSet.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public CudResponse delete(@ApiParam(value = "Идентификатор удаляемого объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_COMPANY_ROLE_SET_DELETE, deleteAction);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.company;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.CompanySymbolNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.CompanySymbolUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.ContactNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/company-symbols")
|
||||
public class CompanySymbolController extends AbstractQueueController {
|
||||
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public CompanySymbolController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "create company symbol.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse create(
|
||||
@ApiParam(value = "Значения полей нового объекта.", required = true)
|
||||
@RequestBody CompanySymbolNewAction companySymbolNewAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.DESTINATION_COMPANY_SYMBOL_NEW, companySymbolNewAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "update company symbol.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse update(
|
||||
@ApiParam(value = "Идентификатор изменяемого объекта.", required = true, example = "1234")
|
||||
@PathVariable("id") Long id,
|
||||
@ApiParam(value = "Новые значения полей объекта.", required = true)
|
||||
@RequestBody CompanySymbolUpdateAction companySymbolsUpdateAction) throws ExecutionException, InterruptedException {
|
||||
companySymbolsUpdateAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_COMPANY_SYMBOL_UPDATE, companySymbolsUpdateAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all CompanySymbols")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "delete company symbol.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public CudResponse delete(@ApiParam(value = "Идентификатор удаляемого объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_COMPANY_SYMBOL_DELETE, deleteAction);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.company;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.profile.Contact;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.ContactNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.ContactUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/contacts")
|
||||
public class ContactController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public ContactController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "update company contact.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse update(
|
||||
@ApiParam(value = "Идентификатор изменяемого объекта.", required = true, example = "1234")
|
||||
@PathVariable("id") Long id,
|
||||
@ApiParam(value = "Новые значения полей объекта.", required = true)
|
||||
@RequestBody ContactUpdateAction contactUpdateAction) throws ExecutionException, InterruptedException {
|
||||
contactUpdateAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_CONTACT_UPDATE, contactUpdateAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "create company contact.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse create(
|
||||
@ApiParam(value = "Значения полей нового объекта.", required = true)
|
||||
@RequestBody ContactNewAction contactNewAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.DESTINATION_CONTACT_NEW, contactNewAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "delete contact.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public CudResponse delete(@ApiParam(value = "Идентификатор удаляемого объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_CONTACT_DELETE, deleteAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all Contacts.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_Contact, Contact.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.company;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.profile.ProfileDocument;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.ProfileDocumentNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.ProfileDocumentUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/profile-documents")
|
||||
public class ProfileDocumentController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public ProfileDocumentController(IStateLoader stateLoader, IOperator operator) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all ProfileDocuments.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_ProfileDocument, ProfileDocument.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "new profile document.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse add(
|
||||
@ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
||||
@RequestBody ProfileDocumentNewAction profileDocumentNewAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.DESTINATION_PROFILE_DOCUMENT_NEW, profileDocumentNewAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "update profile document.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse update(
|
||||
@PathVariable("id") Long id,
|
||||
@ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
||||
@RequestBody ProfileDocumentUpdateAction profileDocumentUpdateAction) throws ExecutionException, InterruptedException {
|
||||
profileDocumentUpdateAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_PROFILE_DOCUMENT_UPDATE, profileDocumentUpdateAction);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "delete profile document.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public CudResponse delete(@ApiParam(value = "Идентификатор удаляемого объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_PROFILE_DOCUMENT_DELETE, deleteAction);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.company;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.RelationUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/relations")
|
||||
public class RelationController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public RelationController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all Relation's.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_Relation, Relation.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "update relation.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse update(
|
||||
@ApiParam(value = "Идентификатор изменяемого объекта.", required = true, example = "1234")
|
||||
@PathVariable("id") Long id,
|
||||
@ApiParam(value = "Новые значения полей объекта.", required = true)
|
||||
@RequestBody RelationUpdateAction relationUpdateAction) throws ExecutionException, InterruptedException {
|
||||
relationUpdateAction.setId(id);
|
||||
return processRequest(Consts.DESTINATION_RELATION_UPDATE, relationUpdateAction);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.execution;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.execution.ExecutionDeposit;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/execution-deposits")
|
||||
public class ExecutionDepositController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
private final ImdgPredicateBuilder imdgPredicateBuilder;
|
||||
|
||||
@Autowired
|
||||
public ExecutionDepositController(IOperator operator, IStateLoader stateLoader,
|
||||
ImdgProvider imdgProvider) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
this.imdgPredicateBuilder = imdgProvider
|
||||
.getImdg(IMDGDistributedNames.Map_ExecutionDeposit, ExecutionDeposit.class)
|
||||
.predicateBuilder();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all ExecutionDeposits.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
ImdgPredicate imdgPredicate = imdgPredicateBuilder.greatEqual("firstLegSettlementDate", LocalDate.now());
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_ExecutionDeposit,
|
||||
ExecutionDeposit.class,
|
||||
imdgPredicate);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.execution;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.execution.ExecutionFond;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/execution-fonds")
|
||||
public class ExecutionFondController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
private final ImdgPredicateBuilder imdgPredicateBuilder;
|
||||
|
||||
@Autowired
|
||||
public ExecutionFondController(IOperator operator,
|
||||
IStateLoader stateLoader,
|
||||
ImdgProvider imdgProvider) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
this.imdgPredicateBuilder = imdgProvider
|
||||
.getImdg(IMDGDistributedNames.Map_ExecutionFond, ExecutionFond.class)
|
||||
.predicateBuilder();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all ExecutionFond.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
ImdgPredicate imdgPredicate = imdgPredicateBuilder.greatEqual("settlementDate", LocalDate.now());
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_ExecutionFond,
|
||||
ExecutionFond.class,
|
||||
imdgPredicate);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.history;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.history.condition.ConditionProvider;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.history.condition.HistorySubscription;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.history.HistoryRequest;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.errors.ActionValidationException;
|
||||
import ru.spcex.clearing.backendapi.errors.BackEndError;
|
||||
import ru.spcex.clearing.backendapi.meta.GetResponseFactory;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/history")
|
||||
public class HistController {
|
||||
private final GetResponseFactory responseFactory;
|
||||
private final IStateLoader stateLoader;
|
||||
private final ConditionProvider conditionProvider;
|
||||
|
||||
@Autowired
|
||||
public HistController(GetResponseFactory responseFactory,
|
||||
IStateLoader stateLoader,
|
||||
ConditionProvider conditionProvider) {
|
||||
this.responseFactory = responseFactory;
|
||||
this.stateLoader = stateLoader;
|
||||
this.conditionProvider = conditionProvider;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Get history")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getHistory(
|
||||
@ApiParam(value = "destination сущности по которой запрашивается история", example = "money-balance-registers", required = true)
|
||||
@RequestParam("destination")
|
||||
String destination,
|
||||
@ApiParam(value = "Начальная точка поиска по дате", example = "2023-01-15")
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
|
||||
@RequestParam(name = "from", required = false)
|
||||
LocalDate from,
|
||||
@ApiParam(value = "Конечная точка поиска по дате", example = "2023-01-15")
|
||||
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
|
||||
@RequestParam(name = "to", required = false)
|
||||
LocalDate to
|
||||
) {
|
||||
if (to == null && from == null) {
|
||||
throw new ActionValidationException(new EnumMessage(BackEndError.ValidationError, "from/to url params both empty"));
|
||||
}
|
||||
|
||||
Optional<Class<? extends SpcexObjectBase>> entityClass = responseFactory.classByDestination(destination);
|
||||
//class may be added to HistorySubscription if needed
|
||||
if (entityClass.isEmpty()) {
|
||||
throw new ActionValidationException(new EnumMessage(BackEndError.ValidationError,
|
||||
"destination " + "'" + destination + "' not supported (meta class not found)"));
|
||||
}
|
||||
|
||||
HistoryRequest req = new HistoryRequest();
|
||||
req.setTable(destination);
|
||||
req.setFrom(from);
|
||||
req.setTo(to);
|
||||
|
||||
HistorySubscription[] subscr = new HistorySubscription[1];
|
||||
ImdgPredicate[] prdct = new ImdgPredicate[1];
|
||||
conditionProvider.conditionForRequest(req).map(s -> subscr[0] = s, p -> prdct[0] = p);
|
||||
|
||||
Collection<Map<String, Object>> searchRes = stateLoader.getAllMetaTransform(
|
||||
subscr[0].getSearchProxyMapName(),
|
||||
subscr[0].getFullHistoryMapName(),
|
||||
entityClass.get(),
|
||||
prdct[0]
|
||||
);
|
||||
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(searchRes);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.history.condition;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.history.HistoryRequest;
|
||||
import ru.spcex.clearing.backendapi.errors.ActionValidationException;
|
||||
import ru.spcex.clearing.backendapi.errors.BackEndError;
|
||||
import ru.spcex.clearing.backendapi.meta.GetResponseFactory;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.utils.collection.Pair;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
public class ConditionProvider {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final GetResponseFactory responseFactory;
|
||||
private final ImdgPredicateBuilder pb;
|
||||
|
||||
private final Map<String, HistorySubscription> subscriptions;
|
||||
|
||||
@Autowired
|
||||
public ConditionProvider(GetResponseFactory responseFactory, ImdgProvider imdgProvider,
|
||||
List<HistorySubscription> subscriptions) {
|
||||
this.responseFactory = responseFactory;
|
||||
this.subscriptions = new HashMap<>();
|
||||
Imdg<SpcexObjectBase> imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SearchMoneyBalanceRegister, SpcexObjectBase.class);
|
||||
this.pb = imdg.predicateBuilder();
|
||||
subscriptions.forEach(s -> this.subscriptions.put(s.getDestination(), s));
|
||||
}
|
||||
|
||||
public Pair<HistorySubscription, ImdgPredicate> conditionForRequest(HistoryRequest req) {
|
||||
String destination = req.getTable();
|
||||
HistorySubscription subscription = subscriptions.get(destination);
|
||||
if (subscription == null) {
|
||||
throw new ActionValidationException(new EnumMessage(BackEndError.ValidationError,
|
||||
"destination " + "'" + destination + "' not supported (subscription info not found)"));
|
||||
}
|
||||
|
||||
List<ImdgPredicate> predicates = subscription
|
||||
.getConditions()
|
||||
.stream()
|
||||
.map(c -> c.condition(req))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.toList();
|
||||
|
||||
ImdgPredicate result;
|
||||
if (predicates.size() == 0) {
|
||||
//add boundary conditions?
|
||||
log.warn("destination '{}' zero predicates found", destination);
|
||||
result = pb.alwaysTrue();
|
||||
} else if (predicates.size() == 1) {
|
||||
result = predicates.iterator().next();
|
||||
} else {
|
||||
result = pb.and(predicates.toArray(new ImdgPredicate[0]));
|
||||
}
|
||||
|
||||
return new Pair<>(subscription, result);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.history.condition;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class HistorySubscription {
|
||||
private String destination;
|
||||
|
||||
private List<IHistoryCondition> conditions;
|
||||
private String searchProxyMapName;
|
||||
private String fullHistoryMapName;
|
||||
//class
|
||||
|
||||
|
||||
public List<IHistoryCondition> getConditions() {
|
||||
return conditions != null ? conditions : Collections.emptyList();
|
||||
}
|
||||
|
||||
public void setConditions(List<IHistoryCondition> conditions) {
|
||||
this.conditions = conditions;
|
||||
}
|
||||
|
||||
public String getSearchProxyMapName() {
|
||||
return searchProxyMapName;
|
||||
}
|
||||
|
||||
public void setSearchProxyMapName(String searchProxyMapName) {
|
||||
this.searchProxyMapName = searchProxyMapName;
|
||||
}
|
||||
|
||||
public String getFullHistoryMapName() {
|
||||
return fullHistoryMapName;
|
||||
}
|
||||
|
||||
public void setFullHistoryMapName(String fullHistoryMapName) {
|
||||
this.fullHistoryMapName = fullHistoryMapName;
|
||||
}
|
||||
|
||||
public String getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDestination(String destination) {
|
||||
this.destination = destination;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.history.condition;
|
||||
|
||||
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.history.HistoryRequest;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface IHistoryCondition {
|
||||
Optional<ImdgPredicate> condition(HistoryRequest req);
|
||||
|
||||
default Optional<ImdgPredicate> of(ImdgPredicate predicate) {
|
||||
return Optional.of(predicate);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.history.condition.specific;
|
||||
|
||||
import ru.spcex.clearing.backendapi.controller.queue.history.condition.IHistoryCondition;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.history.HistoryRequest;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ClearingDateFromCondition implements IHistoryCondition {
|
||||
|
||||
private final ImdgPredicateBuilder pb;
|
||||
|
||||
public ClearingDateFromCondition(ImdgPredicateBuilder pb) {
|
||||
this.pb = pb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ImdgPredicate> condition(HistoryRequest req) {
|
||||
if (req.getFrom() != null) {
|
||||
return Optional.ofNullable(pb.greatEqual("clearingDate", req.getFrom()));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.history.condition.specific;
|
||||
|
||||
import ru.spcex.clearing.backendapi.controller.queue.history.condition.IHistoryCondition;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.history.HistoryRequest;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ClearingDateToCondition implements IHistoryCondition {
|
||||
|
||||
private final ImdgPredicateBuilder pb;
|
||||
|
||||
public ClearingDateToCondition(ImdgPredicateBuilder pb) {
|
||||
this.pb = pb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ImdgPredicate> condition(HistoryRequest req) {
|
||||
if (req.getTo() != null) {
|
||||
return Optional.ofNullable(pb.lessEqual("clearingDate", req.getTo()));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.history.condition.specific;
|
||||
|
||||
import ru.spcex.clearing.backendapi.controller.queue.history.condition.IHistoryCondition;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.history.HistoryRequest;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.utils.time.TimeUtil;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class CreatedFromCondition implements IHistoryCondition {
|
||||
|
||||
private final ImdgPredicateBuilder pb;
|
||||
|
||||
public CreatedFromCondition(ImdgPredicateBuilder pb) {
|
||||
this.pb = pb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ImdgPredicate> condition(HistoryRequest req) {
|
||||
if (req.getFrom() != null) {
|
||||
return Optional.of(pb.greatEqual("created", TimeUtil.localDateToInstant(req.getFrom())));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.history.condition.specific;
|
||||
|
||||
import ru.spcex.clearing.backendapi.controller.queue.history.condition.IHistoryCondition;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.history.HistoryRequest;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.utils.time.TimeUtil;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class CreatedToCondition implements IHistoryCondition {
|
||||
|
||||
private final ImdgPredicateBuilder pb;
|
||||
|
||||
public CreatedToCondition(ImdgPredicateBuilder pb) {
|
||||
this.pb = pb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ImdgPredicate> condition(HistoryRequest req) {
|
||||
if (req.getTo() != null) {
|
||||
return Optional.of(pb.lessEqual("created", TimeUtil.localDateToInstant(req.getTo())));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.history.condition.specific;
|
||||
|
||||
import ru.spcex.clearing.backendapi.controller.queue.history.condition.IHistoryCondition;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.history.HistoryRequest;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class TradingDateFromCondition implements IHistoryCondition {
|
||||
|
||||
private final ImdgPredicateBuilder pb;
|
||||
|
||||
public TradingDateFromCondition(ImdgPredicateBuilder pb) {
|
||||
this.pb = pb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ImdgPredicate> condition(HistoryRequest req) {
|
||||
if (req.getFrom() != null) {
|
||||
return Optional.ofNullable(pb.greatEqual("tradingDate", req.getFrom()));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.history.condition.specific;
|
||||
|
||||
import ru.spcex.clearing.backendapi.controller.queue.history.condition.IHistoryCondition;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.history.HistoryRequest;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class TradingDateToCondition implements IHistoryCondition {
|
||||
|
||||
private final ImdgPredicateBuilder pb;
|
||||
|
||||
public TradingDateToCondition(ImdgPredicateBuilder pb) {
|
||||
this.pb = pb;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ImdgPredicate> condition(HistoryRequest req) {
|
||||
if (req.getTo() != null) {
|
||||
return Optional.ofNullable(pb.lessEqual("tradingDate", req.getTo()));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.journal;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.journal.InDocumentJournal;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/in-document-journals")
|
||||
public class InDocumentJournalController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public InDocumentJournalController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all InDocumentJournals.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_InDocumentJournal,
|
||||
InDocumentJournal.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.journal;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.journal.ManagementJournal;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/management-journals")
|
||||
public class ManagementJournalController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public ManagementJournalController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all management journals.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_ManagementJournal,
|
||||
ManagementJournal.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.journal;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.journal.OutDocumentJournal;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/out-document-journals")
|
||||
public class OutDocumentJournalController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public OutDocumentJournalController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all OutDocumentJournals.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_OutDocumentJournal,
|
||||
OutDocumentJournal.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.misc;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.misc.Currency;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/currencies")
|
||||
public class CurrencyController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public CurrencyController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all currencies.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_Currency, Currency.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.misc;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.messages.ErrorText;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/error-texts")
|
||||
public class ErrorTextController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public ErrorTextController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all ErrorText's.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_ErrorText, ErrorText.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.misc;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.clearing.classes.statics.data.misc.Listing;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.common.CommonDeleteAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.ListingNewAction;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.company.ListingUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/listings")
|
||||
public class ListingController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public ListingController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all listings.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_Listing, Listing.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ApiOperation(value = "create Listing.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse create(
|
||||
@ApiParam(value = "Значения полей нового объекта.", required = true)
|
||||
@RequestBody ListingNewAction listingNewAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.LISTING_NEW, listingNewAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "update Listing.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse update(
|
||||
@ApiParam(value = "Идентификатор изменяемого объекта.", required = true, example = "1234")
|
||||
@PathVariable("id") Long id,
|
||||
@ApiParam(value = "Новые значения полей объекта.", required = true)
|
||||
@RequestBody ListingUpdateAction listingUpdateAction) throws ExecutionException, InterruptedException {
|
||||
listingUpdateAction.setId(id);
|
||||
return processRequest(Consts.LISTING_UPDATE, listingUpdateAction);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "delete Listing.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class)})
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
|
||||
@ResponseBody
|
||||
public CudResponse delete(@ApiParam(value = "Идентификатор удаляемого объекта", required = true, example = "1234")
|
||||
@PathVariable("id") Long id) throws ExecutionException, InterruptedException {
|
||||
CommonDeleteAction deleteAction = new CommonDeleteAction();
|
||||
deleteAction.setId(id);
|
||||
return processRequest(Consts.LISTING_DELETE, deleteAction);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.misc;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.misc.Market;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/markets")
|
||||
public class MarketController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public MarketController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all markets.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_Market, Market.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.misc;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.misc.Notification;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.registry.NotificationUpdateAction;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/notifications")
|
||||
public class NotificationController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public NotificationController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all notifications.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_Notification, Notification.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "create Notification.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse update(
|
||||
@ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
||||
@RequestBody NotificationUpdateAction notificationUpdateAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.NOTIFICATION_UPDATE, notificationUpdateAction);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.misc;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.misc.Session;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/sessions")
|
||||
public class SessionController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public SessionController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all sessions.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_Session, Session.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.payment;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.payment.PaymentInstruction;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.request.cud.payment.PIClearingOutbondActionNew;
|
||||
import ru.spcex.clearing.backendapi.controller.response.BasicSpcexResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.cud.CudResponse;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/payment-instructions")
|
||||
public class PaymentInstructionController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public PaymentInstructionController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all paymentInstructions.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(IMDGDistributedNames.Map_PaymentInstruction, PaymentInstruction.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "Досрочное изъятие части денежных средств по договору")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CudResponse.class), @ApiResponse(code = 400, message = "Ошибка валидации", response = BasicSpcexResponse.class)})
|
||||
@RequestMapping(value = "/clearing-outbound", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
@ResponseBody
|
||||
public CudResponse clearingOutboundAction(
|
||||
@ApiParam(value = "Параметры команды в JSON формате.", required = true)
|
||||
@RequestBody PIClearingOutbondActionNew piClearingOutbondAction) throws ExecutionException, InterruptedException {
|
||||
return processRequest(Consts.PAYMENT_INSTRUCTION_CLEARING_OUTBOUND_ACTION, piClearingOutbondAction);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.register;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.register.AdmittedLiabilitiesRegister;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/admitted-liabilities-registers")
|
||||
public class AdmittedLiabilitiesRegisterController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public AdmittedLiabilitiesRegisterController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all admittedLiabilitiesRegister's")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_AdmittedLiabilitiesRegister,
|
||||
AdmittedLiabilitiesRegister.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.register;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.register.ContractRegister;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/contract-registers")
|
||||
public class ContractRegisterController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public ContractRegisterController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all contract registers.")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_ContractRegister,
|
||||
ContractRegister.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.register;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.register.CoveredLiabilitiesRegister;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/covered-liabilities-registers")
|
||||
public class CoveredLiabilitiesRegisterController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public CoveredLiabilitiesRegisterController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all coveredLiabilitiesRegister's")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_CoveredLiabilitiesRegister,
|
||||
CoveredLiabilitiesRegister.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.register;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.register.DepoBalanceRegister;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/depo-balance-registers")
|
||||
public class DepoBalanceRegisterController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public DepoBalanceRegisterController(IOperator operator, IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all depoBalanceRegister's")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_DepoBalanceRegister,
|
||||
DepoBalanceRegister.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
package ru.spcex.clearing.backendapi.controller.queue.register;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiResponse;
|
||||
import io.swagger.annotations.ApiResponses;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import ru.clearing.classes.statics.data.register.DepoPaymentInstructionRegister;
|
||||
import ru.spcex.clearing.backendapi.controller.queue.AbstractQueueController;
|
||||
import ru.spcex.clearing.backendapi.controller.response.entity.CommonGetAllResponse;
|
||||
import ru.spcex.clearing.backendapi.service.IOperator;
|
||||
import ru.spcex.clearing.backendapi.service.IStateLoader;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/depo-payment-instruction-registers")
|
||||
public class DepoPaymentInstructionRegisterController extends AbstractQueueController {
|
||||
private final IStateLoader stateLoader;
|
||||
|
||||
@Autowired
|
||||
public DepoPaymentInstructionRegisterController(IOperator operator,
|
||||
IStateLoader stateLoader) {
|
||||
super(operator);
|
||||
this.stateLoader = stateLoader;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "get all depoPaymentInstructionRegister's")
|
||||
@ApiResponses(value = {@ApiResponse(code = 200, message = "OK", response = CommonGetAllResponse.class)})
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonGetAllResponse getAll() {
|
||||
Collection<Map<String, Object>> all = stateLoader.getAllMetaTransform(
|
||||
IMDGDistributedNames.Map_DepoPaymentInstructionRegister,
|
||||
DepoPaymentInstructionRegister.class);
|
||||
CommonGetAllResponse response = new CommonGetAllResponse();
|
||||
response.fromEntity(all);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue