diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a654702..4d5c06c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,4 +7,4 @@ on: jobs: build: - uses: valitydev/java-workflow/.github/workflows/maven-service-build.yml@v1 + uses: valitydev/java-workflow/.github/workflows/maven-service-build.yml@v2 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index eee65bd..dfef0b7 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,7 +7,7 @@ on: jobs: build-and-deploy: - uses: valitydev/java-workflow/.github/workflows/maven-service-deploy.yml@v1 + uses: valitydev/java-workflow/.github/workflows/maven-service-deploy.yml@v2 secrets: github-token: ${{ secrets.GITHUB_TOKEN }} mm-webhook-url: ${{ secrets.MATTERMOST_WEBHOOK_URL }} diff --git a/pom.xml b/pom.xml index b49fd70..77318da 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.vality service-parent-pom - 1.0.18 + 2.1.8 deanonimus @@ -27,14 +27,6 @@ - - dev.vality.woody - woody-thrift - - - dev.vality - shared-resources - dev.vality kafka-common-lib @@ -63,7 +55,7 @@ dev.vality deanonimus-proto - 1.36-94fb655 + 1.40-2a02d87 @@ -84,22 +76,14 @@ org.springframework.boot spring-boot-starter-actuator - - org.springframework.data - spring-data-elasticsearch - - 4.2.1 - - - org.elasticsearch.client - elasticsearch-rest-high-level-client - - - org.springframework.kafka spring-kafka + + org.springframework.boot + spring-boot-starter-validation + @@ -118,7 +102,7 @@ org.projectlombok lombok - 1.18.22 + 1.18.26 org.apache.commons @@ -126,19 +110,34 @@ 3.12.0 - org.elasticsearch - elasticsearch - 7.12.1 + org.opensearch + opensearch + 2.11.0 - org.elasticsearch.client - elasticsearch-rest-high-level-client - 7.12.1 + org.opensearch.client + opensearch-rest-client + 2.11.0 + + + org.opensearch.client + opensearch-java + 2.8.0 + + + jakarta.json + jakarta.json-api + 2.1.3 software.amazon.msk aws-msk-iam-auth + + org.jetbrains + annotations + 24.1.0 + @@ -154,19 +153,25 @@ org.awaitility awaitility - 4.0.3 test org.testcontainers kafka - 1.16.2 + 1.17.6 test org.testcontainers - elasticsearch - 1.16.2 + testcontainers + 1.17.6 + test + + + org.testcontainers + junit-jupiter + 1.17.6 + test @@ -200,12 +205,12 @@ org.apache.maven.plugins maven-remote-resources-plugin - 1.6.0 + 3.0.0 org.apache.maven.shared maven-filtering - 1.3 + 3.3.1 diff --git a/src/main/java/dev/vality/deanonimus/config/ElasticsearchConfig.java b/src/main/java/dev/vality/deanonimus/config/ElasticsearchConfig.java deleted file mode 100644 index c09452a..0000000 --- a/src/main/java/dev/vality/deanonimus/config/ElasticsearchConfig.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.vality.deanonimus.config; - -import org.springframework.context.annotation.Configuration; -import org.springframework.data.elasticsearch.config.ElasticsearchConfigurationSupport; - -@Configuration -public class ElasticsearchConfig extends ElasticsearchConfigurationSupport { - -} diff --git a/src/main/java/dev/vality/deanonimus/config/OpenSearchClientConfig.java b/src/main/java/dev/vality/deanonimus/config/OpenSearchClientConfig.java new file mode 100644 index 0000000..519c615 --- /dev/null +++ b/src/main/java/dev/vality/deanonimus/config/OpenSearchClientConfig.java @@ -0,0 +1,74 @@ +package dev.vality.deanonimus.config; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import lombok.SneakyThrows; +import org.apache.http.HttpHost; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.conn.ssl.NoopHostnameVerifier; +import org.apache.http.impl.client.BasicCredentialsProvider; +import org.opensearch.client.RestClient; +import org.opensearch.client.RestClientBuilder; +import org.opensearch.client.json.jackson.JacksonJsonpMapper; +import org.opensearch.client.opensearch.OpenSearchClient; +import org.opensearch.client.transport.rest_client.RestClientTransport; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManagerFactory; +import java.io.InputStream; +import java.security.KeyStore; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; + +@Configuration +public class OpenSearchClientConfig { + + @Bean(destroyMethod = "close") + public RestClient restClient(OpenSearchProperties openSearchProperties) { + var httpHost = new HttpHost(openSearchProperties.getHostname(), + openSearchProperties.getPort(), + openSearchProperties.getSslEnabled() ? "https" : "http"); + RestClientBuilder restClientBuilder = RestClient.builder(httpHost); + if (openSearchProperties.getSslEnabled()) { + final var credentialsProvider = new BasicCredentialsProvider(); + credentialsProvider.setCredentials( + AuthScope.ANY, + new UsernamePasswordCredentials( + openSearchProperties.getUsername(), + openSearchProperties.getPassword())); + restClientBuilder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder + .setDefaultCredentialsProvider(credentialsProvider) + .setSSLContext(sslContext(openSearchProperties.getCertificate())) + .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)); + } + return restClientBuilder.build(); + } + + @Bean + public OpenSearchClient openSearchClient(RestClient restClient) { + var transport = new RestClientTransport(restClient, + new JacksonJsonpMapper(new ObjectMapper().registerModule(new JavaTimeModule()))); + return new OpenSearchClient(transport); + } + + @SneakyThrows + private SSLContext sslContext(Resource certificate) { + var tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); + try (InputStream pKeyFileStream = certificate.getInputStream()) { + var cf = CertificateFactory.getInstance("X.509"); + var caCert = (X509Certificate) cf.generateCertificate(pKeyFileStream); + var ks = KeyStore.getInstance(KeyStore.getDefaultType()); + ks.load(null); + ks.setCertificateEntry("caCert", caCert); + tmf.init(ks); + } + var sslContext = SSLContext.getInstance("TLS"); + sslContext.init(null, tmf.getTrustManagers(), null); + return sslContext; + } + +} diff --git a/src/main/java/dev/vality/deanonimus/config/OpenSearchProperties.java b/src/main/java/dev/vality/deanonimus/config/OpenSearchProperties.java new file mode 100644 index 0000000..1424515 --- /dev/null +++ b/src/main/java/dev/vality/deanonimus/config/OpenSearchProperties.java @@ -0,0 +1,19 @@ +package dev.vality.deanonimus.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; + +@Data +@Configuration +@ConfigurationProperties(prefix = "opensearch") +public class OpenSearchProperties { + + private String username; + private String password; + private String hostname; + private Integer port; + private Resource certificate; + private Boolean sslEnabled; +} diff --git a/src/main/java/dev/vality/deanonimus/constant/ElasticsearchConstants.java b/src/main/java/dev/vality/deanonimus/constant/OpenSearchConstants.java similarity index 60% rename from src/main/java/dev/vality/deanonimus/constant/ElasticsearchConstants.java rename to src/main/java/dev/vality/deanonimus/constant/OpenSearchConstants.java index cff26db..d7ef759 100644 --- a/src/main/java/dev/vality/deanonimus/constant/ElasticsearchConstants.java +++ b/src/main/java/dev/vality/deanonimus/constant/OpenSearchConstants.java @@ -1,7 +1,9 @@ package dev.vality.deanonimus.constant; -public class ElasticsearchConstants { +public class OpenSearchConstants { + public static final String PARTY_INDEX = "party"; public static final String SHOP_INDEX = "shops"; + public static final String WALLET_INDEX = "wallets"; public static final String CONTRACT_INDEX = "contracts"; public static final String CONTRACTOR_INDEX = "contractors"; } diff --git a/src/main/java/dev/vality/deanonimus/converter/ContractorConverter.java b/src/main/java/dev/vality/deanonimus/converter/ContractorConverter.java index 6fadeed..f7e890c 100644 --- a/src/main/java/dev/vality/deanonimus/converter/ContractorConverter.java +++ b/src/main/java/dev/vality/deanonimus/converter/ContractorConverter.java @@ -2,9 +2,9 @@ package dev.vality.deanonimus.converter; import dev.vality.damsel.deanonimus.*; import dev.vality.deanonimus.domain.Contractor; -import org.jetbrains.annotations.NotNull; import org.springframework.stereotype.Component; +import javax.validation.constraints.NotNull; import java.util.Collections; import java.util.List; import java.util.Map; @@ -35,7 +35,6 @@ public class ContractorConverter { case legal_entity -> legal_entity(convertLegalEntity(contractor)); case private_entity -> private_entity(new PrivateEntity()); case registered_user -> registered_user(new RegisteredUser(contractor.getRegisteredUserEmail())); - default -> throw new IllegalArgumentException("No such contractorType: " + contractor.getType()); }; } @@ -43,7 +42,6 @@ public class ContractorConverter { return switch (contractor.getLegalEntity()) { case international_legal_entity -> buildInternationalLegalEntity(contractor); case russian_legal_entity -> buildRussianLegalEntity(contractor); - default -> throw new IllegalArgumentException("No such legalEntity " + contractor.getLegalEntity()); }; } diff --git a/src/main/java/dev/vality/deanonimus/converter/SearchHitConverter.java b/src/main/java/dev/vality/deanonimus/converter/SearchHitConverter.java index 0befa79..59beea4 100644 --- a/src/main/java/dev/vality/deanonimus/converter/SearchHitConverter.java +++ b/src/main/java/dev/vality/deanonimus/converter/SearchHitConverter.java @@ -3,7 +3,8 @@ package dev.vality.deanonimus.converter; import dev.vality.damsel.deanonimus.SearchHit; import dev.vality.deanonimus.domain.Party; import lombok.RequiredArgsConstructor; -import org.springframework.data.elasticsearch.core.SearchHits; +import org.opensearch.client.opensearch.core.SearchResponse; +import org.opensearch.client.opensearch.core.search.Hit; import org.springframework.stereotype.Component; import java.util.List; @@ -16,14 +17,14 @@ public class SearchHitConverter { private final PartyConverter partyConverter; - public List convert(SearchHits searchHits) { - return searchHits.stream() + public List convert(SearchResponse searchHits) { + return searchHits.hits().hits().stream() .map(this::convertSearchHit) .collect(toList()); } - private SearchHit convertSearchHit(org.springframework.data.elasticsearch.core.SearchHit partySearchHit) { - return new SearchHit(partySearchHit.getScore(), partyConverter.convert(partySearchHit.getContent())); + private SearchHit convertSearchHit(Hit partySearchHit) { + return new SearchHit(partySearchHit.score(), partyConverter.convert(partySearchHit.source())); } } diff --git a/src/main/java/dev/vality/deanonimus/converter/SearchHitShopConverter.java b/src/main/java/dev/vality/deanonimus/converter/SearchHitShopConverter.java index c28bb90..ba4c3d6 100644 --- a/src/main/java/dev/vality/deanonimus/converter/SearchHitShopConverter.java +++ b/src/main/java/dev/vality/deanonimus/converter/SearchHitShopConverter.java @@ -3,29 +3,30 @@ package dev.vality.deanonimus.converter; import dev.vality.damsel.deanonimus.SearchShopHit; import dev.vality.deanonimus.domain.Party; import lombok.RequiredArgsConstructor; -import org.springframework.data.elasticsearch.core.SearchHit; -import org.springframework.data.elasticsearch.core.SearchHits; +import org.opensearch.client.opensearch.core.SearchResponse; +import org.opensearch.client.opensearch.core.search.Hit; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.List; -import static java.util.stream.Collectors.toList; - @Component @RequiredArgsConstructor public class SearchHitShopConverter { - private final ShopListConverter converter; + private final ShopListConverter shopListConverter; + private final PartyConverter partyConverter; - public List convert(SearchHits searchHits) { + + public List convert(SearchResponse searchHits) { List hits = new ArrayList<>(); - for (SearchHit searchHit : searchHits) { - hits.addAll(converter.convert(searchHit.getContent().getShops()).values() + for (Hit searchHit : searchHits.hits().hits()) { + hits.addAll(shopListConverter.convert(searchHit.source().getShops()).values() .stream() - .map(shop -> new SearchShopHit(searchHit.getScore(), shop)) - .collect(toList())); + .map(shop -> new SearchShopHit(searchHit.score(), shop, partyConverter.convert(searchHit.source()))) + .toList()); } + return hits; } } diff --git a/src/main/java/dev/vality/deanonimus/converter/SearchHitWalletConverter.java b/src/main/java/dev/vality/deanonimus/converter/SearchHitWalletConverter.java new file mode 100644 index 0000000..bfa0529 --- /dev/null +++ b/src/main/java/dev/vality/deanonimus/converter/SearchHitWalletConverter.java @@ -0,0 +1,35 @@ +package dev.vality.deanonimus.converter; + +import dev.vality.damsel.deanonimus.SearchWalletHit; +import dev.vality.deanonimus.domain.Party; +import lombok.RequiredArgsConstructor; +import org.opensearch.client.opensearch.core.SearchResponse; +import org.opensearch.client.opensearch.core.search.Hit; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +@RequiredArgsConstructor +public class SearchHitWalletConverter { + + private final WalletListConverter walletListConverter; + private final PartyConverter partyConverter; + + + public List convert(SearchResponse searchHits) { + List hits = new ArrayList<>(); + for (Hit searchHit : searchHits.hits().hits()) { + hits.addAll(walletListConverter.convert(searchHit.source().getWallets()).values() + .stream() + .map(wallet -> new SearchWalletHit( + searchHit.score(), + wallet, + partyConverter.convert(searchHit.source()))) + .toList()); + } + + return hits; + } +} diff --git a/src/main/java/dev/vality/deanonimus/converter/WalletListConverter.java b/src/main/java/dev/vality/deanonimus/converter/WalletListConverter.java new file mode 100644 index 0000000..6d6a12e --- /dev/null +++ b/src/main/java/dev/vality/deanonimus/converter/WalletListConverter.java @@ -0,0 +1,30 @@ +package dev.vality.deanonimus.converter; + +import dev.vality.damsel.deanonimus.Wallet; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +@Component +@RequiredArgsConstructor +public class WalletListConverter { + + public Map convert(List wallets) { + return Optional.ofNullable(wallets).orElse(Collections.emptyList()) + .stream() + .map(this::convertToEntity) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a)); + } + + private Map.Entry convertToEntity(dev.vality.deanonimus.domain.Wallet walletDomain) { + return Map.entry(walletDomain.getId(), new Wallet( + walletDomain.getId(), + walletDomain.getName() + )); + } +} diff --git a/src/main/java/dev/vality/deanonimus/db/PartyRepository.java b/src/main/java/dev/vality/deanonimus/db/PartyRepository.java deleted file mode 100644 index d66594b..0000000 --- a/src/main/java/dev/vality/deanonimus/db/PartyRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.vality.deanonimus.db; - -import dev.vality.deanonimus.domain.Party; -import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; -import org.springframework.stereotype.Repository; - -@Repository -public interface PartyRepository extends ElasticsearchRepository { - - -} diff --git a/src/main/java/dev/vality/deanonimus/db/SearchDao.java b/src/main/java/dev/vality/deanonimus/db/SearchDao.java index 8596808..390295b 100644 --- a/src/main/java/dev/vality/deanonimus/db/SearchDao.java +++ b/src/main/java/dev/vality/deanonimus/db/SearchDao.java @@ -1,10 +1,10 @@ package dev.vality.deanonimus.db; import dev.vality.deanonimus.domain.Party; -import org.springframework.data.elasticsearch.core.SearchHits; +import org.opensearch.client.opensearch.core.SearchResponse; public interface SearchDao { - SearchHits searchParty(String text); + SearchResponse searchParty(String text); } diff --git a/src/main/java/dev/vality/deanonimus/db/SearchDaoImpl.java b/src/main/java/dev/vality/deanonimus/db/SearchDaoImpl.java index 777fa22..3d02814 100644 --- a/src/main/java/dev/vality/deanonimus/db/SearchDaoImpl.java +++ b/src/main/java/dev/vality/deanonimus/db/SearchDaoImpl.java @@ -2,19 +2,15 @@ package dev.vality.deanonimus.db; import dev.vality.deanonimus.domain.Party; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; -import org.apache.lucene.search.join.ScoreMode; -import org.elasticsearch.index.query.QueryBuilder; +import org.opensearch.client.opensearch.OpenSearchClient; +import org.opensearch.client.opensearch._types.query_dsl.*; +import org.opensearch.client.opensearch.core.SearchResponse; import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; -import org.springframework.data.elasticsearch.core.SearchHits; -import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; -import org.springframework.data.elasticsearch.core.query.Query; import org.springframework.stereotype.Component; -import static dev.vality.deanonimus.constant.ElasticsearchConstants.*; -import static org.elasticsearch.index.query.QueryBuilders.*; +import static dev.vality.deanonimus.constant.OpenSearchConstants.*; @Slf4j @Component @@ -24,59 +20,91 @@ public class SearchDaoImpl implements SearchDao { @Value("${data.response.limit}") Integer responseLimit; - private final ElasticsearchRestTemplate elasticsearchRestTemplate; + private final OpenSearchClient openSearchClient; + + @SneakyThrows @Override - public SearchHits searchParty(String text) { + public SearchResponse searchParty(String text) { - QueryBuilder builder = boolQuery() - .should(searchPartyFields(text)) - .should(searchShopFields(text)) - .should(searchContractFields(text)) - .should(searchContractorFields(text)); - - Query searchQuery = new NativeSearchQueryBuilder() - .withQuery(builder) - .withPageable(PageRequest.of(0, responseLimit)) + BoolQuery queryBuilder = new BoolQuery.Builder() + .should(searchPartyFields(text), + searchShopFields(text), + searchContractFields(text), + searchContractorFields(text), + searchWalletFields(text)) .build(); - return elasticsearchRestTemplate.search(searchQuery, Party.class); + return openSearchClient.search(s -> s + .size(responseLimit) + .query(new Query.Builder() + .bool(queryBuilder) + .build()), + Party.class); } - private QueryBuilder searchContractorFields(String text) { - return nestedQuery(CONTRACTOR_INDEX, - multiMatchQuery(text, - "contractors.id", - "contractors.registeredUserEmail", - "contractors.russianLegalEntityRegisteredName", - "contractors.russianLegalEntityInn", - "contractors.russianLegalEntityRussianBankAccount", - "contractors.internationalLegalEntityLegalName", - "contractors.internationalLegalEntityTradingName"), ScoreMode.Total); + private Query searchContractorFields(String text) { + return new NestedQuery.Builder() + .path(CONTRACTOR_INDEX) + .query(new Query(new MultiMatchQuery.Builder() + .fields("contractors.id", + "contractors.registeredUserEmail", + "contractors.russianLegalEntityRegisteredName", + "contractors.russianLegalEntityInn", + "contractors.russianLegalEntityRussianBankAccount", + "contractors.internationalLegalEntityLegalName", + "contractors.internationalLegalEntityTradingName") + .query(text) + .type(TextQueryType.Phrase) + .build())) + .build().query(); } - private QueryBuilder searchContractFields(String text) { - return nestedQuery(CONTRACT_INDEX, - multiMatchQuery(text, - "contracts.id", - "contracts.legalAgreementId", - "contracts.reportActSignerFullName"), ScoreMode.Total); + private Query searchContractFields(String text) { + return new NestedQuery.Builder() + .path(CONTRACT_INDEX) + .query(new Query(new MultiMatchQuery.Builder() + .fields("contracts.id", + "contracts.legalAgreementId", + "contracts.reportActSignerFullName") + .query(text) + .type(TextQueryType.Phrase) + .build())) + .build().query(); } - - private QueryBuilder searchPartyFields(String text) { - return multiMatchQuery(text, - "id", - "email" - ); + private Query searchPartyFields(String text) { + return new Query(new MultiMatchQuery.Builder() + .fields("id", + "email") + .query(text) + .type(TextQueryType.Phrase) + .build()); } - private QueryBuilder searchShopFields(String text) { - return nestedQuery(SHOP_INDEX, - multiMatchQuery(text, - "shops.id", - "shops.locationUrl" - ), ScoreMode.Total); + private Query searchShopFields(String text) { + return new NestedQuery.Builder() + .path(SHOP_INDEX) + .query(new Query(new MultiMatchQuery.Builder() + .fields("shops.id", + "shops.locationUrl", + "shops.detailsName") + .query(text) + .type(TextQueryType.Phrase) + .build())) + .build().query(); + } + + private Query searchWalletFields(String text) { + return new NestedQuery.Builder() + .path(WALLET_INDEX) + .query(new Query(new MultiMatchQuery.Builder() + .fields("wallets.id", + "wallets.name") + .query(text) + .type(TextQueryType.Phrase) + .build())) + .build().query(); } } diff --git a/src/main/java/dev/vality/deanonimus/domain/Contract.java b/src/main/java/dev/vality/deanonimus/domain/Contract.java index 2e81b0e..37ddad6 100644 --- a/src/main/java/dev/vality/deanonimus/domain/Contract.java +++ b/src/main/java/dev/vality/deanonimus/domain/Contract.java @@ -4,8 +4,6 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import org.springframework.data.elasticsearch.annotations.Field; -import org.springframework.data.elasticsearch.annotations.FieldType; import java.time.LocalDateTime; @@ -14,7 +12,6 @@ import java.time.LocalDateTime; @NoArgsConstructor @AllArgsConstructor public class Contract { - @Field(type = FieldType.Keyword) private String id; private String contractorId; private String partyId; @@ -23,8 +20,6 @@ public class Contract { private LocalDateTime validUntil; private ContractStatus status; private Integer termsId; - @Field(type = FieldType.Text, analyzer = "autocomplete", searchAnalyzer = "standard") private String legalAgreementId; - @Field(type = FieldType.Text, analyzer = "autocomplete", searchAnalyzer = "standard") private String reportActSignerFullName; } diff --git a/src/main/java/dev/vality/deanonimus/domain/Contractor.java b/src/main/java/dev/vality/deanonimus/domain/Contractor.java index 845e3a3..a7748d4 100644 --- a/src/main/java/dev/vality/deanonimus/domain/Contractor.java +++ b/src/main/java/dev/vality/deanonimus/domain/Contractor.java @@ -4,36 +4,27 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import org.springframework.data.elasticsearch.annotations.Field; -import org.springframework.data.elasticsearch.annotations.FieldType; @Data @Builder @NoArgsConstructor @AllArgsConstructor public class Contractor { - @Field(type = FieldType.Keyword) private String id; private String partyId; private ContractorType type; - @Field(type = FieldType.Text, analyzer = "autocomplete", searchAnalyzer = "standard") private String registeredUserEmail; private LegalEntity legalEntity; - @Field(type = FieldType.Text, analyzer = "autocomplete", searchAnalyzer = "standard") private String russianLegalEntityRegisteredName; private String russianLegalEntityRegisteredNumber; - @Field(type = FieldType.Keyword) private String russianLegalEntityInn; private String russianLegalEntityActualAddress; private String russianLegalEntityPostAddress; - @Field(type = FieldType.Keyword) private String russianLegalEntityRussianBankAccount; private String russianLegalEntityRussianBankName; private String russianLegalEntityRussianBankPostAccount; private String russianLegalEntityRussianBankBik; - @Field(type = FieldType.Text, analyzer = "autocomplete", searchAnalyzer = "standard") private String internationalLegalEntityLegalName; - @Field(type = FieldType.Text, analyzer = "autocomplete", searchAnalyzer = "standard") private String internationalLegalEntityTradingName; private String internationalLegalEntityRegisteredAddress; private String internationalLegalEntityActualAddress; diff --git a/src/main/java/dev/vality/deanonimus/domain/Party.java b/src/main/java/dev/vality/deanonimus/domain/Party.java index df1f6a3..ea20ecb 100644 --- a/src/main/java/dev/vality/deanonimus/domain/Party.java +++ b/src/main/java/dev/vality/deanonimus/domain/Party.java @@ -4,11 +4,6 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import org.springframework.data.annotation.Id; -import org.springframework.data.elasticsearch.annotations.Document; -import org.springframework.data.elasticsearch.annotations.Field; -import org.springframework.data.elasticsearch.annotations.FieldType; -import org.springframework.data.elasticsearch.annotations.Setting; import java.util.ArrayList; import java.util.List; @@ -18,25 +13,18 @@ import java.util.Optional; @Builder @NoArgsConstructor @AllArgsConstructor -@Document(indexName = "party") -@Setting(settingPath = "/settings/autocomplete-analyzer.json") public class Party { - @Id - @Field(type = FieldType.Keyword) private String id; - @Field(type = FieldType.Text, analyzer = "autocomplete", searchAnalyzer = "standard") private String email; private Blocking blocking; private Suspension suspension; - @Field(type = FieldType.Nested, store = true) private List contractors; - @Field(type = FieldType.Nested, store = true) private List contracts; - @Field(type = FieldType.Nested, store = true) private List shops; + private List wallets; public void addShop(Shop shop) { if (this.shops == null) { @@ -59,6 +47,13 @@ public class Party { this.contractors.add(contractor); } + public void addWallet(Wallet wallet) { + if (this.wallets == null) { + this.wallets = new ArrayList<>(); + } + this.wallets.add(wallet); + } + public Optional getShopById(String id) { return this.shops.stream().filter(shop -> shop.getId().equals(id)).findFirst(); } @@ -66,9 +61,4 @@ public class Party { public Optional getContractById(String id) { return this.contracts.stream().filter(contract -> contract.getId().equals(id)).findFirst(); } - - public Optional getContractorById(String id) { - return this.contractors.stream().filter(contractor -> contractor.getId().equals(id)).findFirst(); - } - } diff --git a/src/main/java/dev/vality/deanonimus/domain/Shop.java b/src/main/java/dev/vality/deanonimus/domain/Shop.java index 201c37e..7c00af7 100644 --- a/src/main/java/dev/vality/deanonimus/domain/Shop.java +++ b/src/main/java/dev/vality/deanonimus/domain/Shop.java @@ -4,21 +4,17 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import org.springframework.data.elasticsearch.annotations.Field; -import org.springframework.data.elasticsearch.annotations.FieldType; @Data @Builder @NoArgsConstructor @AllArgsConstructor public class Shop { - @Field(type = FieldType.Keyword) private String id; private Blocking blocking; private Suspension suspension; private String detailsName; private String detailsDescription; - @Field(type = FieldType.Text, analyzer = "autocomplete", searchAnalyzer = "write_url_analyzer") private String locationUrl; private Integer categoryId; private String accountCurrencyCode; diff --git a/src/main/java/dev/vality/deanonimus/domain/Wallet.java b/src/main/java/dev/vality/deanonimus/domain/Wallet.java new file mode 100644 index 0000000..1a65754 --- /dev/null +++ b/src/main/java/dev/vality/deanonimus/domain/Wallet.java @@ -0,0 +1,15 @@ +package dev.vality.deanonimus.domain; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Wallet { + private String id; + private String name; +} diff --git a/src/main/java/dev/vality/deanonimus/handler/DeanonimusServiceHandler.java b/src/main/java/dev/vality/deanonimus/handler/DeanonimusServiceHandler.java index 5099cfc..3155631 100644 --- a/src/main/java/dev/vality/deanonimus/handler/DeanonimusServiceHandler.java +++ b/src/main/java/dev/vality/deanonimus/handler/DeanonimusServiceHandler.java @@ -3,15 +3,15 @@ package dev.vality.deanonimus.handler; import dev.vality.damsel.deanonimus.DeanonimusSrv; import dev.vality.damsel.deanonimus.SearchHit; import dev.vality.damsel.deanonimus.SearchShopHit; +import dev.vality.damsel.deanonimus.SearchWalletHit; import dev.vality.deanonimus.converter.SearchHitConverter; import dev.vality.deanonimus.converter.SearchHitShopConverter; +import dev.vality.deanonimus.converter.SearchHitWalletConverter; import dev.vality.deanonimus.db.SearchDao; import dev.vality.deanonimus.domain.Party; -import dev.vality.deanonimus.domain.Shop; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.thrift.TException; -import org.springframework.data.elasticsearch.core.SearchHits; +import org.opensearch.client.opensearch.core.SearchResponse; import org.springframework.stereotype.Component; import java.util.List; @@ -23,21 +23,30 @@ public class DeanonimusServiceHandler implements DeanonimusSrv.Iface { private final SearchHitConverter searchHitConverter; private final SearchHitShopConverter searchHitShopConverter; + private final SearchHitWalletConverter searchHitWalletConverter; private final SearchDao searchDao; @Override - public List searchParty(String text) throws TException { + public List searchParty(String text) { log.info("Incoming request for party with text: {}", text); - SearchHits searchHits = searchDao.searchParty(text); + SearchResponse searchHits = searchDao.searchParty(text); log.info("Found party: {}", searchHits); return searchHitConverter.convert(searchHits); } @Override - public List searchShopText(String text) throws TException { + public List searchShopText(String text) { log.info("Incoming request for shop with text: {}", text); - SearchHits searchHits = searchDao.searchParty(text); + SearchResponse searchHits = searchDao.searchParty(text); log.info("Found shop: {}", searchHits); return searchHitShopConverter.convert(searchHits); } + + @Override + public List searchWalletText(String text) { + log.info("Incoming request for wallets with text: {}", text); + SearchResponse searchHits = searchDao.searchParty(text); + log.info("Found wallet: {}", searchHits); + return searchHitWalletConverter.convert(searchHits); + } } diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/PartyManagementHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/PartyManagementHandler.java index 58de783..3ef5390 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/PartyManagementHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/PartyManagementHandler.java @@ -3,4 +3,5 @@ package dev.vality.deanonimus.kafka.handler.party.management; import dev.vality.damsel.payment_processing.PartyChange; import dev.vality.machinegun.eventsink.MachineEvent; -public interface PartyManagementHandler extends Handler {} +public interface PartyManagementHandler extends Handler { +} diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractCreatedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractCreatedHandler.java index 8edf355..36f962a 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractCreatedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractCreatedHandler.java @@ -3,12 +3,11 @@ package dev.vality.deanonimus.kafka.handler.party.management.contract; import dev.vality.damsel.payment_processing.ClaimEffect; import dev.vality.damsel.payment_processing.ContractEffectUnit; import dev.vality.damsel.payment_processing.PartyChange; -import dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.domain.Contract; import dev.vality.deanonimus.domain.ContractStatus; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.deanonimus.util.ContractUtil; import dev.vality.geck.common.util.TBaseUtil; import dev.vality.geck.common.util.TypeUtil; @@ -27,7 +26,7 @@ import java.util.UUID; @RequiredArgsConstructor public class ContractCreatedHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -73,9 +72,9 @@ public class ContractCreatedHandler extends AbstractClaimChangedHandler { } String contractorId = initContractorId(contractCreated); contract.setContractorId(contractorId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); party.addContract(contract); - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End contract created handling, sequenceId={}, partyId={}, contractId={}, changeId={}", sequenceId, partyId, contractId, changeId); } diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractLegalAgreementBoundHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractLegalAgreementBoundHandler.java index b934c42..6c7008d 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractLegalAgreementBoundHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractLegalAgreementBoundHandler.java @@ -4,12 +4,11 @@ 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 dev.vality.deanonimus.db.PartyRepository; import dev.vality.deanonimus.db.exception.ContractNotFoundException; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.domain.Contract; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.machinegun.eventsink.MachineEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -24,7 +23,7 @@ import java.util.List; @RequiredArgsConstructor public class ContractLegalAgreementBoundHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -46,12 +45,11 @@ public class ContractLegalAgreementBoundHandler extends AbstractClaimChangedHand String partyId = event.getSourceId(); log.info("Start contract legal agreement bound handling, sequenceId={}, partyId={}, contractId={}, changeId={}", sequenceId, partyId, contractId, changeId); - Party party = partyRepository.findById(partyId) - .orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); Contract contract = party.getContractById(contractId) .orElseThrow(() -> new ContractNotFoundException(contractId)); contract.setLegalAgreementId(legalAgreement.getLegalAgreementId()); - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End contract legal agreement bound handling, sequenceId={}, partyId={}, contractId={}, changeId={}", sequenceId, partyId, contractId, changeId); diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractReportPreferencesChangedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractReportPreferencesChangedHandler.java index ae691a2..91bb5d0 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractReportPreferencesChangedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contract/ContractReportPreferencesChangedHandler.java @@ -4,12 +4,11 @@ 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 dev.vality.deanonimus.db.PartyRepository; import dev.vality.deanonimus.db.exception.ContractNotFoundException; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.domain.Contract; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.deanonimus.util.ContractUtil; import dev.vality.machinegun.eventsink.MachineEvent; import lombok.RequiredArgsConstructor; @@ -25,7 +24,7 @@ import java.util.List; @RequiredArgsConstructor public class ContractReportPreferencesChangedHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -52,7 +51,7 @@ public class ContractReportPreferencesChangedHandler extends AbstractClaimChange """, sequenceId, partyId, contractId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); Contract contract = party.getContractById(contractId).orElseThrow(() -> new ContractNotFoundException(contractId)); @@ -63,12 +62,12 @@ public class ContractReportPreferencesChangedHandler extends AbstractClaimChange ContractUtil.setNullReportPreferences(contract); } - partyRepository.save(party); + openSearchService.updateParty(party); log.info( """ - End contract report preferences changed handling, - sequenceId={}, partyId={}, contractId={}, changeId={} + End contract report preferences changed handling, + sequenceId={}, partyId={}, contractId={}, changeId={} """, sequenceId, partyId, contractId, changeId); } diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contractor/ContractorCreatedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contractor/ContractorCreatedHandler.java index 87975c4..1f7be77 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contractor/ContractorCreatedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/contractor/ContractorCreatedHandler.java @@ -4,10 +4,9 @@ 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 dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.deanonimus.util.ContractorUtil; import dev.vality.machinegun.eventsink.MachineEvent; import lombok.RequiredArgsConstructor; @@ -23,7 +22,7 @@ import java.util.List; @RequiredArgsConstructor public class ContractorCreatedHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -45,13 +44,13 @@ public class ContractorCreatedHandler extends AbstractClaimChangedHandler { String partyId = event.getSourceId(); log.info("Start contractor created handling, eventId={}, partyId={}, contractorId={}", eventId, partyId, contractorId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); dev.vality.deanonimus.domain.Contractor contractor = ContractorUtil.convertContractor(partyId, contractorCreated, contractorId); party.addContractor(contractor); - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End contractor created handling, eventId={}, partyId={}, contractorId={}", eventId, partyId, contractorId); } diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartyBlockingHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartyBlockingHandler.java index bda7975..e4aae6a 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartyBlockingHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartyBlockingHandler.java @@ -2,10 +2,9 @@ package dev.vality.deanonimus.kafka.handler.party.management.party; import dev.vality.damsel.domain.Blocking; import dev.vality.damsel.payment_processing.PartyChange; -import dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.kafka.handler.party.management.PartyManagementHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.geck.filter.Filter; import dev.vality.geck.filter.PathConditionFilter; import dev.vality.geck.filter.condition.IsNullCondition; @@ -22,7 +21,8 @@ import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor public class PartyBlockingHandler implements PartyManagementHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; + private final Filter filter = new PathConditionFilter(new PathConditionRule( "party_blocking", new IsNullCondition().not())); @@ -35,7 +35,7 @@ public class PartyBlockingHandler implements PartyManagementHandler { String partyId = event.getSourceId(); log.info("Start party blocking handling, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId); - Party partySource = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party partySource = openSearchService.findPartyById(partyId); if (partyBlocking.isSetUnblocked()) { partySource.setBlocking(dev.vality.deanonimus.domain.Blocking.unblocked); @@ -43,7 +43,7 @@ public class PartyBlockingHandler implements PartyManagementHandler { partySource.setBlocking(dev.vality.deanonimus.domain.Blocking.blocked); } - partyRepository.save(partySource); + openSearchService.updateParty(partySource); log.info("End party blocking handling, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId); } diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartyCreatedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartyCreatedHandler.java index 050091d..9cb56d4 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartyCreatedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartyCreatedHandler.java @@ -2,11 +2,11 @@ package dev.vality.deanonimus.kafka.handler.party.management.party; import dev.vality.damsel.payment_processing.PartyChange; import dev.vality.damsel.payment_processing.PartyCreated; -import dev.vality.deanonimus.db.PartyRepository; import dev.vality.deanonimus.domain.Blocking; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.domain.Suspension; import dev.vality.deanonimus.kafka.handler.party.management.PartyManagementHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.geck.filter.Filter; import dev.vality.geck.filter.PathConditionFilter; import dev.vality.geck.filter.condition.IsNullCondition; @@ -23,7 +23,7 @@ import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor public class PartyCreatedHandler implements PartyManagementHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; private final Filter filter = new PathConditionFilter(new PathConditionRule( "party_created", new IsNullCondition().not())); @@ -41,7 +41,7 @@ public class PartyCreatedHandler implements PartyManagementHandler { party.setBlocking(Blocking.unblocked); party.setSuspension(Suspension.active); - partyRepository.save(party); + openSearchService.createParty(party); log.info("Party has been saved, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId, changeId); } diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartySuspensionHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartySuspensionHandler.java index e34d5b6..e1723ea 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartySuspensionHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/party/PartySuspensionHandler.java @@ -2,10 +2,9 @@ package dev.vality.deanonimus.kafka.handler.party.management.party; import dev.vality.damsel.domain.Suspension; import dev.vality.damsel.payment_processing.PartyChange; -import dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.kafka.handler.party.management.PartyManagementHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.geck.filter.Filter; import dev.vality.geck.filter.PathConditionFilter; import dev.vality.geck.filter.condition.IsNullCondition; @@ -26,7 +25,7 @@ public class PartySuspensionHandler implements PartyManagementHandler { "party_suspension", new IsNullCondition().not())); - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -35,15 +34,15 @@ public class PartySuspensionHandler implements PartyManagementHandler { Suspension partySuspension = change.getPartySuspension(); String partyId = event.getSourceId(); log.info("Start party suspension handling, eventId={}, partyId={}, changeId={}", sequenceId, partyId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); if (partySuspension.isSetActive()) { party.setSuspension(dev.vality.deanonimus.domain.Suspension.active); } else if (partySuspension.isSetSuspended()) { party.setSuspension(dev.vality.deanonimus.domain.Suspension.suspended); } + openSearchService.updateParty(party); - partyRepository.save(party); log.info("End party suspension handling, eventId={}, partyId={}, changeId={}", sequenceId, partyId, changeId); } diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopAccountCreatedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopAccountCreatedHandler.java index 62794bf..0173242 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopAccountCreatedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopAccountCreatedHandler.java @@ -4,11 +4,10 @@ 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 dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.db.exception.ShopNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.deanonimus.util.ShopUtil; import dev.vality.machinegun.eventsink.MachineEvent; import lombok.RequiredArgsConstructor; @@ -24,7 +23,7 @@ import java.util.List; @RequiredArgsConstructor public class ShopAccountCreatedHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -46,12 +45,12 @@ public class ShopAccountCreatedHandler extends AbstractClaimChangedHandler { log.info("Start shop accountCreated handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); ShopUtil.fillShopAccount(party.getShopById(shopId).orElseThrow(() -> new ShopNotFoundException(shopId)), accountCreated); - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End shop accountCreated handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopBlockingHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopBlockingHandler.java index 3b9e624..63d9196 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopBlockingHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopBlockingHandler.java @@ -2,12 +2,11 @@ package dev.vality.deanonimus.kafka.handler.party.management.shop; import dev.vality.damsel.domain.Blocking; import dev.vality.damsel.payment_processing.PartyChange; -import dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.db.exception.ShopNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.domain.Shop; import dev.vality.deanonimus.kafka.handler.party.management.PartyManagementHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.geck.filter.Filter; import dev.vality.geck.filter.PathConditionFilter; import dev.vality.geck.filter.condition.IsNullCondition; @@ -24,7 +23,7 @@ import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor public class ShopBlockingHandler implements PartyManagementHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; private final Filter filter = new PathConditionFilter(new PathConditionRule( "shop_blocking", new IsNullCondition().not())); @@ -39,11 +38,11 @@ public class ShopBlockingHandler implements PartyManagementHandler { log.info("Start shop blocking handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); initBlockingFields(blocking, party.getShopById(shopId).orElseThrow(() -> new ShopNotFoundException(shopId))); - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End shop blocking handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopCategoryChangedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopCategoryChangedHandler.java index e0d1886..4962845 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopCategoryChangedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopCategoryChangedHandler.java @@ -3,12 +3,11 @@ package dev.vality.deanonimus.kafka.handler.party.management.shop; import dev.vality.damsel.payment_processing.ClaimEffect; import dev.vality.damsel.payment_processing.PartyChange; import dev.vality.damsel.payment_processing.ShopEffectUnit; -import dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.db.exception.ShopNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.domain.Shop; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.machinegun.eventsink.MachineEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -23,7 +22,7 @@ import java.util.List; @RequiredArgsConstructor public class ShopCategoryChangedHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -45,12 +44,12 @@ public class ShopCategoryChangedHandler extends AbstractClaimChangedHandler { log.info("Start shop categoryId changed handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); Shop shop = party.getShopById(shopId).orElseThrow(() -> new ShopNotFoundException(shopId)); shop.setCategoryId(categoryId); - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End shop categoryId changed handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopContractChangedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopContractChangedHandler.java index daa7ad0..47d3d39 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopContractChangedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopContractChangedHandler.java @@ -4,12 +4,11 @@ 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 dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.db.exception.ShopNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.domain.Shop; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.machinegun.eventsink.MachineEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -24,7 +23,7 @@ import java.util.List; @RequiredArgsConstructor public class ShopContractChangedHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -46,13 +45,13 @@ public class ShopContractChangedHandler extends AbstractClaimChangedHandler { log.info("Start shop contractChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); Shop shop = party.getShopById(shopId).orElseThrow(() -> new ShopNotFoundException(shopId)); shop.setContractId(contractChanged.getContractId()); shop.setPayoutToolId(contractChanged.getPayoutToolId()); - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End shop contractChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopCreatedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopCreatedHandler.java index 0e8e0f8..ec77eac 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopCreatedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopCreatedHandler.java @@ -4,13 +4,12 @@ package dev.vality.deanonimus.kafka.handler.party.management.shop; import dev.vality.damsel.payment_processing.ClaimEffect; import dev.vality.damsel.payment_processing.PartyChange; import dev.vality.damsel.payment_processing.ShopEffectUnit; -import dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.domain.Blocking; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.domain.Shop; import dev.vality.deanonimus.domain.Suspension; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.deanonimus.util.ShopUtil; import dev.vality.machinegun.eventsink.MachineEvent; import lombok.RequiredArgsConstructor; @@ -26,7 +25,7 @@ import java.util.List; @RequiredArgsConstructor public class ShopCreatedHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -48,13 +47,13 @@ public class ShopCreatedHandler extends AbstractClaimChangedHandler { log.info("Start shop created handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); Shop shop = fillShopInfo(shopCreated, shopId); party.addShop(shop); - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End shop created handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopDetailsChangedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopDetailsChangedHandler.java index ba35c43..de7bb9a 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopDetailsChangedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopDetailsChangedHandler.java @@ -4,12 +4,11 @@ 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 dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.db.exception.ShopNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.domain.Shop; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.machinegun.eventsink.MachineEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -24,7 +23,7 @@ import java.util.List; @RequiredArgsConstructor public class ShopDetailsChangedHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -46,14 +45,14 @@ public class ShopDetailsChangedHandler extends AbstractClaimChangedHandler { log.info("Start shop detailsChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); Shop shop = party.getShopById(shopId).orElseThrow(() -> new ShopNotFoundException(shopId)); shop.setDetailsName(detailsChanged.getName()); shop.setDetailsDescription(detailsChanged.getDescription()); - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End shop detailsChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopLocationChangedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopLocationChangedHandler.java index ef5508d..530ee01 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopLocationChangedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopLocationChangedHandler.java @@ -4,12 +4,11 @@ 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 dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.db.exception.ShopNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.domain.Shop; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.machinegun.eventsink.MachineEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -24,7 +23,7 @@ import java.util.List; @RequiredArgsConstructor public class ShopLocationChangedHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -45,7 +44,7 @@ public class ShopLocationChangedHandler extends AbstractClaimChangedHandler { String partyId = event.getSourceId(); log.info("Start shop locationChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); Shop shop = party.getShopById(shopId).orElseThrow(() -> new ShopNotFoundException(shopId)); @@ -55,7 +54,7 @@ public class ShopLocationChangedHandler extends AbstractClaimChangedHandler { throw new IllegalArgumentException("Illegal shop location " + locationChanged); } - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End shop locationChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopPayoutScheduleChangedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopPayoutScheduleChangedHandler.java index 42334f8..c696acc 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopPayoutScheduleChangedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopPayoutScheduleChangedHandler.java @@ -4,12 +4,11 @@ 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 dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.db.exception.ShopNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.domain.Shop; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.machinegun.eventsink.MachineEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -24,7 +23,7 @@ import java.util.List; @RequiredArgsConstructor public class ShopPayoutScheduleChangedHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -46,7 +45,7 @@ public class ShopPayoutScheduleChangedHandler extends AbstractClaimChangedHandle log.info("Start shop payoutScheduleChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); Shop shop = party.getShopById(shopId).orElseThrow(() -> new ShopNotFoundException(shopId)); if (payoutScheduleChanged.isSetSchedule()) { @@ -55,7 +54,7 @@ public class ShopPayoutScheduleChangedHandler extends AbstractClaimChangedHandle shop.setPayoutScheduleId(null); } - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End shop payoutScheduleChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopPayoutToolChangedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopPayoutToolChangedHandler.java index 9c0cfc5..e7d7c37 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopPayoutToolChangedHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopPayoutToolChangedHandler.java @@ -3,12 +3,11 @@ package dev.vality.deanonimus.kafka.handler.party.management.shop; import dev.vality.damsel.payment_processing.ClaimEffect; import dev.vality.damsel.payment_processing.PartyChange; import dev.vality.damsel.payment_processing.ShopEffectUnit; -import dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.db.exception.ShopNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.domain.Shop; import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.machinegun.eventsink.MachineEvent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -23,7 +22,7 @@ import java.util.List; @RequiredArgsConstructor public class ShopPayoutToolChangedHandler extends AbstractClaimChangedHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; @Override @Transactional(propagation = Propagation.REQUIRED) @@ -45,12 +44,12 @@ public class ShopPayoutToolChangedHandler extends AbstractClaimChangedHandler { log.info("Start shop payoutToolChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); Shop shop = party.getShopById(shopId).orElseThrow(() -> new ShopNotFoundException(shopId)); shop.setPayoutToolId(payoutToolChanged); - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End shop payoutToolChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopSuspensionHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopSuspensionHandler.java index f71c860..eb11f76 100644 --- a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopSuspensionHandler.java +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/shop/ShopSuspensionHandler.java @@ -2,12 +2,11 @@ package dev.vality.deanonimus.kafka.handler.party.management.shop; import dev.vality.damsel.domain.Suspension; import dev.vality.damsel.payment_processing.PartyChange; -import dev.vality.deanonimus.db.PartyRepository; -import dev.vality.deanonimus.db.exception.PartyNotFoundException; import dev.vality.deanonimus.db.exception.ShopNotFoundException; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.domain.Shop; import dev.vality.deanonimus.kafka.handler.party.management.PartyManagementHandler; +import dev.vality.deanonimus.service.OpenSearchService; import dev.vality.geck.filter.Filter; import dev.vality.geck.filter.PathConditionFilter; import dev.vality.geck.filter.condition.IsNullCondition; @@ -24,7 +23,7 @@ import org.springframework.transaction.annotation.Transactional; @RequiredArgsConstructor public class ShopSuspensionHandler implements PartyManagementHandler { - private final PartyRepository partyRepository; + private final OpenSearchService openSearchService; private final Filter filter = new PathConditionFilter(new PathConditionRule( "shop_suspension", new IsNullCondition().not())); @@ -39,7 +38,7 @@ public class ShopSuspensionHandler implements PartyManagementHandler { log.info("Start shop suspension handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); - Party party = partyRepository.findById(partyId).orElseThrow(() -> new PartyNotFoundException(partyId)); + Party party = openSearchService.findPartyById(partyId); Shop shop = party.getShopById(shopId).orElseThrow(() -> new ShopNotFoundException(shopId)); if (suspension.isSetActive()) { @@ -48,7 +47,7 @@ public class ShopSuspensionHandler implements PartyManagementHandler { shop.setSuspension(dev.vality.deanonimus.domain.Suspension.suspended); } - partyRepository.save(party); + openSearchService.updateParty(party); log.info("End shop suspension handling, sequenceId={}, partyId={}, shopId={}, changeId={}", sequenceId, partyId, shopId, changeId); diff --git a/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/wallet/WalletCreatedHandler.java b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/wallet/WalletCreatedHandler.java new file mode 100644 index 0000000..24e46f8 --- /dev/null +++ b/src/main/java/dev/vality/deanonimus/kafka/handler/party/management/wallet/WalletCreatedHandler.java @@ -0,0 +1,63 @@ +package dev.vality.deanonimus.kafka.handler.party.management.wallet; + +import dev.vality.damsel.payment_processing.ClaimEffect; +import dev.vality.damsel.payment_processing.PartyChange; +import dev.vality.damsel.payment_processing.WalletEffectUnit; +import dev.vality.deanonimus.domain.Party; +import dev.vality.deanonimus.domain.Wallet; +import dev.vality.deanonimus.kafka.handler.party.management.AbstractClaimChangedHandler; +import dev.vality.deanonimus.service.OpenSearchService; +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 WalletCreatedHandler extends AbstractClaimChangedHandler { + + private final OpenSearchService openSearchService; + + @Override + @Transactional(propagation = Propagation.REQUIRED) + public void handle(PartyChange change, MachineEvent event, Integer changeId) { + List claimEffects = getClaimStatus(change).getAccepted().getEffects(); + for (ClaimEffect claimEffect : claimEffects) { + if (claimEffect.isSetWalletEffect() && claimEffect.getWalletEffect().getEffect().isSetCreated()) { + handleEvent(event, changeId, claimEffect); + } + } + } + + private void handleEvent(MachineEvent event, Integer changeId, ClaimEffect e) { + long sequenceId = event.getEventId(); + WalletEffectUnit walletEffect = e.getWalletEffect(); + dev.vality.damsel.domain.Wallet walletCreated = walletEffect.getEffect().getCreated(); + String walletId = walletEffect.getId(); + String partyId = event.getSourceId(); + log.info("Start wallet created handling, sequenceId={}, partyId={}, walletId={}, changeId={}", + sequenceId, partyId, walletId, changeId); + + Party party = openSearchService.findPartyById(partyId); + Wallet wallet = fillWalletInfo(walletCreated, walletId); + party.addWallet(wallet); + + openSearchService.updateParty(party); + + log.info("End wallet created handling, sequenceId={}, partyId={}, walletId={}, changeId={}", + sequenceId, partyId, walletId, changeId); + } + + private Wallet fillWalletInfo(dev.vality.damsel.domain.Wallet walletCreated, String walletId) { + Wallet wallet = new Wallet(); + wallet.setId(walletId); + wallet.setName(walletCreated.getName()); + + return wallet; + } +} diff --git a/src/main/java/dev/vality/deanonimus/service/OpenSearchService.java b/src/main/java/dev/vality/deanonimus/service/OpenSearchService.java new file mode 100644 index 0000000..a7e7c47 --- /dev/null +++ b/src/main/java/dev/vality/deanonimus/service/OpenSearchService.java @@ -0,0 +1,51 @@ +package dev.vality.deanonimus.service; + +import dev.vality.deanonimus.domain.Party; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.opensearch.client.opensearch.OpenSearchClient; +import org.opensearch.client.opensearch.core.GetRequest; +import org.opensearch.client.opensearch.core.IndexRequest; +import org.opensearch.client.opensearch.core.UpdateRequest; +import org.springframework.stereotype.Service; + +import static dev.vality.deanonimus.constant.OpenSearchConstants.PARTY_INDEX; + +@Service +@RequiredArgsConstructor +@Slf4j +public class OpenSearchService { + + private final OpenSearchClient openSearchClient; + + @SneakyThrows + public Party findPartyById(String partyId) { + return openSearchClient.get(new GetRequest.Builder() + .index(PARTY_INDEX) + .id(partyId) + .build(), + Party.class).source(); + } + + @SneakyThrows + public void updateParty(Party party) { + openSearchClient.update( + new UpdateRequest.Builder() + .index(PARTY_INDEX) + .id(party.getId()) + .doc(party) + .build(), + Party.class); + } + + @SneakyThrows + public Party createParty(Party party) { + openSearchClient.index(new IndexRequest.Builder() + .index(PARTY_INDEX) + .id(party.getId()) + .document(party) + .build()); + return party; + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0e00a57..8267cea 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,11 +1,11 @@ server: - port: '@server.port@' + port: '${server.port}' management: security: flag: false server: - port: '@management.port@' + port: '${management.port}' metrics: export: prometheus: @@ -28,8 +28,6 @@ spring: output: ansi: enabled: always - elasticsearch: - uris: "http://localhost:9200" kafka: bootstrap-servers: localhost:9092 client-id: deanonimus @@ -42,6 +40,14 @@ spring: max.poll.interval.ms: 30000 session.timeout.ms: 30000 +opensearch: + username: none + password: none + hostname: localhost + port: 9200 + certificate: none + sslEnabled: false + info: version: '@project.version@' stage: dev diff --git a/src/test/java/dev/vality/deanonimus/AbstractIntegrationTest.java b/src/test/java/dev/vality/deanonimus/AbstractIntegrationTest.java index ed08487..6f6cd56 100644 --- a/src/test/java/dev/vality/deanonimus/AbstractIntegrationTest.java +++ b/src/test/java/dev/vality/deanonimus/AbstractIntegrationTest.java @@ -31,12 +31,8 @@ public abstract class AbstractIntegrationTest { @DynamicPropertySource static void containersProps(DynamicPropertyRegistry registry) { registry.add("spring.kafka.bootstrap-servers", KafkaContainerExtension.KAFKA::getBootstrapServers); - registry.add("spring.elasticsearch.rest.uris", () -> { - return "http://" + - OpensearchContainerExtension.OPENSEARCH.getHost() + - ":" + - OpensearchContainerExtension.OPENSEARCH.getFirstMappedPort(); - }); + registry.add("opensearch.hostname", () -> OpensearchContainerExtension.OPENSEARCH.getHost()); + registry.add("opensearch.port", () -> OpensearchContainerExtension.OPENSEARCH.getFirstMappedPort()); } public static void sendMessages(List sinkEvents) { diff --git a/src/test/java/dev/vality/deanonimus/PartyFlowGenerator.java b/src/test/java/dev/vality/deanonimus/PartyFlowGenerator.java index e634f83..9371f33 100644 --- a/src/test/java/dev/vality/deanonimus/PartyFlowGenerator.java +++ b/src/test/java/dev/vality/deanonimus/PartyFlowGenerator.java @@ -16,53 +16,23 @@ import lombok.NoArgsConstructor; import java.io.IOException; import java.time.Instant; import java.time.LocalDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; @NoArgsConstructor(access = AccessLevel.PRIVATE) public class PartyFlowGenerator { - public static final String PARTY_EMAIL = "testPartyEmail"; - public static final String SOURCE_NS = "source_ns"; - public static final String PARTY_BLOCK_REASON = "testPartyBlockReason"; - public static final String SHOP_BLOCK_REASON = "testShopBlockReason"; - public static final String SHOP_UNBLOCK_REASON = "testShopUnblockReason"; - public static final Long PARTY_REVISION_ID = 12345L; - public static final Long CLAIM_ID = 524523L; - public static final Integer REVISION_ID = 431531; - public static final Integer CATEGORY_ID = 542432; - public static final String CONTRACT_ID = "142534"; - public static final String PAYOUT_ID = "654635"; - public static final String DETAILS_NAME = "testDetailsName"; - public static final String DETAILS_DESCRIPTION = "testDescription"; - public static final Integer SCHEDULE_ID = 15643653; - public static final String PAYOUT_TOOL_ID = "654635"; - public static final String CURRENCY_SYMBOL = "RUB"; - public static final Long SETTLEMENT_ID = 245234L; - public static final String CONTRACTOR_ID = "563462"; - public static final Long SHOP_ACCOUNT_PAYOUT = 5425234L; - public static final String INN = "213123123123"; - - public static List generatePartyFlow(String partyId, String shopId) throws IOException { - List sinkEvents = new ArrayList<>(); - Long sequenceId = 0L; - sinkEvents.add(buildSinkEvent(buildMessagePartyCreated(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildMessagePartyBlocking(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildMessagePartySuspension(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildMessagePartyRevisionChanged(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildContractorCreated(sequenceId++, buildPartyContractor(partyId), partyId))); - sinkEvents.add(buildSinkEvent(buildContractorIdentificationLevelChanged(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildMessageShopCreated(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopBlocking(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopSuspension(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopCategoryChanged(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopContractChanged(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopDetailsChanged(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopPayoutScheduleChanged(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopPayoutToolChanged(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopAccountCreated(sequenceId++, partyId, shopId))); - - return sinkEvents; - } + private static final String PARTY_EMAIL = "testPartyEmail"; + private static final String SOURCE_NS = "source_ns"; + private static final String PARTY_BLOCK_REASON = "testPartyBlockReason"; + private static final Long PARTY_REVISION_ID = 12345L; + private static final Long CLAIM_ID = 524523L; + private static final Integer REVISION_ID = 431531; + private static final String WALLET_ID = "345435435"; + private static final String CONTRACTOR_ID = "563462"; + private static final String INN = "213123123123"; public static List generatePartyContractorFlow(String partyId) throws IOException { List sinkEvents = new ArrayList<>(); @@ -73,161 +43,19 @@ public class PartyFlowGenerator { sinkEvents.add(buildSinkEvent(buildMessagePartyRevisionChanged(sequenceId++, partyId))); sinkEvents.add(buildSinkEvent( buildContractorCreated(sequenceId++, buildRussianLegalPartyContractor(partyId), partyId))); - sinkEvents.add(buildSinkEvent(buildContractorIdentificationLevelChanged(sequenceId++, partyId))); + sinkEvents.add(buildSinkEvent(buildContractorIdentificationLevelChanged(sequenceId, partyId))); return sinkEvents; } - public static List generateShopFlow(String partyId, String shopId) throws IOException { + public static List generateWalletFlow(String partyId) throws IOException { List sinkEvents = new ArrayList<>(); - Long sequenceId = 0L; + long sequenceId = 0L; sinkEvents.add(buildSinkEvent(buildMessagePartyCreated(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildMessageShopCreated(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopBlocking(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopPayoutToolChanged(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopSuspension(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopCategoryChanged(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopContractChanged(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopDetailsChanged(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopPayoutScheduleChanged(sequenceId++, partyId, shopId))); - sinkEvents.add(buildSinkEvent(buildMessageShopAccountCreated(sequenceId++, partyId, shopId))); - - sinkEvents.add(buildSinkEvent(buildMessageShopSuspension( - sequenceId++, partyId, - buildSuspendedShopSuspension(TypeUtil.temporalToString(LocalDateTime.now()), shopId)))); - + sinkEvents.add(buildSinkEvent(buildMessageWalletCreated(sequenceId, partyId, WALLET_ID))); return sinkEvents; } - public static List generatePartyFlowWithCount(int count, String lastPartyId, PartyContractor contractor) - throws IOException { - List sinkEvents = new ArrayList<>(); - Long sequenceId = 0L; - for (int i = 0; i < count; i++) { - if (i == count - 1) { - sinkEvents.add(buildSinkEvent(buildMessagePartyCreated(sequenceId++, lastPartyId))); - sinkEvents.add(buildSinkEvent(buildMessagePartyBlocking(sequenceId++, lastPartyId))); - sinkEvents.add(buildSinkEvent(buildContractorCreated(sequenceId++, contractor, lastPartyId))); - sinkEvents.add(buildSinkEvent(buildContractorIdentificationLevelChanged(sequenceId++, lastPartyId))); - } else { - String partyId = UUID.randomUUID().toString(); - sinkEvents.add(buildSinkEvent(buildMessagePartyCreated(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent( - buildContractorCreated(sequenceId++, buildRussianLegalPartyContractor(partyId), partyId))); - sinkEvents.add(buildSinkEvent(buildContractorIdentificationLevelChanged(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildMessagePartyBlocking(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildMessagePartySuspension(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildMessagePartyRevisionChanged(sequenceId++, partyId))); - } - } - - return sinkEvents; - } - - public static List generatePartyFlowWithMultiplePartyChange(int count, - String lastPartyId, - PartyContractor partyContractor) - throws IOException { - List sinkEvents = new ArrayList<>(); - Long sequenceId = 0L; - for (int i = 0; i < count; i++) { - if (i == count - 1) { - PartyChange partyChange = buildContractorCreatedPartyChange(partyContractor); - sinkEvents.add(buildSinkEvent(buildMultiPartyChange(sequenceId, lastPartyId, partyChange))); - } else { - String partyId = UUID.randomUUID().toString(); - sinkEvents.add(buildSinkEvent(buildMultiPartyChange(sequenceId, partyId, null))); - } - } - - return sinkEvents; - } - - public static List generatePartyFlowWithMultiplePartyShopChange(int count, - String lastPartyId, - String lastShopId, - PartyChange customPartyChange) - throws IOException { - List sinkEvents = new ArrayList<>(); - Long sequenceId = 0L; - for (int i = 0; i < count; i++) { - if (i == count - 1) { - sinkEvents.add(buildSinkEvent( - buildMultiShopChange(sequenceId, lastPartyId, lastShopId, customPartyChange))); - } else { - String partyId = UUID.randomUUID().toString(); - String shopId = UUID.randomUUID().toString(); - sinkEvents.add(buildSinkEvent(buildMultiShopChange(sequenceId, partyId, shopId, null))); - } - } - - return sinkEvents; - } - - public static List generatePartyFlowWithMultipleShopInOneChange(String lastPartyId, - String lastShopId, - PartyChange customPartyChange) - throws IOException { - List sinkEvents = new ArrayList<>(); - Long sequenceId = 0L; - sinkEvents.add(buildSinkEvent( - buildMultiShopChangeDifferentShopId(sequenceId, lastPartyId, lastShopId, customPartyChange))); - - return sinkEvents; - } - - public static List generatePartyFlowWithContract(String partyId, LegalEntity legalEntity) - throws IOException { - List sinkEvents = new ArrayList<>(); - Long sequenceId = 0L; - sinkEvents.add(buildSinkEvent(buildMessagePartyCreated(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildMessagePartyBlocking(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildMessagePartySuspension(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildMessagePartyRevisionChanged(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent( - buildContractorCreated(sequenceId++, buildRussianLegalPartyContractor(partyId), partyId))); - sinkEvents.add(buildSinkEvent(buildContractorIdentificationLevelChanged(sequenceId++, partyId))); - sinkEvents.add(buildSinkEvent(buildContractContractorCreated(sequenceId++, partyId, legalEntity))); - - return sinkEvents; - } - - public static MachineEvent buildContractContractorCreated(Long sequenceId, String partyId, - LegalEntity legalEntity) { - Contract contract = new Contract(); - contract.setId("testContractId"); - contract.setContractorId("testContractorId"); - contract.setCreatedAt(TypeUtil.temporalToString(LocalDateTime.now())); - contract.setStatus(ContractStatus.active(new ContractActive())); - contract.setAdjustments(Collections.emptyList()); - contract.setPayoutTools(Collections.emptyList()); - TermSetHierarchyRef termSetHierarchyRef = new TermSetHierarchyRef(); - termSetHierarchyRef.setId(12345); - contract.setTerms(termSetHierarchyRef); - Contractor contractor = new Contractor(); - contractor.setLegalEntity(legalEntity); - contract.setContractor(contractor); - ContractEffect contractEffect = new ContractEffect(); - contractEffect.setCreated(contract); - ContractEffectUnit contractEffectUnit = new ContractEffectUnit(); - contractEffectUnit.setContractId("testContractId"); - contractEffectUnit.setEffect(contractEffect); - ClaimEffect claimEffect = new ClaimEffect(); - claimEffect.setContractEffect(contractEffectUnit); - Claim claim = buildClaimCreated(claimEffect); - PartyChange partyChange = new PartyChange(); - partyChange.setClaimCreated(claim); - return buildMachineEvent(partyId, sequenceId, partyChange); - } - - public static RussianLegalEntity buildRussianLegalEntity() throws IOException { - RussianLegalEntity russianLegalEntity = new RussianLegalEntity(); - russianLegalEntity = new MockTBaseProcessor(MockMode.ALL) - .process(russianLegalEntity, new TBaseHandler<>(RussianLegalEntity.class)); - russianLegalEntity.setInn(INN); - return russianLegalEntity; - } - public static MachineEvent buildMessagePartyCreated(Long sequenceId, String partyId) { PartyChange partyChange = buildPartyCreatedPartyChange(partyId); return buildMachineEvent(partyId, sequenceId, partyChange); @@ -276,190 +104,30 @@ public class PartyFlowGenerator { return partyChange; } - public static MachineEvent buildMessageShopBlocking(Long sequenceId, String partyId, String shopId) { - PartyChange partyChange = buildShopBlockingPartyChange(shopId); - return buildMachineEvent(partyId, sequenceId, partyChange); - } - - public static MachineEvent buildMessageShopSuspension(Long sequenceId, String partyId, String shopId) { - PartyChange partyChange = buildShopSuspensionPartyChange(shopId); - return buildMachineEvent(partyId, sequenceId, partyChange); - } - - public static MachineEvent buildMessageShopSuspension(Long sequenceId, String partyId, - ShopSuspension shopSuspension) { - PartyChange partyChange = new PartyChange(); - partyChange.setShopSuspension(shopSuspension); - return buildMachineEvent(partyId, sequenceId, partyChange); - } - - public static PartyChange buildShopBlockingPartyChange(String shopId) { - ShopBlocking shopBlocking = buildShopBlocking(shopId); - PartyChange partyChange = new PartyChange(); - partyChange.setShopBlocking(shopBlocking); - return partyChange; - } - - public static PartyChange buildShopSuspensionPartyChange(String shopId) { - ShopSuspension shopSuspension = - buildActiveShopSuspension(TypeUtil.temporalToString(LocalDateTime.now()), shopId); - PartyChange partyChange = new PartyChange(); - partyChange.setShopSuspension(shopSuspension); - return partyChange; - } - - public static MachineEvent buildMessageShopCreated(Long sequenceId, String partyId, String shopId) + public static MachineEvent buildMessageWalletCreated(Long sequenceId, String partyId, String walletId) throws IOException { - PartyChange partyChange = buildShopCreatedPartyChange(shopId); + PartyChange partyChange = buildWalletCreatedPartyChange(walletId); return buildMachineEvent(partyId, sequenceId, partyChange); } - public static PartyChange buildShopCreatedPartyChange(String shopId) throws IOException { - Shop shop = buildShopCreated(); - ShopEffectUnit shopEffectUnit = new ShopEffectUnit(); - shopEffectUnit.setShopId(shopId); - ShopEffect shopEffect = new ShopEffect(); - shopEffect.setCreated(buildShopCreated()); - shopEffectUnit.setEffect(shopEffect); + public static PartyChange buildWalletCreatedPartyChange(String walletd) throws IOException { + WalletEffectUnit walletEffectUnit = new WalletEffectUnit(); + walletEffectUnit.setId(walletd); + WalletEffect shopEffect = new WalletEffect(); + shopEffect.setCreated(buildWalletCreated()); + walletEffectUnit.setEffect(shopEffect); ClaimEffect claimEffect = new ClaimEffect(); - claimEffect.setShopEffect(shopEffectUnit); - Claim claim = buildClaimCreated(claimEffect); - PartyChange partyChange = new PartyChange(); - partyChange.setClaimCreated(claim); - - return partyChange; - } - - public static MachineEvent buildMessageShopCategoryChanged(Long sequenceId, String partyId, String shopId) { - PartyChange partyChange = buildShopCategoryPartyChange(shopId); - return buildMachineEvent(partyId, sequenceId, partyChange); - } - - public static PartyChange buildShopCategoryPartyChange(String shopId) { - ShopEffectUnit shopEffectUnit = new ShopEffectUnit(); - shopEffectUnit.setShopId(shopId); - ShopEffect shopEffect = new ShopEffect(); - CategoryRef categoryRef = new CategoryRef(); - categoryRef.setId(CATEGORY_ID); - shopEffect.setCategoryChanged(categoryRef); - shopEffectUnit.setEffect(shopEffect); - ClaimEffect claimEffect = new ClaimEffect(); - claimEffect.setShopEffect(shopEffectUnit); + claimEffect.setWalletEffect(walletEffectUnit); Claim claim = buildClaimCreated(claimEffect); PartyChange partyChange = new PartyChange(); partyChange.setClaimCreated(claim); return partyChange; } - public static MachineEvent buildMessageShopContractChanged(Long sequenceId, String partyId, String shopId) { - PartyChange partyChange = buildShopContractPartyChange(shopId); - return buildMachineEvent(partyId, sequenceId, partyChange); - } - - public static PartyChange buildShopContractPartyChange(String shopId) { - ShopEffectUnit shopEffectUnit = new ShopEffectUnit(); - shopEffectUnit.setShopId(shopId); - ShopContractChanged shopContractChanged = new ShopContractChanged(); - shopContractChanged.setContractId(CONTRACT_ID); - shopContractChanged.setPayoutToolId(PAYOUT_ID); - ShopEffect shopEffect = new ShopEffect(); - shopEffect.setContractChanged(shopContractChanged); - shopEffectUnit.setEffect(shopEffect); - ClaimEffect claimEffect = new ClaimEffect(); - claimEffect.setShopEffect(shopEffectUnit); - Claim claim = buildClaimCreated(claimEffect); - PartyChange partyChange = new PartyChange(); - partyChange.setClaimCreated(claim); - return partyChange; - } - - public static MachineEvent buildMessageShopDetailsChanged(Long sequenceId, String partyId, String shopId) { - PartyChange partyChange = buildShopDetailsPartyChange(shopId); - return buildMachineEvent(partyId, sequenceId, partyChange); - } - - public static PartyChange buildShopDetailsPartyChange(String shopId) { - ShopEffectUnit shopEffectUnit = new ShopEffectUnit(); - shopEffectUnit.setShopId(shopId); - ShopDetails shopDetails = new ShopDetails(); - shopDetails.setName(DETAILS_NAME); - shopDetails.setDescription(DETAILS_DESCRIPTION); - ShopEffect shopEffect = new ShopEffect(); - shopEffect.setDetailsChanged(shopDetails); - shopEffectUnit.setEffect(shopEffect); - ClaimEffect claimEffect = new ClaimEffect(); - claimEffect.setShopEffect(shopEffectUnit); - Claim claim = buildClaimCreated(claimEffect); - PartyChange partyChange = new PartyChange(); - partyChange.setClaimCreated(claim); - return partyChange; - } - - public static MachineEvent buildMessageShopPayoutScheduleChanged(Long sequenceId, String partyId, String shopdId) { - PartyChange partyChange = buildShopPayouScheduleChangedPartyChange(shopdId); - return buildMachineEvent(partyId, sequenceId, partyChange); - } - - public static PartyChange buildShopPayouScheduleChangedPartyChange(String shopdId) { - ShopEffectUnit shopEffectUnit = new ShopEffectUnit(); - shopEffectUnit.setShopId(shopdId); - ScheduleChanged scheduleChanged = new ScheduleChanged(); - scheduleChanged.setSchedule(new BusinessScheduleRef(SCHEDULE_ID)); - ShopEffect shopEffect = new ShopEffect(); - shopEffect.setPayoutScheduleChanged(scheduleChanged); - shopEffectUnit.setEffect(shopEffect); - ClaimEffect claimEffect = new ClaimEffect(); - claimEffect.setShopEffect(shopEffectUnit); - Claim claim = buildClaimCreated(claimEffect); - PartyChange partyChange = new PartyChange(); - partyChange.setClaimCreated(claim); - return partyChange; - } - - public static MachineEvent buildMessageShopPayoutToolChanged(Long sequenceId, String partyId, String shopdId) { - PartyChange partyChange = buildShopPayoutToolChangedPartyChange(shopdId, PAYOUT_TOOL_ID); - return buildMachineEvent(partyId, sequenceId, partyChange); - } - - public static PartyChange buildShopPayoutToolChangedPartyChange(String shopdId, String payoutToolId) { - ShopEffectUnit shopEffectUnit = new ShopEffectUnit(); - shopEffectUnit.setShopId(shopdId); - ShopEffect shopEffect = new ShopEffect(); - shopEffect.setPayoutToolChanged(payoutToolId); - shopEffectUnit.setEffect(shopEffect); - ClaimEffect claimEffect = new ClaimEffect(); - claimEffect.setShopEffect(shopEffectUnit); - Claim claim = buildClaimCreated(claimEffect); - PartyChange partyChange = new PartyChange(); - partyChange.setClaimCreated(claim); - return partyChange; - } - - public static MachineEvent buildMessageShopAccountCreated(Long sequenceId, String partyId, String shopdId) { - PartyChange partyChange = buildShopAccountCreatedPartyChange(shopdId); - return buildMachineEvent(partyId, sequenceId, partyChange); - } - - public static PartyChange buildShopAccountCreatedPartyChange(String shopdId) { - ShopEffectUnit shopEffectUnit = new ShopEffectUnit(); - shopEffectUnit.setShopId(shopdId); - ShopAccount shopAccount = new ShopAccount(); - shopAccount.setCurrency(new CurrencyRef(CURRENCY_SYMBOL)); - shopAccount.setPayout(SHOP_ACCOUNT_PAYOUT); - shopAccount.setSettlement(SETTLEMENT_ID); - ShopEffect shopEffect = new ShopEffect(); - shopEffect.setAccountCreated(shopAccount); - shopEffectUnit.setEffect(shopEffect); - ClaimEffect claimEffect = new ClaimEffect(); - claimEffect.setShopEffect(shopEffectUnit); - Claim claim = buildClaimCreated(claimEffect); - PartyChange partyChange = new PartyChange(); - partyChange.setClaimCreated(claim); - return partyChange; - } - - public static MachineEvent buildContractorCreated(Long sequenceId, PartyContractor partyContractor, String partyId) - throws IOException { + public static MachineEvent buildContractorCreated( + Long sequenceId, + PartyContractor partyContractor, + String partyId) { PartyChange partyChange = buildContractorCreatedPartyChange(partyContractor); return buildMachineEvent(partyId, sequenceId, partyChange); } @@ -497,95 +165,6 @@ public class PartyFlowGenerator { return partyChange; } - public static MachineEvent buildMultiPartyChange(Long sequenceId, String partyId, PartyChange customPartyChange) - throws IOException { - PartyChange partyCreatedChange = buildPartyCreatedPartyChange(partyId); - PartyChange partyRevisionChange = buildPartyRevisionChangedPartyChange(); - PartyChange partyBlockingChange = buildPartyBlockingPartyChange(); - PartyChange contractorCreatedPartyChange = buildContractorCreatedPartyChange(buildPartyContractor(partyId)); - PartyChange identificationLevelChangedPartyChange = buildContractorIdentificationLevelChangedPartyChange(); - if (customPartyChange == null) { - return buildMachineEvent(partyId, sequenceId, partyCreatedChange, partyRevisionChange, - partyBlockingChange, contractorCreatedPartyChange, identificationLevelChangedPartyChange); - } else { - return buildMachineEvent(partyId, sequenceId, partyCreatedChange, partyRevisionChange, - partyBlockingChange, contractorCreatedPartyChange, identificationLevelChangedPartyChange, - customPartyChange); - } - } - - public static MachineEvent buildMultiShopChange(Long sequenceId, String partyId, String shopId, - PartyChange customPartyChange) throws IOException { - PartyChange shopCreatedPartyChange = buildShopCreatedPartyChange(shopId); - PartyChange shopBlockingPartyChange = buildShopBlockingPartyChange(shopId); - PartyChange shopCategoryPartyChange = buildShopCategoryPartyChange(shopId); - PartyChange shopContractPartyChange = buildShopContractPartyChange(shopId); - PartyChange shopDetailsPartyChange = buildShopDetailsPartyChange(shopId); - PartyChange shopSuspensionPartyChange = buildShopSuspensionPartyChange(shopId); - PartyChange shopAccountCreatedPartyChange = buildShopAccountCreatedPartyChange(shopId); - PartyChange shopPayoutToolChangedPartyChange = buildShopPayoutToolChangedPartyChange(shopId, PAYOUT_TOOL_ID); - PartyChange shopPayouScheduleChangedPartyChange = buildShopPayouScheduleChangedPartyChange(shopId); - if (customPartyChange == null) { - return buildMachineEvent(partyId, sequenceId, shopCreatedPartyChange, shopBlockingPartyChange, - shopCategoryPartyChange, shopContractPartyChange, shopDetailsPartyChange, shopSuspensionPartyChange, - shopAccountCreatedPartyChange, shopPayoutToolChangedPartyChange, - shopPayouScheduleChangedPartyChange); - } else { - return buildMachineEvent(partyId, sequenceId, shopCreatedPartyChange, shopBlockingPartyChange, - shopCategoryPartyChange, shopContractPartyChange, shopDetailsPartyChange, shopSuspensionPartyChange, - shopAccountCreatedPartyChange, shopPayoutToolChangedPartyChange, - shopPayouScheduleChangedPartyChange, customPartyChange); - } - } - - public static MachineEvent buildMultiShopChangeDifferentShopId(Long sequenceId, String partyId, String shopId, - PartyChange customPartyChange) throws IOException { - String firstShopId = UUID.randomUUID().toString(); - PartyChange shopCreatedPartyChange = buildShopCreatedPartyChange(firstShopId); - PartyChange shopBlockingPartyChange = buildShopBlockingPartyChange(firstShopId); - String secondShopId = UUID.randomUUID().toString(); - PartyChange shopCreatedPartyChangeSec = buildShopCreatedPartyChange(secondShopId); - PartyChange shopCategoryPartyChangeSec = buildShopCategoryPartyChange(secondShopId); - PartyChange shopContractPartyChangeSec = buildShopContractPartyChange(secondShopId); - String thirdShopId = UUID.randomUUID().toString(); - PartyChange shopCreatedPartyChangeThird = buildShopCreatedPartyChange(thirdShopId); - PartyChange shopDetailsPartyChangeThird = buildShopDetailsPartyChange(thirdShopId); - PartyChange shopSuspensionPartyChangeThird = buildShopSuspensionPartyChange(thirdShopId); - String fourthShopId = shopId != null ? shopId : UUID.randomUUID().toString(); - PartyChange shopCreatedPartyChangeFourth = buildShopCreatedPartyChange(fourthShopId); - PartyChange shopAccountCreatedPartyChangeFourth = buildShopAccountCreatedPartyChange(fourthShopId); - PartyChange shopPayoutToolChangedPartyChangeFourth = - buildShopPayoutToolChangedPartyChange(fourthShopId, PAYOUT_TOOL_ID); - PartyChange shopPayouScheduleChangedPartyChangeFourth = buildShopPayouScheduleChangedPartyChange(fourthShopId); - if (customPartyChange == null) { - return buildMachineEvent(partyId, sequenceId, shopCreatedPartyChange, shopBlockingPartyChange, - shopCreatedPartyChangeSec, shopCategoryPartyChangeSec, shopContractPartyChangeSec, - shopCreatedPartyChangeThird, - shopDetailsPartyChangeThird, shopSuspensionPartyChangeThird, shopCreatedPartyChangeFourth, - shopAccountCreatedPartyChangeFourth, - shopPayoutToolChangedPartyChangeFourth, shopPayouScheduleChangedPartyChangeFourth); - } else { - return buildMachineEvent(partyId, sequenceId, shopCreatedPartyChange, shopBlockingPartyChange, - shopCreatedPartyChangeSec, shopCategoryPartyChangeSec, shopContractPartyChangeSec, - shopCreatedPartyChangeThird, - shopDetailsPartyChangeThird, shopSuspensionPartyChangeThird, shopCreatedPartyChangeFourth, - shopAccountCreatedPartyChangeFourth, - shopPayoutToolChangedPartyChangeFourth, shopPayouScheduleChangedPartyChangeFourth, - customPartyChange); - } - } - - public static PartyContractor buildPartyContractor(String partyId) throws IOException { - PartyContractor partyContractor = new PartyContractor(); - partyContractor.setId(partyId); - partyContractor.setStatus(ContractorIdentificationLevel.full); - Contractor contractor = new Contractor(); - contractor = new MockTBaseProcessor(MockMode.ALL).process(contractor, new TBaseHandler<>(Contractor.class)); - partyContractor.setContractor(contractor); - partyContractor.setIdentityDocuments(Collections.emptyList()); - return partyContractor; - } - public static PartyContractor buildRussianLegalPartyContractor(String partyId) throws IOException { PartyContractor partyContractor = new PartyContractor(); partyContractor.setId(partyId); @@ -611,33 +190,12 @@ public class PartyFlowGenerator { TypeUtil.temporalToString(LocalDateTime.now())); } - public static Shop buildShopCreated() throws IOException { - Shop shop = new Shop(); - shop = new MockTBaseProcessor(MockMode.ALL).process(shop, new TBaseHandler<>(Shop.class)); - shop.setCreatedAt(TypeUtil.temporalToString(LocalDateTime.now())); - Blocking blocking = new Blocking(); - blocking.setBlocked(new Blocked(SHOP_BLOCK_REASON, TypeUtil.temporalToString(LocalDateTime.now()))); - shop.setBlocking(blocking); - shop.setSuspension(buildPartySuspension()); - return shop; - } - - public static ShopSuspension buildActiveShopSuspension(String since, String shopId) { - Suspension suspension = new Suspension(); - suspension.setActive(new Active(since)); - return new ShopSuspension(shopId, suspension); - } - - public static ShopSuspension buildSuspendedShopSuspension(String since, String shopId) { - Suspension suspension = new Suspension(); - suspension.setSuspended(new Suspended(since)); - return new ShopSuspension(shopId, suspension); - } - - public static ShopBlocking buildShopBlocking(String shopId) { - Blocking blocking = new Blocking(); - blocking.setUnblocked(new Unblocked(SHOP_UNBLOCK_REASON, TypeUtil.temporalToString(LocalDateTime.now()))); - return new ShopBlocking(shopId, blocking); + public static Wallet buildWalletCreated() throws IOException { + Wallet wallet = new Wallet(); + wallet = new MockTBaseProcessor(MockMode.ALL).process(wallet, new TBaseHandler<>(Wallet.class)); + wallet.setCreatedAt(TypeUtil.temporalToString(LocalDateTime.now())); + wallet.setSuspension(buildPartySuspension()); + return wallet; } public static PartyRevisionChanged buildPartyRevisionChanged() { @@ -681,5 +239,4 @@ public class PartyFlowGenerator { sinkEvent.setEvent(machineEvent); return sinkEvent; } - } diff --git a/src/test/java/dev/vality/deanonimus/ReadTest.java b/src/test/java/dev/vality/deanonimus/ReadTest.java index d0199e1..2baef1a 100644 --- a/src/test/java/dev/vality/deanonimus/ReadTest.java +++ b/src/test/java/dev/vality/deanonimus/ReadTest.java @@ -2,12 +2,14 @@ package dev.vality.deanonimus; import dev.vality.damsel.deanonimus.SearchHit; import dev.vality.damsel.deanonimus.SearchShopHit; -import dev.vality.deanonimus.db.PartyRepository; +import dev.vality.damsel.deanonimus.SearchWalletHit; import dev.vality.deanonimus.domain.Party; import dev.vality.deanonimus.handler.DeanonimusServiceHandler; +import dev.vality.deanonimus.service.OpenSearchService; +import lombok.SneakyThrows; import org.apache.thrift.TException; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.opensearch.client.opensearch.OpenSearchClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -21,7 +23,10 @@ public class ReadTest extends AbstractIntegrationTest { Integer responseLimit; @Autowired - PartyRepository partyRepository; + OpenSearchService openSearchService; + + @Autowired + OpenSearchClient client; @Autowired DeanonimusServiceHandler deanonimusServiceHandler; @@ -32,18 +37,16 @@ public class ReadTest extends AbstractIntegrationTest { private static final String URL = "http://url.com"; private static final String CONTRACT = "contract"; private static final String CONTRACTOR = "contractor"; + private static final String WALLET = "wallet"; + private static final String WALLET_NAME = "wallet_name"; private static final String INN = "1234234123"; private static final String ACCOUNT = "9999999999"; - @BeforeEach - void setUp() { - partyRepository.deleteAll(); - } @Test void searchByPartyId() throws TException { givenParty(PARTY, EMAIL); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty(PARTY); assertFalse(searchHits.isEmpty()); @@ -58,7 +61,7 @@ public class ReadTest extends AbstractIntegrationTest { givenParty(PARTY + "-test-rofl", EMAIL + "3"); givenParty(PARTY + "-test-ricardo", EMAIL + "4"); givenParty(PARTY + "-test-milos", EMAIL + "5"); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty(PARTY + "-test-lol"); assertEquals(1, searchHits.size()); @@ -67,7 +70,7 @@ public class ReadTest extends AbstractIntegrationTest { @Test void searchByPartyEmail() throws TException { givenParty(PARTY, EMAIL); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty(EMAIL); assertFalse(searchHits.isEmpty()); @@ -79,7 +82,7 @@ public class ReadTest extends AbstractIntegrationTest { void searchByShopUrl() throws TException { Party party = givenParty(PARTY, EMAIL); givenShop(party, SHOP, URL); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty(URL); assertFalse(searchHits.isEmpty()); @@ -92,7 +95,7 @@ public class ReadTest extends AbstractIntegrationTest { void searchByShopId() throws TException { Party party = givenParty(PARTY, EMAIL); givenShop(party, SHOP, URL); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty(SHOP); assertFalse(searchHits.isEmpty()); @@ -105,7 +108,7 @@ public class ReadTest extends AbstractIntegrationTest { void searchShopByShopId() throws TException { Party party = givenParty(PARTY, EMAIL); givenShop(party, SHOP, URL); - + refreshIndices(); List searchShopHits = deanonimusServiceHandler.searchShopText(SHOP); assertFalse(searchShopHits.isEmpty()); @@ -117,7 +120,7 @@ public class ReadTest extends AbstractIntegrationTest { void searchShopByShopUrl() throws TException { Party party = givenParty(PARTY, EMAIL); givenShop(party, SHOP, URL); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchShopText(URL); assertFalse(searchHits.isEmpty()); @@ -125,12 +128,36 @@ public class ReadTest extends AbstractIntegrationTest { .anyMatch(partySearchHit -> partySearchHit.getShop().getLocation().getUrl().contains(URL))); } + @Test + void searchWalletByName() throws TException { + Party party = givenParty(PARTY, EMAIL); + givenWallet(party, WALLET, WALLET_NAME); + refreshIndices(); + List searchHits = deanonimusServiceHandler.searchWalletText(WALLET_NAME); + + assertFalse(searchHits.isEmpty()); + assertTrue(searchHits.stream() + .anyMatch(partySearchHit -> partySearchHit.getWallet().getName().contains(WALLET_NAME))); + } + + @Test + void searchWalletById() throws TException { + Party party = givenParty(PARTY, EMAIL); + givenWallet(party, WALLET, WALLET_NAME); + refreshIndices(); + List searchHits = deanonimusServiceHandler.searchWalletText(WALLET); + + assertFalse(searchHits.isEmpty()); + assertTrue(searchHits.stream() + .anyMatch(partySearchHit -> partySearchHit.getWallet().getId().contains(WALLET))); + } + @Test void searchByContractorEmail() throws TException { Party party = givenParty(PARTY, null); givenRegisteredUserContractor(party, CONTRACTOR, EMAIL); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty(EMAIL); assertFalse(searchHits.isEmpty()); @@ -144,7 +171,7 @@ public class ReadTest extends AbstractIntegrationTest { Party party = givenParty(PARTY, null); givenRussianContractor(party, CONTRACTOR, "ООО \"ЧИ ИЛИ НЕ ЧИ\"", INN, ACCOUNT); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty("ЧИ"); assertFalse(searchHits.isEmpty()); @@ -159,8 +186,8 @@ public class ReadTest extends AbstractIntegrationTest { Party party = givenParty(PARTY, null); givenRussianContractor(party, CONTRACTOR, "ООО \"ЧИ ИЛИ НЕ ЧИ\"", INN, ACCOUNT); - - List searchHits = deanonimusServiceHandler.searchParty("ЧИ ДА"); + refreshIndices(); + List searchHits = deanonimusServiceHandler.searchParty("ЧИ ИЛИ"); assertFalse(searchHits.isEmpty()); assertTrue(searchHits.stream() @@ -173,7 +200,7 @@ public class ReadTest extends AbstractIntegrationTest { Party party = givenParty(PARTY, null); givenRussianContractor(party, CONTRACTOR, "ООО \"ЧИ ИЛИ НЕ ЧИ\"", INN, ACCOUNT); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty("ДА"); assertTrue(searchHits.isEmpty()); @@ -184,7 +211,7 @@ public class ReadTest extends AbstractIntegrationTest { Party party = givenParty(PARTY, null); givenRussianContractor(party, CONTRACTOR, "ООО \"ЧИ ИЛИ НЕ ЧИ\"", INN, ACCOUNT); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty(INN); assertFalse(searchHits.isEmpty()); @@ -199,7 +226,7 @@ public class ReadTest extends AbstractIntegrationTest { Party party = givenParty(PARTY, null); givenRussianContractor(party, CONTRACTOR, "ООО \"ЧИ ИЛИ НЕ ЧИ\"", INN, ACCOUNT); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty(INN.substring(0, 6)); assertTrue(searchHits.isEmpty()); @@ -210,7 +237,7 @@ public class ReadTest extends AbstractIntegrationTest { Party party = givenParty(PARTY, null); givenInternationalContractor(party, CONTRACTOR, "SoMe LeGaL NaMe", "ANOTHER TRADING NAME"); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty("legal"); assertFalse(searchHits.isEmpty()); @@ -224,7 +251,7 @@ public class ReadTest extends AbstractIntegrationTest { Party party = givenParty(PARTY, null); givenContract(party, CONTRACT, 123, "ДГ-123432", "Василий Пупкин"); - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty("ДГ"); assertFalse(searchHits.isEmpty()); @@ -239,7 +266,7 @@ public class ReadTest extends AbstractIntegrationTest { Party party = givenParty(i + "", i + EMAIL.substring(EMAIL.indexOf("@"))); givenShop(party, 9 - i + "", URL + i); } - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty("1"); assertEquals(2, searchHits.size()); @@ -253,7 +280,7 @@ public class ReadTest extends AbstractIntegrationTest { Party party = givenParty(i + "", EMAIL); givenShop(party, 29 - i + "", URL + i); } - + refreshIndices(); List searchHits = deanonimusServiceHandler.searchParty("email"); assertEquals((long) responseLimit, searchHits.size()); @@ -269,7 +296,7 @@ public class ReadTest extends AbstractIntegrationTest { null, null, null)); - partyRepository.save(party); + openSearchService.updateParty(party); } private void givenRussianContractor(Party party, @@ -284,16 +311,21 @@ public class ReadTest extends AbstractIntegrationTest { russianLegalEntityRussianBankAccount, null, null)); - partyRepository.save(party); + openSearchService.updateParty(party); } private void givenShop(Party party, String id, String url) { party.addShop(TestData.shop(id, url)); - partyRepository.save(party); + openSearchService.updateParty(party); + } + + private void givenWallet(Party party, String id, String name) { + party.addWallet(TestData.wallet(id, name)); + openSearchService.updateParty(party); } private Party givenParty(String id, String email) { - return partyRepository.save(TestData.party(id, email)); + return openSearchService.createParty(TestData.party(id, email)); } private void givenInternationalContractor(Party party, @@ -307,7 +339,7 @@ public class ReadTest extends AbstractIntegrationTest { null, internationalLegalEntityLegalName, internationalLegalEntityTradingName)); - partyRepository.save(party); + openSearchService.updateParty(party); } private void givenContract(Party party, @@ -319,7 +351,11 @@ public class ReadTest extends AbstractIntegrationTest { termsId, legalAgreementId, reportActSignerFullName)); - partyRepository.save(party); + openSearchService.updateParty(party); } + @SneakyThrows + private void refreshIndices() { + client.indices().refresh(); + } } diff --git a/src/test/java/dev/vality/deanonimus/TestData.java b/src/test/java/dev/vality/deanonimus/TestData.java index 4f70714..372f1c2 100644 --- a/src/test/java/dev/vality/deanonimus/TestData.java +++ b/src/test/java/dev/vality/deanonimus/TestData.java @@ -15,7 +15,7 @@ public abstract class TestData { private static final Map.Entry timeFields = Map.entry( structHandler -> structHandler.value(Instant.now().toString()), - new String[] {"created_at", "at", "due"} + new String[]{"created_at", "at", "due"} ); private static final MockTBaseProcessor mockTBaseProcessor = new MockTBaseProcessor(MockMode.ALL, 15, 1); @@ -38,10 +38,17 @@ public abstract class TestData { .build(); } + public static dev.vality.deanonimus.domain.Wallet wallet(String id, String name) { + return dev.vality.deanonimus.domain.Wallet.builder() + .id(id) + .name(name) + .build(); + } + public static dev.vality.deanonimus.domain.Contract contract(String id, - Integer termsId, - String legalAgreementId, - String reportActSignerFullName) { + Integer termsId, + String legalAgreementId, + String reportActSignerFullName) { return dev.vality.deanonimus.domain.Contract.builder() .id(id) .status(ContractStatus.active) @@ -52,12 +59,12 @@ public abstract class TestData { } public static dev.vality.deanonimus.domain.Contractor contractor(String id, - String registeredUserEmail, - String russianLegalEntityRegisteredName, - String russianLegalEntityRegisteredInn, - String russianLegalEntityRussianBankAccount, - String internationalLegalEntityLegalName, - String internationalLegalEntityTradingName) { + String registeredUserEmail, + String russianLegalEntityRegisteredName, + String russianLegalEntityRegisteredInn, + String russianLegalEntityRussianBankAccount, + String internationalLegalEntityLegalName, + String internationalLegalEntityTradingName) { return dev.vality.deanonimus.domain.Contractor.builder() .id(id) .type(getContractorType(registeredUserEmail, russianLegalEntityRegisteredInn, diff --git a/src/test/java/dev/vality/deanonimus/WriteTest.java b/src/test/java/dev/vality/deanonimus/WriteTest.java index 06cd852..6ca86fd 100644 --- a/src/test/java/dev/vality/deanonimus/WriteTest.java +++ b/src/test/java/dev/vality/deanonimus/WriteTest.java @@ -1,8 +1,9 @@ package dev.vality.deanonimus; -import dev.vality.deanonimus.db.PartyRepository; import dev.vality.deanonimus.domain.Blocking; +import dev.vality.deanonimus.service.OpenSearchService; +import lombok.SneakyThrows; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -15,15 +16,27 @@ import static org.awaitility.Awaitility.await; public class WriteTest extends AbstractIntegrationTest { @Autowired - private PartyRepository partyRepository; + OpenSearchService openSearchService; @Test void onPartyCreatedElasticHaveIt() throws IOException { sendMessages(generatePartyContractorFlow(TestData.SOURCE_ID_ONE)); + sleep(); + await().until(() -> openSearchService.findPartyById(TestData.SOURCE_ID_ONE), + party -> party != null && party.getId().equals(TestData.SOURCE_ID_ONE) + ); - await().until(() -> partyRepository.findById(TestData.SOURCE_ID_ONE), - partyOptional -> partyOptional.isPresent() && partyOptional.get().getId().equals(TestData.SOURCE_ID_ONE) + } + + @Test + void onPartyCreatedWalletFlowElasticHaveIt() throws IOException { + + sendMessages(generateWalletFlow(TestData.SOURCE_ID_ONE)); + sleep(); + await().until(() -> openSearchService.findPartyById(TestData.SOURCE_ID_ONE), + party -> party != null && party.getId().equals(TestData.SOURCE_ID_ONE) + && !party.getWallets().isEmpty() ); } @@ -36,13 +49,17 @@ public class WriteTest extends AbstractIntegrationTest { buildSinkEvent(buildMessagePartyBlocking(0L, TestData.SOURCE_ID_ONE)) ) ); - - await().until(() -> partyRepository.findById(TestData.SOURCE_ID_ONE), - partyOptional -> partyOptional.isPresent() - && partyOptional.get().getId().equals(TestData.SOURCE_ID_ONE) - && partyOptional.get().getBlocking().equals(Blocking.blocked) + sleep(); + await().until(() -> openSearchService.findPartyById(TestData.SOURCE_ID_ONE), + partyOptional -> partyOptional != null + && partyOptional.getId().equals(TestData.SOURCE_ID_ONE) + && partyOptional.getBlocking().equals(Blocking.blocked) ); } + @SneakyThrows + private void sleep() { + Thread.sleep(5000L); + } } diff --git a/src/test/java/dev/vality/deanonimus/extension/OpensearchContainerExtension.java b/src/test/java/dev/vality/deanonimus/extension/OpensearchContainerExtension.java index 52ecb63..4920a79 100644 --- a/src/test/java/dev/vality/deanonimus/extension/OpensearchContainerExtension.java +++ b/src/test/java/dev/vality/deanonimus/extension/OpensearchContainerExtension.java @@ -9,8 +9,9 @@ import org.testcontainers.utility.DockerImageName; public class OpensearchContainerExtension implements BeforeAllCallback, AfterAllCallback { + public static GenericContainer OPENSEARCH = new GenericContainer<>( - DockerImageName.parse("opensearchproject/opensearch").withTag("1.2.4") + DockerImageName.parse("opensearchproject/opensearch:2.0.0") ); @Override