FIN-29: Add common implementation (#1)

This commit is contained in:
Baikov Dmitrii 2024-04-25 16:46:47 +03:00 committed by GitHub
parent 9412afed73
commit 5f5857d482
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
137 changed files with 7312 additions and 0 deletions

2
.github/settings.yml vendored Normal file
View File

@ -0,0 +1,2 @@
# These settings are synced to GitHub by https://probot.github.io/apps/settings/
_extends: .github

10
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,10 @@
name: Build Maven Artifact
on:
pull_request:
branches:
- '**'
jobs:
build:
uses: valitydev/base-workflow/.github/workflows/maven-service-build.yml@v2

15
.github/workflows/deploy.yml vendored Normal file
View File

@ -0,0 +1,15 @@
name: Deploy Docker Image
on:
push:
branches:
- 'master'
- 'main'
- 'epic/**'
jobs:
build-and-deploy:
uses: valitydev/base-workflow/.github/workflows/maven-service-deploy.yml@v2
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}
mm-webhook-url: ${{ secrets.MATTERMOST_WEBHOOK_URL }}

83
.gitignore vendored Normal file
View File

@ -0,0 +1,83 @@
# Created by .ignore support plugin (hsz.mobi)
### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format:
*.iws
*.ipr
*.iml
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### Java template
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
env.list
# OSX
*.DS_Store
.AppleDouble
.LSOverride
# TestContainers
.testcontainers-*

402
pom.xml Normal file
View File

@ -0,0 +1,402 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>dev.vality</groupId>
<artifactId>service-parent-pom</artifactId>
<version>3.0.0</version>
</parent>
<artifactId>dominator</artifactId>
<version>2.0.0</version>
<packaging>jar</packaging>
<name>dominator</name>
<description>Service for interation with the dominant data</description>
<properties>
<dockerfile.registry>${env.REGISTRY}</dockerfile.registry>
<server.port>8022</server.port>
<management.port>8023</management.port>
<exposed.ports>${server.port} ${management.port}</exposed.ports>
<db.url>jdbc:postgresql://localhost:5432/dominator</db.url>
<db.user>postgres</db.user>
<db.password>postgres</db.password>
<db.name>dominator</db.name>
<db.schema>dmn</db.schema>
<local.pg.url>jdbc:postgresql://localhost:5432/dominator</local.pg.url>
<local.pg.port>5432</local.pg.port>
<checkstyle.config.suppressions.path>./src/main/resources/checkstyle/checkstyle-suppressions.xml
</checkstyle.config.suppressions.path>
</properties>
<dependencies>
<!--spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.1.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>6.1.6</version>
</dependency>
<!--Thrirdparty libs-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
</dependency>
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>7.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-jdbc-template</artifactId>
<version>4.46.0</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
<version>4.46.0</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>
<!--dev.vality-->
<dependency>
<groupId>dev.vality</groupId>
<artifactId>db-common-lib</artifactId>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>payout-manager-proto</artifactId>
<version>1.36-063163d</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>kafka-common-lib</artifactId>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>sink-common-lib</artifactId>
<version>0.0.1</version>
</dependency>
<dependency>
<groupId>dev.vality.woody</groupId>
<artifactId>woody-thrift</artifactId>
<version>${woody.version}</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>machinegun-proto</artifactId>
<version>1.31-b43d6fd</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>damsel</artifactId>
<version>1.611-958e5f0</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>fistful-proto</artifactId>
<version>1.166-be67e59</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>xrates-proto</artifactId>
<version>1.23-bf0d62d</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>limiter-proto</artifactId>
<version>1.33-31de59b</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>exrates-proto</artifactId>
<version>1.7-ce9563e</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>shared-resources</artifactId>
<version>${shared-resources.version}</version>
</dependency>
<dependency>
<groupId>dev.vality.geck</groupId>
<artifactId>serializer</artifactId>
</dependency>
<dependency>
<groupId>dev.vality.geck</groupId>
<artifactId>filter</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>testcontainers-annotations</artifactId>
<version>2.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${project.build.directory}/maven-shared-archive-resources</directory>
<targetPath>${project.build.directory}</targetPath>
<includes>
<include>Dockerfile</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>${project.build.directory}/maven-shared-archive-resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>Dockerfile</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>dev.vality.maven.plugins</groupId>
<artifactId>pg-embedded-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<port>${local.pg.port}</port>
<dbName>${db.name}</dbName>
<schemas>
<schema>${db.schema}</schema>
</schemas>
</configuration>
<executions>
<execution>
<id>PG_server_start</id>
<phase>initialize</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>PG_server_stop</id>
<phase>generate-resources</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<configuration>
<url>${local.pg.url}</url>
<user>${db.user}</user>
<password>${db.password}</password>
<schemas>
<schema>${db.schema}</schema>
</schemas>
</configuration>
<executions>
<execution>
<id>migrate</id>
<phase>initialize</phase>
<goals>
<goal>migrate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.9</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<configuration>
<jdbc>
<driver>org.postgresql.Driver</driver>
<url>${local.pg.url}</url>
<user>${db.user}</user>
<password>${db.password}</password>
</jdbc>
<generator>
<generate>
<javaTimeTypes>true</javaTimeTypes>
<pojos>true</pojos>
<pojosEqualsAndHashCode>true</pojosEqualsAndHashCode>
<pojosToString>true</pojosToString>
</generate>
<database>
<name>org.jooq.meta.postgres.PostgresDatabase</name>
<includes>.*</includes>
<excludes>
schema_version|.*func|get_adjustment.*|get_cashflow.*|get_payment.*|get_payout.*|get_refund.*
</excludes>
<inputSchema>${db.schema}</inputSchema>
</database>
<target>
<packageName>com.empayre.dominator.domain</packageName>
<directory>target/generated-sources/</directory>
</target>
</generator>
</configuration>
<executions>
<execution>
<id>gen-src</id>
<phase>initialize</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>3.1.0</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
<configuration>
<resourceBundles>
<resourceBundle>dev.vality:shared-resources:${shared-resources.version}</resourceBundle>
</resourceBundles>
<attachToMain>false</attachToMain>
<attachToTest>false</attachToTest>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>p12</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
</build>
</project>

4
renovate.json Normal file
View File

@ -0,0 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["local>valitydev/.github:renovate-config"]
}

View File

@ -0,0 +1,17 @@
package com.empayre.dominator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@ServletComponentScan
@SpringBootApplication(scanBasePackages = {"com.empayre.dominator"})
public class DominatorApplication {
public static void main(String[] args) {
SpringApplication.run(DominatorApplication.class, args);
}
}

View File

@ -0,0 +1,30 @@
package com.empayre.dominator.config;
import com.empayre.dominator.domain.Dmn;
import dev.vality.damsel.domain_config.RepositorySrv;
import dev.vality.woody.thrift.impl.http.THSpawnClientBuilder;
import org.jooq.Schema;
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 java.io.IOException;
@Configuration
public class ApplicationConfig {
@Bean
public RepositorySrv.Iface dominantClient(@Value("${dmt.url}") Resource resource,
@Value("${dmt.networkTimeout}") int networkTimeout) throws IOException {
return new THSpawnClientBuilder()
.withNetworkTimeout(networkTimeout)
.withAddress(resource.getURI())
.build(RepositorySrv.Iface.class);
}
@Bean
public Schema schema() {
return Dmn.DMN;
}
}

View File

@ -0,0 +1,99 @@
package com.empayre.dominator.config;
import com.empayre.dominator.config.properties.KafkaConsumerProperties;
import com.empayre.dominator.serde.SinkEventDeserializer;
import com.empayre.dominator.service.FileService;
import dev.vality.kafka.common.util.ExponentialBackOffDefaultErrorHandlerFactory;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.config.KafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
import org.springframework.kafka.listener.ContainerProperties;
import java.util.Map;
import java.util.Objects;
@Configuration
@RequiredArgsConstructor
@SuppressWarnings("LineLength")
public class KafkaConfig {
private final KafkaProperties kafkaProperties;
private final KafkaConsumerProperties kafkaConsumerProperties;
private final FileService fileService;
@Value("${kafka.topics.party-management.consumer.group-id}")
private String partyConsumerGroup;
@Value("${kafka.rack.path:/tmp/.kafka_rack_env}")
private String rackPath;
@Bean
public Map<String, Object> consumerConfigs() {
return createConsumerConfig();
}
private Map<String, Object> createConsumerConfig() {
Map<String, Object> props = kafkaProperties.buildConsumerProperties(null);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, SinkEventDeserializer.class);
props.put(ConsumerConfig.GROUP_ID_CONFIG, kafkaConsumerProperties.getGroupId());
String clientRack = fileService.getClientRack(rackPath);
if (Objects.nonNull(clientRack)) {
props.put(ConsumerConfig.CLIENT_RACK_CONFIG, clientRack);
}
return props;
}
@Bean
public ConsumerFactory<String, MachineEvent> consumerFactory() {
return new DefaultKafkaConsumerFactory<>(consumerConfigs());
}
@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, MachineEvent>> partyManagementContainerFactory() {
Map<String, Object> configs = createConsumerConfig();
configs.put(ConsumerConfig.GROUP_ID_CONFIG, partyConsumerGroup);
ConsumerFactory<String, MachineEvent> consumerFactory = new DefaultKafkaConsumerFactory<>(configs);
return createConcurrentFactory(consumerFactory, kafkaConsumerProperties.getPartyManagementConcurrency());
}
@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, MachineEvent>> identityContainerFactory(
ConsumerFactory<String, MachineEvent> consumerFactory) {
return createConcurrentFactory(consumerFactory, kafkaConsumerProperties.getIdentityConcurrency());
}
@Bean
public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, MachineEvent>> walletContainerFactory(
ConsumerFactory<String, MachineEvent> consumerFactory) {
return createConcurrentFactory(consumerFactory, kafkaConsumerProperties.getWalletConcurrency());
}
private <T> KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, T>> createConcurrentFactory(
ConsumerFactory<String, T> consumerFactory, int threadsNumber) {
ConcurrentKafkaListenerContainerFactory<String, T> factory =
new ConcurrentKafkaListenerContainerFactory<>();
initFactory(consumerFactory, threadsNumber, factory);
return factory;
}
private <T> void initFactory(ConsumerFactory<String, T> consumerFactory,
int threadsNumber,
ConcurrentKafkaListenerContainerFactory<String, T> factory) {
factory.setConsumerFactory(consumerFactory);
factory.setBatchListener(true);
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL);
factory.setCommonErrorHandler(ExponentialBackOffDefaultErrorHandlerFactory.create());
factory.setConcurrency(threadsNumber);
}
}

View File

@ -0,0 +1,35 @@
package com.empayre.dominator.config;
import com.empayre.dominator.handler.dominant.DominantPoller;
import com.empayre.dominator.service.DominantService;
import dev.vality.damsel.domain_config.RepositorySrv;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import javax.sql.DataSource;
@Configuration
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "PT5M")
public class SchedulerConfig {
public static final String TABLE_NAME = "dmn.shedlock";
@Bean
public DominantPoller dominantPoller(RepositorySrv.Iface dominantClient,
DominantService dominantService,
@Value("${dmt.polling.maxQuerySize}") int maxQuerySize,
@Value("${dmt.polling.enabled}") boolean pollingEnabled) {
return new DominantPoller(dominantClient, dominantService, maxQuerySize, pollingEnabled);
}
@Bean
public LockProvider lockProvider(DataSource dataSource) {
return new JdbcTemplateLockProvider(dataSource, TABLE_NAME);
}
}

View File

@ -0,0 +1,182 @@
package com.empayre.dominator.config;
import dev.vality.damsel.payment_processing.EventPayload;
import dev.vality.damsel.payment_processing.PartyEventData;
import dev.vality.damsel.payment_processing.RecurrentPaymentToolEventData;
import dev.vality.geck.serializer.Geck;
import dev.vality.sink.common.parser.impl.MachineEventParser;
import dev.vality.sink.common.parser.impl.PartyEventDataMachineEventParser;
import dev.vality.sink.common.parser.impl.PaymentEventPayloadMachineEventParser;
import dev.vality.sink.common.serialization.BinaryDeserializer;
import dev.vality.sink.common.serialization.impl.AbstractThriftBinaryDeserializer;
import dev.vality.sink.common.serialization.impl.PartyEventDataDeserializer;
import dev.vality.sink.common.serialization.impl.PaymentEventPayloadDeserializer;
import dev.vality.xrates.rate.Change;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@SuppressWarnings("LineLength")
public class SerializationConfig {
@Bean
public BinaryDeserializer<EventPayload> paymentEventPayloadDeserializer() {
return new PaymentEventPayloadDeserializer();
}
@Bean
public MachineEventParser<EventPayload> paymentEventPayloadMachineEventParser(
BinaryDeserializer<EventPayload> paymentEventPayloadDeserializer) {
return new PaymentEventPayloadMachineEventParser(paymentEventPayloadDeserializer);
}
@Bean
public BinaryDeserializer<PartyEventData> partyEventDataBinaryDeserializer() {
return new PartyEventDataDeserializer();
}
@Bean
public MachineEventParser<PartyEventData> partyEventDataMachineEventParser(
BinaryDeserializer<PartyEventData> partyEventDataBinaryDeserializer) {
return new PartyEventDataMachineEventParser(partyEventDataBinaryDeserializer);
}
@Bean
public BinaryDeserializer<RecurrentPaymentToolEventData> recurrentPaymentToolEventDataBinaryDeserializer() {
return new AbstractThriftBinaryDeserializer<>() {
@Override
public RecurrentPaymentToolEventData deserialize(byte[] bytes) {
return deserialize(bytes, new RecurrentPaymentToolEventData());
}
};
}
@Bean
public BinaryDeserializer<Change> rateEventDataBinaryDeserializer() {
return new AbstractThriftBinaryDeserializer<>() {
@Override
public Change deserialize(byte[] bytes) {
return Geck.msgPackToTBase(bytes, Change.class);
}
};
}
@Bean
public MachineEventParser<RecurrentPaymentToolEventData> recurrentPaymentToolEventDataMachineEventParser(
BinaryDeserializer<RecurrentPaymentToolEventData> recurrentPaymentToolEventDataBinaryDeserializer
) {
return new MachineEventParser<>(recurrentPaymentToolEventDataBinaryDeserializer);
}
@Bean
public BinaryDeserializer<dev.vality.fistful.deposit.Event> depositEventDataBinaryDeserializer() {
return new AbstractThriftBinaryDeserializer<>() {
@Override
public dev.vality.fistful.deposit.Event deserialize(byte[] bytes) {
return Geck.msgPackToTBase(bytes, dev.vality.fistful.deposit.Event.class);
}
};
}
@Bean
public MachineEventParser<dev.vality.fistful.deposit.Event> depositEventDataMachineEventParser(
BinaryDeserializer<dev.vality.fistful.deposit.Event> depositEventDataBinaryDeserializer) {
return new MachineEventParser<>(depositEventDataBinaryDeserializer);
}
@Bean
public BinaryDeserializer<dev.vality.fistful.destination.Event> destinationEventDataBinaryDeserializer() {
return new AbstractThriftBinaryDeserializer<>() {
@Override
public dev.vality.fistful.destination.Event deserialize(byte[] bytes) {
return Geck.msgPackToTBase(bytes, dev.vality.fistful.destination.Event.class);
}
};
}
@Bean
public MachineEventParser<dev.vality.fistful.destination.Event> destinationEventDataMachineEventParser(
BinaryDeserializer<dev.vality.fistful.destination.Event> destinationEventDataBinaryDeserializer) {
return new MachineEventParser<>(destinationEventDataBinaryDeserializer);
}
@Bean
public BinaryDeserializer<dev.vality.fistful.identity.Event> identityEventDataBinaryDeserializer() {
return new AbstractThriftBinaryDeserializer<>() {
@Override
public dev.vality.fistful.identity.Event deserialize(byte[] bytes) {
return Geck.msgPackToTBase(bytes, dev.vality.fistful.identity.Event.class);
}
};
}
@Bean
public MachineEventParser<dev.vality.fistful.identity.Event> identityEventDataMachineEventParser(
BinaryDeserializer<dev.vality.fistful.identity.Event> identityEventDataBinaryDeserializer) {
return new MachineEventParser<>(identityEventDataBinaryDeserializer);
}
@Bean
public BinaryDeserializer<dev.vality.fistful.source.Event> sourceEventDataBinaryDeserializer() {
return new AbstractThriftBinaryDeserializer<>() {
@Override
public dev.vality.fistful.source.Event deserialize(byte[] bytes) {
return Geck.msgPackToTBase(bytes, dev.vality.fistful.source.Event.class);
}
};
}
@Bean
public MachineEventParser<dev.vality.fistful.source.Event> sourceEventDataMachineEventParser(
BinaryDeserializer<dev.vality.fistful.source.Event> sourceEventDataBinaryDeserializer) {
return new MachineEventParser<>(sourceEventDataBinaryDeserializer);
}
@Bean
public BinaryDeserializer<dev.vality.fistful.wallet.Event> walletEventDataBinaryDeserializer() {
return new AbstractThriftBinaryDeserializer<>() {
@Override
public dev.vality.fistful.wallet.Event deserialize(byte[] bytes) {
return Geck.msgPackToTBase(bytes, dev.vality.fistful.wallet.Event.class);
}
};
}
@Bean
public MachineEventParser<dev.vality.fistful.wallet.Event> walletEventDataMachineEventParser(
BinaryDeserializer<dev.vality.fistful.wallet.Event> walletEventDataBinaryDeserializer) {
return new MachineEventParser<>(walletEventDataBinaryDeserializer);
}
@Bean
public BinaryDeserializer<dev.vality.fistful.withdrawal.Event> withdrawalEventDataBinaryDeserializer() {
return new AbstractThriftBinaryDeserializer<>() {
@Override
public dev.vality.fistful.withdrawal.Event deserialize(byte[] bytes) {
return Geck.msgPackToTBase(bytes, dev.vality.fistful.withdrawal.Event.class);
}
};
}
@Bean
public MachineEventParser<dev.vality.fistful.withdrawal.Event> withdrawalEventDataMachineEventParser(
BinaryDeserializer<dev.vality.fistful.withdrawal.Event> withdrawalEventDataBinaryDeserializer) {
return new MachineEventParser<>(withdrawalEventDataBinaryDeserializer);
}
@Bean
public BinaryDeserializer<dev.vality.fistful.withdrawal_session.Event> withdrawalSessionEventDataBinaryDeserializer() {
return new AbstractThriftBinaryDeserializer<>() {
@Override
public dev.vality.fistful.withdrawal_session.Event deserialize(byte[] bytes) {
return Geck.msgPackToTBase(bytes, dev.vality.fistful.withdrawal_session.Event.class);
}
};
}
@Bean
public MachineEventParser<dev.vality.fistful.withdrawal_session.Event> withdrawalSessionEventDataMachineEventParser(
BinaryDeserializer<dev.vality.fistful.withdrawal_session.Event> withdrawalSessionEventDataBinaryDeserializer) {
return new MachineEventParser<>(withdrawalSessionEventDataBinaryDeserializer);
}
}

View File

@ -0,0 +1,31 @@
package com.empayre.dominator.config.properties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "kafka.consumer")
public class KafkaConsumerProperties {
private String groupId;
private int invoicingConcurrency;
private int recurrentPaymentToolConcurrency;
private int partyManagementConcurrency;
private int rateConcurrency;
private int depositConcurrency;
private int identityConcurrency;
private int walletConcurrency;
private int withdrawalConcurrency;
private int payoutConcurrency;
private int sourceConcurrency;
private int destinationConcurrency;
private int withdrawalSessionConcurrency;
private int limitConfigConcurrency;
private int exrateConcurrency;
private int withdrawalAdjustmentConcurrency;
}

View File

@ -0,0 +1,22 @@
package com.empayre.dominator.constant;
import lombok.experimental.UtilityClass;
@UtilityClass
public final class RevisionQuery {
public static final String SAVE_SHOPS_QUERY = """
insert into dmn.shop_revision(obj_id, revision)
select id, :revision from dmn.shop where party_id = :party_id and current;
""";
public static final String SAVE_CONTRACTS_QUERY = """
insert into dmn.contract_revision(obj_id, revision)
select id, :revision from dmn.contract where party_id = :party_id and current;
""";
public static final String SAVE_CONTRACTORS_QUERY = """
insert into dmn.contractor_revision(obj_id, revision)
select id, :revision from dmn.contractor where party_id = :party_id and current;
""";
}

View File

@ -0,0 +1,11 @@
package com.empayre.dominator.dao.dominant.iface;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
public interface DomainObjectDao<T, I> extends GenericDao {
Long save(T domainObject) throws DaoException;
void updateNotCurrent(I objectId) throws DaoException;
}

View File

@ -0,0 +1,10 @@
package com.empayre.dominator.dao.dominant.iface;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
public interface DominantDao extends GenericDao {
Long getLastVersionId() throws DaoException;
void updateLastVersionId(Long versionId) throws DaoException;
}

View File

@ -0,0 +1,37 @@
package com.empayre.dominator.dao.dominant.impl;
import com.empayre.dominator.dao.dominant.iface.DominantDao;
import com.empayre.dominator.domain.Tables;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.impl.AbstractGenericDao;
import org.jooq.Query;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.time.LocalDateTime;
@Component
public class DominantDaoImpl extends AbstractGenericDao implements DominantDao {
public DominantDaoImpl(DataSource dataSource) {
super(dataSource);
}
@Override
public Long getLastVersionId() throws DaoException {
Query query = getDslContext()
.select(Tables.DOMINANT_LAST_VERSION_ID.VERSION_ID)
.from(Tables.DOMINANT_LAST_VERSION_ID);
return fetchOne(query, Long.class);
}
@Override
public void updateLastVersionId(Long versionId) throws DaoException {
Query query = getDslContext()
.update(Tables.DOMINANT_LAST_VERSION_ID)
.set(Tables.DOMINANT_LAST_VERSION_ID.VERSION_ID, versionId)
.set(Tables.DOMINANT_LAST_VERSION_ID.WTIME, LocalDateTime.now());
executeOne(query);
}
}

View File

@ -0,0 +1,42 @@
package com.empayre.dominator.dao.dominant.impl;
import com.empayre.dominator.dao.dominant.iface.DomainObjectDao;
import com.empayre.dominator.domain.Tables;
import com.empayre.dominator.domain.tables.pojos.Provider;
import com.empayre.dominator.domain.tables.records.ProviderRecord;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.impl.AbstractGenericDao;
import org.jooq.Query;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
@Component
public class ProviderDaoImpl extends AbstractGenericDao implements DomainObjectDao<Provider, Integer> {
public ProviderDaoImpl(DataSource dataSource) {
super(dataSource);
}
@Override
public Long save(Provider provider) throws DaoException {
ProviderRecord providerRecord = getDslContext().newRecord(Tables.PROVIDER, provider);
Query query = getDslContext()
.insertInto(Tables.PROVIDER)
.set(providerRecord)
.returning(Tables.PROVIDER.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
executeOne(query, keyHolder);
return keyHolder.getKey().longValue();
}
@Override
public void updateNotCurrent(Integer providerId) throws DaoException {
Query query = getDslContext()
.update(Tables.PROVIDER)
.set(Tables.PROVIDER.CURRENT, false)
.where(Tables.PROVIDER.PROVIDER_REF_ID.eq(providerId).and(Tables.PROVIDER.CURRENT));
executeOne(query);
}
}

View File

@ -0,0 +1,42 @@
package com.empayre.dominator.dao.dominant.impl;
import com.empayre.dominator.dao.dominant.iface.DomainObjectDao;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.impl.AbstractGenericDao;
import com.empayre.dominator.domain.Tables;
import com.empayre.dominator.domain.tables.pojos.Terminal;
import com.empayre.dominator.domain.tables.records.TerminalRecord;
import org.jooq.Query;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
@Component
public class TerminalDaoImpl extends AbstractGenericDao implements DomainObjectDao<Terminal, Integer> {
public TerminalDaoImpl(DataSource dataSource) {
super(dataSource);
}
@Override
public Long save(Terminal terminal) throws DaoException {
TerminalRecord terminalRecord = getDslContext().newRecord(Tables.TERMINAL, terminal);
Query query = getDslContext()
.insertInto(Tables.TERMINAL)
.set(terminalRecord)
.returning(Tables.TERMINAL.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
executeOne(query, keyHolder);
return keyHolder.getKey().longValue();
}
@Override
public void updateNotCurrent(Integer terminalId) throws DaoException {
Query query = getDslContext()
.update(Tables.TERMINAL)
.set(Tables.TERMINAL.CURRENT, false)
.where(Tables.TERMINAL.TERMINAL_REF_ID.eq(terminalId).and(Tables.TERMINAL.CURRENT));
executeOne(query);
}
}

View File

@ -0,0 +1,17 @@
package com.empayre.dominator.dao.identity.iface;
import com.empayre.dominator.domain.tables.pojos.Challenge;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
import java.util.Optional;
public interface ChallengeDao extends GenericDao {
Optional<Long> save(Challenge challenge) throws DaoException;
Challenge get(String identityId, String challengeId) throws DaoException;
void updateNotCurrent(String identityId, Long challengeId) throws DaoException;
}

View File

@ -0,0 +1,17 @@
package com.empayre.dominator.dao.identity.iface;
import com.empayre.dominator.domain.tables.pojos.Identity;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
import java.util.Optional;
public interface IdentityDao extends GenericDao {
Optional<Long> save(Identity identity) throws DaoException;
Identity get(String identityId) throws DaoException;
void updateNotCurrent(Long identityId) throws DaoException;
}

View File

@ -0,0 +1,71 @@
package com.empayre.dominator.dao.identity.impl;
import com.empayre.dominator.dao.identity.iface.ChallengeDao;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.impl.AbstractGenericDao;
import com.empayre.dominator.domain.tables.pojos.Challenge;
import com.empayre.dominator.domain.tables.records.ChallengeRecord;
import dev.vality.mapper.RecordRowMapper;
import org.jooq.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.util.Optional;
import static com.empayre.dominator.domain.tables.Challenge.CHALLENGE;
@Component
public class ChallengeDaoImpl extends AbstractGenericDao implements ChallengeDao {
private final RowMapper<Challenge> challengeRowMapper;
@Autowired
public ChallengeDaoImpl(DataSource dataSource) {
super(dataSource);
challengeRowMapper = new RecordRowMapper<>(CHALLENGE, Challenge.class);
}
@Override
public Optional<Long> save(Challenge challenge) throws DaoException {
ChallengeRecord record = getDslContext().newRecord(CHALLENGE, challenge);
Query query = getDslContext()
.insertInto(CHALLENGE)
.set(record)
.onConflict(CHALLENGE.IDENTITY_ID, CHALLENGE.CHALLENGE_ID, CHALLENGE.SEQUENCE_ID)
.doNothing()
.returning(CHALLENGE.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
execute(query, keyHolder);
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
}
@Override
public Challenge get(String identityId, String challengeId) throws DaoException {
Query query = getDslContext()
.selectFrom(CHALLENGE)
.where(
CHALLENGE.IDENTITY_ID.eq(identityId)
.and(CHALLENGE.CHALLENGE_ID.eq(challengeId))
.and(CHALLENGE.CURRENT)
);
return fetchOne(query, challengeRowMapper);
}
@Override
public void updateNotCurrent(String identityId, Long challengeId) throws DaoException {
Query query = getDslContext()
.update(CHALLENGE)
.set(CHALLENGE.CURRENT, false)
.where(
CHALLENGE.ID.eq(challengeId)
.and(CHALLENGE.IDENTITY_ID.eq(identityId))
.and(CHALLENGE.CURRENT)
);
execute(query);
}
}

View File

@ -0,0 +1,69 @@
package com.empayre.dominator.dao.identity.impl;
import com.empayre.dominator.dao.identity.iface.IdentityDao;
import com.empayre.dominator.domain.tables.pojos.Identity;
import com.empayre.dominator.domain.tables.records.IdentityRecord;
import com.empayre.dominator.exception.DaoException;
import com.empayre.dominator.exception.NotFoundException;
import dev.vality.dao.impl.AbstractGenericDao;
import dev.vality.mapper.RecordRowMapper;
import org.jooq.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import jakarta.validation.constraints.NotNull;
import java.util.Optional;
import static com.empayre.dominator.domain.tables.Identity.IDENTITY;
@Component
public class IdentityDaoImpl extends AbstractGenericDao implements IdentityDao {
private final RowMapper<Identity> identityRowMapper;
@Autowired
public IdentityDaoImpl(DataSource dataSource) {
super(dataSource);
identityRowMapper = new RecordRowMapper<>(IDENTITY, Identity.class);
}
@Override
public Optional<Long> save(Identity identity) throws DaoException {
IdentityRecord record = getDslContext().newRecord(IDENTITY, identity);
Query query = getDslContext()
.insertInto(IDENTITY)
.set(record)
.onConflict(IDENTITY.IDENTITY_ID, IDENTITY.SEQUENCE_ID)
.doNothing()
.returning(IDENTITY.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
execute(query, keyHolder);
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
}
@NotNull
@Override
public Identity get(String identityId) throws DaoException {
Query query = getDslContext()
.selectFrom(IDENTITY)
.where(IDENTITY.IDENTITY_ID.eq(identityId)
.and(IDENTITY.CURRENT));
return Optional.ofNullable(fetchOne(query, identityRowMapper))
.orElseThrow(
() -> new NotFoundException(String.format("Identity not found, identityId='%s'", identityId)));
}
@Override
public void updateNotCurrent(Long identityId) throws DaoException {
Query query = getDslContext()
.update(IDENTITY)
.set(IDENTITY.CURRENT, false)
.where(IDENTITY.ID.eq(identityId).and(IDENTITY.CURRENT));
execute(query);
}
}

View File

@ -0,0 +1,13 @@
package com.empayre.dominator.dao.party.iface;
import com.empayre.dominator.domain.tables.pojos.ContractAdjustment;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
import java.util.List;
public interface ContractAdjustmentDao extends GenericDao {
void save(List<ContractAdjustment> contractAdjustmentList) throws DaoException;
List<ContractAdjustment> getByContractId(Long contractId) throws DaoException;
}

View File

@ -0,0 +1,16 @@
package com.empayre.dominator.dao.party.iface;
import com.empayre.dominator.domain.tables.pojos.Contract;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
import java.util.Optional;
public interface ContractDao extends GenericDao {
Optional<Long> save(Contract contract) throws DaoException;
Contract get(String partyId, String contractId) throws DaoException;
void updateNotCurrent(Long contractId) throws DaoException;
}

View File

@ -0,0 +1,16 @@
package com.empayre.dominator.dao.party.iface;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
import com.empayre.dominator.domain.tables.pojos.Contractor;
import java.util.Optional;
public interface ContractorDao extends GenericDao {
Optional<Long> save(Contractor contractor) throws DaoException;
Contractor get(String partyId, String contractorId) throws DaoException;
void updateNotCurrent(Long id) throws DaoException;
}

View File

@ -0,0 +1,17 @@
package com.empayre.dominator.dao.party.iface;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
import com.empayre.dominator.domain.tables.pojos.Party;
import java.util.Optional;
public interface PartyDao extends GenericDao {
Optional<Long> save(Party party) throws DaoException;
Party get(String partyId) throws DaoException;
void updateNotCurrent(Long partyId) throws DaoException;
void saveWithUpdateCurrent(Party partySource, Long oldId, String eventName);
}

View File

@ -0,0 +1,13 @@
package com.empayre.dominator.dao.party.iface;
import com.empayre.dominator.domain.tables.pojos.PayoutTool;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
import java.util.List;
public interface PayoutToolDao extends GenericDao {
void save(List<PayoutTool> payoutToolList) throws DaoException;
List<PayoutTool> getByContractId(Long cntrctId) throws DaoException;
}

View File

@ -0,0 +1,13 @@
package com.empayre.dominator.dao.party.iface;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
public interface RevisionDao extends GenericDao {
void saveShopsRevision(String partyId, long revision) throws DaoException;
void saveContractsRevision(String partyId, long revision) throws DaoException;
void saveContractorsRevision(String partyId, long revision) throws DaoException;
}

View File

@ -0,0 +1,18 @@
package com.empayre.dominator.dao.party.iface;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
import com.empayre.dominator.domain.tables.pojos.Shop;
import java.util.Optional;
public interface ShopDao extends GenericDao {
Optional<Long> save(Shop shop) throws DaoException;
Shop get(String partyId, String shopId) throws DaoException;
void updateNotCurrent(Long id) throws DaoException;
void saveWithUpdateCurrent(Shop shopSource, Long oldEventId, String eventName);
}

View File

@ -0,0 +1,46 @@
package com.empayre.dominator.dao.party.impl;
import com.empayre.dominator.dao.party.iface.ContractAdjustmentDao;
import com.empayre.dominator.domain.tables.pojos.ContractAdjustment;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.impl.AbstractGenericDao;
import dev.vality.mapper.RecordRowMapper;
import org.jooq.Query;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.util.List;
import java.util.stream.Collectors;
import static com.empayre.dominator.domain.Tables.CONTRACT_ADJUSTMENT;
@Component
public class ContractAdjustmentDaoImpl extends AbstractGenericDao implements ContractAdjustmentDao {
private final RowMapper<ContractAdjustment> contractAdjustmentRowMapper;
public ContractAdjustmentDaoImpl(DataSource dataSource) {
super(dataSource);
this.contractAdjustmentRowMapper = new RecordRowMapper<>(CONTRACT_ADJUSTMENT, ContractAdjustment.class);
}
@Override
public void save(List<ContractAdjustment> contractAdjustmentList) throws DaoException {
List<Query> queries = contractAdjustmentList.stream()
.map(contractAdjustment -> getDslContext().newRecord(CONTRACT_ADJUSTMENT, contractAdjustment))
.map(contractAdjustmentRecord ->
getDslContext().insertInto(CONTRACT_ADJUSTMENT).set(contractAdjustmentRecord))
.collect(Collectors.toList());
batchExecute(queries);
}
@Override
public List<ContractAdjustment> getByContractId(Long contractId) throws DaoException {
Query query = getDslContext()
.selectFrom(CONTRACT_ADJUSTMENT)
.where(CONTRACT_ADJUSTMENT.CONTRACT_ID.eq(contractId))
.orderBy(CONTRACT_ADJUSTMENT.ID.asc());
return fetch(query, contractAdjustmentRowMapper);
}
}

View File

@ -0,0 +1,68 @@
package com.empayre.dominator.dao.party.impl;
import com.empayre.dominator.dao.party.iface.ContractDao;
import com.empayre.dominator.domain.tables.pojos.Contract;
import com.empayre.dominator.domain.tables.records.ContractRecord;
import com.empayre.dominator.exception.DaoException;
import com.empayre.dominator.exception.NotFoundException;
import dev.vality.dao.impl.AbstractGenericDao;
import dev.vality.mapper.RecordRowMapper;
import org.jooq.Query;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import jakarta.validation.constraints.NotNull;
import java.util.Optional;
import static com.empayre.dominator.domain.Tables.CONTRACT;
@Component
public class ContractDaoImpl extends AbstractGenericDao implements ContractDao {
private final RowMapper<Contract> contractRowMapper;
public ContractDaoImpl(DataSource dataSource) {
super(dataSource);
contractRowMapper = new RecordRowMapper<>(CONTRACT, Contract.class);
}
@Override
public Optional<Long> save(Contract contract) throws DaoException {
ContractRecord record = getDslContext().newRecord(CONTRACT, contract);
Query query = getDslContext()
.insertInto(CONTRACT)
.set(record)
.onConflict(CONTRACT.PARTY_ID, CONTRACT.CONTRACT_ID, CONTRACT.SEQUENCE_ID, CONTRACT.CHANGE_ID,
CONTRACT.CLAIM_EFFECT_ID)
.doNothing()
.returning(CONTRACT.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
execute(query, keyHolder);
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
}
@NotNull
@Override
public Contract get(String partyId, String contractId) throws DaoException {
Query query = getDslContext()
.selectFrom(CONTRACT)
.where(CONTRACT.PARTY_ID.eq(partyId)
.and(CONTRACT.CONTRACT_ID.eq(contractId))
.and(CONTRACT.CURRENT));
return Optional.ofNullable(fetchOne(query, contractRowMapper))
.orElseThrow(
() -> new NotFoundException(String.format("Contract not found, contractId='%s'", contractId)));
}
@Override
public void updateNotCurrent(Long id) throws DaoException {
Query query = getDslContext()
.update(CONTRACT)
.set(CONTRACT.CURRENT, false)
.where(CONTRACT.ID.eq(id));
executeOne(query);
}
}

View File

@ -0,0 +1,66 @@
package com.empayre.dominator.dao.party.impl;
import com.empayre.dominator.dao.party.iface.ContractorDao;
import com.empayre.dominator.domain.tables.pojos.Contractor;
import com.empayre.dominator.domain.tables.records.ContractorRecord;
import com.empayre.dominator.exception.DaoException;
import com.empayre.dominator.exception.NotFoundException;
import dev.vality.dao.impl.AbstractGenericDao;
import dev.vality.mapper.RecordRowMapper;
import org.jooq.Query;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import jakarta.validation.constraints.NotNull;
import java.util.Optional;
import static com.empayre.dominator.domain.Tables.CONTRACTOR;
@Component
public class ContractorDaoImpl extends AbstractGenericDao implements ContractorDao {
private final RowMapper<Contractor> contractorRowMapper;
public ContractorDaoImpl(DataSource dataSource) {
super(dataSource);
contractorRowMapper = new RecordRowMapper<>(CONTRACTOR, Contractor.class);
}
@Override
public Optional<Long> save(Contractor contractor) throws DaoException {
ContractorRecord record = getDslContext().newRecord(CONTRACTOR, contractor);
Query query = getDslContext()
.insertInto(CONTRACTOR)
.set(record)
.onConflict(CONTRACTOR.PARTY_ID, CONTRACTOR.CONTRACTOR_ID, CONTRACTOR.SEQUENCE_ID, CONTRACTOR.CHANGE_ID,
CONTRACTOR.CLAIM_EFFECT_ID)
.doNothing()
.returning(CONTRACTOR.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
execute(query, keyHolder);
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
}
@NotNull
@Override
public Contractor get(String partyId, String contractorId) throws DaoException {
Query query = getDslContext().selectFrom(CONTRACTOR)
.where(CONTRACTOR.PARTY_ID.eq(partyId)
.and(CONTRACTOR.CONTRACTOR_ID.eq(contractorId))
.and(CONTRACTOR.CURRENT));
return Optional.ofNullable(fetchOne(query, contractorRowMapper))
.orElseThrow(() -> new NotFoundException(
String.format("Contractor not found, contractorId='%s'", contractorId)));
}
@Override
public void updateNotCurrent(Long id) throws DaoException {
Query query = getDslContext()
.update(CONTRACTOR)
.set(CONTRACTOR.CURRENT, false)
.where(CONTRACTOR.ID.eq(id).and(CONTRACTOR.CURRENT));
executeOne(query);
}
}

View File

@ -0,0 +1,80 @@
package com.empayre.dominator.dao.party.impl;
import com.empayre.dominator.dao.party.iface.PartyDao;
import com.empayre.dominator.domain.tables.pojos.Party;
import com.empayre.dominator.domain.tables.records.PartyRecord;
import com.empayre.dominator.exception.DaoException;
import com.empayre.dominator.exception.NotFoundException;
import dev.vality.dao.impl.AbstractGenericDao;
import dev.vality.mapper.RecordRowMapper;
import lombok.extern.slf4j.Slf4j;
import org.jooq.Query;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import jakarta.validation.constraints.NotNull;
import java.util.Optional;
import static com.empayre.dominator.domain.Tables.PARTY;
@Slf4j
@Component
public class PartyDaoImpl extends AbstractGenericDao implements PartyDao {
private final RowMapper<Party> partyRowMapper;
public PartyDaoImpl(DataSource dataSource) {
super(dataSource);
partyRowMapper = new RecordRowMapper<>(PARTY, Party.class);
}
@Override
public Optional<Long> save(Party party) throws DaoException {
PartyRecord record = getDslContext().newRecord(PARTY, party);
Query query = getDslContext()
.insertInto(PARTY)
.set(record)
.onConflict(PARTY.PARTY_ID, PARTY.SEQUENCE_ID, PARTY.CHANGE_ID)
.doNothing()
.returning(PARTY.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
execute(query, keyHolder);
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
}
@NotNull
@Override
public Party get(String partyId) throws DaoException {
Query query = getDslContext()
.selectFrom(PARTY)
.where(PARTY.PARTY_ID.eq(partyId).and(PARTY.CURRENT));
return Optional.ofNullable(fetchOne(query, partyRowMapper))
.orElseThrow(() -> new NotFoundException(String.format("Party not found, partyId='%s'", partyId)));
}
@Override
public void updateNotCurrent(Long id) throws DaoException {
Query query = getDslContext()
.update(PARTY)
.set(PARTY.CURRENT, false)
.where(PARTY.ID.eq(id));
executeOne(query);
}
@Override
public void saveWithUpdateCurrent(Party partySource, Long oldId, String eventName) {
save(partySource)
.ifPresentOrElse(
saveResult -> {
updateNotCurrent(oldId);
log.info("Party {} has been saved, sequenceId={}, partyId={}, changeId={}", eventName,
partySource.getSequenceId(), partySource.getPartyId(), partySource.getChangeId());
},
() -> log.info("Party {} duplicated, sequenceId={}, partyId={}, changeId={}", eventName,
partySource.getSequenceId(), partySource.getPartyId(), partySource.getChangeId())
);
}
}

View File

@ -0,0 +1,44 @@
package com.empayre.dominator.dao.party.impl;
import com.empayre.dominator.dao.party.iface.PayoutToolDao;
import com.empayre.dominator.domain.tables.pojos.PayoutTool;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.impl.AbstractGenericDao;
import dev.vality.mapper.RecordRowMapper;
import org.jooq.Query;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.util.List;
import java.util.stream.Collectors;
import static com.empayre.dominator.domain.Tables.PAYOUT_TOOL;
@Component
public class PayoutToolDaoImpl extends AbstractGenericDao implements PayoutToolDao {
private final RowMapper<PayoutTool> payoutToolRowMapper;
public PayoutToolDaoImpl(DataSource dataSource) {
super(dataSource);
this.payoutToolRowMapper = new RecordRowMapper<>(PAYOUT_TOOL, PayoutTool.class);
}
@Override
public void save(List<PayoutTool> payoutToolList) throws DaoException {
List<Query> queries = payoutToolList.stream()
.map(payoutTool -> getDslContext().newRecord(PAYOUT_TOOL, payoutTool))
.map(payoutToolRecord -> getDslContext().insertInto(PAYOUT_TOOL).set(payoutToolRecord))
.collect(Collectors.toList());
batchExecute(queries);
}
@Override
public List<PayoutTool> getByContractId(Long contractId) throws DaoException {
Query query = getDslContext()
.selectFrom(PAYOUT_TOOL)
.where(PAYOUT_TOOL.CONTRACT_ID.eq(contractId));
return fetch(query, payoutToolRowMapper);
}
}

View File

@ -0,0 +1,42 @@
package com.empayre.dominator.dao.party.impl;
import com.empayre.dominator.constant.RevisionQuery;
import com.empayre.dominator.dao.party.iface.RevisionDao;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.impl.AbstractGenericDao;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
@Component
public class RevisionDaoImpl extends AbstractGenericDao implements RevisionDao {
public RevisionDaoImpl(DataSource dataSource) {
super(dataSource);
}
@Override
public void saveShopsRevision(String partyId, long revision) throws DaoException {
getNamedParameterJdbcTemplate().update(RevisionQuery.SAVE_SHOPS_QUERY,
new MapSqlParameterSource()
.addValue("party_id", partyId)
.addValue("revision", revision));
}
@Override
public void saveContractsRevision(String partyId, long revision) throws DaoException {
getNamedParameterJdbcTemplate().update(RevisionQuery.SAVE_CONTRACTS_QUERY,
new MapSqlParameterSource()
.addValue("party_id", partyId)
.addValue("revision", revision));
}
@Override
public void saveContractorsRevision(String partyId, long revision) throws DaoException {
getNamedParameterJdbcTemplate().update(RevisionQuery.SAVE_CONTRACTORS_QUERY,
new MapSqlParameterSource()
.addValue("party_id", partyId)
.addValue("revision", revision));
}
}

View File

@ -0,0 +1,82 @@
package com.empayre.dominator.dao.party.impl;
import com.empayre.dominator.dao.party.iface.ShopDao;
import com.empayre.dominator.domain.tables.pojos.Shop;
import com.empayre.dominator.domain.tables.records.ShopRecord;
import com.empayre.dominator.exception.DaoException;
import com.empayre.dominator.exception.NotFoundException;
import dev.vality.dao.impl.AbstractGenericDao;
import dev.vality.mapper.RecordRowMapper;
import lombok.extern.slf4j.Slf4j;
import org.jooq.Query;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import jakarta.validation.constraints.NotNull;
import java.util.Optional;
import static com.empayre.dominator.domain.Tables.SHOP;
@Slf4j
@Component
public class ShopDaoImpl extends AbstractGenericDao implements ShopDao {
private final RowMapper<Shop> shopRowMapper;
public ShopDaoImpl(DataSource dataSource) {
super(dataSource);
shopRowMapper = new RecordRowMapper<>(SHOP, Shop.class);
}
@Override
public Optional<Long> save(Shop shop) throws DaoException {
ShopRecord record = getDslContext().newRecord(SHOP, shop);
Query query = getDslContext()
.insertInto(SHOP)
.set(record)
.onConflict(SHOP.PARTY_ID, SHOP.SHOP_ID, SHOP.SEQUENCE_ID, SHOP.CHANGE_ID, SHOP.CLAIM_EFFECT_ID)
.doNothing()
.returning(SHOP.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
execute(query, keyHolder);
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
}
@NotNull
@Override
public Shop get(String partyId, String shopId) throws DaoException {
Query query = getDslContext()
.selectFrom(SHOP)
.where(SHOP.PARTY_ID.eq(partyId)
.and(SHOP.SHOP_ID.eq(shopId))
.and(SHOP.CURRENT));
return Optional.ofNullable(fetchOne(query, shopRowMapper))
.orElseThrow(() -> new NotFoundException(String.format("Shop not found, shopId='%s'", shopId)));
}
@Override
public void updateNotCurrent(Long id) throws DaoException {
Query query = getDslContext()
.update(SHOP)
.set(SHOP.CURRENT, false)
.where(SHOP.ID.eq(id));
executeOne(query);
}
@Override
public void saveWithUpdateCurrent(Shop shopSource, Long oldEventId, String eventName) {
save(shopSource).ifPresentOrElse(
atLong -> {
updateNotCurrent(oldEventId);
log.info("Shop {} has been saved, sequenceId={}, partyId={}, shopId={}, changeId={}",
eventName, shopSource.getSequenceId(), shopSource.getPartyId(), shopSource.getShopId(),
shopSource.getChangeId());
},
() -> log.info("Shop {} duplicated, sequenceId={}, partyId={}, shopId={}, changeId={}",
eventName, shopSource.getSequenceId(), shopSource.getPartyId(), shopSource.getShopId(),
shopSource.getChangeId())
);
}
}

View File

@ -0,0 +1,44 @@
package com.empayre.dominator.dao.party.impl;
import com.empayre.dominator.dao.dominant.iface.DomainObjectDao;
import com.empayre.dominator.domain.Tables;
import com.empayre.dominator.domain.tables.pojos.TermSetHierarchy;
import com.empayre.dominator.domain.tables.records.TermSetHierarchyRecord;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.impl.AbstractGenericDao;
import org.jooq.Query;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
@Component
public class TermSetHierarchyDaoImpl extends AbstractGenericDao implements DomainObjectDao<TermSetHierarchy, Integer> {
public TermSetHierarchyDaoImpl(DataSource dataSource) {
super(dataSource);
}
@Override
public Long save(TermSetHierarchy termSetHierarchy) throws DaoException {
TermSetHierarchyRecord termSetHierarchyRecord =
getDslContext().newRecord(Tables.TERM_SET_HIERARCHY, termSetHierarchy);
Query query = getDslContext()
.insertInto(Tables.TERM_SET_HIERARCHY)
.set(termSetHierarchyRecord)
.returning(Tables.TERM_SET_HIERARCHY.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
executeOne(query, keyHolder);
return keyHolder.getKey().longValue();
}
@Override
public void updateNotCurrent(Integer termSetHierarchyId) throws DaoException {
Query query = getDslContext()
.update(Tables.TERM_SET_HIERARCHY)
.set(Tables.TERM_SET_HIERARCHY.CURRENT, false)
.where(Tables.TERM_SET_HIERARCHY.TERM_SET_HIERARCHY_REF_ID.eq(termSetHierarchyId)
.and(Tables.TERM_SET_HIERARCHY.CURRENT));
executeOne(query);
}
}

View File

@ -0,0 +1,17 @@
package com.empayre.dominator.dao.wallet.iface;
import com.empayre.dominator.domain.tables.pojos.Wallet;
import com.empayre.dominator.exception.DaoException;
import dev.vality.dao.GenericDao;
import java.util.Optional;
public interface WalletDao extends GenericDao {
Optional<Long> save(Wallet wallet) throws DaoException;
Wallet get(String walletId) throws DaoException;
void updateNotCurrent(Long id) throws DaoException;
}

View File

@ -0,0 +1,67 @@
package com.empayre.dominator.dao.wallet.impl;
import com.empayre.dominator.dao.wallet.iface.WalletDao;
import com.empayre.dominator.domain.tables.pojos.Wallet;
import com.empayre.dominator.domain.tables.records.WalletRecord;
import com.empayre.dominator.exception.DaoException;
import com.empayre.dominator.exception.NotFoundException;
import dev.vality.dao.impl.AbstractGenericDao;
import dev.vality.mapper.RecordRowMapper;
import org.jooq.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import jakarta.validation.constraints.NotNull;
import java.util.Optional;
import static com.empayre.dominator.domain.tables.Wallet.WALLET;
@Component
public class WalletDaoImpl extends AbstractGenericDao implements WalletDao {
private final RowMapper<Wallet> walletRowMapper;
@Autowired
public WalletDaoImpl(DataSource dataSource) {
super(dataSource);
walletRowMapper = new RecordRowMapper<>(WALLET, Wallet.class);
}
@Override
public Optional<Long> save(Wallet wallet) throws DaoException {
WalletRecord record = getDslContext().newRecord(WALLET, wallet);
Query query = getDslContext()
.insertInto(WALLET)
.set(record)
.onConflict(WALLET.WALLET_ID, WALLET.SEQUENCE_ID)
.doNothing()
.returning(WALLET.ID);
GeneratedKeyHolder keyHolder = new GeneratedKeyHolder();
execute(query, keyHolder);
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
}
@NotNull
@Override
public Wallet get(String walletId) throws DaoException {
Query query = getDslContext()
.selectFrom(WALLET)
.where(WALLET.WALLET_ID.eq(walletId).and(WALLET.CURRENT));
return Optional.ofNullable(fetchOne(query, walletRowMapper))
.orElseThrow(
() -> new NotFoundException(String.format("Wallet not found, walletId='%s'", walletId)));
}
@Override
public void updateNotCurrent(Long walletId) throws DaoException {
Query query = getDslContext()
.update(WALLET)
.set(WALLET.CURRENT, false)
.where(WALLET.ID.eq(walletId).and(WALLET.CURRENT));
execute(query);
}
}

View File

@ -0,0 +1,23 @@
package com.empayre.dominator.exception;
public class DaoException extends RuntimeException {
public DaoException() {
super();
}
public DaoException(String message) {
super(message);
}
public DaoException(String message, Throwable cause) {
super(message, cause);
}
public DaoException(Throwable cause) {
super(cause);
}
protected DaoException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -0,0 +1,11 @@
package com.empayre.dominator.exception;
public class NotFoundException extends RuntimeException {
public NotFoundException() {
}
public NotFoundException(String message) {
super(message);
}
}

View File

@ -0,0 +1,23 @@
package com.empayre.dominator.exception;
public class ParseException extends RuntimeException {
public ParseException() {
}
public ParseException(String message) {
super(message);
}
public ParseException(String message, Throwable cause) {
super(message, cause);
}
public ParseException(Throwable cause) {
super(cause);
}
public ParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -0,0 +1,13 @@
package com.empayre.dominator.factory.claim.effect;
import dev.vality.machinegun.eventsink.MachineEvent;
public interface ClaimEffectCopyFactory<T, K> {
T create(MachineEvent event, long sequenceId, Integer claimEffectId, K id, T copiedObject);
default T create(MachineEvent event, long sequenceId, Integer claimEffectId, K id) {
return create(event, sequenceId, claimEffectId, id, null);
}
}

View File

@ -0,0 +1,29 @@
package com.empayre.dominator.factory.claim.effect;
import com.empayre.dominator.domain.tables.pojos.Contract;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import org.springframework.stereotype.Component;
@Component
public class ContractClaimEffectCopyFactoryImpl implements ClaimEffectCopyFactory<Contract, Integer> {
@Override
public Contract create(MachineEvent event, long sequenceId, Integer claimEffectId, Integer id,
Contract withdrawalSessionOld) {
Contract contract;
if (withdrawalSessionOld != null) {
contract = new Contract(withdrawalSessionOld);
} else {
contract = new Contract();
}
contract.setId(null);
contract.setWtime(null);
contract.setSequenceId((int) sequenceId);
contract.setChangeId(id);
contract.setClaimEffectId(claimEffectId);
contract.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
return contract;
}
}

View File

@ -0,0 +1,29 @@
package com.empayre.dominator.factory.claim.effect;
import com.empayre.dominator.domain.tables.pojos.Contractor;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import org.springframework.stereotype.Component;
@Component
public class ContractorClaimEffectCopyFactoryImpl implements ClaimEffectCopyFactory<Contractor, Integer> {
@Override
public Contractor create(MachineEvent event, long sequenceId, Integer claimEffectId, Integer id,
Contractor contractorOld) {
Contractor contractor;
if (contractorOld != null) {
contractor = new Contractor(contractorOld);
} else {
contractor = new Contractor();
}
contractor.setId(null);
contractor.setWtime(null);
contractor.setSequenceId((int) sequenceId);
contractor.setChangeId(id);
contractor.setClaimEffectId(claimEffectId);
contractor.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
return contractor;
}
}

View File

@ -0,0 +1,23 @@
package com.empayre.dominator.factory.claim.effect;
import com.empayre.dominator.domain.tables.pojos.Shop;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import org.springframework.stereotype.Component;
@Component
public class ShopClaimEffectCopyFactoryImpl implements ClaimEffectCopyFactory<Shop, Integer> {
@Override
public Shop create(MachineEvent event, long sequenceId, Integer claimEffectId, Integer id,
Shop old) {
Shop shop = old == null ? new Shop() : new Shop(old);
shop.setId(null);
shop.setWtime(null);
shop.setSequenceId((int) sequenceId);
shop.setChangeId(id);
shop.setClaimEffectId(claimEffectId);
shop.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
return shop;
}
}

View File

@ -0,0 +1,80 @@
package com.empayre.dominator.factory.contractor;
import com.empayre.dominator.domain.enums.ContractorType;
import com.empayre.dominator.domain.enums.LegalEntity;
import com.empayre.dominator.domain.enums.PrivateEntity;
import com.empayre.dominator.domain.tables.pojos.Contractor;
import dev.vality.damsel.domain.InternationalLegalEntity;
import dev.vality.damsel.domain.RussianLegalEntity;
import dev.vality.damsel.domain.RussianPrivateEntity;
import dev.vality.geck.common.util.TBaseUtil;
import dev.vality.geck.common.util.TypeUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ContractorFactory {
public static Contractor build(long sequenceId, String eventCreatedAt, String partyId,
dev.vality.damsel.domain.Contractor contractorSource,
String contractorId, Integer changeId, Integer claimEffectId) {
Contractor contractor = new Contractor();
contractor.setSequenceId((int) sequenceId);
contractor.setChangeId(changeId);
contractor.setClaimEffectId(claimEffectId);
contractor.setEventCreatedAt(TypeUtil.stringToLocalDateTime(eventCreatedAt));
contractor.setPartyId(partyId);
contractor.setContractorId(contractorId);
contractor.setType(TBaseUtil.unionFieldToEnum(contractorSource, ContractorType.class));
if (contractorSource.isSetRegisteredUser()) {
contractor.setRegisteredUserEmail(contractorSource.getRegisteredUser().getEmail());
} else if (contractorSource.isSetLegalEntity()) {
contractor.setLegalEntity(TBaseUtil.unionFieldToEnum(contractorSource.getLegalEntity(), LegalEntity.class));
if (contractorSource.getLegalEntity().isSetRussianLegalEntity()) {
RussianLegalEntity russianLegalEntity = contractorSource.getLegalEntity().getRussianLegalEntity();
contractor.setRussianLegalEntityRegisteredName(russianLegalEntity.getRegisteredName());
contractor.setRussianLegalEntityRegisteredNumber(russianLegalEntity.getRegisteredNumber());
contractor.setRussianLegalEntityInn(russianLegalEntity.getInn());
contractor.setRussianLegalEntityActualAddress(russianLegalEntity.getActualAddress());
contractor.setRussianLegalEntityPostAddress(russianLegalEntity.getPostAddress());
contractor.setRussianLegalEntityRepresentativePosition(russianLegalEntity.getRepresentativePosition());
contractor.setRussianLegalEntityRepresentativeFullName(russianLegalEntity.getRepresentativeFullName());
contractor.setRussianLegalEntityRepresentativeDocument(russianLegalEntity.getRepresentativeDocument());
contractor.setRussianLegalEntityRussianBankAccount(
russianLegalEntity.getRussianBankAccount().getAccount());
contractor
.setRussianLegalEntityRussianBankName(russianLegalEntity.getRussianBankAccount().getBankName());
contractor.setRussianLegalEntityRussianBankPostAccount(
russianLegalEntity.getRussianBankAccount().getBankPostAccount());
contractor.setRussianLegalEntityRussianBankBik(russianLegalEntity.getRussianBankAccount().getBankBik());
} else if (contractorSource.getLegalEntity().isSetInternationalLegalEntity()) {
InternationalLegalEntity internationalLegalEntity =
contractorSource.getLegalEntity().getInternationalLegalEntity();
contractor.setInternationalLegalEntityLegalName(internationalLegalEntity.getLegalName());
contractor.setInternationalLegalEntityTradingName(internationalLegalEntity.getTradingName());
contractor
.setInternationalLegalEntityRegisteredAddress(internationalLegalEntity.getRegisteredAddress());
contractor.setInternationalLegalEntityActualAddress(internationalLegalEntity.getActualAddress());
contractor.setInternationalLegalEntityRegisteredNumber(internationalLegalEntity.getRegisteredNumber());
if (internationalLegalEntity.isSetCountry()) {
contractor.setInternationalLegalEntityCountryCode(
internationalLegalEntity.getCountry().getId().name());
}
}
} else if (contractorSource.isSetPrivateEntity()) {
contractor.setPrivateEntity(
TBaseUtil.unionFieldToEnum(contractorSource.getPrivateEntity(), PrivateEntity.class));
if (contractorSource.getPrivateEntity().isSetRussianPrivateEntity()) {
RussianPrivateEntity russianPrivateEntity =
contractorSource.getPrivateEntity().getRussianPrivateEntity();
contractor.setRussianPrivateEntityFirstName(russianPrivateEntity.getFirstName());
contractor.setRussianPrivateEntitySecondName(russianPrivateEntity.getSecondName());
contractor.setRussianPrivateEntityMiddleName(russianPrivateEntity.getMiddleName());
contractor.setRussianPrivateEntityPhoneNumber(russianPrivateEntity.getContactInfo().getPhoneNumber());
contractor.setRussianPrivateEntityEmail(russianPrivateEntity.getContactInfo().getEmail());
}
}
return contractor;
}
}

View File

@ -0,0 +1,27 @@
package com.empayre.dominator.factory.machine.event;
import com.empayre.dominator.domain.tables.pojos.Challenge;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import org.springframework.stereotype.Component;
@Component
public class ChallengeMachineEventCopyFactoryImpl implements MachineEventCopyFactory<Challenge, String> {
@Override
public Challenge create(MachineEvent event, Long sequenceId, String identityId, Challenge old, String occurredAt) {
Challenge challenge = old == null ? new Challenge() : new Challenge(old);
challenge.setId(null);
challenge.setWtime(null);
challenge.setSequenceId(sequenceId.intValue());
challenge.setIdentityId(identityId);
challenge.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
challenge.setEventOccuredAt(TypeUtil.stringToLocalDateTime(occurredAt));
return challenge;
}
@Override
public Challenge create(MachineEvent event, Long sequenceId, String id, String occurredAt) {
return create(event, sequenceId, id, null, occurredAt);
}
}

View File

@ -0,0 +1,27 @@
package com.empayre.dominator.factory.machine.event;
import com.empayre.dominator.domain.tables.pojos.Identity;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import org.springframework.stereotype.Component;
@Component
public class IdentityMachineEventCopyFactoryImpl implements MachineEventCopyFactory<Identity, String> {
@Override
public Identity create(MachineEvent event, Long sequenceId, String id, Identity old, String occurredAt) {
Identity identity = old == null ? new Identity() : new Identity(old);
identity.setId(null);
identity.setWtime(null);
identity.setIdentityId(id);
identity.setSequenceId(sequenceId.intValue());
identity.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
identity.setEventOccuredAt(TypeUtil.stringToLocalDateTime(occurredAt));
return identity;
}
@Override
public Identity create(MachineEvent event, Long sequenceId, String id, String occurredAt) {
return create(event, sequenceId, id, null, occurredAt);
}
}

View File

@ -0,0 +1,11 @@
package com.empayre.dominator.factory.machine.event;
import dev.vality.machinegun.eventsink.MachineEvent;
public interface MachineEventCopyFactory<T, K> {
T create(MachineEvent event, Long sequenceId, K id, T copiedObject, String occurredAt);
T create(MachineEvent event, Long sequenceId, K id, String occurredAt);
}

View File

@ -0,0 +1,26 @@
package com.empayre.dominator.factory.machine.event;
import com.empayre.dominator.domain.tables.pojos.Party;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import org.springframework.stereotype.Component;
@Component
public class PartyMachineEventCopyFactoryImpl implements MachineEventCopyFactory<Party, Integer> {
@Override
public Party create(MachineEvent event, Long sequenceId, Integer id, Party old, String occurredAt) {
Party party = old == null ? new Party() : new Party(old);
party.setId(null);
party.setWtime(null);
party.setSequenceId(sequenceId.intValue());
party.setChangeId(id);
party.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
return party;
}
@Override
public Party create(MachineEvent event, Long sequenceId, Integer id, String occurredAt) {
return create(event, sequenceId, id, null, occurredAt);
}
}

View File

@ -0,0 +1,27 @@
package com.empayre.dominator.factory.machine.event;
import com.empayre.dominator.domain.tables.pojos.Wallet;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import org.springframework.stereotype.Component;
@Component
public class WalletMachineEventCopyFactoryImpl implements MachineEventCopyFactory<Wallet, String> {
@Override
public Wallet create(MachineEvent event, Long sequenceId, String id, Wallet walletOld, String occurredAt) {
Wallet wallet = walletOld == null ? new Wallet() : new Wallet(walletOld);
wallet.setId(null);
wallet.setWtime(null);
wallet.setSequenceId(sequenceId.intValue());
wallet.setWalletId(id);
wallet.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
wallet.setEventOccuredAt(TypeUtil.stringToLocalDateTime(occurredAt));
return wallet;
}
@Override
public Wallet create(MachineEvent event, Long sequenceId, String id, String occurredAt) {
return create(event, sequenceId, id, null, occurredAt);
}
}

View File

@ -0,0 +1,102 @@
package com.empayre.dominator.handler.dominant;
import com.empayre.dominator.dao.dominant.iface.DomainObjectDao;
import dev.vality.damsel.domain.DomainObject;
import dev.vality.damsel.domain_config.Operation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
* @param <T> - damsel object class (CategoryObject, CurrencyObject etc.)
* @param <C> - jooq object class (Category, Currency etc.)
* @param <I> - object reference id class (Integer, String etc.)
*/
public abstract class AbstractDominantHandler<T, C, I> implements DominantHandler<Operation> {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private static final String UNKNOWN_TYPE_EX = "Unknown type of operation. Only insert/update/remove supports. " +
"Operation: ";
private DomainObject domainObject;
public DomainObject getDomainObject() {
return domainObject;
}
public void setDomainObject(DomainObject domainObject) {
this.domainObject = domainObject;
}
protected abstract DomainObjectDao<C, I> getDomainObjectDao();
protected abstract T getTargetObject();
protected abstract I getTargetObjectRefId();
protected abstract boolean acceptDomainObject();
public abstract C convertToDatabaseObject(T object, Long versionId, boolean current);
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(Operation operation, Long versionId) {
T object = getTargetObject();
if (operation.isSetInsert()) {
insertDomainObject(object, versionId);
} else if (operation.isSetUpdate()) {
updateDomainObject(object, versionId);
} else if (operation.isSetRemove()) {
removeDomainObject(object, versionId);
} else {
throw new IllegalStateException(
UNKNOWN_TYPE_EX + operation);
}
}
@Override
public boolean acceptAndSet(Operation operation) {
if (operation.isSetInsert()) {
setDomainObject(operation.getInsert().getObject());
} else if (operation.isSetUpdate()) {
setDomainObject(operation.getUpdate().getNewObject());
} else if (operation.isSetRemove()) {
setDomainObject(operation.getRemove().getObject());
} else {
throw new IllegalStateException(
UNKNOWN_TYPE_EX + operation);
}
return acceptDomainObject();
}
@Transactional(propagation = Propagation.REQUIRED)
public void insertDomainObject(T object, Long versionId) {
log.info("Start to insert '{}' with id={}, versionId={}", object.getClass().getSimpleName(),
getTargetObjectRefId(), versionId);
getDomainObjectDao().save(convertToDatabaseObject(object, versionId, true));
log.info("End to insert '{}' with id={}, versionId={}", object.getClass().getSimpleName(),
getTargetObjectRefId(), versionId);
}
@Transactional(propagation = Propagation.REQUIRED)
public void updateDomainObject(T object, Long versionId) {
log.info("Start to update '{}' with id={}, versionId={}", object.getClass().getSimpleName(),
getTargetObjectRefId(), versionId);
getDomainObjectDao().updateNotCurrent(getTargetObjectRefId());
getDomainObjectDao().save(convertToDatabaseObject(object, versionId, true));
log.info("End to update '{}' with id={}, versionId={}", object.getClass().getSimpleName(),
getTargetObjectRefId(), versionId);
}
@Transactional(propagation = Propagation.REQUIRED)
public void removeDomainObject(T object, Long versionId) {
log.info("Start to remove '{}' with id={}, versionId={}", object.getClass().getSimpleName(),
getTargetObjectRefId(), versionId);
getDomainObjectDao().updateNotCurrent(getTargetObjectRefId());
getDomainObjectDao().save(convertToDatabaseObject(object, versionId, false));
log.info("End to remove '{}' with id={}, versionId={}", object.getClass().getSimpleName(),
getTargetObjectRefId(), versionId);
}
}

View File

@ -0,0 +1,8 @@
package com.empayre.dominator.handler.dominant;
public interface DominantHandler<T> {
boolean acceptAndSet(T change);
void handle(T change, Long versionId);
}

View File

@ -0,0 +1,52 @@
package com.empayre.dominator.handler.dominant;
import com.empayre.dominator.service.DominantService;
import dev.vality.damsel.domain_config.Commit;
import dev.vality.damsel.domain_config.RepositorySrv;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.context.annotation.DependsOn;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
@Slf4j
@DependsOn("flywayInitializer")
@RequiredArgsConstructor
public class DominantPoller {
private final RepositorySrv.Iface dominantClient;
private final DominantService dominantService;
private final int maxQuerySize;
private final boolean pollingEnabled;
@Scheduled(fixedDelayString = "${dmt.polling.delay}")
@SchedulerLock(name = "TaskScheduler_dominant_polling_process")
public void process() {
if (pollingEnabled) {
final AtomicLong lastVersionId = new AtomicLong(dominantService.getLastVersionId().orElse(0L));
try {
Map<Long, Commit> pullRange = dominantClient.pullRange(lastVersionId.get(), maxQuerySize);
pullRange.entrySet().stream()
.sorted(Map.Entry.comparingByKey())
.forEach(entry -> handleDominantData(lastVersionId, entry));
} catch (Exception ex) {
log.warn("Dominant polling error (lastVersionId={})", lastVersionId, ex);
}
}
}
private void handleDominantData(AtomicLong lastVersionId, Map.Entry<Long, Commit> entry) {
AtomicLong versionId = new AtomicLong(entry.getKey());
try {
dominantService.processCommit(versionId.get(), entry);
dominantService.updateLastVersionId(versionId.get());
lastVersionId.set(versionId.get());
} catch (RuntimeException ex) {
throw new RuntimeException(
String.format("Unexpected error when polling dominant, versionId=%d", versionId.get()), ex);
}
}
}

View File

@ -0,0 +1,93 @@
package com.empayre.dominator.handler.dominant.impl;
import com.empayre.dominator.dao.dominant.iface.DomainObjectDao;
import com.empayre.dominator.dao.dominant.impl.ProviderDaoImpl;
import com.empayre.dominator.domain.tables.pojos.Provider;
import com.empayre.dominator.handler.dominant.AbstractDominantHandler;
import com.empayre.dominator.util.JsonUtil;
import dev.vality.damsel.domain.ProviderObject;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class ProviderHandler extends AbstractDominantHandler<ProviderObject, Provider, Integer> {
private final ProviderDaoImpl providerDao;
public ProviderHandler(ProviderDaoImpl providerDao) {
this.providerDao = providerDao;
}
@Override
protected DomainObjectDao<Provider, Integer> getDomainObjectDao() {
return providerDao;
}
@Override
protected ProviderObject getTargetObject() {
return getDomainObject().getProvider();
}
@Override
protected Integer getTargetObjectRefId() {
return getTargetObject().getRef().getId();
}
@Override
protected boolean acceptDomainObject() {
return getDomainObject().isSetProvider();
}
@Override
public Provider convertToDatabaseObject(ProviderObject providerObject, Long versionId, boolean current) {
Provider provider = new Provider();
provider.setVersionId(versionId);
provider.setProviderRefId(getTargetObjectRefId());
dev.vality.damsel.domain.Provider data = providerObject.getData();
provider.setName(data.getName());
provider.setDescription(data.getDescription());
provider.setProxyRefId(data.getProxy().getRef().getId());
if (data.isSetAbsAccount()) {
provider.setAbsAccount(data.getAbsAccount());
}
if (data.isSetTerms() && data.getTerms().isSetPayments()) {
provider.setPaymentTermsJson(JsonUtil.thriftBaseToJsonString(data.getTerms().getPayments()));
} else if (data.isSetPaymentTerms()) {
provider.setPaymentTermsJson(JsonUtil.thriftBaseToJsonString(data.getPaymentTerms()));
}
if (data.isSetTerms() && data.getTerms().isSetRecurrentPaytools()) {
provider.setRecurrentPaytoolTermsJson(
JsonUtil.thriftBaseToJsonString(data.getTerms().getRecurrentPaytools()));
} else if (data.isSetRecurrentPaytoolTerms()) {
provider.setRecurrentPaytoolTermsJson(JsonUtil.thriftBaseToJsonString(data.getRecurrentPaytoolTerms()));
}
if (data.isSetIdentity()) {
provider.setIdentity(data.getIdentity());
}
if (data.isSetTerms() && data.getTerms().isSetWallet()) {
provider.setWalletTermsJson(JsonUtil.thriftBaseToJsonString(data.getTerms().getWallet()));
}
if (data.isSetParamsSchema()) {
provider.setParamsSchemaJson(
JsonUtil.objectToJsonString(
data.getParamsSchema().stream().map(
JsonUtil::thriftBaseToJsonNode).collect(Collectors.toList())
)
);
}
if (data.isSetAccounts()) {
Map<String, Long> accountsMap = data.getAccounts().entrySet()
.stream()
.collect(Collectors.toMap(e -> e.getKey().getSymbolicCode(), e -> e.getValue().getSettlement()));
provider.setAccountsJson(JsonUtil.objectToJsonString(accountsMap));
}
provider.setCurrent(current);
return provider;
}
}

View File

@ -0,0 +1,63 @@
package com.empayre.dominator.handler.dominant.impl;
import com.empayre.dominator.dao.dominant.iface.DomainObjectDao;
import com.empayre.dominator.dao.party.impl.TermSetHierarchyDaoImpl;
import com.empayre.dominator.domain.tables.pojos.TermSetHierarchy;
import com.empayre.dominator.handler.dominant.AbstractDominantHandler;
import com.empayre.dominator.util.JsonUtil;
import com.fasterxml.jackson.databind.JsonNode;
import dev.vality.damsel.domain.TermSetHierarchyObject;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
public class TermSetHierarchyHandler
extends AbstractDominantHandler<TermSetHierarchyObject, TermSetHierarchy, Integer> {
private final TermSetHierarchyDaoImpl termSetHierarchyDao;
@Override
protected DomainObjectDao<TermSetHierarchy, Integer> getDomainObjectDao() {
return termSetHierarchyDao;
}
@Override
protected TermSetHierarchyObject getTargetObject() {
return getDomainObject().getTermSetHierarchy();
}
@Override
protected Integer getTargetObjectRefId() {
return getTargetObject().getRef().getId();
}
@Override
protected boolean acceptDomainObject() {
return getDomainObject().isSetTermSetHierarchy();
}
@Override
public TermSetHierarchy convertToDatabaseObject(TermSetHierarchyObject termSetHierarchyObject,
Long versionId,
boolean current) {
TermSetHierarchy termSetHierarchy = new TermSetHierarchy();
termSetHierarchy.setVersionId(versionId);
termSetHierarchy.setTermSetHierarchyRefId(getTargetObjectRefId());
dev.vality.damsel.domain.TermSetHierarchy data = termSetHierarchyObject.getData();
termSetHierarchy.setName(data.getName());
termSetHierarchy.setDescription(data.getDescription());
if (data.isSetParentTerms()) {
termSetHierarchy.setParentTermsRefId(data.getParentTerms().getId());
}
List<JsonNode> jsonNodes = data.getTermSets().stream()
.map(JsonUtil::thriftBaseToJsonNode)
.collect(Collectors.toList());
termSetHierarchy.setTermSetsJson(JsonUtil.objectToJsonString(jsonNodes));
termSetHierarchy.setCurrent(current);
return termSetHierarchy;
}
}

View File

@ -0,0 +1,61 @@
package com.empayre.dominator.handler.dominant.impl;
import com.empayre.dominator.handler.dominant.AbstractDominantHandler;
import dev.vality.damsel.domain.TerminalObject;
import com.empayre.dominator.dao.dominant.iface.DomainObjectDao;
import com.empayre.dominator.dao.dominant.impl.TerminalDaoImpl;
import com.empayre.dominator.domain.tables.pojos.Terminal;
import com.empayre.dominator.util.JsonUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class TerminalHandler extends AbstractDominantHandler<TerminalObject, Terminal, Integer> {
private final TerminalDaoImpl terminalDao;
@Override
protected DomainObjectDao<Terminal, Integer> getDomainObjectDao() {
return terminalDao;
}
@Override
protected TerminalObject getTargetObject() {
return getDomainObject().getTerminal();
}
@Override
protected Integer getTargetObjectRefId() {
return getTargetObject().getRef().getId();
}
@Override
protected boolean acceptDomainObject() {
return getDomainObject().isSetTerminal();
}
@Override
public Terminal convertToDatabaseObject(TerminalObject terminalObject, Long versionId, boolean current) {
Terminal terminal = new Terminal();
terminal.setVersionId(versionId);
terminal.setTerminalRefId(getTargetObjectRefId());
dev.vality.damsel.domain.Terminal data = terminalObject.getData();
terminal.setName(data.getName());
terminal.setDescription(data.getDescription());
if (data.isSetRiskCoverage()) {
terminal.setRiskCoverage(data.getRiskCoverage().name());
}
if (data.isSetTerms()) {
terminal.setTermsJson(JsonUtil.thriftBaseToJsonString(data.getTerms()));
}
terminal.setExternalTerminalId(data.getExternalTerminalId());
terminal.setExternalMerchantId(data.getExternalMerchantId());
terminal.setMcc(data.getMcc());
if (data.isSetProviderRef()) {
terminal.setTerminalProviderRefId(data.getProviderRef().getId());
}
terminal.setCurrent(current);
return terminal;
}
}

View File

@ -0,0 +1,22 @@
package com.empayre.dominator.handler.event.stock;
import dev.vality.geck.filter.Filter;
import org.apache.commons.lang3.NotImplementedException;
public interface Handler<T, E> {
default boolean accept(T change) {
return getFilter().match(change);
}
default void handle(T change, E event, Integer changeId) {
throw new NotImplementedException("Override it!");
}
default void handle(T change, E event) {
throw new NotImplementedException("Override it!");
}
Filter<T> getFilter();
}

View File

@ -0,0 +1,70 @@
package com.empayre.dominator.handler.event.stock.impl.identity;
import com.empayre.dominator.dao.identity.iface.ChallengeDao;
import com.empayre.dominator.domain.enums.ChallengeStatus;
import com.empayre.dominator.domain.tables.pojos.Challenge;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import com.empayre.dominator.util.JsonUtil;
import dev.vality.fistful.identity.ChallengeChange;
import dev.vality.fistful.identity.ChallengeChangePayload;
import dev.vality.fistful.identity.Change;
import dev.vality.fistful.identity.TimestampedChange;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.stream.Collectors;
@Slf4j
@Component
@RequiredArgsConstructor
public class IdentityChallengeCreatedHandler implements IdentityHandler {
private final ChallengeDao challengeDao;
private final MachineEventCopyFactory<Challenge, String> challengeMachineEventCopyFactory;
@Getter
private Filter filter = new PathConditionFilter(
new PathConditionRule("change.identity_challenge.payload.created", new IsNullCondition().not()));
@Override
public void handle(TimestampedChange timestampedChange, MachineEvent event) {
Change change = timestampedChange.getChange();
ChallengeChange challengeChange = change.getIdentityChallenge();
long sequenceId = event.getEventId();
String identityId = event.getSourceId();
String challengeId = challengeChange.getId();
log.info("Start identity challenge created handling, sequenceId={}, identityId={}, challengeId={}",
sequenceId, identityId, challengeId);
Challenge challenge = challengeMachineEventCopyFactory
.create(event, sequenceId, identityId, timestampedChange.getOccuredAt());
challenge.setChallengeId(challengeChange.getId());
ChallengeChangePayload challengePayload = challengeChange.getPayload();
dev.vality.fistful.identity.Challenge challengePayloadCreated = challengePayload.getCreated();
challenge.setChallengeClassId(challengePayloadCreated.getCls());
if (challengePayloadCreated.isSetProofs()) {
challenge.setProofsJson(JsonUtil.objectToJsonString(
challengePayloadCreated.getProofs().stream().map(JsonUtil::thriftBaseToJsonNode)
.collect(Collectors.toList())));
}
challenge.setChallengeStatus(ChallengeStatus.pending);
challengeDao.save(challenge).ifPresentOrElse(
id -> log
.info("Start identity challenge have been changed, " +
"sequenceId={}, identityId={}, challengeId={}",
sequenceId, identityId, challengeId),
() -> log.info("Identity challenge have been saved, sequenceId={}, identityId={}, challengeId={}",
sequenceId, identityId, challengeId)
);
}
}

View File

@ -0,0 +1,71 @@
package com.empayre.dominator.handler.event.stock.impl.identity;
import com.empayre.dominator.dao.identity.iface.ChallengeDao;
import com.empayre.dominator.domain.tables.pojos.Challenge;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import dev.vality.fistful.identity.*;
import dev.vality.geck.common.util.TBaseUtil;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Component
@RequiredArgsConstructor
public class IdentityChallengeStatusChangedHandler implements IdentityHandler {
private final ChallengeDao challengeDao;
private final MachineEventCopyFactory<Challenge, String> challengeMachineEventCopyFactory;
@Getter
private Filter filter = new PathConditionFilter(new PathConditionRule(
"change.identity_challenge.payload.status_changed", new IsNullCondition().not()));
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(TimestampedChange timestampedChange, MachineEvent event) {
Change change = timestampedChange.getChange();
ChallengeChange challengeChange = change.getIdentityChallenge();
ChallengeStatus status = challengeChange.getPayload().getStatusChanged();
long sequenceId = event.getEventId();
String identityId = event.getSourceId();
String challengeId = challengeChange.getId();
log.info("Start identity challenge status changed handling, sequenceId={}, identityId={}, challengeId={}",
sequenceId, identityId, challengeId);
var challengeOld = challengeDao.get(identityId, challengeChange.getId());
var challengeNew = challengeMachineEventCopyFactory
.create(event, sequenceId, identityId, challengeOld, timestampedChange.getOccuredAt());
challengeNew.setChallengeId(challengeChange.getId());
challengeNew.setChallengeStatus(TBaseUtil.unionFieldToEnum(
status, com.empayre.dominator.domain.enums.ChallengeStatus.class));
if (status.isSetCompleted()) {
ChallengeCompleted challengeCompleted = status.getCompleted();
challengeNew.setChallengeResolution(TypeUtil.toEnumField(
challengeCompleted.getResolution().toString(),
com.empayre.dominator.domain.enums.ChallengeResolution.class));
if (challengeCompleted.isSetValidUntil()) {
challengeNew.setChallengeValidUntil(TypeUtil.stringToLocalDateTime(challengeCompleted.getValidUntil()));
}
}
challengeDao.save(challengeNew).ifPresentOrElse(
id -> {
challengeDao.updateNotCurrent(identityId, challengeOld.getId());
log.info("Identity challenge status have been changed, sequenceId={}, identityId={}", sequenceId,
identityId);
},
() -> log.info("Identity challenge status have been saved, sequenceId={}, identityId={}", sequenceId,
identityId));
}
}

View File

@ -0,0 +1,62 @@
package com.empayre.dominator.handler.event.stock.impl.identity;
import com.fasterxml.jackson.databind.JsonNode;
import com.empayre.dominator.dao.identity.iface.IdentityDao;
import com.empayre.dominator.domain.tables.pojos.Identity;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import com.empayre.dominator.util.JsonUtil;
import dev.vality.fistful.identity.Change;
import dev.vality.fistful.identity.TimestampedChange;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Component
@RequiredArgsConstructor
public class IdentityCreatedHandler implements IdentityHandler {
private final IdentityDao identityDao;
private final MachineEventCopyFactory<Identity, String> identityMachineEventCopyFactory;
@Getter
private Filter filter =
new PathConditionFilter(new PathConditionRule("change.created", new IsNullCondition().not()));
@Override
public void handle(TimestampedChange timestampedChange, MachineEvent event) {
long sequenceId = event.getEventId();
String identityId = event.getSourceId();
log.info("Start identity created handling, sequenceId={}, identityId={}", sequenceId, identityId);
Identity identity =
identityMachineEventCopyFactory.create(event, sequenceId, identityId, timestampedChange.getOccuredAt());
Change change = timestampedChange.getChange();
dev.vality.fistful.identity.Identity changeCreated = change.getCreated();
identity.setPartyId(changeCreated.getParty());
identity.setPartyContractId(changeCreated.getContract());
identity.setIdentityProviderId(changeCreated.getProvider());
identity.setExternalId(changeCreated.getExternalId());
if (changeCreated.isSetMetadata()) {
Map<String, JsonNode> jsonNodeMap = changeCreated.getMetadata().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> JsonUtil.thriftBaseToJsonNode(e.getValue())));
identity.setContextJson(JsonUtil.objectToJsonString(jsonNodeMap));
}
identityDao.save(identity).ifPresentOrElse(
id -> log.info("Identity haven been saved, sequenceId={}, identityId={}", sequenceId, identityId),
() -> log
.info("Identity created bound duplicated, sequenceId={}, identityId={}", sequenceId, identityId)
);
}
}

View File

@ -0,0 +1,56 @@
package com.empayre.dominator.handler.event.stock.impl.identity;
import com.empayre.dominator.dao.identity.iface.IdentityDao;
import com.empayre.dominator.domain.tables.pojos.Identity;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import dev.vality.fistful.identity.Change;
import dev.vality.fistful.identity.TimestampedChange;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Component
@RequiredArgsConstructor
public class IdentityEffectiveChallengeChangedHandler implements IdentityHandler {
private final IdentityDao identityDao;
private final MachineEventCopyFactory<Identity, String> identityMachineEventCopyFactory;
@Getter
private Filter filter = new PathConditionFilter(
new PathConditionRule("change.effective_challenge_changed", new IsNullCondition().not()));
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(TimestampedChange timestampedChange, MachineEvent event) {
Change change = timestampedChange.getChange();
long sequenceId = event.getEventId();
String identityId = event.getSourceId();
log.info("Start effective identity challenge changed handling, sequenceId={}, identityId={}", sequenceId,
identityId);
final Identity identityOld = identityDao.get(identityId);
Identity identityNew = identityMachineEventCopyFactory
.create(event, sequenceId, identityId, identityOld, timestampedChange.getOccuredAt());
identityNew.setIdentityEffectiveChalengeId(change.getEffectiveChallengeChanged());
identityDao.save(identityNew).ifPresentOrElse(
id -> {
identityDao.updateNotCurrent(identityOld.getId());
log.info("Effective identity challenge have been changed, sequenceId={}, identityId={}", sequenceId,
identityId);
},
() -> log.info("Effective identity challenge have been saved, sequenceId={}, identityId={}", sequenceId,
identityId));
}
}

View File

@ -0,0 +1,8 @@
package com.empayre.dominator.handler.event.stock.impl.identity;
import com.empayre.dominator.handler.event.stock.Handler;
import dev.vality.fistful.identity.TimestampedChange;
import dev.vality.machinegun.eventsink.MachineEvent;
public interface IdentityHandler extends Handler<TimestampedChange, MachineEvent> {
}

View File

@ -0,0 +1,52 @@
package com.empayre.dominator.handler.event.stock.impl.identity;
import com.empayre.dominator.dao.identity.iface.IdentityDao;
import com.empayre.dominator.domain.tables.pojos.Identity;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import dev.vality.fistful.identity.Change;
import dev.vality.fistful.identity.TimestampedChange;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Component
@RequiredArgsConstructor
public class IdentityLevelChangedHandler implements IdentityHandler {
private final IdentityDao identityDao;
private final MachineEventCopyFactory<Identity, String> identityMachineEventCopyFactory;
@Getter
private Filter filter = new PathConditionFilter(
new PathConditionRule("change.level_changed", new IsNullCondition().not()));
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(TimestampedChange timestampedChange, MachineEvent event) {
Change change = timestampedChange.getChange();
long sequenceId = event.getEventId();
String identityId = event.getSourceId();
log.info("Start identity level changed handling, sequenceId={}, identityId={}", sequenceId, identityId);
final Identity identityOld = identityDao.get(identityId);
Identity identityNew = identityMachineEventCopyFactory
.create(event, sequenceId, identityId, identityOld, timestampedChange.getOccuredAt());
identityNew.setIdentityLevelId(change.getLevelChanged());
identityDao.save(identityNew).ifPresentOrElse(
id -> {
identityDao.updateNotCurrent(identityOld.getId());
log.info("Identity level have been changed, sequenceId={}, identityId={}", sequenceId, identityId);
},
() -> log.info("Identity level have been saved, sequenceId={}, identityId={}", sequenceId, identityId));
}
}

View File

@ -0,0 +1,38 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt;
import dev.vality.damsel.payment_processing.ClaimStatus;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
public abstract class AbstractClaimChangedHandler implements PartyManagementHandler {
private final Filter claimCreatedFilter = new PathConditionFilter(
new PathConditionRule("claim_created.status.accepted", new IsNullCondition().not()));
private final Filter claimStatusChangedFilter = new PathConditionFilter(
new PathConditionRule("claim_status_changed.status.accepted", new IsNullCondition().not()));
@Override
public boolean accept(PartyChange change) {
return claimCreatedFilter.match(change) || claimStatusChangedFilter.match(change);
}
@Override
public Filter<PartyChange> getFilter() {
return claimCreatedFilter;
}
protected ClaimStatus getClaimStatus(PartyChange change) {
ClaimStatus claimStatus = null;
if (change.isSetClaimCreated()) {
claimStatus = change.getClaimCreated().getStatus();
} else if (change.isSetClaimStatusChanged()) {
claimStatus = change.getClaimStatusChanged().getStatus();
}
return claimStatus;
}
}

View File

@ -0,0 +1,8 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt;
import com.empayre.dominator.handler.event.stock.Handler;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.machinegun.eventsink.MachineEvent;
public interface PartyManagementHandler extends Handler<PartyChange, MachineEvent> {
}

View File

@ -0,0 +1,95 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contract;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.ContractEffectUnit;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.ContractAdjustmentDao;
import com.empayre.dominator.dao.party.iface.ContractDao;
import com.empayre.dominator.dao.party.iface.PayoutToolDao;
import com.empayre.dominator.domain.tables.pojos.Contract;
import com.empayre.dominator.domain.tables.pojos.ContractAdjustment;
import com.empayre.dominator.domain.tables.pojos.PayoutTool;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import com.empayre.dominator.util.ContractUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class ContractAdjustmentCreatedHandler extends AbstractClaimChangedHandler {
private final ContractDao contractDao;
private final ContractAdjustmentDao contractAdjustmentDao;
private final PayoutToolDao payoutToolDao;
private final ClaimEffectCopyFactory<Contract, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetContractEffect()
&& claimEffect.getContractEffect().getEffect().isSetAdjustmentCreated()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect,
Integer claimEffectId) {
ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
dev.vality.damsel.domain.ContractAdjustment adjustmentCreated =
contractEffectUnit.getEffect().getAdjustmentCreated();
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSourceId();
log.info("Start contract adjustment created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
Contract contractSourceOld = contractDao.get(partyId, contractId);
Contract contractNew =
claimEffectCopyFactory.create(event, sequenceId, changeId, claimEffectId, contractSourceOld);
contractDao.save(contractNew).ifPresentOrElse(
cntrctId -> {
Long contractSourceOldId = contractSourceOld.getId();
contractDao.updateNotCurrent(contractSourceOldId);
updateContractReference(adjustmentCreated, contractSourceOldId, cntrctId);
log.info(
"Contract adjustment has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
},
() -> log.info("Contract adjustment duplicated, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId)
);
}
private void updateContractReference(dev.vality.damsel.domain.ContractAdjustment adjustmentCreated,
Long contractSourceId,
Long contractId) {
List<ContractAdjustment> adjustments = new ArrayList<>(contractAdjustmentDao.getByContractId(contractSourceId));
adjustments.forEach(a -> {
a.setId(null);
a.setContractId(contractId);
});
adjustments.add(ContractUtil.convertContractAdjustment(adjustmentCreated, contractId));
contractAdjustmentDao.save(adjustments);
List<PayoutTool> payoutTools = payoutToolDao.getByContractId(contractSourceId);
payoutTools.forEach(pt -> {
pt.setId(null);
pt.setContractId(contractId);
});
payoutToolDao.save(payoutTools);
}
}

View File

@ -0,0 +1,72 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contract;
import com.empayre.dominator.service.ContractReferenceService;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.ContractEffectUnit;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.ContractDao;
import com.empayre.dominator.domain.tables.pojos.Contract;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@RequiredArgsConstructor
@Component
public class ContractContractorIDChangedHandler extends AbstractClaimChangedHandler {
private final ContractDao contractDao;
private final ContractReferenceService contractReferenceService;
private final ClaimEffectCopyFactory<Contract, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetContractEffect()
&& claimEffect.getContractEffect().getEffect().isSetContractorChanged()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect,
Integer claimEffectId) {
ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
String contractorChanged = contractEffectUnit.getEffect().getContractorChanged();
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSourceId();
log.info("Start contract contractorChanged changed handling, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}", sequenceId, partyId, contractId, changeId);
Contract contractSourceOld = contractDao.get(partyId, contractId);
Contract contractNew =
claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, contractSourceOld);
contractNew.setContractorId(contractorChanged);
contractDao.save(contractNew).ifPresentOrElse(
cntrctId -> {
Long oldId = contractSourceOld.getId();
contractDao.updateNotCurrent(oldId);
contractReferenceService.updateContractReference(oldId, cntrctId);
log.info("Contract contractorChanged has been saved, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
},
() -> log.info("Contract contractorChanged duplicated, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId)
);
}
}

View File

@ -0,0 +1,137 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contract;
import com.empayre.dominator.dao.party.iface.*;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.ContractEffectUnit;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.*;
import com.empayre.dominator.domain.enums.ContractStatus;
import com.empayre.dominator.domain.tables.pojos.Contract;
import com.empayre.dominator.domain.tables.pojos.ContractAdjustment;
import com.empayre.dominator.domain.tables.pojos.Contractor;
import com.empayre.dominator.domain.tables.pojos.PayoutTool;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import com.empayre.dominator.factory.contractor.ContractorFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import com.empayre.dominator.util.ContractUtil;
import dev.vality.geck.common.util.TBaseUtil;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.UUID;
import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;
@Slf4j
@Component
@Order(HIGHEST_PRECEDENCE)
@RequiredArgsConstructor
public class ContractCreatedHandler extends AbstractClaimChangedHandler {
private final ContractDao contractDao;
private final ContractorDao contractorDao;
private final PartyDao partyDao;
private final ContractAdjustmentDao contractAdjustmentDao;
private final PayoutToolDao payoutToolDao;
private final ClaimEffectCopyFactory<Contract, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetContractEffect() && claimEffect.getContractEffect().getEffect().isSetCreated()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e,
Integer claimEffectId) {
ContractEffectUnit contractEffectUnit = e.getContractEffect();
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSourceId();
log.info("Start contract created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
Contract contract = claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId);
partyDao.get(partyId); //check party is exist
contract.setContractId(contractId);
contract.setPartyId(partyId);
dev.vality.damsel.domain.Contract contractCreated = contractEffectUnit.getEffect().getCreated();
if (contractCreated.isSetPaymentInstitution()) {
contract.setPaymentInstitutionId(contractCreated.getPaymentInstitution().getId());
}
contract.setCreatedAt(TypeUtil.stringToLocalDateTime(contractCreated.getCreatedAt()));
if (contractCreated.isSetValidSince()) {
contract.setValidSince(TypeUtil.stringToLocalDateTime(contractCreated.getValidSince()));
}
if (contractCreated.isSetValidUntil()) {
contract.setValidUntil(TypeUtil.stringToLocalDateTime(contractCreated.getValidUntil()));
}
contract.setStatus(TBaseUtil.unionFieldToEnum(contractCreated.getStatus(), ContractStatus.class));
if (contractCreated.getStatus().isSetTerminated()) {
contract.setStatusTerminatedAt(
TypeUtil.stringToLocalDateTime(contractCreated.getStatus().getTerminated().getTerminatedAt()));
}
contract.setTermsId(contractCreated.getTerms().getId());
if (contractCreated.isSetLegalAgreement()) {
ContractUtil.fillContractLegalAgreementFields(contract, contractCreated.getLegalAgreement());
}
if (contractCreated.isSetReportPreferences()
&& contractCreated.getReportPreferences().isSetServiceAcceptanceActPreferences()) {
ContractUtil.fillReportPreferences(contract,
contractCreated.getReportPreferences().getServiceAcceptanceActPreferences());
}
String contractorId = initContractorId(contractCreated);
contract.setContractorId(contractorId);
contractDao.save(contract).ifPresentOrElse(
cntrctId -> updateContractReference(event, changeId, sequenceId, contractCreated, contractId, partyId,
contractorId, cntrctId, claimEffectId),
() -> log.info("contract create duplicated, sequenceId={}, partyId={}, changeId={}",
sequenceId, partyId, changeId)
);
}
private String initContractorId(dev.vality.damsel.domain.Contract contractCreated) {
String contractorId = "";
if (contractCreated.isSetContractorId()) {
contractorId = contractCreated.getContractorId();
} else if (contractCreated.isSetContractor()) {
contractorId = UUID.randomUUID().toString();
}
return contractorId;
}
private void updateContractReference(MachineEvent event, Integer changeId, long sequenceId,
dev.vality.damsel.domain.Contract contractCreated,
String contractId, String partyId, String contractorId, Long cntrctId,
Integer claimEffectId) {
if (contractCreated.isSetContractor()) {
Contractor contractor = ContractorFactory.build(sequenceId, event.getCreatedAt(),
partyId, contractCreated.getContractor(), contractorId, changeId, claimEffectId);
contractorDao.save(contractor);
}
List<ContractAdjustment> adjustments = ContractUtil.convertContractAdjustments(contractCreated, cntrctId);
contractAdjustmentDao.save(adjustments);
List<PayoutTool> payoutTools =
ContractUtil.convertPayoutTools(contractCreated, cntrctId);
payoutToolDao.save(payoutTools);
log.info("Contract has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
}
}

View File

@ -0,0 +1,74 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contract;
import com.empayre.dominator.service.ContractReferenceService;
import dev.vality.damsel.domain.LegalAgreement;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.ContractEffectUnit;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.ContractDao;
import com.empayre.dominator.domain.tables.pojos.Contract;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import com.empayre.dominator.util.ContractUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class ContractLegalAgreementBoundHandler extends AbstractClaimChangedHandler {
private final ContractDao contractDao;
private final ContractReferenceService contractReferenceService;
private final ClaimEffectCopyFactory<Contract, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetContractEffect()
&& claimEffect.getContractEffect().getEffect().isSetLegalAgreementBound()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect,
Integer claimEffectId) {
ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
LegalAgreement legalAgreementBound = contractEffectUnit.getEffect().getLegalAgreementBound();
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSourceId();
log.info("Start contract legal agreement bound handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
Contract contractSourceOld = contractDao.get(partyId, contractId);
Contract contractNew =
claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, contractSourceOld);
ContractUtil.fillContractLegalAgreementFields(contractNew, legalAgreementBound);
contractDao.save(contractNew).ifPresentOrElse(
dbContractId -> {
Long oldId = contractSourceOld.getId();
contractDao.updateNotCurrent(oldId);
contractReferenceService.updateContractReference(oldId, dbContractId);
log.info("Contract legal agreement bound has been saved, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
},
() -> log.info("Contract legal agreement bound duplicated, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId)
);
}
}

View File

@ -0,0 +1,74 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contract;
import com.empayre.dominator.service.ContractReferenceService;
import dev.vality.damsel.domain.PayoutTool;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.ContractEffectUnit;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.ContractDao;
import com.empayre.dominator.dao.party.iface.PayoutToolDao;
import com.empayre.dominator.domain.tables.pojos.Contract;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import com.empayre.dominator.util.ContractUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class ContractPayoutToolCreatedHandler extends AbstractClaimChangedHandler {
private final ContractDao contractDao;
private final PayoutToolDao payoutToolDao;
private final ContractReferenceService contractReferenceService;
private final ClaimEffectCopyFactory<Contract, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetContractEffect()
&& claimEffect.getContractEffect().getEffect().isSetPayoutToolCreated()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect,
Integer claimEffectId) {
ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
PayoutTool payoutToolCreated = contractEffectUnit.getEffect().getPayoutToolCreated();
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSourceId();
log.info("Start contract payout tool created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
Contract contractSourceOld = contractDao.get(partyId, contractId);
Contract contractNew =
claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, contractSourceOld);
contractDao.save(contractNew).ifPresentOrElse(
dbContractId -> {
Long oldId = contractSourceOld.getId();
contractDao.updateNotCurrent(oldId);
contractReferenceService.updateContractReference(oldId, dbContractId);
payoutToolDao.save(List.of(ContractUtil.convertPayoutTool(payoutToolCreated, dbContractId)));
log.info("Contract contract payout tool created has been saved, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
},
() -> log.info("Contract contract payout tool created duplicated, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId)
);
}
}

View File

@ -0,0 +1,109 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contract;
import com.empayre.dominator.service.ContractReferenceService;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.ContractEffectUnit;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.PayoutToolInfoChanged;
import com.empayre.dominator.dao.party.iface.ContractDao;
import com.empayre.dominator.dao.party.iface.PayoutToolDao;
import com.empayre.dominator.domain.tables.pojos.Contract;
import com.empayre.dominator.domain.tables.pojos.PayoutTool;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import com.empayre.dominator.util.ContractUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Slf4j
@Component
@RequiredArgsConstructor
public class ContractPayoutToolInfoChangedHandler extends AbstractClaimChangedHandler {
private final ContractDao contractDao;
private final PayoutToolDao payoutToolDao;
private final ContractReferenceService contractReferenceService;
private final ClaimEffectCopyFactory<Contract, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetContractEffect()
&& claimEffect.getContractEffect().getEffect().isSetPayoutToolInfoChanged()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect,
Integer claimEffectId) {
ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSourceId();
log.info("Start contract payout tool info changed handling, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
Contract contractSourceOld = contractDao.get(partyId, contractId);
Contract contractNew =
claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, contractSourceOld);
contractDao.save(contractNew).ifPresentOrElse(
dbContractId -> {
Long oldId = contractSourceOld.getId();
contractDao.updateNotCurrent(oldId);
contractReferenceService.updateAdjustments(oldId, dbContractId);
updatePayoutTools(contractEffectUnit, oldId, dbContractId);
log.info("Contract payout tool info changed has been saved, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
},
() -> log.info("Contract payout tool info changed duplicated, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId)
);
}
private void updatePayoutTools(ContractEffectUnit contractEffectUnit, Long oldId, Long dbContractId) {
List<PayoutTool> currentPayoutTools = payoutToolDao.getByContractId(oldId);
currentPayoutTools.forEach(payoutTool -> {
payoutTool.setId(null);
payoutTool.setContractId(dbContractId);
});
PayoutToolInfoChanged payoutToolInfoChanged =
contractEffectUnit.getEffect().getPayoutToolInfoChanged();
Optional<PayoutTool> payoutToolForChangeOptional = currentPayoutTools.stream()
.filter(payoutTool -> payoutTool.getPayoutToolId().equals(payoutToolInfoChanged.getPayoutToolId()))
.findAny();
List<PayoutTool> modifiedPayoutTools;
if (payoutToolForChangeOptional.isPresent()) {
PayoutTool payoutToolForChange = payoutToolForChangeOptional.get();
PayoutTool newPayoutTool = ContractUtil.buildPayoutTool(dbContractId,
payoutToolInfoChanged.getPayoutToolId(),
payoutToolForChange.getCreatedAt(),
payoutToolForChange.getCurrencyCode(),
payoutToolInfoChanged.getInfo()
);
modifiedPayoutTools = Stream.concat(
Stream.of(newPayoutTool),
currentPayoutTools.stream()
.filter(p -> !p.getPayoutToolId().equals(payoutToolInfoChanged.getPayoutToolId()))
).collect(Collectors.toList());
} else {
modifiedPayoutTools = currentPayoutTools;
}
payoutToolDao.save(modifiedPayoutTools);
}
}

View File

@ -0,0 +1,79 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contract;
import com.empayre.dominator.service.ContractReferenceService;
import dev.vality.damsel.domain.ReportPreferences;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.ContractEffectUnit;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.ContractDao;
import com.empayre.dominator.domain.tables.pojos.Contract;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import com.empayre.dominator.util.ContractUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class ContractReportPreferencesChangedHandler extends AbstractClaimChangedHandler {
private final ContractDao contractDao;
private final ContractReferenceService contractReferenceService;
private final ClaimEffectCopyFactory<Contract, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetContractEffect()
&& claimEffect.getContractEffect().getEffect().isSetReportPreferencesChanged()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect,
Integer claimEffectId) {
ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
ReportPreferences reportPreferencesChanged = contractEffectUnit.getEffect().getReportPreferencesChanged();
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSourceId();
log.info("Start contract report preferences changed handling, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}", sequenceId, partyId, contractId, changeId);
Contract contractSourceOld = contractDao.get(partyId, contractId);
Contract contractNew =
claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, contractSourceOld);
if (reportPreferencesChanged != null && reportPreferencesChanged.isSetServiceAcceptanceActPreferences()) {
ContractUtil.fillReportPreferences(contractNew,
reportPreferencesChanged.getServiceAcceptanceActPreferences());
} else {
ContractUtil.setNullReportPreferences(contractNew);
}
contractDao.save(contractNew).ifPresentOrElse(
dbContractId -> {
Long oldId = contractSourceOld.getId();
contractDao.updateNotCurrent(oldId);
contractReferenceService.updateContractReference(oldId, dbContractId);
log.info("Contract report preferences has been saved, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
},
() -> log.info("Contract report preferences duplicated, " +
"sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId)
);
}
}

View File

@ -0,0 +1,78 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contract;
import com.empayre.dominator.service.ContractReferenceService;
import dev.vality.damsel.domain.ContractStatus;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.ContractEffectUnit;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.ContractDao;
import com.empayre.dominator.domain.tables.pojos.Contract;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.geck.common.util.TBaseUtil;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
@SuppressWarnings("VariableDeclarationUsageDistance")
public class ContractStatusChangedHandler extends AbstractClaimChangedHandler {
private final ContractDao contractDao;
private final ContractReferenceService contractReferenceService;
private final ClaimEffectCopyFactory<Contract, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetContractEffect() && claimEffect.getContractEffect().getEffect().isSetStatusChanged()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e,
Integer claimEffectId) {
ContractEffectUnit contractEffectUnit = e.getContractEffect();
ContractStatus statusChanged = contractEffectUnit.getEffect().getStatusChanged();
String contractId = contractEffectUnit.getContractId();
String partyId = event.getSourceId();
log.info("Start contractSource status changed handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
Contract contractSourceOld = contractDao.get(partyId, contractId);
Contract contractNew =
claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, contractSourceOld);
contractNew.setStatus(TBaseUtil.unionFieldToEnum(
statusChanged, com.empayre.dominator.domain.enums.ContractStatus.class));
if (statusChanged.isSetTerminated()) {
contractNew.setStatusTerminatedAt(
TypeUtil.stringToLocalDateTime(statusChanged.getTerminated().getTerminatedAt()));
}
contractDao.save(contractNew).ifPresentOrElse(
dbContractId -> {
Long oldId = contractSourceOld.getId();
contractDao.updateNotCurrent(oldId);
contractReferenceService.updateContractReference(oldId, dbContractId);
log.info("Contract status has been saved, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId);
},
() -> log.info("Contract status duplicated, sequenceId={}, partyId={}, contractId={}, changeId={}",
sequenceId, partyId, contractId, changeId)
);
}
}

View File

@ -0,0 +1,70 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contractor;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.damsel.domain.PartyContractor;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.ContractorEffectUnit;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.ContractorDao;
import com.empayre.dominator.dao.party.iface.PartyDao;
import com.empayre.dominator.domain.tables.pojos.Contractor;
import com.empayre.dominator.factory.contractor.ContractorFactory;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;
@Slf4j
@Component
@Order(HIGHEST_PRECEDENCE)
@RequiredArgsConstructor
public class ContractorCreatedHandler extends AbstractClaimChangedHandler {
private final ContractorDao contractorDao;
private final PartyDao partyDao;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long eventId = event.getEventId();
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetContractorEffect() && claimEffect.getContractorEffect().getEffect().isSetCreated()) {
handleEvent(event, changeId, eventId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long eventId, long sequenceId,
ClaimEffect claimEffect, Integer claimEffectId) {
ContractorEffectUnit contractorEffect = claimEffect.getContractorEffect();
PartyContractor partyContractor = contractorEffect.getEffect().getCreated();
dev.vality.damsel.domain.Contractor contractorCreated = partyContractor.getContractor();
String contractorId = contractorEffect.getId();
String partyId = event.getSourceId();
log.info("Start contractor created handling, eventId={}, partyId={}, contractorId={}",
eventId, partyId, contractorId);
partyDao.get(partyId); //check party is exist
Contractor contractor = ContractorFactory.build(
eventId, event.getCreatedAt(), partyId, contractorCreated, contractorId, changeId, claimEffectId);
contractor.setIdentificationalLevel(partyContractor.getStatus().name());
contractorDao.save(contractor).ifPresentOrElse(
cntrctId -> log.info("Contract contractor has been saved, eventId={}, partyId={}, contractorId={}",
eventId, partyId, contractorId),
() -> log.info("contract contractor duplicated, sequenceId={}, partyId={}, changeId={}",
sequenceId, partyId, changeId)
);
}
}

View File

@ -0,0 +1,68 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contractor;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.damsel.domain.ContractorIdentificationLevel;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.ContractorEffectUnit;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.ContractorDao;
import com.empayre.dominator.domain.tables.pojos.Contractor;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class ContractorIdentificationalLevelChangedHandler extends AbstractClaimChangedHandler {
private final ContractorDao contractorDao;
private final ClaimEffectCopyFactory<Contractor, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetContractorEffect()
&& claimEffect.getContractorEffect().getEffect().isSetIdentificationLevelChanged()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect,
Integer claimEffectId) {
ContractorEffectUnit contractorEffect = claimEffect.getContractorEffect();
ContractorIdentificationLevel identificationLevelChanged =
contractorEffect.getEffect().getIdentificationLevelChanged();
String contractorId = contractorEffect.getId();
String partyId = event.getSourceId();
log.info("Start identificational level changed handling, sequenceId={}, partyId={}, contractorId={}",
sequenceId, partyId, contractorId);
Contractor contractorOld = contractorDao.get(partyId, contractorId);
Contractor contractorNew =
claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, contractorOld);
contractorNew.setIdentificationalLevel(identificationLevelChanged.name());
contractorDao.save(contractorNew)
.ifPresentOrElse(
saveResult -> {
contractorDao.updateNotCurrent(contractorOld.getId());
log.info("Contractor identificational has been saved, " +
"sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId);
},
() -> log.info("Contractor identificational duplicated, " +
"sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId)
);
}
}

View File

@ -0,0 +1,63 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.party;
import com.empayre.dominator.dao.party.iface.PartyDao;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import dev.vality.damsel.domain.Blocking;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.domain.tables.pojos.Party;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import dev.vality.geck.common.util.TBaseUtil;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Component
@RequiredArgsConstructor
public class PartyBlockingHandler implements PartyManagementHandler {
private final PartyDao partyDao;
private final MachineEventCopyFactory<Party, Integer> partyIntegerMachineEventCopyFactory;
@Getter
private final Filter filter =
new PathConditionFilter(new PathConditionRule("party_blocking", new IsNullCondition().not()));
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
Blocking partyBlocking = change.getPartyBlocking();
String partyId = event.getSourceId();
log.info("Start party blocking handling, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId,
changeId);
Party partyOld = partyDao.get(partyId);
Party partyNew = partyIntegerMachineEventCopyFactory.create(event, sequenceId, changeId, partyOld, null);
partyNew.setBlocking(
TBaseUtil.unionFieldToEnum(partyBlocking, com.empayre.dominator.domain.enums.Blocking.class));
if (partyBlocking.isSetUnblocked()) {
partyNew.setBlockingUnblockedReason(partyBlocking.getUnblocked().getReason());
partyNew.setBlockingUnblockedSince(TypeUtil.stringToLocalDateTime(partyBlocking.getUnblocked().getSince()));
partyNew.setBlockingBlockedReason(null);
partyNew.setBlockingBlockedSince(null);
} else if (partyBlocking.isSetBlocked()) {
partyNew.setBlockingUnblockedReason(null);
partyNew.setBlockingUnblockedSince(null);
partyNew.setBlockingBlockedReason(partyBlocking.getBlocked().getReason());
partyNew.setBlockingBlockedSince(TypeUtil.stringToLocalDateTime(partyBlocking.getBlocked().getSince()));
}
partyDao.saveWithUpdateCurrent(partyNew, partyOld.getId(), "blocking");
}
}

View File

@ -0,0 +1,66 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.party;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.PartyCreated;
import com.empayre.dominator.dao.party.iface.PartyDao;
import com.empayre.dominator.domain.enums.Blocking;
import com.empayre.dominator.domain.enums.Suspension;
import com.empayre.dominator.domain.tables.pojos.Party;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
@Slf4j
@Component
@RequiredArgsConstructor
public class PartyCreatedHandler implements PartyManagementHandler {
private final PartyDao partyDao;
private final MachineEventCopyFactory<Party, Integer> partyIntegerMachineEventCopyFactory;
@Getter
private final Filter filter =
new PathConditionFilter(new PathConditionRule("party_created", new IsNullCondition().not()));
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
PartyCreated partyCreated = change.getPartyCreated();
String partyId = partyCreated.getId();
log.info("Start party created handling, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId);
Party party = partyIntegerMachineEventCopyFactory.create(event, sequenceId, changeId, null);
party.setPartyId(partyId);
party.setContactInfoEmail(partyCreated.getContactInfo().getEmail());
LocalDateTime partyCreatedAt = TypeUtil.stringToLocalDateTime(partyCreated.getCreatedAt());
party.setCreatedAt(partyCreatedAt);
party.setBlocking(Blocking.unblocked);
party.setBlockingUnblockedReason("");
party.setBlockingUnblockedSince(partyCreatedAt);
party.setSuspension(Suspension.active);
party.setSuspensionActiveSince(partyCreatedAt);
party.setRevision(0L);
party.setRevisionChangedAt(partyCreatedAt);
partyDao.save(party).ifPresentOrElse(
atLong -> log.info("Party has been saved, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId,
changeId),
() -> log.info("Party create duplicated, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId,
changeId));
}
}

View File

@ -0,0 +1,51 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.party;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.PartyMetaSet;
import com.empayre.dominator.dao.party.iface.PartyDao;
import com.empayre.dominator.domain.tables.pojos.Party;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import com.empayre.dominator.util.JsonUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Component
@RequiredArgsConstructor
public class PartyMetaSetHandler implements PartyManagementHandler {
private final PartyDao partyDao;
private final MachineEventCopyFactory<Party, Integer> partyIntegerMachineEventCopyFactory;
@Getter
private final Filter filter =
new PathConditionFilter(new PathConditionRule("party_meta_set", new IsNullCondition().not()));
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
PartyMetaSet partyMetaSet = change.getPartyMetaSet();
String partyId = event.getSourceId();
log.info("Start party metaset handling, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId);
Party partyOld = partyDao.get(partyId);
Party partyNew = partyIntegerMachineEventCopyFactory.create(event, sequenceId, changeId, partyOld, null);
partyNew.setPartyMetaSetNs(partyMetaSet.getNs());
partyNew.setPartyMetaSetDataJson(JsonUtil.thriftBaseToJsonString(partyMetaSet.getData()));
partyDao.saveWithUpdateCurrent(partyNew, partyOld.getId(), "metaset");
}
}

View File

@ -0,0 +1,74 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.party;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.PartyRevisionChanged;
import com.empayre.dominator.dao.party.iface.PartyDao;
import com.empayre.dominator.dao.party.iface.RevisionDao;
import com.empayre.dominator.domain.tables.pojos.Party;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Component
@RequiredArgsConstructor
public class PartyRevisionChangedHandler implements PartyManagementHandler {
private final PartyDao partyDao;
private final RevisionDao revisionDao;
private final MachineEventCopyFactory<Party, Integer> partyIntegerMachineEventCopyFactory;
@Getter
private final Filter filter =
new PathConditionFilter(new PathConditionRule("revision_changed", new IsNullCondition().not()));
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
PartyRevisionChanged partyRevisionChanged = change.getRevisionChanged();
String partyId = event.getSourceId();
log.info("Start partySource revision changed handling, eventId={}, partyId={}, changeId={}",
sequenceId, partyId, changeId);
Party partyOld = partyDao.get(partyId);
long revision = partyRevisionChanged.getRevision();
Party partyNew = partyIntegerMachineEventCopyFactory.create(event, sequenceId, changeId, partyOld, null);
partyNew.setRevision(revision);
partyNew.setRevisionChangedAt(TypeUtil.stringToLocalDateTime(partyRevisionChanged.getTimestamp()));
partyDao.save(partyNew)
.ifPresentOrElse(
anLong -> {
partyDao.updateNotCurrent(partyOld.getId());
updatePartyReferences(partyId, revision);
log.info("Party revision changed has been saved, sequenceId={}, partyId={}, changeId={}",
sequenceId, partyId, changeId);
},
() -> log.info("Party revision changed duplicated, sequenceId={}, partyId={}, changeId={}",
sequenceId, partyId, changeId)
);
}
private void updatePartyReferences(String partyId, long revision) {
log.info("Start to save revisions, partyId={}, revision={}", partyId, revision);
revisionDao.saveContractorsRevision(partyId, revision);
log.info("Contractors revisions has been saved, partyId={}, revision={}", partyId, revision);
revisionDao.saveContractsRevision(partyId, revision);
log.info("Contracts revision has been saved, partyId={}, revision={}", partyId, revision);
revisionDao.saveShopsRevision(partyId, revision);
log.info("Shops revisions has been saved, partyId={}, revision={}", partyId, revision);
}
}

View File

@ -0,0 +1,64 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.party;
import dev.vality.damsel.domain.Suspension;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.PartyDao;
import com.empayre.dominator.domain.tables.pojos.Party;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import dev.vality.geck.common.util.TBaseUtil;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Component
@RequiredArgsConstructor
public class PartySuspensionHandler implements PartyManagementHandler {
public static final String PARTY_SUSPENSION = "party_suspension";
private final PartyDao partyDao;
private final MachineEventCopyFactory<Party, Integer> partyIntegerMachineEventCopyFactory;
@Getter
private final Filter filter =
new PathConditionFilter(new PathConditionRule(PARTY_SUSPENSION, new IsNullCondition().not()));
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
Suspension partySuspension = change.getPartySuspension();
String partyId = event.getSourceId();
log.info("Start {} handling, eventId={}, partyId={}, changeId={}", PARTY_SUSPENSION, sequenceId, partyId,
changeId);
Party partyOld = partyDao.get(partyId);
Party partyNew = partyIntegerMachineEventCopyFactory.create(event, sequenceId, changeId, partyOld, null);
partyNew.setSuspension(TBaseUtil.unionFieldToEnum(
partySuspension,
com.empayre.dominator.domain.enums.Suspension.class
));
if (partySuspension.isSetActive()) {
partyNew.setSuspensionActiveSince(TypeUtil.stringToLocalDateTime(partySuspension.getActive().getSince()));
partyNew.setSuspensionSuspendedSince(null);
} else if (partySuspension.isSetSuspended()) {
partyNew.setSuspensionActiveSince(null);
partyNew.setSuspensionSuspendedSince(
TypeUtil.stringToLocalDateTime(partySuspension.getSuspended().getSince()));
}
partyDao.saveWithUpdateCurrent(partyNew, partyOld.getId(), PARTY_SUSPENSION);
}
}

View File

@ -0,0 +1,59 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.damsel.domain.ShopAccount;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.ShopEffectUnit;
import com.empayre.dominator.dao.party.iface.ShopDao;
import com.empayre.dominator.domain.tables.pojos.Shop;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import com.empayre.dominator.util.ShopUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class ShopAccountCreatedHandler extends AbstractClaimChangedHandler {
private final ShopDao shopDao;
private final ClaimEffectCopyFactory<Shop, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetAccountCreated()) {
handleEvent(event, changeId, sequenceId, claimEffect, i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e,
Integer claimEffectId) {
ShopEffectUnit shopEffect = e.getShopEffect();
ShopAccount accountCreated = shopEffect.getEffect().getAccountCreated();
String shopId = shopEffect.getShopId();
String partyId = event.getSourceId();
log.info("Start shop accountCreated handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
sequenceId, partyId, shopId, changeId);
final Shop shopOld = shopDao.get(partyId, shopId);
Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, shopOld);
ShopUtil.fillShopAccount(shopNew, accountCreated);
shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "accountCreated");
}
}

View File

@ -0,0 +1,70 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import dev.vality.damsel.domain.Blocking;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.ShopDao;
import com.empayre.dominator.domain.tables.pojos.Shop;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import dev.vality.geck.common.util.TBaseUtil;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Component
@RequiredArgsConstructor
public class ShopBlockingHandler implements PartyManagementHandler {
private final ShopDao shopDao;
private final ClaimEffectCopyFactory<Shop, Integer> claimEffectCopyFactory;
@Getter
private final Filter filter = new PathConditionFilter(new PathConditionRule(
"shop_blocking",
new IsNullCondition().not()));
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
Blocking blocking = change.getShopBlocking().getBlocking();
String shopId = change.getShopBlocking().getShopId();
String partyId = event.getSourceId();
log.info("Start shop blocking handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
sequenceId, partyId, shopId, changeId);
final Shop shopOld = shopDao.get(partyId, shopId);
Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, -1, changeId, shopOld);
initBlockingFields(blocking, shopNew);
shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "blocking");
}
private void initBlockingFields(Blocking blocking, Shop shopSource) {
shopSource.setBlocking(
TBaseUtil.unionFieldToEnum(blocking, com.empayre.dominator.domain.enums.Blocking.class));
if (blocking.isSetUnblocked()) {
shopSource.setBlockingUnblockedReason(blocking.getUnblocked().getReason());
shopSource.setBlockingUnblockedSince(TypeUtil.stringToLocalDateTime(blocking.getUnblocked().getSince()));
shopSource.setBlockingBlockedReason(null);
shopSource.setBlockingBlockedSince(null);
} else if (blocking.isSetBlocked()) {
shopSource.setBlockingUnblockedReason(null);
shopSource.setBlockingUnblockedSince(null);
shopSource.setBlockingBlockedReason(blocking.getBlocked().getReason());
shopSource.setBlockingBlockedSince(TypeUtil.stringToLocalDateTime(blocking.getBlocked().getSince()));
}
}
}

View File

@ -0,0 +1,56 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.ShopEffectUnit;
import com.empayre.dominator.dao.party.iface.ShopDao;
import com.empayre.dominator.domain.tables.pojos.Shop;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class ShopCategoryChangedHandler extends AbstractClaimChangedHandler {
private final ShopDao shopDao;
private final ClaimEffectCopyFactory<Shop, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetCategoryChanged()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e,
Integer claimEffectId) {
ShopEffectUnit shopEffect = e.getShopEffect();
int categoryId = shopEffect.getEffect().getCategoryChanged().getId();
String shopId = shopEffect.getShopId();
String partyId = event.getSourceId();
log.info("Start shop categoryId changed handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
sequenceId, partyId, shopId, changeId);
final Shop shopOld = shopDao.get(partyId, shopId);
Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, shopOld);
shopNew.setCategoryId(categoryId);
shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "categoryId");
}
}

View File

@ -0,0 +1,59 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.ShopContractChanged;
import dev.vality.damsel.payment_processing.ShopEffectUnit;
import com.empayre.dominator.dao.party.iface.ShopDao;
import com.empayre.dominator.domain.tables.pojos.Shop;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
@SuppressWarnings("VariableDeclarationUsageDistance")
public class ShopContractChangedHandler extends AbstractClaimChangedHandler {
private final ShopDao shopDao;
private final ClaimEffectCopyFactory<Shop, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetContractChanged()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect,
Integer claimEffectId) {
ShopEffectUnit shopEffect = claimEffect.getShopEffect();
ShopContractChanged contractChanged = shopEffect.getEffect().getContractChanged();
String shopId = shopEffect.getShopId();
String partyId = event.getSourceId();
log.info("Start shop contractChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
sequenceId, partyId, shopId, changeId);
final Shop shopOld = shopDao.get(partyId, shopId);
Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, shopOld);
shopNew.setContractId(contractChanged.getContractId());
shopNew.setPayoutToolId(contractChanged.getPayoutToolId());
shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "contractChanged");
}
}

View File

@ -0,0 +1,120 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.damsel.domain.Shop;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.ShopEffectUnit;
import com.empayre.dominator.dao.party.iface.PartyDao;
import com.empayre.dominator.dao.party.iface.ShopDao;
import com.empayre.dominator.domain.enums.Blocking;
import com.empayre.dominator.domain.enums.Suspension;
import com.empayre.dominator.util.ShopUtil;
import dev.vality.geck.common.util.TBaseUtil;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;
@Slf4j
@Component
@Order(HIGHEST_PRECEDENCE)
@RequiredArgsConstructor
public class ShopCreatedHandler extends AbstractClaimChangedHandler {
private final ShopDao shopDao;
private final PartyDao partyDao;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetCreated()) {
handleEvent(event, changeId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, ClaimEffect e, Integer claimEffectId) {
long sequenceId = event.getEventId();
ShopEffectUnit shopEffect = e.getShopEffect();
Shop shopCreated = shopEffect.getEffect().getCreated();
String shopId = shopEffect.getShopId();
String partyId = event.getSourceId();
log.info("Start shop created handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
sequenceId, partyId, shopId, changeId);
partyDao.get(partyId); //check party is exist
com.empayre.dominator.domain.tables.pojos.Shop shop =
createShop(event, changeId, sequenceId, shopCreated, shopId, partyId, claimEffectId);
shopDao.save(shop).ifPresentOrElse(
atLong -> log.info("Shop has been saved, sequenceId={}, ppartyId={}, shopId={}, changeId={}",
sequenceId,
partyId, shopId, changeId),
() -> log.info("Shop create duplicated, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId,
partyId, shopId, changeId));
}
private com.empayre.dominator.domain.tables.pojos.Shop createShop(MachineEvent event, Integer changeId,
long sequenceId,
Shop shopCreated, String shopId, String partyId,
Integer claimEffectId) {
com.empayre.dominator.domain.tables.pojos.Shop shop =
new com.empayre.dominator.domain.tables.pojos.Shop();
shop.setSequenceId((int) sequenceId);
shop.setChangeId(changeId);
shop.setEventCreatedAt(TypeUtil.stringToLocalDateTime(event.getCreatedAt()));
shop.setShopId(shopId);
shop.setPartyId(partyId);
shop.setClaimEffectId(claimEffectId);
shop.setCreatedAt(TypeUtil.stringToLocalDateTime(shopCreated.getCreatedAt()));
shop.setBlocking(
TBaseUtil.unionFieldToEnum(shopCreated.getBlocking(), Blocking.class));
if (shopCreated.getBlocking().isSetUnblocked()) {
shop.setBlockingUnblockedReason(shopCreated.getBlocking().getUnblocked().getReason());
shop.setBlockingUnblockedSince(
TypeUtil.stringToLocalDateTime(shopCreated.getBlocking().getUnblocked().getSince()));
} else if (shopCreated.getBlocking().isSetBlocked()) {
shop.setBlockingBlockedReason(shopCreated.getBlocking().getBlocked().getReason());
shop.setBlockingBlockedSince(
TypeUtil.stringToLocalDateTime(shopCreated.getBlocking().getBlocked().getSince()));
}
shop.setSuspension(TBaseUtil
.unionFieldToEnum(shopCreated.getSuspension(), Suspension.class));
if (shopCreated.getSuspension().isSetActive()) {
shop.setSuspensionActiveSince(
TypeUtil.stringToLocalDateTime(shopCreated.getSuspension().getActive().getSince()));
} else if (shopCreated.getSuspension().isSetSuspended()) {
shop.setSuspensionSuspendedSince(
TypeUtil.stringToLocalDateTime(shopCreated.getSuspension().getSuspended().getSince()));
}
shop.setDetailsName(shopCreated.getDetails().getName());
shop.setDetailsDescription(shopCreated.getDetails().getDescription());
if (shopCreated.getLocation().isSetUrl()) {
shop.setLocationUrl(shopCreated.getLocation().getUrl());
} else {
throw new IllegalArgumentException("Illegal shop location " + shopCreated.getLocation());
}
shop.setCategoryId(shopCreated.getCategory().getId());
if (shopCreated.isSetAccount()) {
ShopUtil.fillShopAccount(shop, shopCreated.getAccount());
}
shop.setContractId(shopCreated.getContractId());
shop.setPayoutToolId(shopCreated.getPayoutToolId());
if (shopCreated.isSetPayoutSchedule()) {
shop.setPayoutScheduleId(shopCreated.getPayoutSchedule().getId());
}
return shop;
}
}

View File

@ -0,0 +1,59 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.damsel.domain.ShopDetails;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.ShopEffectUnit;
import com.empayre.dominator.dao.party.iface.ShopDao;
import com.empayre.dominator.domain.tables.pojos.Shop;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
@SuppressWarnings("VariableDeclarationUsageDistance")
public class ShopDetailsChangedHandler extends AbstractClaimChangedHandler {
private final ShopDao shopDao;
private final ClaimEffectCopyFactory<Shop, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetDetailsChanged()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e,
Integer claimEffectId) {
ShopEffectUnit shopEffect = e.getShopEffect();
ShopDetails detailsChanged = shopEffect.getEffect().getDetailsChanged();
String shopId = shopEffect.getShopId();
String partyId = event.getSourceId();
log.info("Start shop detailsChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
sequenceId, partyId, shopId, changeId);
final Shop shopOld = shopDao.get(partyId, shopId);
Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, shopOld);
shopNew.setDetailsName(detailsChanged.getName());
shopNew.setDetailsDescription(detailsChanged.getDescription());
shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "detailsChanged");
}
}

View File

@ -0,0 +1,60 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.damsel.domain.ShopLocation;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.ShopEffectUnit;
import com.empayre.dominator.dao.party.iface.ShopDao;
import com.empayre.dominator.domain.tables.pojos.Shop;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class ShopLocationChangedHandler extends AbstractClaimChangedHandler {
private final ShopDao shopDao;
private final ClaimEffectCopyFactory<Shop, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetLocationChanged()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect,
Integer claimEffectId) {
ShopEffectUnit shopEffect = claimEffect.getShopEffect();
ShopLocation locationChanged = shopEffect.getEffect().getLocationChanged();
String shopId = shopEffect.getShopId();
String partyId = event.getSourceId();
log.info("Start shop locationChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
sequenceId, partyId, shopId, changeId);
final Shop shopOld = shopDao.get(partyId, shopId);
Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, shopOld);
if (locationChanged.isSetUrl()) {
shopNew.setLocationUrl(locationChanged.getUrl());
} else {
throw new IllegalArgumentException("Illegal shop location " + locationChanged);
}
shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "locationChanged");
}
}

View File

@ -0,0 +1,61 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.ScheduleChanged;
import dev.vality.damsel.payment_processing.ShopEffectUnit;
import com.empayre.dominator.dao.party.iface.ShopDao;
import com.empayre.dominator.domain.tables.pojos.Shop;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class ShopPayoutScheduleChangedHandler extends AbstractClaimChangedHandler {
private final ShopDao shopDao;
private final ClaimEffectCopyFactory<Shop, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetPayoutScheduleChanged()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e,
Integer claimEffectId) {
ShopEffectUnit shopEffect = e.getShopEffect();
ScheduleChanged payoutScheduleChanged = shopEffect.getEffect().getPayoutScheduleChanged();
String shopId = shopEffect.getShopId();
String partyId = event.getSourceId();
log.info("Start shop payoutScheduleChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
sequenceId, partyId, shopId, changeId);
final Shop shopOld = shopDao.get(partyId, shopId);
Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, shopOld);
if (payoutScheduleChanged.isSetSchedule()) {
shopNew.setPayoutScheduleId(payoutScheduleChanged.getSchedule().getId());
} else {
shopNew.setPayoutScheduleId(null);
}
shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "payoutScheduleChanged");
}
}

View File

@ -0,0 +1,56 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
import dev.vality.damsel.payment_processing.ClaimEffect;
import dev.vality.damsel.payment_processing.PartyChange;
import dev.vality.damsel.payment_processing.ShopEffectUnit;
import com.empayre.dominator.dao.party.iface.ShopDao;
import com.empayre.dominator.domain.tables.pojos.Shop;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Slf4j
@Component
@RequiredArgsConstructor
public class ShopPayoutToolChangedHandler extends AbstractClaimChangedHandler {
private final ShopDao shopDao;
private final ClaimEffectCopyFactory<Shop, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
for (int i = 0; i < claimEffects.size(); i++) {
ClaimEffect claimEffect = claimEffects.get(i);
if (claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetPayoutToolChanged()) {
handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
}
}
}
private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e,
Integer claimEffectId) {
ShopEffectUnit shopEffect = e.getShopEffect();
String payoutToolChanged = shopEffect.getEffect().getPayoutToolChanged();
String shopId = shopEffect.getShopId();
String partyId = event.getSourceId();
log.info("Start shop payoutToolChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
sequenceId, partyId, shopId, changeId);
final Shop shopOld = shopDao.get(partyId, shopId);
Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, shopOld);
shopNew.setPayoutToolId(payoutToolChanged);
shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "payoutToolChanged");
}
}

View File

@ -0,0 +1,62 @@
package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
import com.empayre.dominator.handler.event.stock.impl.partymngmnt.PartyManagementHandler;
import dev.vality.damsel.domain.Suspension;
import dev.vality.damsel.payment_processing.PartyChange;
import com.empayre.dominator.dao.party.iface.ShopDao;
import com.empayre.dominator.domain.tables.pojos.Shop;
import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
import dev.vality.geck.common.util.TBaseUtil;
import dev.vality.geck.common.util.TypeUtil;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Component
@RequiredArgsConstructor
@SuppressWarnings("VariableDeclarationUsageDistance")
public class ShopSuspensionHandler implements PartyManagementHandler {
private final ShopDao shopDao;
private final ClaimEffectCopyFactory<Shop, Integer> claimEffectCopyFactory;
@Getter
private final Filter filter = new PathConditionFilter(new PathConditionRule("shop_suspension",
new IsNullCondition().not()));
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
Suspension suspension = change.getShopSuspension().getSuspension();
String shopId = change.getShopSuspension().getShopId();
String partyId = event.getSourceId();
log.info("Start shop suspension handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
sequenceId, partyId, shopId, changeId);
Shop shopOld = shopDao.get(partyId, shopId);
Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, -1, changeId, shopOld);
shopNew.setSuspension(
TBaseUtil.unionFieldToEnum(suspension, com.empayre.dominator.domain.enums.Suspension.class));
if (suspension.isSetActive()) {
shopNew.setSuspensionActiveSince(TypeUtil.stringToLocalDateTime(suspension.getActive().getSince()));
shopNew.setSuspensionSuspendedSince(null);
} else if (suspension.isSetSuspended()) {
shopNew.setSuspensionActiveSince(null);
shopNew.setSuspensionSuspendedSince(TypeUtil.stringToLocalDateTime(suspension.getSuspended().getSince()));
}
shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "suspension");
}
}

View File

@ -0,0 +1,64 @@
package com.empayre.dominator.handler.event.stock.impl.wallet;
import com.empayre.dominator.dao.identity.iface.IdentityDao;
import com.empayre.dominator.dao.wallet.iface.WalletDao;
import com.empayre.dominator.domain.tables.pojos.Identity;
import com.empayre.dominator.domain.tables.pojos.Wallet;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import dev.vality.fistful.account.Account;
import dev.vality.fistful.wallet.Change;
import dev.vality.fistful.wallet.TimestampedChange;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Component
@RequiredArgsConstructor
public class WalletAccountCreatedHandler implements WalletHandler {
private final IdentityDao identityDao;
private final WalletDao walletDao;
private final MachineEventCopyFactory<Wallet, String> walletMachineEventCopyFactory;
@Getter
private final Filter filter = new PathConditionFilter(
new PathConditionRule("change.account.created", new IsNullCondition().not()));
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(TimestampedChange timestampedChange, MachineEvent event) {
Change change = timestampedChange.getChange();
Account account = change.getAccount().getCreated();
long sequenceId = event.getEventId();
String walletId = event.getSourceId();
log.info("Start wallet account created handling, sequenceId={}, walletId={}",
sequenceId, walletId);
final Wallet walletOld = walletDao.get(walletId);
Identity identity = identityDao.get(account.getIdentity());
Wallet walletNew = walletMachineEventCopyFactory
.create(event, sequenceId, walletId, walletOld, timestampedChange.getOccuredAt());
walletNew.setIdentityId(account.getIdentity());
walletNew.setAccountId(account.getId());
walletNew.setPartyId(identity.getPartyId());
walletNew.setAccounterAccountId(account.getAccounterAccountId());
walletNew.setCurrencyCode(account.getCurrency().getSymbolicCode());
walletDao.save(walletNew).ifPresentOrElse(
id -> {
walletDao.updateNotCurrent(walletOld.getId());
log.info("Wallet account have been changed, sequenceId={}, walletId={}", sequenceId, walletId);
},
() -> log.info("Wallet account have been saved, sequenceId={}, walletId={}", sequenceId, walletId));
}
}

View File

@ -0,0 +1,47 @@
package com.empayre.dominator.handler.event.stock.impl.wallet;
import com.empayre.dominator.dao.wallet.iface.WalletDao;
import com.empayre.dominator.domain.tables.pojos.Wallet;
import com.empayre.dominator.factory.machine.event.MachineEventCopyFactory;
import dev.vality.fistful.wallet.Change;
import dev.vality.fistful.wallet.TimestampedChange;
import dev.vality.geck.filter.Filter;
import dev.vality.geck.filter.PathConditionFilter;
import dev.vality.geck.filter.condition.IsNullCondition;
import dev.vality.geck.filter.rule.PathConditionRule;
import dev.vality.machinegun.eventsink.MachineEvent;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Slf4j
@Component
@RequiredArgsConstructor
public class WalletCreatedHandler implements WalletHandler {
private final WalletDao walletDao;
private final MachineEventCopyFactory<Wallet, String> walletMachineEventCopyFactory;
@Getter
private final Filter filter =
new PathConditionFilter(new PathConditionRule("change.created", new IsNullCondition().not()));
@Override
public void handle(TimestampedChange timestampedChange, MachineEvent event) {
Change change = timestampedChange.getChange();
long sequenceId = event.getEventId();
String walletId = event.getSourceId();
log.info("Start wallet created handling, sequenceId={}, walletId={}", sequenceId, walletId);
Wallet wallet =
walletMachineEventCopyFactory.create(event, sequenceId, walletId, timestampedChange.getOccuredAt());
wallet.setWalletName(change.getCreated().getName());
wallet.setExternalId(change.getCreated().getExternalId());
walletDao.save(wallet).ifPresentOrElse(
id -> log.info("Wallet created has been saved, sequenceId={}, walletId={}", sequenceId, walletId),
() -> log.info("Wallet created bound duplicated, sequenceId={}, walletId={}", sequenceId, walletId));
}
}

View File

@ -0,0 +1,8 @@
package com.empayre.dominator.handler.event.stock.impl.wallet;
import com.empayre.dominator.handler.event.stock.Handler;
import dev.vality.fistful.wallet.TimestampedChange;
import dev.vality.machinegun.eventsink.MachineEvent;
public interface WalletHandler extends Handler<TimestampedChange, MachineEvent> {
}

View File

@ -0,0 +1,36 @@
package com.empayre.dominator.listener;
import com.empayre.dominator.service.IdentityService;
import dev.vality.kafka.common.util.LogUtil;
import dev.vality.machinegun.eventsink.SinkEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@RequiredArgsConstructor
@Service
public class IdentityKafkaListener {
private final IdentityService identityService;
@KafkaListener(
autoStartup = "${kafka.topics.identity.enabled}",
topics = "${kafka.topics.identity.id}",
containerFactory = "identityContainerFactory")
public void handle(List<ConsumerRecord<String, SinkEvent>> messages, Acknowledgment ack) {
log.info("Got machineEvent batch with size: {}", messages.size());
identityService.handleEvents(messages.stream()
.map(m -> m.value().getEvent())
.collect(Collectors.toList()));
ack.acknowledge();
log.info("Batch has been committed, size={}, {}", messages.size(),
LogUtil.toSummaryStringWithSinkEventValues(messages));
}
}

View File

@ -0,0 +1,38 @@
package com.empayre.dominator.listener;
import com.empayre.dominator.service.PartyManagementService;
import dev.vality.kafka.common.util.LogUtil;
import dev.vality.machinegun.eventsink.SinkEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@RequiredArgsConstructor
@Service
public class PartyManagementListener {
private final PartyManagementService partyManagementService;
@KafkaListener(
autoStartup = "${kafka.topics.party-management.enabled}",
topics = "${kafka.topics.party-management.id}",
containerFactory = "partyManagementContainerFactory")
public void handle(List<ConsumerRecord<String, SinkEvent>> messages, Acknowledgment ack) {
log.info("Got partyManagement machineEvent batch with size: {}", messages.size());
partyManagementService.handleEvents(
messages.stream()
.map(m -> m.value().getEvent())
.collect(Collectors.toList())
);
ack.acknowledge();
log.info("Batch partyManagement has been committed, size={}, {}", messages.size(),
LogUtil.toSummaryStringWithSinkEventValues(messages));
}
}

View File

@ -0,0 +1,36 @@
package com.empayre.dominator.listener;
import com.empayre.dominator.service.WalletService;
import dev.vality.kafka.common.util.LogUtil;
import dev.vality.machinegun.eventsink.SinkEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@RequiredArgsConstructor
@Service
public class WalletKafkaListener {
private final WalletService walletService;
@KafkaListener(
autoStartup = "${kafka.topics.wallet.enabled}",
topics = "${kafka.topics.wallet.id}",
containerFactory = "walletContainerFactory")
public void handle(List<ConsumerRecord<String, SinkEvent>> messages, Acknowledgment ack) {
log.info("Got machineEvent batch with size: {}", messages.size());
walletService.handleEvents(messages.stream()
.map(m -> m.value().getEvent())
.collect(Collectors.toList()));
ack.acknowledge();
log.info("Batch has been committed, size={}, {}", messages.size(),
LogUtil.toSummaryStringWithSinkEventValues(messages));
}
}

View File

@ -0,0 +1,82 @@
package com.empayre.dominator.model;
import dev.vality.damsel.domain.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public enum CashFlowType {
UNKNOWN(Collections.emptyList(), Collections.emptyList()),
AMOUNT(
CashFlowAccount.provider(ProviderCashFlowAccount.settlement),
CashFlowAccount.merchant(MerchantCashFlowAccount.settlement)
),
EXTERNAL_FEE(
CashFlowAccount.system(SystemCashFlowAccount.settlement),
Arrays.asList(
CashFlowAccount.external(ExternalCashFlowAccount.income),
CashFlowAccount.external(ExternalCashFlowAccount.outcome)
)
),
PROVIDER_FEE(
CashFlowAccount.system(SystemCashFlowAccount.settlement),
CashFlowAccount.provider(ProviderCashFlowAccount.settlement)
),
RETURN_FEE(
CashFlowAccount.system(SystemCashFlowAccount.settlement),
CashFlowAccount.merchant(MerchantCashFlowAccount.settlement)
),
FEE(
CashFlowAccount.merchant(MerchantCashFlowAccount.settlement),
CashFlowAccount.system(SystemCashFlowAccount.settlement)
),
REFUND_AMOUNT(
CashFlowAccount.merchant(MerchantCashFlowAccount.settlement),
CashFlowAccount.provider(ProviderCashFlowAccount.settlement)
),
GUARANTEE_DEPOSIT(
CashFlowAccount.merchant(MerchantCashFlowAccount.settlement),
CashFlowAccount.merchant(MerchantCashFlowAccount.guarantee)
);
private final List<CashFlowAccount> sources;
private final List<CashFlowAccount> destinations;
CashFlowType(CashFlowAccount source, CashFlowAccount destination) {
this(Collections.singletonList(source), Collections.singletonList(destination));
}
CashFlowType(CashFlowAccount source, List<CashFlowAccount> destinations) {
this(Collections.singletonList(source), destinations);
}
CashFlowType(List<CashFlowAccount> sources, List<CashFlowAccount> destinations) {
this.sources = sources;
this.destinations = destinations;
}
public static CashFlowType getCashFlowType(FinalCashFlowPosting cashFlowPosting) {
return getCashFlowType(cashFlowPosting.getSource().getAccountType(),
cashFlowPosting.getDestination().getAccountType());
}
public static CashFlowType getCashFlowType(CashFlowAccount source, CashFlowAccount destination) {
for (CashFlowType cashFlowType : values()) {
if (cashFlowType.sources.contains(source) && cashFlowType.destinations.contains(destination)) {
return cashFlowType;
}
}
return UNKNOWN;
}
public List<CashFlowAccount> getSources() {
return sources;
}
public List<CashFlowAccount> getDestinations() {
return destinations;
}
}

View File

@ -0,0 +1,11 @@
package com.empayre.dominator.model;
import lombok.Data;
@Data
public class PartyShop {
private final String partyId;
private final String shopId;
}

Some files were not shown because too many files have changed in this diff Show More