diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fb08ff7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,78 @@ +# Created by .ignore support plugin (hsz.mobi) +.eunit +deps +*.o +*.beam +*.plt +erl_crash.dump +ebin/*.beam +rel/example_project +.concrete/DEV_MODE +.rebar +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/ +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +*.iws +*.ipr +*.iml + + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* +env.list diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..ca5a761 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "build_utils"] + path = build_utils + url = git@github.com:rbkmoney/build_utils.git + branch = master diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..7d46bfa --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,18 @@ +#!groovy +build('questionary', 'java-maven') { + checkoutRepo() + loadBuildUtils() + + def javaServicePipeline + runStage('load JavaService pipeline') { + javaServicePipeline = load("build_utils/jenkins_lib/pipeJavaService.groovy") + } + + def serviceName = env.REPO_NAME + def mvnArgs = '-DjvmArgs="-Xmx256m"' + def useJava11 = true + def registry = 'dr2.rbkmoney.com' + def registryCredsId = 'jenkins_harbor' + + javaServicePipeline(serviceName, useJava11, mvnArgs, registry, registryCredsId) +} \ No newline at end of file diff --git a/build_utils b/build_utils new file mode 160000 index 0000000..ea4aa04 --- /dev/null +++ b/build_utils @@ -0,0 +1 @@ +Subproject commit ea4aa042f482551d624fd49a570d28488f479e93 diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml new file mode 100644 index 0000000..608bd45 --- /dev/null +++ b/docker-compose-dev.yml @@ -0,0 +1,12 @@ +version: '3' +services: + postgresql: + image: postgres:9.6 + volumes: + - ./data:/var/lib/postgresql + ports: + - "5432:5432" + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: worksheet diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..20eb9f9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,271 @@ + + + 4.0.0 + + + com.rbkmoney + spring-boot-starter-parent + 2.1.1.RELEASE + + + questionary + 0.0.1-SNAPSHOT + jar + + Questionary + + + UTF-8 + UTF-8 + 11 + 8022 + ${server.port} + bc95d0d6dc13c693acd2b274531a7d604b877bf3 + ${env.REGISTRY} + 0.3.6 + 5432 + postgres + postgres + questionary + qs + jdbc:postgresql://localhost:${db.port}/${db.name} + + + + + + com.rbkmoney + spring-boot-starter-metrics-statsd + 1.1.0 + + + com.rbkmoney.woody + woody-thrift + 1.1.15 + + + com.rbkmoney + shared-resources + ${shared.resources.version} + + + com.rbkmoney + db-common-lib + 0.0.1-SNAPSHOT + + + com.rbkmoney + ank-proto + 1.9-31453e7 + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + org.hibernate + hibernate-validator + + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + javax.servlet + javax.servlet-api + 4.0.1 + + + org.projectlombok + lombok + 1.18.4 + provided + + + org.postgresql + postgresql + ${postgresql.version} + + + org.jooq + jooq + ${jooq.version} + + + org.flywaydb + flyway-core + ${flyway.version} + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + ${project.build.directory}/maven-shared-archive-resources + ${project.build.directory} + + Dockerfile + + true + + + ${project.build.directory}/maven-shared-archive-resources + true + + Dockerfile + + + + src/main/resources + true + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.1.RELEASE + + + org.apache.maven.plugins + maven-remote-resources-plugin + 1.6.0 + + + org.apache.maven.shared + maven-filtering + 1.3 + + + + + com.rbkmoney:shared-resources:${shared.resources.version} + + false + false + + + + + process + + + + + + com.rbkmoney.maven.plugins + pg-embedded-plugin + 1.4 + + ${db.port} + ${db.name} + + ${db.schema} + + + + + PG_server_start + initialize + + start + + + + PG_server_stop + compile + + stop + + + + + + org.flywaydb + flyway-maven-plugin + ${flyway.version} + + ${db.url} + ${db.user} + ${db.password} + + ${db.schema} + + + + + migrate + initialize + + migrate + + + + + + org.postgresql + postgresql + ${postgresql.version} + + + + + org.jooq + jooq-codegen-maven + ${jooq.version} + + + org.postgresql.Driver + ${db.url} + ${db.user} + ${db.password} + + + + true + true + true + true + + + org.jooq.meta.postgres.PostgresDatabase + .* + schema_version|.*func|get_adjustment.*|get_cashflow.*|get_payment.*|get_payout.*|get_refund.* + ${db.schema} + + + com.rbkmoney.questionary.domain + src/main/java/ + + + + + + gen-src + initialize + + generate + + + + + + + diff --git a/src/main/java/com/rbkmoney/questionary/QuestionaryApplication.java b/src/main/java/com/rbkmoney/questionary/QuestionaryApplication.java new file mode 100644 index 0000000..d2d4588 --- /dev/null +++ b/src/main/java/com/rbkmoney/questionary/QuestionaryApplication.java @@ -0,0 +1,15 @@ +package com.rbkmoney.questionary; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.servlet.ServletComponentScan; + +@ServletComponentScan +@SpringBootApplication +public class QuestionaryApplication extends SpringApplication { + + public static void main(String[] args) { + SpringApplication.run(QuestionaryApplication.class, args); + } + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..48f389f --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,19 @@ +server: + port: @server.port@ +management: + security: + flag: false + metrics: + export: + statsd: + flavor: etsy + enabled: false +spring: + application: + name: @project.name@ + output: + ansi: + enabled: always +info: + version: @project.version@ + stage: dev diff --git a/src/main/resources/db.migration/V1__1.0.0_init.sql b/src/main/resources/db.migration/V1__1.0.0_init.sql new file mode 100644 index 0000000..2752395 --- /dev/null +++ b/src/main/resources/db.migration/V1__1.0.0_init.sql @@ -0,0 +1,272 @@ +CREATE SCHEMA IF NOT EXISTS qs; + +CREATE TYPE qs.questionary_entity_type AS ENUM ('legal', 'individual'); + +CREATE TABLE qs.questionary +( + id BIGSERIAL NOT NULL, + owner_id BIGINT NOT NULL, + type qs.questionary_entity_type NOT NULL, + inn CHARACTER VARYING, + phone_number CHARACTER VARYING NOT NULL, + email CHARACTER VARYING NOT NULL, + site CHARACTER VARYING NOT NULL, + reg_date TIMESTAMP WITHOUT TIME ZONE NOT NULL, + reg_place CHARACTER VARYING NOT NULL, + okvd CHARACTER VARYING NOT NULL, + activity_type CHARACTER VARYING NOT NULL, + property_info CHARACTER VARYING NOT NULL, + tax_resident BOOLEAN NOT NULL DEFAULT FALSE, + + CONSTRAINT questionary_pkey PRIMARY KEY (id) +); + +CREATE INDEX questionary_owner_id on qs.questionary (owner_id); + +CREATE TABLE qs.individual_entity_questionary +( + id BIGSERIAL NOT NULL, + residence_name CHARACTER VARYING, + residence_series CHARACTER VARYING, + residence_number CHARACTER VARYING, + residence_beginning_date TIMESTAMP WITHOUT TIME ZONE, + residence_expiration_date TIMESTAMP WITHOUT TIME ZONE, + ogrnip CHARACTER VARYING NOT NULL, + foreign_public_person BOOLEAN NOT NULL DEFAULT FALSE, + foreign_relative_person BOOLEAN NOT NULL DEFAULT FALSE, + behalf_of_foreign BOOLEAN NOT NULL DEFAULT FALSE, + worldwide_org_public_person BOOLEAN NOT NULL DEFAULT FALSE, + has_representative BOOLEAN NOT NULL DEFAULT FALSE, + beneficial_owner BOOLEAN NOT NULL DEFAULT FALSE, + + CONSTRAINT fk_individual_entity_to_questionary FOREIGN KEY (id) REFERENCES qs.questionary (id) +); + +CREATE TABLE qs.legal_entity_questionary +( + id BIGSERIAL NOT NULL, + name CHARACTER VARYING NOT NULL, + foreign_name CHARACTER VARYING, + legal_form CHARACTER VARYING NOT NULL, + ogrn CHARACTER VARYING NOT NULL, + reg_address CHARACTER VARYING NOT NULL, + reg_actual_address CHARACTER VARYING, + additional_space CHARACTER VARYING NOT NULL, + okato_code CHARACTER VARYING, + okpo_code CHARACTER VARYING, + postal_address CHARACTER VARYING NOT NULL, + owner_resident BOOLEAN NOT NULL DEFAULT FALSE, + fatca BOOLEAN NOT NULL DEFAULT FALSE, + + CONSTRAINT fk_legal_entity_to_questionary FOREIGN KEY (id) REFERENCES qs.questionary (id) +); + +CREATE TABLE qs.license_info +( + id BIGSERIAL NOT NULL, + questionary_id BIGINT NOT NULL, + type CHARACTER VARYING NOT NULL, + number CHARACTER VARYING NOT NULL, + issue_date TIMESTAMP WITHOUT TIME ZONE NOT NULL, + issuer CHARACTER VARYING NOT NULL, + validity TIMESTAMP WITHOUT TIME ZONE NOT NULL, + + CONSTRAINT license_info_pkey PRIMARY KEY (id), + CONSTRAINT fk_license_info_to_questionary_data FOREIGN KEY (questionary_id) REFERENCES qs.questionary (id) +); + +CREATE UNIQUE INDEX license_info_to_q_data_id ON qs.license_info (questionary_id); + +CREATE TYPE qs.month_operation_count AS ENUM ('lt_ten', 'btw_ten_to_fifty', 'gt_fifty'); + +CREATE TYPE qs.month_operation_sum AS ENUM ('lt_five_hundred_thousand', 'btw_five_hundred_thousand_to_one_million', 'gt_one_million'); + +CREATE TYPE qs.relation_process AS ENUM ('insolvency_proceedings', 'bankrupt_judicial_decision', 'liquidation_process'); + +CREATE TYPE qs.business_reputation AS ENUM ('provide_reviews', 'no_reviews'); + +CREATE TABLE qs.additional_info +( + id BIGSERIAL NOT NULL, + questionary_id BIGINT NOT NULL, + staff_count BOOLEAN NOT NULL DEFAULT FALSE, + accounting CHARACTER VARYING, + accounting_org CHARACTER VARYING, + nko_relation_target CHARACTER VARYING NOT NULL, + relationship_with_nko CHARACTER VARYING NOT NULL, + month_operation_count qs.month_operation_count NOT NULL, + month_operation_sum qs.month_operation_sum NOT NULL, + storage_facilities BOOLEAN NOT NULL DEFAULT FALSE NOT NULL, + counterparties CHARACTER VARYING NOT NULL, + relation_process qs.relation_process NOT NULL, + benefit_third_parties BOOLEAN NOT NULL DEFAULT FALSE NOT NULL, + business_reputation qs.business_reputation NOT NULL, + bank_details CHARACTER VARYING NOT NULL, + + CONSTRAINT additional_info_pkey PRIMARY KEY (id), + CONSTRAINT fk_additional_info_to_questionary_data FOREIGN KEY (questionary_id) REFERENCES qs.questionary (id) +); + +CREATE INDEX additional_info_to_questionary_id ON qs.additional_info (questionary_id); + +CREATE TABLE qs.financial_position +( + id BIGSERIAL NOT NULL, + additional_info_id BIGINT NOT NULL, + description CHARACTER VARYING NOT NULL, + + CONSTRAINT financial_position_pkey PRIMARY KEY (id), + CONSTRAINT fk_financial_position_to_additional_info FOREIGN KEY (additional_info_id) REFERENCES qs.additional_info (id) +); + +CREATE INDEX financial_position_additional_info_id ON qs.financial_position (additional_info_id); + +CREATE TABLE qs.business_info +( + id BIGSERIAL NOT NULL, + additional_info_id BIGINT NOT NULL, + description CHARACTER VARYING NOT NULL, + + CONSTRAINT business_info_pkey PRIMARY KEY (id), + CONSTRAINT fk_business_info_to_additional_info FOREIGN KEY (additional_info_id) REFERENCES qs.additional_info (id) +); + +CREATE INDEX business_info_additional_info_id ON qs.business_info (additional_info_id); + +CREATE TABLE qs.license_activity +( + id BIGSERIAL NOT NULL, + license_info_id BIGINT NOT NULL, + name CHARACTER VARYING NOT NULL, + + CONSTRAINT license_activity_pkey PRIMARY KEY (id), + CONSTRAINT fk_license_activities_to_license_info FOREIGN KEY (license_info_id) REFERENCES qs.license_info (id) +); + +CREATE INDEX license_activities_q_data_id ON qs.license_activity (license_info_id); + +CREATE TABLE qs.legal_org_info +( + id BIGSERIAL NOT NULL, + questionary_id BIGINT NOT NULL, + description CHARACTER VARYING NOT NULL, + + CONSTRAINT legal_org_info_pkey PRIMARY KEY (id), + CONSTRAINT fk_legal_org_info_to_questionary FOREIGN KEY (questionary_id) REFERENCES qs.questionary (id) +); + +CREATE TABLE qs.russian_private_entity +( + id BIGSERIAL NOT NULL, + questionary_id BIGINT NOT NULL, + first_name CHARACTER VARYING NOT NULL, + second_name CHARACTER VARYING NOT NULL, + middle_name CHARACTER VARYING NOT NULL, + birth_date TIMESTAMP WITHOUT TIME ZONE NOT NULL, + citizenship CHARACTER VARYING NOT NULL, + residence_address CHARACTER VARYING NOT NULL, + actual_address CHARACTER VARYING, + contact_info CHARACTER VARYING, + + CONSTRAINT russian_private_entity_pkey PRIMARY KEY (id), + CONSTRAINT fk_russian_private_entity_to_questionary FOREIGN KEY (questionary_id) REFERENCES qs.questionary (id) +); + +CREATE INDEX russian_private_entity_questionary_id ON qs.russian_private_entity (questionary_id); + +CREATE TABLE qs.identity_document +( + id BIGSERIAL NOT NULL, + questionary_id BIGINT NOT NULL, + name BIGSERIAL NOT NULL, + + CONSTRAINT identity_document_pkey PRIMARY KEY (id), + CONSTRAINT fk_identity_doc_questionary FOREIGN KEY (questionary_id) REFERENCES qs.questionary (id) +); + +CREATE INDEX identity_document_questionary_id ON qs.identity_document (questionary_id); + +CREATE TABLE qs.russian_passport +( + id BIGSERIAL NOT NULL, + serial CHARACTER VARYING, + number CHARACTER VARYING NOT NULL, + issuer CHARACTER VARYING NOT NULL, + issuer_code CHARACTER VARYING, + issued_at TIMESTAMP WITHOUT TIME ZONE NOT NULL, + + CONSTRAINT fk_russian_passport_to_identity_document FOREIGN KEY (id) REFERENCES qs.identity_document (id) +); + +CREATE TABLE qs.migration_card +( + id BIGSERIAL NOT NULL, + questionary_id BIGINT NOT NULL, + card_number CHARACTER VARYING NOT NULL, + beginning_date TIMESTAMP WITHOUT TIME ZONE NOT NULL, + expiration_date TIMESTAMP WITHOUT TIME ZONE, + + CONSTRAINT migration_card_pkey PRIMARY KEY (id), + CONSTRAINT fk_migration_card_to_questionary_data FOREIGN KEY (questionary_id) REFERENCES qs.questionary (id) +); + +CREATE INDEX migration_card_questionary_id ON qs.migration_card (questionary_id); + +CREATE TABLE qs.residence_approve +( + id BIGSERIAL NOT NULL, + questionary_id BIGINT NOT NULL, + name CHARACTER VARYING NOT NULL, + series CHARACTER VARYING, + number CHARACTER VARYING NOT NULL, + beginning_date TIMESTAMP WITHOUT TIME ZONE NOT NULL, + expiration_date TIMESTAMP WITHOUT TIME ZONE NOT NULL, + + CONSTRAINT residence_approve_pkey PRIMARY KEY (id), + CONSTRAINT fk_residence_approve_to_questionary FOREIGN KEY (questionary_id) REFERENCES qs.questionary (id) +); + +CREATE INDEX residence_approve_questionary_id ON qs.residence_approve (questionary_id); + +CREATE TABLE qs.legal_owner +( + id BIGSERIAL NOT NULL, + questionary_id BIGINT NOT NULL, + private_entity_id BIGINT NOT NULL, + identity_document_id BIGINT NOT NULL, + migration_card_id BIGINT, + residence_approve_id BIGINT, + inn CHARACTER VARYING, + pdl_category BOOLEAN NOT NULL, + + CONSTRAINT legal_approve_pkey PRIMARY KEY (id), + CONSTRAINT fk_legal_owner_to_questionary_data FOREIGN KEY (questionary_id) REFERENCES qs.questionary (id), + CONSTRAINT fk_legal_owner_to_private_entity FOREIGN KEY (private_entity_id) REFERENCES qs.russian_private_entity (id), + CONSTRAINT fk_legal_owner_to_identity_doc FOREIGN KEY (identity_document_id) REFERENCES qs.identity_document (id), + CONSTRAINT fk_legal_owner_to_migration_card FOREIGN KEY (migration_card_id) REFERENCES qs.migration_card (id), + CONSTRAINT fk_legal_owner_to_residence_approve FOREIGN KEY (residence_approve_id) REFERENCES qs.residence_approve (id) +); + +CREATE UNIQUE INDEX legal_owner_questionary_id ON qs.legal_owner (questionary_id); + +CREATE TABLE qs.beneficial_owner +( + id BIGSERIAL NOT NULL, + questionary_id BIGINT NOT NULL, + private_entity_id BIGINT NOT NULL, + identity_document_id BIGINT NOT NULL, + migration_card_id BIGINT, + residence_approve_id BIGINT, + ownership_percentage SMALLINT NOT NULL, + inn CHARACTER VARYING, + pdl_category BOOLEAN NOT NULL, + + CONSTRAINT beneficial_owner_pkey PRIMARY KEY (id), + CONSTRAINT fk_beneficial_owner_to_questionary_data FOREIGN KEY (questionary_id) REFERENCES qs.questionary (id), + CONSTRAINT fk_beneficial_owner_to_private_entity FOREIGN KEY (private_entity_id) REFERENCES qs.russian_private_entity (id), + CONSTRAINT fk_beneficial_owner_to_identity_doc FOREIGN KEY (identity_document_id) REFERENCES qs.identity_document (id), + CONSTRAINT fk_beneficial_owner_to_migration_card FOREIGN KEY (migration_card_id) REFERENCES qs.migration_card (id), + CONSTRAINT fk_beneficial_owner_to_residence_approve FOREIGN KEY (residence_approve_id) REFERENCES qs.residence_approve (id) +); + +CREATE INDEX beneficial_owner_questionary_id ON qs.beneficial_owner (questionary_id) diff --git a/src/test/java/com/rbkmoney/questionary/QuestionaryApplicationTest.java b/src/test/java/com/rbkmoney/questionary/QuestionaryApplicationTest.java new file mode 100644 index 0000000..780d765 --- /dev/null +++ b/src/test/java/com/rbkmoney/questionary/QuestionaryApplicationTest.java @@ -0,0 +1,16 @@ +package com.rbkmoney.questionary; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = QuestionaryApplication.class) +public class QuestionaryApplicationTest { + + @Test + public void contextLoads() { + + } +} diff --git a/src/test/resources/logback-test.xml b/src/test/resources/logback-test.xml new file mode 100644 index 0000000..e1f57ed --- /dev/null +++ b/src/test/resources/logback-test.xml @@ -0,0 +1,10 @@ + + + + + + + + + +