From b53dfda7a1e1b4204296bca23b03f0bd8271d838 Mon Sep 17 00:00:00 2001 From: psemenkov Date: Wed, 12 Oct 2022 15:01:46 +0300 Subject: [PATCH] Added tests for dictionary MapStore(with CompanyHistoryMapStore) --- .../dictionary/InterestStatusDictionary.java | 24 ++-- .../businessevent/CompanyHistoryMapStore.java | 9 +- .../imdg/config/HazelcastConfiguration.java | 10 +- .../clearing/imdg/config/PoolMapConfigs.java | 94 +++----------- .../InterestStatusDictionaryMapStore.java | 62 ++++----- .../imdg/services/UpdateMapService.java | 65 +++++++++- .../src/main/resources/application.properties | 1 - .../spcex/clearing/imdg/AllMapStoreTest.java | 42 +++++- .../imdg/config/DbTestConnectionConfig.java | 15 +-- .../imdg/config/TestConfiguration.java | 0 ...bjectAndBusinessEventForCheckMapStore.java | 0 .../DictionaryObjectForCheckMapStore.java | 0 .../RunnableMapNamesForTesting.java} | 33 ++++- .../imdg/utils/AbstractHistoryRowMapper.java | 74 +++++++++++ .../imdg/utils/BusinessEventRowMapper.java | 65 ++++++++++ .../clearing/imdg/utils/DbDataUtils.java | 37 +++++- .../clearing/imdg/utils/MatcherFactory.java | 0 .../imdg/utils/SpcexObjectBaseRowMapper.java | 48 +++++++ .../imdg/src/test/{ => resources}/ddl.sql | 0 .../imdg/utils/BusinessEventRowMapper.java | 120 ------------------ .../clearing/imdg/IMDGDistributedNames.java | 2 +- .../cud/utilities/KeyRateNewRequest.java | 7 +- .../cud/utilities/KeyRateUpdateRequest.java | 7 +- 23 files changed, 429 insertions(+), 286 deletions(-) rename clearing-parent/imdg/src/test/{ => java}/ru/spcex/clearing/imdg/AllMapStoreTest.java (83%) rename clearing-parent/imdg/src/test/{ => java}/ru/spcex/clearing/imdg/config/DbTestConnectionConfig.java (82%) rename clearing-parent/imdg/src/test/{ => java}/ru/spcex/clearing/imdg/config/TestConfiguration.java (100%) rename clearing-parent/imdg/src/test/{ => java}/ru/spcex/clearing/imdg/structure/BusinessObjectAndBusinessEventForCheckMapStore.java (100%) rename clearing-parent/imdg/src/test/{ => java}/ru/spcex/clearing/imdg/structure/DictionaryObjectForCheckMapStore.java (100%) rename clearing-parent/imdg/src/test/{ru/spcex/clearing/imdg/structure/GeneratorMapNamesForHazelcast.java => java/ru/spcex/clearing/imdg/structure/RunnableMapNamesForTesting.java} (64%) create mode 100644 clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/AbstractHistoryRowMapper.java create mode 100644 clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/BusinessEventRowMapper.java rename clearing-parent/imdg/src/test/{ => java}/ru/spcex/clearing/imdg/utils/DbDataUtils.java (88%) rename clearing-parent/imdg/src/test/{ => java}/ru/spcex/clearing/imdg/utils/MatcherFactory.java (100%) create mode 100644 clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/SpcexObjectBaseRowMapper.java rename clearing-parent/imdg/src/test/{ => resources}/ddl.sql (100%) delete mode 100644 clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/utils/BusinessEventRowMapper.java diff --git a/clearing-parent/dictionary/src/main/java/ru/clearing/platform/dictionary/InterestStatusDictionary.java b/clearing-parent/dictionary/src/main/java/ru/clearing/platform/dictionary/InterestStatusDictionary.java index 92a3c3d18..b8d2576a7 100644 --- a/clearing-parent/dictionary/src/main/java/ru/clearing/platform/dictionary/InterestStatusDictionary.java +++ b/clearing-parent/dictionary/src/main/java/ru/clearing/platform/dictionary/InterestStatusDictionary.java @@ -1,12 +1,12 @@ -//package ru.clearing.platform.dictionary; -// -///** -// * Справочник статусов возваращения процентов -// * -// * Dictionary DB table: INTEREST_STATUS_DICTIONARY -// **/ -//public class InterestStatusDictionary extends AbstractDictionary { -// private static final long serialVersionUID = ConstDictionarySerializable.serialVersionUID; -// -// -//} \ No newline at end of file +package ru.clearing.platform.dictionary; + +/** + * Справочник статусов возваращения процентов + *

+ * Dictionary DB table: INTEREST_STATUS_DICTIONARY + **/ +public class InterestStatusDictionary extends AbstractDictionary { + private static final long serialVersionUID = ConstDictionarySerializable.serialVersionUID; + + +} \ No newline at end of file diff --git a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/businessevent/CompanyHistoryMapStore.java b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/businessevent/CompanyHistoryMapStore.java index ce029e5a9..5c0e5a212 100644 --- a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/businessevent/CompanyHistoryMapStore.java +++ b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/businessevent/CompanyHistoryMapStore.java @@ -2,6 +2,7 @@ package ru.spcex.clearing.imdg.businessevent; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.lang.NonNull; +import org.springframework.stereotype.Component; import ru.clearing.classes.statics.data.company.Company; import ru.clearing.classes.statics.data.company.CompanyHistory; import ru.clearing.classes.statics.data.profile.CompanyInfo; @@ -13,9 +14,12 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -//@Component +@Component public class CompanyHistoryMapStore extends BusinessEventMapStore { + protected final String insertStatement = makeInsertSql(getTableName(), getFields(), "id"); + protected final String insertCompanyInfoStatement = makeInsertSql("COMPANY_INFO_HISTORY", getFieldsForCompanyInfo(), "id"); + public CompanyHistoryMapStore(JdbcTemplate jdbcTemplate) { super(jdbcTemplate); } @@ -42,9 +46,6 @@ public class CompanyHistoryMapStore extends BusinessEventMapStore map) { List batchArgs = new ArrayList<>(); diff --git a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/config/HazelcastConfiguration.java b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/config/HazelcastConfiguration.java index 362651331..ed760d9c4 100644 --- a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/config/HazelcastConfiguration.java +++ b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/config/HazelcastConfiguration.java @@ -16,7 +16,6 @@ public class HazelcastConfiguration { private final PoolMapConfigs poolMapConfigs; private final HazelcastServerSettings hzSettings; - private final ConfigurationRootElement configRoot = DfaConfig.get().getRoot(); @Autowired public HazelcastConfiguration(PoolMapConfigs poolMapConfigs, @@ -52,13 +51,8 @@ public class HazelcastConfiguration { ) ); -// config.addMapConfig(poolMapConfigs.map_CompanyRoleSet()); todo протестировать автоконфигуратор конфигурации мапсторов - config.addMapConfig(poolMapConfigs.map_CompanySymbols()); - config.addMapConfig(poolMapConfigs.map_ProfileDocument()); - config.addMapConfig(poolMapConfigs.map_Contact()); - config.addMapConfig(poolMapConfigs.map_Company()); -// config.addMapConfig(poolMapConfigs.map_CompanyUpdate()); - + config.addMapConfig(poolMapConfigs.map_Company()); //todo убедиться, что CompanyMapStore extends BusinessObjectMapStore теперь будет TemplateMapStore. + config.addMapConfig(poolMapConfigs.map_CompanyHistory()); // Автоподключение мап List autoMapCfg = poolMapConfigs.autoconfiguratorOfMapstorages(); for (MapConfig cfg : autoMapCfg) { diff --git a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/config/PoolMapConfigs.java b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/config/PoolMapConfigs.java index 7b2d9d7c2..d5889abff 100644 --- a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/config/PoolMapConfigs.java +++ b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/config/PoolMapConfigs.java @@ -12,10 +12,6 @@ import ru.spcex.clearing.imdg.base.AutoconfiguredMap; import ru.spcex.clearing.imdg.base.DictionaryTMapStore; import ru.spcex.clearing.imdg.businessevent.CompanyHistoryMapStore; import ru.spcex.clearing.imdg.businessobject.CompanyMapStore; -import ru.spcex.clearing.imdg.dictionary.*; -import ru.spcex.clearing.imdg.object.CompanySymbolsMapStore; -import ru.spcex.clearing.imdg.object.ContactMapStore; -import ru.spcex.clearing.imdg.object.ProfileDocumentMapStore; import java.util.ArrayList; import java.util.Arrays; @@ -24,12 +20,21 @@ import java.util.List; @Configuration public class PoolMapConfigs { - private Logger log = LoggerFactory.getLogger(getClass()); + private final Logger log = LoggerFactory.getLogger(getClass()); + @Autowired + private CompanyMapStore companyMapStore; + + @Autowired + private CompanyHistoryMapStore companyHistoryMapStore; + + // Автоконфигурируемые мапсторы: + @Autowired + private List> listOfAutopluginStores; private MapStoreConfig makeDefaultMapStoreConfig(MapLoader mapBean) { return new MapStoreConfig() .setImplementation(mapBean) -;//todo config: .setWriteDelaySeconds(configRoot.getIMDG().getDbSyncSeconds()); + ;//todo config: .setWriteDelaySeconds(configRoot.getIMDG().getDbSyncSeconds()); } public ScheduledExecutorConfig makeDefaultScheduledExecutorConfig(String name) { @@ -67,82 +72,13 @@ public class PoolMapConfigs { return makeMapIndexConfig(attributeName, false); } - - - @Autowired private AllowedDictionaryMapStore allowedDictionaryMapStore; - public MapConfig map_AllowedDictionary() { - return makeDefaultMapConfig(IMDGDistributedNames.Map_AllowedDictionary, allowedDictionaryMapStore) - .setNearCacheConfig(makeDefaultNearCacheConfig()) - .addMapIndexConfig(makeMapIndexConfig("code")); - } - @Autowired private CompanyRoleDictionaryMapStore companyRoleDictionaryMapStore; - public MapConfig map_CompanyRoleDictionary() { - return makeDefaultMapConfig(IMDGDistributedNames.Map_CompanyRoleDictionary, companyRoleDictionaryMapStore) - .setNearCacheConfig(makeDefaultNearCacheConfig()) - .addMapIndexConfig(makeMapIndexConfig("code")); - } - @Autowired private CompanySymbolDictionaryMapStore companySymbolDictionaryMapStore; - public MapConfig map_CompanySymbolDictionary() { - return makeDefaultMapConfig(IMDGDistributedNames.Map_CompanySymbolDictionary, companySymbolDictionaryMapStore) - .setNearCacheConfig(makeDefaultNearCacheConfig()) - .addMapIndexConfig(makeMapIndexConfig("code")); - } - @Autowired private ContactTypeDictionaryMapStore contactTypeDictionaryMapStore; - public MapConfig map_ContactTypeDictionary() { - return makeDefaultMapConfig(IMDGDistributedNames.Map_ContactTypeDictionary, contactTypeDictionaryMapStore) - .setNearCacheConfig(makeDefaultNearCacheConfig()) - .addMapIndexConfig(makeMapIndexConfig("code")); - } - @Autowired private CorporationSoleTypeDictionaryMapStore corporationSoleTypeDictionaryMapStore; - public MapConfig map_CorporationSoleTypeDictionary() { - return makeDefaultMapConfig(IMDGDistributedNames.Map_CorporationSoleTypeDictionary, corporationSoleTypeDictionaryMapStore) - .setNearCacheConfig(makeDefaultNearCacheConfig()) - .addMapIndexConfig(makeMapIndexConfig("code")); - } - @Autowired private CountryCodeDictionaryMapStore countryCodeDictionaryMapStore; - public MapConfig map_CountryCodeDictionary() { - return makeDefaultMapConfig(IMDGDistributedNames.Map_CountryCodeDictionary, countryCodeDictionaryMapStore) - .setNearCacheConfig(makeDefaultNearCacheConfig()) - .addMapIndexConfig(makeMapIndexConfig("code")); - } - @Autowired private DocumentTypeDictionaryMapStore documentTypeDictionaryMapStore; - public MapConfig map_DocumentTypeDictionary() { - return makeDefaultMapConfig(IMDGDistributedNames.Map_DocumentTypeDictionary, documentTypeDictionaryMapStore) - .setNearCacheConfig(makeDefaultNearCacheConfig()) - .addMapIndexConfig(makeMapIndexConfig("code")); - } - @Autowired private LegalKindDictionaryMapStore legalKindDictionaryMapStore; - public MapConfig map_LegalKindDictionary() { - return makeDefaultMapConfig(IMDGDistributedNames.Map_LegalKindDictionary, legalKindDictionaryMapStore) - .setNearCacheConfig(makeDefaultNearCacheConfig()) - .addMapIndexConfig(makeMapIndexConfig("code")); - } - @Autowired private OrganizationTypeDictionaryMapStore organizationTypeDictionaryMapStore; - public MapConfig map_OrganizationTypeDictionary() { - return makeDefaultMapConfig(IMDGDistributedNames.Map_OrganizationTypeDictionary, organizationTypeDictionaryMapStore) - .setNearCacheConfig(makeDefaultNearCacheConfig()) - .addMapIndexConfig(makeMapIndexConfig("code")); - } - @Autowired private WorkflowStatusDictionaryMapStore workflowStatusDictionaryMapStore; - public MapConfig map_WorkflowStatusDictionary() { - return makeDefaultMapConfig(IMDGDistributedNames.Map_WorkflowStatusDictionary, workflowStatusDictionaryMapStore) - .setNearCacheConfig(makeDefaultNearCacheConfig()) - .addMapIndexConfig(makeMapIndexConfig("code")); - } - - - - @Autowired - private CompanyMapStore companyMapStore; - public MapConfig map_Company() { return makeDefaultMapConfig(IMDGDistributedNames.Map_Company, companyMapStore); } - - // Автоконфигурируемые мапсторы: - @Autowired - private List> listOfAutopluginStores; + public MapConfig map_CompanyHistory() { + return makeDefaultMapConfig(IMDGDistributedNames.Map_CompanyHistory, companyHistoryMapStore); + } // @Qualifier("AutoconfiguredMapStore") public List autoconfiguratorOfMapstorages() { @@ -173,7 +109,7 @@ public class PoolMapConfigs { } out.add(mapCfg); } catch (RuntimeException e) { - throw new RuntimeException("Can not configure MapStore " + mapStore.getMapName() + "(" + mapStore.toString() + "): " + e, e); + throw new RuntimeException("Can not configure MapStore " + mapStore.getMapName() + "(" + mapStore + "): " + e, e); } } log.debug("Configured {} mapStore's", out.size()); diff --git a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/dictionary/InterestStatusDictionaryMapStore.java b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/dictionary/InterestStatusDictionaryMapStore.java index ccde56222..af6609e62 100644 --- a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/dictionary/InterestStatusDictionaryMapStore.java +++ b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/dictionary/InterestStatusDictionaryMapStore.java @@ -1,31 +1,31 @@ -//package ru.spcex.clearing.imdg.dictionary; -// -//import org.springframework.jdbc.core.JdbcTemplate; -//import org.springframework.stereotype.Component; -//import ru.clearing.platform.dictionary.InterestStatusDictionary; -//import ru.spcex.clearing.imdg.base.DictionaryTMapStore; -//import ru.spcex.clearing.imdg.IMDGDistributedNames; -// -//@Component -//public class InterestStatusDictionaryMapStore extends DictionaryTMapStore { -// -// public InterestStatusDictionaryMapStore(JdbcTemplate jdbcTemplate) { -// super(jdbcTemplate); -// } -// -// @Override -// public String getMapName() { -// return IMDGDistributedNames.Map_InterestStatusDictionary; -// } -// -// @Override -// public String getTableName() { -// return "INTEREST_STATUS_DICTIONARY"; -// } -// -// @Override -// public InterestStatusDictionary getDictionaryObject() { -// return new InterestStatusDictionary(); -// } -// -//} \ No newline at end of file +package ru.spcex.clearing.imdg.dictionary; + +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Component; +import ru.clearing.platform.dictionary.InterestStatusDictionary; +import ru.spcex.clearing.imdg.IMDGDistributedNames; +import ru.spcex.clearing.imdg.base.DictionaryTMapStore; + +@Component +public class InterestStatusDictionaryMapStore extends DictionaryTMapStore { + + public InterestStatusDictionaryMapStore(JdbcTemplate jdbcTemplate) { + super(jdbcTemplate); + } + + @Override + public String getMapName() { + return IMDGDistributedNames.Map_InterestStatusDictionary; + } + + @Override + public String getTableName() { + return "INTEREST_STATUS_DICTIONARY"; + } + + @Override + public InterestStatusDictionary getDictionaryObject() { + return new InterestStatusDictionary(); + } + +} \ No newline at end of file diff --git a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/services/UpdateMapService.java b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/services/UpdateMapService.java index 760974ebe..74b84ca1e 100644 --- a/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/services/UpdateMapService.java +++ b/clearing-parent/imdg/src/main/java/ru/spcex/clearing/imdg/services/UpdateMapService.java @@ -7,8 +7,17 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import ru.clearing.classes.statics.data.account.*; import ru.clearing.classes.statics.data.company.Company; import ru.clearing.classes.statics.data.company.CompanyHistory; +import ru.clearing.classes.statics.data.company.relation.Relation; +import ru.clearing.classes.statics.data.company.relation.RelationHistory; +import ru.clearing.classes.statics.data.security.Security; +import ru.clearing.classes.statics.data.security.SecurityHistory; +import ru.clearing.classes.statics.data.user.User; +import ru.clearing.classes.statics.data.user.UserConnect; +import ru.clearing.classes.statics.data.user.UserConnectHistory; +import ru.clearing.classes.statics.data.user.UserHistory; import ru.spcex.clearing.imdg.IMDGDistributedNames; @Service @@ -22,18 +31,72 @@ public class UpdateMapService extends AbstractUpdateMapService { @Override public void addingListenersToCards() { + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_AccountBalance).addLocalEntryListener(this, Predicates.alwaysTrue(), true); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_Account).addLocalEntryListener(this, Predicates.alwaysTrue(), true); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_AccountRouting).addLocalEntryListener(this, Predicates.alwaysTrue(), true); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_BankAccount).addLocalEntryListener(this, Predicates.alwaysTrue(), true); hazelcastServerInstance.getMap(IMDGDistributedNames.Map_Company).addLocalEntryListener(this, Predicates.alwaysTrue(), true); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_InformationAccount).addLocalEntryListener(this, Predicates.alwaysTrue(), true); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_Relation).addLocalEntryListener(this, Predicates.alwaysTrue(), true); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_Security).addLocalEntryListener(this, Predicates.alwaysTrue(), true); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_UserConnect).addLocalEntryListener(this, Predicates.alwaysTrue(), true); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_User).addLocalEntryListener(this, Predicates.alwaysTrue(), true); } @Override protected void entryModified(EntryEvent event, String eventType) { log.debug("{} {}", event, eventType); Object value = (EVENT_DELETE.equals(eventType) ? event.getOldValue() : event.getValue()); - if (value instanceof Company) { + if (value instanceof AccountBalance) { + AccountBalanceHistory accountBalanceHistory = new AccountBalanceHistory(); + createBusinessEvent(accountBalanceHistory, eventType); + accountBalanceHistory.setObject((AccountBalance) value); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_AccountBalanceHistory).put(accountBalanceHistory.getId(), accountBalanceHistory); + } else if (value instanceof Account) { + AccountHistory accountHistory = new AccountHistory(); + createBusinessEvent(accountHistory, eventType); + accountHistory.setObject((Account) value); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_AccountHistory).put(accountHistory.getId(), accountHistory); + } else if (value instanceof AccountRouting) { + AccountRoutingHistory accountRoutingHistory = new AccountRoutingHistory(); + createBusinessEvent(accountRoutingHistory, eventType); + accountRoutingHistory.setObject((AccountRouting) value); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_AccountRoutingHistory).put(accountRoutingHistory.getId(), accountRoutingHistory); + } else if (value instanceof BankAccount) { + BankAccountHistory bankAccountHistory = new BankAccountHistory(); + createBusinessEvent(bankAccountHistory, eventType); + bankAccountHistory.setObject((BankAccount) value); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_BankAccountHistory).put(bankAccountHistory.getId(), bankAccountHistory); + } else if (value instanceof Company) { CompanyHistory companyHistory = new CompanyHistory(); createBusinessEvent(companyHistory, eventType); companyHistory.setObject((Company) value); hazelcastServerInstance.getMap(IMDGDistributedNames.Map_CompanyHistory).put(companyHistory.getId(), companyHistory); + } else if (value instanceof InformationAccount) { + InformationAccountHistory informationAccountHistory = new InformationAccountHistory(); + createBusinessEvent(informationAccountHistory, eventType); + informationAccountHistory.setObject((InformationAccount) value); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_InformationAccountHistory).put(informationAccountHistory.getId(), informationAccountHistory); + } else if (value instanceof Relation) { + RelationHistory relationHistory = new RelationHistory(); + createBusinessEvent(relationHistory, eventType); + relationHistory.setObject((Relation) value); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_RelationHistory).put(relationHistory.getId(), relationHistory); + } else if (value instanceof Security) { + SecurityHistory securityHistory = new SecurityHistory(); + createBusinessEvent(securityHistory, eventType); + securityHistory.setObject((Security) value); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_SecurityHistory).put(securityHistory.getId(), securityHistory); + } else if (value instanceof UserConnect) { + UserConnectHistory userConnectHistory = new UserConnectHistory(); + createBusinessEvent(userConnectHistory, eventType); + userConnectHistory.setObject((UserConnect) value); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_UserConnectHistory).put(userConnectHistory.getId(), userConnectHistory); + } else if (value instanceof User) { + UserHistory userHistory = new UserHistory(); + createBusinessEvent(userHistory, eventType); + userHistory.setObject((User) value); + hazelcastServerInstance.getMap(IMDGDistributedNames.Map_UserHistory).put(userHistory.getId(), userHistory); } else { log.error("unexpected event {}", event); } diff --git a/clearing-parent/imdg/src/main/resources/application.properties b/clearing-parent/imdg/src/main/resources/application.properties index 0d8a53ff5..25d107bdb 100644 --- a/clearing-parent/imdg/src/main/resources/application.properties +++ b/clearing-parent/imdg/src/main/resources/application.properties @@ -2,7 +2,6 @@ imdg.hazelcast.listenPort=5701 imdg.hazelcast.login=dev imdg.hazelcast.password=dev-pass imdg.hazelcast.cluster-members[0]=127.0.0.1 - imdg.database.login=clearing imdg.database.password=Aa111111 imdg.database.url=jdbc:postgresql://10.200.200.133:5432/postgres \ No newline at end of file diff --git a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/AllMapStoreTest.java b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/AllMapStoreTest.java similarity index 83% rename from clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/AllMapStoreTest.java rename to clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/AllMapStoreTest.java index 05cc769c7..cd1797148 100644 --- a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/AllMapStoreTest.java +++ b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/AllMapStoreTest.java @@ -20,6 +20,9 @@ import org.springframework.lang.NonNull; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit.jupiter.SpringExtension; +import ru.clearing.classes.statics.data.company.Company; +import ru.clearing.classes.statics.data.company.CompanyHistory; +import ru.clearing.classes.statics.data.profile.CompanyInfo; import ru.clearing.platform.dictionary.AbstractDictionary; import ru.clearing.platform.dictionary.CompanySymbolDictionary; import ru.spcex.clearing.imdg.base.*; @@ -29,6 +32,7 @@ import ru.spcex.clearing.imdg.structure.BusinessObjectAndBusinessEventForCheckMa import ru.spcex.clearing.imdg.structure.DictionaryObjectForCheckMapStore; import ru.spcex.clearing.imdg.utils.BusinessEventRowMapper; import ru.spcex.clearing.imdg.utils.DbDataUtils; +import ru.spcex.clearing.imdg.utils.SpcexObjectBaseRowMapper; import ru.spcex.platform.classes.base.SpcexObjectBase; import ru.spcex.platform.utils.text.TextUtil; @@ -38,8 +42,8 @@ import java.sql.*; import java.util.*; import java.util.stream.Collectors; -import static ru.spcex.clearing.imdg.structure.GeneratorMapNamesForHazelcast.businessObjectAndBusinessEventForCheckMapStores; -import static ru.spcex.clearing.imdg.structure.GeneratorMapNamesForHazelcast.dictionaryObjectForCheckMapStores; +import static ru.spcex.clearing.imdg.structure.RunnableMapNamesForTesting.businessObjectAndBusinessEventForCheckMapStores; +import static ru.spcex.clearing.imdg.structure.RunnableMapNamesForTesting.dictionaryObjectForCheckMapStores; @ContextConfiguration(classes = { TestConfiguration.class, @@ -61,7 +65,21 @@ public class AllMapStoreTest { for (BusinessObjectAndBusinessEventForCheckMapStore objectForCheck : businessObjectAndBusinessEventForCheckMapStores) { SpcexObjectBase object = objectForCheck.getClazz().getDeclaredConstructor().newInstance(); DbDataUtils.fillObjectDefaultValues(object, object.getClass()); - objectForCheck.setPredictableObj(object); + if (objectForCheck.getClazz().equals(CompanyHistory.class)) { + CompanyHistory companyHistory = (CompanyHistory) object; + CompanyInfo companyInfo = companyHistory.getObject().getProfile(); + companyInfo.setCompanyId(companyHistory.getObject().getId()); + companyInfo.setId(1000000L); + objectForCheck.setPredictableObj(companyHistory); + } else if (objectForCheck.getClazz().equals(Company.class)) { + Company company = (Company) object; + CompanyInfo companyInfo = company.getProfile(); + companyInfo.setCompanyId(1000000L); + companyInfo.setId(1000000L); + objectForCheck.setPredictableObj(company); + } else { + objectForCheck.setPredictableObj(object); + } } for (DictionaryObjectForCheckMapStore objectForCheck : dictionaryObjectForCheckMapStores) { AbstractDictionary object = objectForCheck.getClazz().getDeclaredConstructor().newInstance(); @@ -104,6 +122,8 @@ public class AllMapStoreTest { tableName = ((TemplateEventMapStore) mapStore).getTableName(); } else if (mapStore instanceof BusinessObjectMapStore) { tableName = ((BusinessObjectMapStore) mapStore).getTableName(); + } else if (mapStore instanceof BusinessEventMapStore) { + tableName = ((BusinessEventMapStore) mapStore).getTableName(); } else if (mapName.equals("default")) { continue; } else { @@ -112,9 +132,9 @@ public class AllMapStoreTest { } nameTables.remove(tableName.toLowerCase()); } - System.out.println("** Результата поиска таблиц которым нужно добавить mapStore **"); + System.out.println("** Результат поиска таблиц которым нужно добавить mapStore **"); nameTables.forEach(System.out::println); - System.out.println("**************************************************************"); + System.out.println("*************************************************************"); Assertions.assertEquals(0, nameTables.size()); } @@ -132,6 +152,15 @@ public class AllMapStoreTest { String sql = String.format("SELECT * FROM %s WHERE id = %d", getTableNameFromMapStore(objectForCheck.getMapName()), ID); List obj = jdbcTemplate.query(sql, new BusinessEventRowMapper<>(objectForCheck.getClazz())); actual = DataAccessUtils.singleResult(obj); + } else if (getMapStore(mapName) instanceof BusinessEventMapStore) { + String sql = String.format("SELECT * FROM %s WHERE id = %d", getTableNameFromMapStore(objectForCheck.getMapName()), ID); + List objCompanyHistory = jdbcTemplate.query(sql, new BusinessEventRowMapper<>(objectForCheck.getClazz())); + CompanyHistory companyHistory = DataAccessUtils.singleResult(objCompanyHistory); + String sqlI = String.format("SELECT * FROM %s WHERE id = %d", "COMPANY_INFO_HISTORY", ID); + List objCompanyInfo = jdbcTemplate.query(sqlI, new SpcexObjectBaseRowMapper<>(CompanyInfo.class)); + CompanyInfo companyInfo = DataAccessUtils.singleResult(objCompanyInfo); + companyHistory.getObject().setProfile(companyInfo); + actual = companyHistory; } else { IMap map = testConfig.getHazelcastInstance().getMap(mapName); actual = map.get(ID); @@ -176,6 +205,8 @@ public class AllMapStoreTest { tableName = ((TemplateEventMapStore) mapStore).getTableName(); } else if (mapStore instanceof BusinessObjectMapStore) { tableName = ((BusinessObjectMapStore) mapStore).getTableName(); + } else if (mapStore instanceof BusinessEventMapStore) { + tableName = ((BusinessEventMapStore) mapStore).getTableName(); } return tableName; } @@ -191,7 +222,6 @@ public class AllMapStoreTest { SpcexObjectBase spcexObjectBase = objectForCheck.getPredictableObj(); spcexObjectBase.setId(ID); log.info("Запись в мап {} объекта {}", mapName, spcexObjectBase); - Object mapStore = getMapStore(mapName); IMap map = testConfig.getHazelcastInstance().getMap(mapName); map.put(spcexObjectBase.getId(), spcexObjectBase); } diff --git a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/config/DbTestConnectionConfig.java b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/config/DbTestConnectionConfig.java similarity index 82% rename from clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/config/DbTestConnectionConfig.java rename to clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/config/DbTestConnectionConfig.java index bdcaa1d6a..b292343e3 100644 --- a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/config/DbTestConnectionConfig.java +++ b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/config/DbTestConnectionConfig.java @@ -19,8 +19,6 @@ import java.sql.Connection; public class DbTestConnectionConfig { private final Logger log = LoggerFactory.getLogger(this.getClass()); - private final ConfigurationRootElement configRoot = DfaConfig.get().getRoot(); - private DatabasePopulator createDatabasePopulator() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); databasePopulator.setContinueOnError(true); @@ -35,7 +33,7 @@ public class DbTestConnectionConfig { String password = "Aa111111"; String logTimeoutPart = ""; String dbPath = "jdbc:postgresql://10.200.200.133:5432/postgres?currentSchema=clearing_tester"; - int timeoutSec = configRoot.getDatabase().getConnectionAcquireTimeoutSeconds(); + int timeoutSec = 30; ComboPooledDataSource cpds = new ComboPooledDataSource(); try { @@ -46,11 +44,12 @@ public class DbTestConnectionConfig { cpds.setJdbcUrl(dbPath); cpds.setUser(login); cpds.setPassword(password); - cpds.setInitialPoolSize(configRoot.getDatabase().getMinPoolSize()); - cpds.setMinPoolSize(configRoot.getDatabase().getMinPoolSize()); - cpds.setMaxPoolSize(configRoot.getDatabase().getMaxPoolSize()); - cpds.setNumHelperThreads(configRoot.getDatabase().getNumHelperThreads()); - cpds.setCheckoutTimeout(timeoutSec * 1000/*todo common 1000==ConstsCommon.SECOND*/); + cpds.setInitialPoolSize(10); + cpds.setMinPoolSize(01); + cpds.setMaxPoolSize(30); + int numHelperThreads = Runtime.getRuntime().availableProcessors() * 2; + cpds.setNumHelperThreads(numHelperThreads); + cpds.setCheckoutTimeout(timeoutSec * 1000); logTimeoutPart = String.format(" (timeout=%ds)", timeoutSec); // DatabasePopulatorUtils.execute(createDatabasePopulator(), cpds); result = cpds; diff --git a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/config/TestConfiguration.java b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/config/TestConfiguration.java similarity index 100% rename from clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/config/TestConfiguration.java rename to clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/config/TestConfiguration.java diff --git a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/structure/BusinessObjectAndBusinessEventForCheckMapStore.java b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/structure/BusinessObjectAndBusinessEventForCheckMapStore.java similarity index 100% rename from clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/structure/BusinessObjectAndBusinessEventForCheckMapStore.java rename to clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/structure/BusinessObjectAndBusinessEventForCheckMapStore.java diff --git a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/structure/DictionaryObjectForCheckMapStore.java b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/structure/DictionaryObjectForCheckMapStore.java similarity index 100% rename from clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/structure/DictionaryObjectForCheckMapStore.java rename to clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/structure/DictionaryObjectForCheckMapStore.java diff --git a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/structure/GeneratorMapNamesForHazelcast.java b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/structure/RunnableMapNamesForTesting.java similarity index 64% rename from clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/structure/GeneratorMapNamesForHazelcast.java rename to clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/structure/RunnableMapNamesForTesting.java index 02b8c39eb..6e7e9b50c 100644 --- a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/structure/GeneratorMapNamesForHazelcast.java +++ b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/structure/RunnableMapNamesForTesting.java @@ -2,6 +2,7 @@ package ru.spcex.clearing.imdg.structure; import ru.clearing.classes.statics.data.account.*; import ru.clearing.classes.statics.data.company.Company; +import ru.clearing.classes.statics.data.company.CompanyHistory; import ru.clearing.classes.statics.data.company.relation.Relation; import ru.clearing.classes.statics.data.company.relation.RelationHistory; import ru.clearing.classes.statics.data.messages.ErrorText; @@ -24,7 +25,7 @@ import java.math.BigDecimal; import java.util.LinkedList; import java.util.List; -public class GeneratorMapNamesForHazelcast { +public class RunnableMapNamesForTesting { public static List businessObjectAndBusinessEventForCheckMapStores; public static List dictionaryObjectForCheckMapStores; @@ -41,7 +42,7 @@ public class GeneratorMapNamesForHazelcast { businessObjectAndBusinessEventForCheckMapStores.add(new BusinessObjectAndBusinessEventForCheckMapStore<>(IMDGDistributedNames.Map_AccountHistory, AccountHistory.class)); businessObjectAndBusinessEventForCheckMapStores.add(new BusinessObjectAndBusinessEventForCheckMapStore<>(IMDGDistributedNames.Map_AccountRoutingHistory, AccountRoutingHistory.class)); businessObjectAndBusinessEventForCheckMapStores.add(new BusinessObjectAndBusinessEventForCheckMapStore<>(IMDGDistributedNames.Map_BankAccountHistory, BankAccountHistory.class)); -// objectForCheckMapStores.add(new ObjectForCheckMapStore<>(IMDGDistributedNames.Map_CompanyHistory, CompanyHistory.class)); + businessObjectAndBusinessEventForCheckMapStores.add(new BusinessObjectAndBusinessEventForCheckMapStore<>(IMDGDistributedNames.Map_CompanyHistory, CompanyHistory.class)); businessObjectAndBusinessEventForCheckMapStores.add(new BusinessObjectAndBusinessEventForCheckMapStore<>(IMDGDistributedNames.Map_InformationAccountHistory, InformationAccountHistory.class)); businessObjectAndBusinessEventForCheckMapStores.add(new BusinessObjectAndBusinessEventForCheckMapStore<>(IMDGDistributedNames.Map_RelationHistory, RelationHistory.class)); businessObjectAndBusinessEventForCheckMapStores.add(new BusinessObjectAndBusinessEventForCheckMapStore<>(IMDGDistributedNames.Map_SecurityHistory, SecurityHistory.class)); @@ -80,5 +81,33 @@ public class GeneratorMapNamesForHazelcast { dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_CourierTypeDictionary, CourierTypeDictionary.class)); dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_CurrencyCodeDictionary, CurrencyCodeDictionary.class)); dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_DocumentTypeDictionary, DocumentTypeDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_ErrorCodeDictionary, ErrorCodeDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_InOutDirectionDictionary, InOutDirectionDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_InstrumentTypeDictionary, InstrumentTypeDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_InterestStatusDictionary, InterestStatusDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_LegalKindDictionary, LegalKindDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_ManagementJournalPurposeDictionary, ManagementJournalPurposeDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_ManagementJournalStatusDictionary, ManagementJournalStatusDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_ManagementJournalTypeDictionary, ManagementJournalTypeDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_MoneyFlowSideDictionary, MoneyFlowSideDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_OperationStatusDictionary, OperationStatusDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_OperationTypeDictionary, OperationTypeDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_OrganizationTypeDictionary, OrganizationTypeDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_ResultStatusDictionary, ResultStatusDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_SectorDictionary, SectorDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_ServiceDictionary, ServiceDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_ServiceProductDictionary, ServiceProductDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_ServiceStatusDictionary, ServiceStatusDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_SourceDictionary, SourceDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_StatementTypeDictionary, StatementTypeDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_TaskDictionary, TaskDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_TaskStatusDictionary, TaskStatusDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_TermTypeDictionary, TermTypeDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_TradingStatusDictionary, TradingStatusDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_UserRoleDictionary, UserRoleDictionary.class)); + dictionaryObjectForCheckMapStores.add(new DictionaryObjectForCheckMapStore<>(IMDGDistributedNames.Map_WorkflowStatusDictionary, WorkflowStatusDictionary.class)); + + //object + businessObjectAndBusinessEventForCheckMapStores.add(new BusinessObjectAndBusinessEventForCheckMapStore<>(IMDGDistributedNames.Map_AccountRouting, AccountRouting.class)); } } diff --git a/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/AbstractHistoryRowMapper.java b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/AbstractHistoryRowMapper.java new file mode 100644 index 000000000..00f746706 --- /dev/null +++ b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/AbstractHistoryRowMapper.java @@ -0,0 +1,74 @@ +package ru.spcex.clearing.imdg.utils; + +import org.springframework.jdbc.core.RowMapper; +import ru.spcex.platform.classes.base.SpcexObjectBase; + +import java.lang.reflect.Field; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Time; +import java.sql.Timestamp; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.ZoneId; +import java.util.Date; + +public abstract class AbstractHistoryRowMapper implements RowMapper { + @Override + abstract public T mapRow(ResultSet rs, int rowNum) throws SQLException; + + + protected void setValueFildForObjectIfFildExists(SpcexObjectBase object, Class clazz, String fildName, Object value) { + try { + Field field = clazz.getDeclaredField(fildName); + field.setAccessible(true); + Class typeField = field.getType(); + if (typeField.equals(LocalDate.class)) { + Date date = (Date) value; + field.set(object, value != null ? Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate() : null); + } else if (typeField.equals(LocalTime.class)) { + Time time = (Time) value; + field.set(object, value != null ? time.toLocalTime() : null); + } else if (typeField.getName().equals(Instant.class.getName())) { + field.set(object, value != null ? ((Timestamp) value).toInstant() : null); + } else { + field.set(object, value); + } + } catch (NoSuchFieldException e) { + if (!clazz.getSuperclass().getName().equals(Object.class.getName())) { + setValueFildForObjectIfFildExists(object, clazz.getSuperclass(), fildName, value); + } + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + protected String getFildName(String str, String objIdColumn) { + if (str.equals(objIdColumn)) { + return "objId"; + } else if (str.equals("created_at")) { + return "created"; + } else if (str.equals("updated_at")) { + return "updated"; + } + return snakeCaseToCamelCase(str); + } + + protected String snakeCaseToCamelCase(String str) { + StringBuilder builder = new StringBuilder(str); + for (int i = 0; i < builder.length(); i++) { + + // Check char is underscore + if (builder.charAt(i) == '_') { + builder.deleteCharAt(i); + builder.replace( + i, i + 1, + String.valueOf( + Character.toUpperCase( + builder.charAt(i)))); + } + } + return builder.toString(); + } +} \ No newline at end of file diff --git a/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/BusinessEventRowMapper.java b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/BusinessEventRowMapper.java new file mode 100644 index 000000000..0b04f8be5 --- /dev/null +++ b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/BusinessEventRowMapper.java @@ -0,0 +1,65 @@ +package ru.spcex.clearing.imdg.utils; + +import org.springframework.beans.BeanUtils; +import org.springframework.beans.NotWritablePropertyException; +import org.springframework.beans.TypeMismatchException; +import org.springframework.jdbc.support.JdbcUtils; +import ru.clearing.classes.objects.BusinessEvent; +import ru.spcex.platform.classes.base.SpcexObjectBase; + +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; + +public class BusinessEventRowMapper extends AbstractHistoryRowMapper { + + private final Class mappedClass; + + public BusinessEventRowMapper(Class mappedClass) { + this.mappedClass = mappedClass; + } + + @Override + public T mapRow(ResultSet rs, int rowNum) throws SQLException { + T historyObject = BeanUtils.instantiateClass(this.mappedClass); + SpcexObjectBase objectFild = null; + try { + objectFild = (SpcexObjectBase) BeanUtils.instantiateClass(historyObject.getClass().getDeclaredField("object").getType()); + } catch (NoSuchFieldException e) { + throw new RuntimeException(e); + } + ResultSetMetaData meta_data = rs.getMetaData(); + String objIdColumn = rs.getMetaData().getTableName(1).replace("_history", "_id"); + + int columnCount = meta_data.getColumnCount(); + + for (int index = 1; index <= columnCount; index++) { + String column = JdbcUtils.lookupColumnName(meta_data, index); + String fildName = getFildName(column, objIdColumn); + try { + Object value = JdbcUtils.getResultSetValue(rs, index, Class.forName(meta_data.getColumnClassName(index))); + if (fildName.equals("id")) { + historyObject.setId((Long) value); + continue; + } else if (fildName.equals("eventUserId")) { + historyObject.setUserId((Long) value); + continue; + } else if (fildName.equals("userId")) { + setValueFildForObjectIfFildExists(objectFild, objectFild.getClass(), fildName, value); + continue; + } else if (fildName.equals("objId")) { + objectFild.setId((Long) value); + continue; + } + setValueFildForObjectIfFildExists(historyObject, historyObject.getClass(), fildName, value); + setValueFildForObjectIfFildExists(objectFild, objectFild.getClass(), fildName, value); + } catch (TypeMismatchException | NotWritablePropertyException e) { + // Ignore + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + historyObject.setObject(objectFild); + return historyObject; + } +} \ No newline at end of file diff --git a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/utils/DbDataUtils.java b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/DbDataUtils.java similarity index 88% rename from clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/utils/DbDataUtils.java rename to clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/DbDataUtils.java index 7e98a96c5..10ec1bca6 100644 --- a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/utils/DbDataUtils.java +++ b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/DbDataUtils.java @@ -187,17 +187,17 @@ public final class DbDataUtils { Class typeField = field.getType(); try { if (typeField.getName().equals(String.class.getName())) { - field.set(object, "qwer"); + field.set(object, generatingRandomString(4)); } else if (typeField.equals(Integer.TYPE) || typeField.equals(Integer.class)) { - field.set(object, 0); + field.set(object, generatingRandomInteger()); } else if (typeField.getName().equals(BigDecimal.class.getName())) { - field.set(object, new BigDecimal("23.220000000000000000")); + field.set(object, new BigDecimal(String.format("%d3.220000000000000000", generatingRandomInteger()))); } else if (typeField.equals(Long.TYPE) || typeField.equals(Long.class)) { - field.set(object, 1000000L); + field.set(object, generatingRandomLong()); } else if (typeField.equals(LocalDate.class)) { - field.set(object, LocalDate.of(2022, 10, 7)); + field.set(object, LocalDate.of(2022, generatingRandomInteger(), generatingRandomInteger())); } else if (typeField.equals(LocalTime.class)) { - field.set(object, LocalTime.of(19, 0)); + field.set(object, LocalTime.of(generatingRandomInteger(), generatingRandomInteger())); } else if (typeField.getName().equals(Date.class.getName())) { field.set(object, new Date()); } else if (typeField.getName().equals(Boolean.class.getName())) { @@ -205,7 +205,7 @@ public final class DbDataUtils { } else if (typeField.getName().equals(UUID.class.getName())) { field.set(object, UUID.randomUUID()); } else if (typeField.getName().equals(Instant.class.getName())) { - field.set(object, Instant.parse("2022-10-05T15:39:18.659Z")); + field.set(object, Instant.parse(String.format("2022-10-0%dT15:39:18.659Z", generatingRandomInteger()))); // } else if (typeField.getSimpleName().equals(CompanyInfo.class.getSimpleName())) { // CompanyInfo companyInfo = new CompanyInfo(); // fillObjectDefaultValues(companyInfo, CompanyInfo.class); @@ -225,4 +225,27 @@ public final class DbDataUtils { throw new RuntimeException(e); } } + + public static String generatingRandomString(int targetStringLength) { + int leftLimit = 97; // letter 'a' + int rightLimit = 122; // letter 'z' + Random random = new Random(); + + return random.ints(leftLimit, rightLimit + 1) + .limit(targetStringLength) + .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) + .toString(); + } + + public static Long generatingRandomLong() { + long leftLimit = 1L; + long rightLimit = 1000000L; + return leftLimit + (long) (Math.random() * (rightLimit - leftLimit)); + } + + public static int generatingRandomInteger() { + int leftLimit = 1; + int rightLimit = 9; + return leftLimit + (int) (new Random().nextFloat() * (rightLimit - leftLimit)); + } } diff --git a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/utils/MatcherFactory.java b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/MatcherFactory.java similarity index 100% rename from clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/utils/MatcherFactory.java rename to clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/MatcherFactory.java diff --git a/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/SpcexObjectBaseRowMapper.java b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/SpcexObjectBaseRowMapper.java new file mode 100644 index 000000000..ce1d441d2 --- /dev/null +++ b/clearing-parent/imdg/src/test/java/ru/spcex/clearing/imdg/utils/SpcexObjectBaseRowMapper.java @@ -0,0 +1,48 @@ +package ru.spcex.clearing.imdg.utils; + +import org.springframework.beans.BeanUtils; +import org.springframework.beans.NotWritablePropertyException; +import org.springframework.beans.TypeMismatchException; +import org.springframework.jdbc.support.JdbcUtils; +import ru.spcex.platform.classes.base.SpcexObjectBase; + +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; + +public class SpcexObjectBaseRowMapper extends AbstractHistoryRowMapper { + + private final Class mappedClass; + + public SpcexObjectBaseRowMapper(Class mappedClass) { + this.mappedClass = mappedClass; + } + + @Override + public T mapRow(ResultSet rs, int rowNum) throws SQLException { + T object = BeanUtils.instantiateClass(this.mappedClass); + ResultSetMetaData meta_data = rs.getMetaData(); + String objIdColumn = rs.getMetaData().getTableName(1).replace("_history", "_id"); + + int columnCount = meta_data.getColumnCount(); + + for (int index = 1; index <= columnCount; index++) { + String column = JdbcUtils.lookupColumnName(meta_data, index); + String fildName = getFildName(column, objIdColumn); + try { + Object value = JdbcUtils.getResultSetValue(rs, index, Class.forName(meta_data.getColumnClassName(index))); + if (fildName.equals("objId")) { + object.setId((Long) value); + continue; + } + setValueFildForObjectIfFildExists(object, object.getClass(), fildName, value); + } catch (TypeMismatchException | NotWritablePropertyException e) { + // Ignore + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + + } + return object; + } +} \ No newline at end of file diff --git a/clearing-parent/imdg/src/test/ddl.sql b/clearing-parent/imdg/src/test/resources/ddl.sql similarity index 100% rename from clearing-parent/imdg/src/test/ddl.sql rename to clearing-parent/imdg/src/test/resources/ddl.sql diff --git a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/utils/BusinessEventRowMapper.java b/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/utils/BusinessEventRowMapper.java deleted file mode 100644 index 4e437e236..000000000 --- a/clearing-parent/imdg/src/test/ru/spcex/clearing/imdg/utils/BusinessEventRowMapper.java +++ /dev/null @@ -1,120 +0,0 @@ -package ru.spcex.clearing.imdg.utils; - -import org.springframework.beans.BeanUtils; -import org.springframework.beans.NotWritablePropertyException; -import org.springframework.beans.TypeMismatchException; -import org.springframework.jdbc.core.RowMapper; -import org.springframework.jdbc.support.JdbcUtils; -import ru.clearing.classes.objects.BusinessEvent; -import ru.spcex.platform.classes.base.SpcexObjectBase; - -import java.lang.reflect.Field; -import java.sql.*; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalTime; -import java.time.ZoneId; -import java.util.Date; - -public class BusinessEventRowMapper implements RowMapper { - - private final Class mappedClass; - - public BusinessEventRowMapper(Class mappedClass) { - this.mappedClass = mappedClass; - } - - @Override - public T mapRow(ResultSet rs, int rowNum) throws SQLException { - T historyObject = BeanUtils.instantiateClass(this.mappedClass); - SpcexObjectBase objectFild = null; - try { - objectFild = (SpcexObjectBase) BeanUtils.instantiateClass(historyObject.getClass().getDeclaredField("object").getType()); - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } - ResultSetMetaData meta_data = rs.getMetaData(); - String tableName = rs.getMetaData().getTableName(1); - tableName.replace("_history", ""); - int columnCount = meta_data.getColumnCount(); - - for (int index = 1; index <= columnCount; index++) { - String column = JdbcUtils.lookupColumnName(meta_data, index); - String fildName = getFildName(column, tableName); - try { - Object value = JdbcUtils.getResultSetValue(rs, index, Class.forName(meta_data.getColumnClassName(index))); - setValueFildForObjectIfFildExists(historyObject, historyObject.getClass(), fildName, value); - setValueFildForObjectIfFildExists(objectFild, objectFild.getClass(), fildName, value); - } catch (TypeMismatchException | NotWritablePropertyException e) { - // Ignore - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - } - - } - historyObject.setObject(objectFild); - return historyObject; - } - - public void setValueFildForObjectIfFildExists(SpcexObjectBase object, Class clazz, String fildName, Object value) { - try { - Field field = clazz.getDeclaredField(fildName); - field.setAccessible(true); - Class typeField = field.getType(); - if (typeField.equals(LocalDate.class)) { - Date date = (Date) value; - field.set(object, value != null ? Instant.ofEpochMilli(date.getTime()).atZone(ZoneId.systemDefault()).toLocalDate() : null); - } else if (typeField.equals(LocalTime.class)) { - Time time = (Time) value; - field.set(object, value != null ? time.toLocalTime() : null); - } else if (typeField.getName().equals(Instant.class.getName())) { - field.set(object, value != null ? ((Timestamp) value).toInstant() : null); - } else { - field.set(object, value); - } - } catch (NoSuchFieldException e) { - if (!clazz.getSuperclass().getName().equals(Object.class.getName())) { - setValueFildForObjectIfFildExists(object, clazz.getSuperclass(), fildName, value); - } - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - - private String getFildName(String str, String tableName) { - if (str.startsWith(tableName)) { - return "id"; - } else if (str.equals("created_at")) { - return "created"; - } else if (str.equals("updated_at")) { - return "updated"; - } else if (str.equals("event_user_id")) { - return "userId"; - } - return snakeToCamel(str); - } - - private String snakeToCamel(String str) { - StringBuilder builder = new StringBuilder(str); - - // Traverse the string character by - // character and remove underscore - // and capitalize next letter - for (int i = 0; i < builder.length(); i++) { - - // Check char is underscore - if (builder.charAt(i) == '_') { - - builder.deleteCharAt(i); - builder.replace( - i, i + 1, - String.valueOf( - Character.toUpperCase( - builder.charAt(i)))); - } - } - - // Return in String type - return builder.toString(); - } -} \ No newline at end of file diff --git a/platform-parent/platform-imdg-api/src/main/java/ru/spcex/clearing/imdg/IMDGDistributedNames.java b/platform-parent/platform-imdg-api/src/main/java/ru/spcex/clearing/imdg/IMDGDistributedNames.java index b3c3b9d8d..4b7889a9f 100644 --- a/platform-parent/platform-imdg-api/src/main/java/ru/spcex/clearing/imdg/IMDGDistributedNames.java +++ b/platform-parent/platform-imdg-api/src/main/java/ru/spcex/clearing/imdg/IMDGDistributedNames.java @@ -55,7 +55,7 @@ public final class IMDGDistributedNames { public static final String Map_SDf09 = "Map_SDf09"; public static final String Map_SDf12 = "Map_SDf12"; public static final String Map_SDf18 = "Map_SDf18"; - // public static final String Map_InterestStatusDictionary = "Map_InterestStatusDictionary"; future + public static final String Map_InterestStatusDictionary = "Map_InterestStatusDictionary"; public static final String Map_AllowedDictionary = "Map_AllowedDictionary"; // public static final String Map_ClearingMemberCategoryDictionary = "Map_ClearingMemberCategoryDictionary"; future public static final String Map_CompanyRoleDictionary = "Map_CompanyRoleDictionary"; diff --git a/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/utilities/KeyRateNewRequest.java b/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/utilities/KeyRateNewRequest.java index 35f0c2a2a..f68b094ab 100644 --- a/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/utilities/KeyRateNewRequest.java +++ b/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/utilities/KeyRateNewRequest.java @@ -6,11 +6,12 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import ru.spcex.clearing.platform.messaging.domain.json.deserialize.InstantDeserializer; import ru.spcex.clearing.platform.messaging.domain.json.serialize.InstantSerializer; +import java.math.BigDecimal; import java.time.Instant; public class KeyRateNewRequest { @JsonProperty - public Double keyRate; + public BigDecimal keyRate; @JsonSerialize(using = InstantSerializer.class) @JsonDeserialize(using = InstantDeserializer.class) @JsonProperty @@ -22,11 +23,11 @@ public class KeyRateNewRequest { @JsonProperty public String document; - public Double getKeyRate() { + public BigDecimal getKeyRate() { return keyRate; } - public void setKeyRate(Double keyRate) { + public void setKeyRate(BigDecimal keyRate) { this.keyRate = keyRate; } diff --git a/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/utilities/KeyRateUpdateRequest.java b/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/utilities/KeyRateUpdateRequest.java index 0c4f1e32f..22b8fab1d 100644 --- a/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/utilities/KeyRateUpdateRequest.java +++ b/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/utilities/KeyRateUpdateRequest.java @@ -6,13 +6,14 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import ru.spcex.clearing.platform.messaging.domain.json.deserialize.InstantDeserializer; import ru.spcex.clearing.platform.messaging.domain.json.serialize.InstantSerializer; +import java.math.BigDecimal; import java.time.Instant; public class KeyRateUpdateRequest { @JsonProperty public Long id; @JsonProperty - public Double keyRate; + public BigDecimal keyRate; @JsonSerialize(using = InstantSerializer.class) @JsonDeserialize(using = InstantDeserializer.class) @JsonProperty @@ -32,11 +33,11 @@ public class KeyRateUpdateRequest { this.id = id; } - public Double getKeyRate() { + public BigDecimal getKeyRate() { return keyRate; } - public void setKeyRate(Double keyRate) { + public void setKeyRate(BigDecimal keyRate) { this.keyRate = keyRate; }