NoSQL and JPA DB integration first steps
authorelgekko <vasary@elgekko.net>
Tue, 13 Jun 2023 06:53:04 +0000 (08:53 +0200)
committerelgekko <vasary@elgekko.net>
Tue, 13 Jun 2023 06:53:04 +0000 (08:53 +0200)
86 files changed:
TODO.txt
lis-app/src/main/java/hu/user/lis/LoggerConfiguration.java [moved from lis-app/src/main/java/hu/user/lis/app/LoggerConfiguration.java with 97% similarity]
lis-app/src/main/java/hu/user/lis/Main.java [moved from lis-app/src/main/java/hu/user/lis/app/Main.java with 91% similarity]
lis-app/src/main/java/hu/user/lis/WebAppConfigurer.java [moved from lis-app/src/main/java/hu/user/lis/app/WebAppConfigurer.java with 97% similarity]
lis-app/src/main/resources/application-dev.yaml [new file with mode: 0644]
lis-app/src/main/resources/application.yaml
lis-app/src/test/java/hu/user/lis/MainTest.java [moved from lis-app/src/test/java/hu/user/lis/app/MainTest.java with 91% similarity]
lis-db/migrations/README [new file with mode: 0644]
lis-db/migrations/bootstrap.sql [new file with mode: 0644]
lis-db/migrations/environments/development.properties [new file with mode: 0644]
lis-db/migrations/scripts/001_create_changelog.sql [new file with mode: 0644]
lis-db/migrations/scripts/002_create_initial_schema.sql [new file with mode: 0644]
lis-db/pom.xml
lis-db/src/main/java/hu/user/lis/db/Associate.java
lis-db/src/main/java/hu/user/lis/db/EDocument.java [new file with mode: 0644]
lis-db/src/main/java/hu/user/lis/db/Invoice.java
lis-db/src/main/java/hu/user/lis/db/Partner.java
lis-db/src/main/java/hu/user/lis/db/Project.java
lis-db/src/main/java/hu/user/lis/db/ProjectAssociate.java
lis-db/src/main/java/hu/user/lis/db/ProjectStatus.java
lis-db/src/main/java/hu/user/lis/db/ServiceRecord.java
lis-db/src/main/java/hu/user/lis/db/Treasury.java
lis-db/src/main/java/hu/user/lis/db/repository/ProjectStatusRepository.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/api/AssociateApi.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/api/DbApi.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/api/GenerateApi.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/api/InvoiceApi.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/api/PartnerApi.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/api/ProjectApi.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/api/ProjectAssociateApi.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/api/ProjectStatusApi.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/api/ServiceRecordApi.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/api/TreasuryApi.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/data/AssociateService.java
lis-services/src/main/java/hu/user/lis/services/data/AssociateServiceImpl.java
lis-services/src/main/java/hu/user/lis/services/data/EDocumentService.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/data/EDocumentServiceImpl.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/data/InvoiceService.java
lis-services/src/main/java/hu/user/lis/services/data/InvoiceServiceImpl.java
lis-services/src/main/java/hu/user/lis/services/data/PartnerService.java
lis-services/src/main/java/hu/user/lis/services/data/PartnerServiceImpl.java
lis-services/src/main/java/hu/user/lis/services/data/ProjectAssociateService.java
lis-services/src/main/java/hu/user/lis/services/data/ProjectAssociateServiceImpl.java
lis-services/src/main/java/hu/user/lis/services/data/ProjectService.java
lis-services/src/main/java/hu/user/lis/services/data/ProjectServiceImpl.java
lis-services/src/main/java/hu/user/lis/services/data/ProjectStatusService.java
lis-services/src/main/java/hu/user/lis/services/data/ProjectStatusServiceImpl.java
lis-services/src/main/java/hu/user/lis/services/data/ServiceRecordService.java
lis-services/src/main/java/hu/user/lis/services/data/ServiceRecordServiceImpl.java
lis-services/src/main/java/hu/user/lis/services/data/SupplierServiceImpl.java
lis-services/src/main/java/hu/user/lis/services/data/TreasuryServiceImpl.java
lis-services/src/main/java/hu/user/lis/services/nosql/AssociateDbService.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/nosql/DbService.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/nosql/InvoiceDbService.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/nosql/PartnerDbService.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/nosql/ProjectAssociateDbService.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/nosql/ProjectDbService.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/nosql/ProjectStatusDbService.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/nosql/ServiceRecordDbService.java [new file with mode: 0644]
lis-services/src/main/java/hu/user/lis/services/nosql/TreasuryDbService.java [new file with mode: 0644]
lis-ui/src/main/java/hu/user/lis/ui/converter/ProjectStatusConverter.java
lis-ui/src/main/java/hu/user/lis/ui/data/AssociateSelectorDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/AssociatesDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/CachedDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/FormDocument.java
lis-ui/src/main/java/hu/user/lis/ui/data/IncomeMargin.java
lis-ui/src/main/java/hu/user/lis/ui/data/IncomeMarginsDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/PartnerSelectorDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/PartnersDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/ProjectAssociatesDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/ProjectSelectorDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/ProjectStatusDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/ProjectsDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/ServiceRecordsDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/SuppliersDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/data/SuppliersSimpleDataModel.java
lis-ui/src/main/java/hu/user/lis/ui/editor/ProjectEditorModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/AssociatesViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/PartnersViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java
lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java
lis-ui/src/main/resources/web/associates.zul
lis-ui/src/main/resources/web/partners.zul
lis-ui/src/main/resources/web/project-editor.zul
lis-ui/src/main/resources/web/projects.zul
lis-ui/src/main/resources/web/service-records.zul

index db4874a783fac00045a8b2003fff8ba7dab15422..c64c8209f960d61fd177aa932ab95f865b2b10b7 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
 * A munkalapok lista szűrhető projektre és résztvevőre. Ezt használjuk ki, amikor a projekt összevont nézetből a munkalap bontást szeretnénk látni
 * A projektben a munkalap összesitve jelenjen meg személyenként, de navigáljon el bontott nézetbe kattintásra
 * Projekt szerkesztő: ergonómikusabb elrendezés
-- A projekt szerkesztés/részletezés tetején az adatok legyenek bal oldalon bekeretezve.
+* A projekt szerkesztés/részletezés tetején az adatok legyenek bal oldalon bekeretezve.
     A jobb oldalon pedig legyen látható a projekt árrése.
     Az árrés annyi sorból áll ahány devizanem van a projekt számláiban. Egy adott devizanem esetén a számolás:
     Kimenő - Bejövő - Treasury eladás + Treasury vétel
 
+
+db persist
+- servicerecord:
+    project generalas
+    generalas
+    project szuro
+
+auth/ldap
+autorizacio
+nav
+szamla erkeztetes camunda: egy felasznalohoz jon be, projekthez lehessen csatolni, projektszanot ellenorizze
+
+
 - Számla kiegyenlítés
 - Autentikáció: AD és helyi
 - legyen felhasználó specifikus beállításokra lehetőség
 - Plugin: lehet egyedi testreszabási igény, de ennek valahogy el kell teljesen különülnie a "core" forráskódtól. Pl. javascript motort be lehetne építeni, a szkriptek pedig meghatározott pontokon lehetnének becsatolva a logikába. Számla részletezés volt a példa (10000EUR számla 3 részletben forintban, kérdés mennyi pl. az utsó számla összege); 10 custom mező, javascripttel futna a custom mezők módosítására.
 
 
+fds.in.useribm.hu
+389
+
+ldaps
+fds.useribm.hu
+636
+
+
similarity index 97%
rename from lis-app/src/main/java/hu/user/lis/app/LoggerConfiguration.java
rename to lis-app/src/main/java/hu/user/lis/LoggerConfiguration.java
index b4d664e47822f74cab618e6f1e78635b17010deb..17f3fd628452c83a0ab41edd708107b63e233572 100644 (file)
@@ -3,7 +3,7 @@
  * By elGekko
  */
 
-package hu.user.lis.app;
+package hu.user.lis;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
similarity index 91%
rename from lis-app/src/main/java/hu/user/lis/app/Main.java
rename to lis-app/src/main/java/hu/user/lis/Main.java
index d170059ed361ebabcad4a858f097b3e5d1bf4f36..a0d6f732fe5eb6a8d0b666feec1c68cab9637873 100644 (file)
@@ -3,7 +3,7 @@
  * By elGekko
  */
 
-package hu.user.lis.app;
+package hu.user.lis;
 
 import hu.user.lis.ui.config.WebSecurityConfig;
 import org.apache.logging.log4j.LogManager;
@@ -18,6 +18,7 @@ import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.FilterType;
 import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.core.SpringVersion;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
 
 //@SpringBootApplication(scanBasePackages = {"hu.user.lis"})
@@ -28,6 +29,8 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
 @ComponentScan(basePackages = {"hu.user.lis"}, excludeFilters = {
         @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = WebSecurityConfig.class)})
 @EnableWebMvc
+//@EnableMongoRepositories(basePackages = "hu.user.lis.db.repository")
+@EnableJpaRepositories(basePackages = "hu.user.lis.db.repository")
 public class Main extends SpringBootServletInitializer implements ApplicationListener<ContextRefreshedEvent> {
 
     private static final Logger logger = LogManager.getLogger();
similarity index 97%
rename from lis-app/src/main/java/hu/user/lis/app/WebAppConfigurer.java
rename to lis-app/src/main/java/hu/user/lis/WebAppConfigurer.java
index 4831d34deb0dd6dd304621ad58d8fc028e957264..0378be2a35db995f89174ef2bed0aa7489c2a398 100644 (file)
@@ -3,7 +3,7 @@
  * By elGekko
  */
 
-package hu.user.lis.app;
+package hu.user.lis;
 
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
diff --git a/lis-app/src/main/resources/application-dev.yaml b/lis-app/src/main/resources/application-dev.yaml
new file mode 100644 (file)
index 0000000..ffbd75e
--- /dev/null
@@ -0,0 +1,26 @@
+server:
+  port: 8080
+  servlet:
+    context-path: /
+zk:
+  homepage: index
+  zul-view-resolver-enabled: true
+spring:
+  output:
+    ansi:
+      enabled: always
+  #  data:
+  #    mongodb:
+  #      host: localhost
+  #      port: 27017
+  #      database: lis
+  datasource:
+    #    driver-class-name: com.mysql.jdbc.Driver
+    type: com.zaxxer.hikari.HikariDataSource
+    url: jdbc:db2://localhost:50000/lis
+    username: db2admin
+    password: password
+#    hikari:
+#      pool-name: testmc
+#      maximum-pool-size: 50
+#      minimum-idle: 10
index 21cf75ab9db4bca23aff20bd1e331c48db88e87b..df7e09776a0933ac2589ea7e4dd002042acf0c47 100644 (file)
@@ -39,15 +39,24 @@ spring:
   #    pool-name: pool-maszkaweb
   #    maximum-pool-size: 50
   #    minimum-idle: 10
-  datasource:
-    #    driver-class-name: com.mysql.jdbc.Driver
-    type: com.zaxxer.hikari.HikariDataSource
-    url: jdbc:db2://localvm:50000/testmc
-    username: db2admin
-    password: password
-    hikari:
-      pool-name: testmc
-      maximum-pool-size: 50
-      minimum-idle: 10
+  #  data:
+  #    mongodb:
+  #      #      host: dvdev.in.useribm.hu
+  #      host: localvm
+  #      port: 27017
+  #      database: lis
+
+  #      username: db2admin
+  #      password: password
+#  datasource:
+#    #    driver-class-name: com.mysql.jdbc.Driver
+#    type: com.zaxxer.hikari.HikariDataSource
+#    url: jdbc:db2://localvm:50000/testmc
+#    username: db2admin
+#    password: password
+#    hikari:
+#      pool-name: testmc
+#      maximum-pool-size: 50
+#      minimum-idle: 10
 service:
   message: Hello, World
similarity index 91%
rename from lis-app/src/test/java/hu/user/lis/app/MainTest.java
rename to lis-app/src/test/java/hu/user/lis/MainTest.java
index c3b8e336018bb031638c1cf893734ca235651510..06bf1268c9d22705707a8f9f355f032141e4dc40 100644 (file)
@@ -3,7 +3,7 @@
  * By elGekko
  */
 
-package hu.user.lis.app;
+package hu.user.lis;
 
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
diff --git a/lis-db/migrations/README b/lis-db/migrations/README
new file mode 100644 (file)
index 0000000..48ba8a5
--- /dev/null
@@ -0,0 +1,46 @@
+Welcome!
+
+This is an MyBatis Migration repository.  You can specify the repository
+directory when running migrations using the --path=<repos-directory>
+option.  The default path is the current working directory ("./").
+
+The repository base directory contains three subdirectories as follows:
+
+./drivers
+
+Place your JDBC driver .jar or .zip files in this directory.  Upon running a
+migration, the drivers will be dynamically loaded.
+
+Download driver: 
+<dependency>
+       <groupId>com.ibm.db2</groupId>
+       <artifactId>jcc</artifactId>
+       <version>11.5.8.0</version>
+</dependency>
+
+
+./environments
+
+In the environments folder you will find .properties files that represent
+your database instances.  By default a development.properties file is
+created for you to configure your development time database properties.
+You can also create test.properties and production.properties files.
+The environment can be specified when running a migration by using
+the --env=<environment> option (without the path or ".properties" part).
+
+The default environment is "development".
+
+./scripts
+
+This directory contains your migration SQL files.  These are the files
+that contain your DDL to both upgrade and downgrade your database
+structure.  By default, the directory will contain the script to
+create the changelog table, plus one empty "first" migration script.
+To create a new migration script, use the "new" command.  To run
+all pending migrations, use the "up" command.  To undo the last
+migration applied, use the "down" command etc.
+
+For more information about commands and options, run the MyBatis
+Migration script with the --help option.
+
+Enjoy.
diff --git a/lis-db/migrations/bootstrap.sql b/lis-db/migrations/bootstrap.sql
new file mode 100644 (file)
index 0000000..910a80b
--- /dev/null
@@ -0,0 +1,3 @@
+-- // Bootstrap.sql
+DROP DATABASE IF EXISTS LIS;
+CREATE DATABASE LIS AUTOMATIC STORAGE YES USING CODESET UTF-8 TERRITORY hu COLLATE USING UCA500R1_S2 PAGESIZE 32 K;
diff --git a/lis-db/migrations/environments/development.properties b/lis-db/migrations/environments/development.properties
new file mode 100644 (file)
index 0000000..7f3b454
--- /dev/null
@@ -0,0 +1,67 @@
+## Base time zone to ensure times are consistent across machines
+time_zone=GMT+0:00
+
+## The character set that scripts are encoded with
+script_char_set=UTF-8
+
+## JDBC connection properties.
+driver=com.ibm.db2.jcc.DB2Driver
+url=jdbc:db2://localhost:50000/lis
+username=db2admin
+password=password
+
+#
+# A NOTE ON STORED PROCEDURES AND DELIMITERS
+#
+# Stored procedures and functions commonly have nested delimiters
+# that conflict with the schema migration parsing.  If you tend
+# to use procs, functions, triggers or anything that could create
+# this situation, then you may want to experiment with
+# send_full_script=true (preferred), or if you can't use
+# send_full_script, then you may have to resort to a full
+# line delimiter such as "GO" or "/" or "!RUN!".
+#
+# Also play with the autocommit settings, as some drivers
+# or databases don't support creating procs, functions or
+# even tables in a transaction, and others require it.
+#
+
+# This ignores the line delimiters and
+# simply sends the entire script at once.
+# Use with JDBC drivers that can accept large
+# blocks of delimited text at once.
+send_full_script=false
+
+# This controls how statements are delimited.
+# By default statements are delimited by an
+# end of line semicolon.  Some databases may
+# (e.g. MS SQL Server) may require a full line
+# delimiter such as GO.
+# These are ignored if send_full_script is true.
+delimiter=;
+full_line_delimiter=false
+
+# If set to true, each statement is isolated
+# in its own transaction.  Otherwise the entire
+# script is executed in one transaction.
+# Few databases should need this set to true,
+# but some do.
+auto_commit=false
+
+# If set to false, warnings from the database will interrupt migrations.
+ignore_warnings=false
+
+# Custom driver path to allow you to centralize your driver files
+# Default requires the drivers to be in the drivers directory of your
+# initialized migration directory (created with "migrate init")
+# driver_path=
+
+# Name of the table that tracks changes to the database
+changelog=CHANGELOG
+
+# Migrations support variable substitutions in the form of ${variable}
+# in the migration scripts.  All of the above properties will be ignored though,
+# with the exception of changelog.
+# Example: The following would be referenced in a migration file as ${ip_address}
+# ip_address=192.168.0.1
+
diff --git a/lis-db/migrations/scripts/001_create_changelog.sql b/lis-db/migrations/scripts/001_create_changelog.sql
new file mode 100644 (file)
index 0000000..2892d2a
--- /dev/null
@@ -0,0 +1,24 @@
+-- // Create Changelog
+
+-- Default DDL for changelog table that will keep
+-- a record of the migrations that have been run.
+
+-- You can modify this to suit your database before
+-- running your first migration.
+
+-- Be sure that ID and DESCRIPTION fields exist in
+-- BigInteger and String compatible fields respectively.
+
+CREATE TABLE ${changelog} (
+ID NUMERIC(20,0) NOT NULL,
+APPLIED_AT VARCHAR(25) NOT NULL,
+DESCRIPTION VARCHAR(255) NOT NULL
+);
+
+ALTER TABLE ${changelog}
+ADD CONSTRAINT PK_${changelog}
+PRIMARY KEY (id);
+
+-- //@UNDO
+
+DROP TABLE ${changelog};
diff --git a/lis-db/migrations/scripts/002_create_initial_schema.sql b/lis-db/migrations/scripts/002_create_initial_schema.sql
new file mode 100644 (file)
index 0000000..a1dc58c
--- /dev/null
@@ -0,0 +1,124 @@
+-- // create_initial_schema
+-- Migration SQL that makes the change goes here.
+CREATE TABLE associate (
+  id BIGINT NOT NULL,
+   name VARCHAR(255),
+   login VARCHAR(255),
+   password VARCHAR(255),
+   monthly_cost DOUBLE NOT NULL,
+   active SMALLINT NOT NULL,
+   CONSTRAINT pk_associate PRIMARY KEY (id)
+);
+
+CREATE TABLE edocument (
+  id BIGINT NOT NULL,
+   created TIMESTAMP,
+   name VARCHAR(255),
+   description VARCHAR(255),
+   size INTEGER NOT NULL,
+   file BLOB,
+   CONSTRAINT pk_edocument PRIMARY KEY (id)
+);
+
+CREATE TABLE project_status (
+  id BIGINT NOT NULL,
+   name VARCHAR(255),
+   active SMALLINT NOT NULL,
+   order INTEGER NOT NULL,
+   CONSTRAINT pk_projectstatus PRIMARY KEY (id)
+);
+
+CREATE TABLE partner (
+  id BIGINT NOT NULL,
+   name VARCHAR(255),
+   vat_nr VARCHAR(255),
+   address VARCHAR(255),
+   active SMALLINT NOT NULL,
+   CONSTRAINT pk_partner PRIMARY KEY (id)
+);
+
+CREATE TABLE project (
+  id BIGINT NOT NULL,
+   project_status_id BIGINT,
+   name VARCHAR(255),
+   human_id VARCHAR(255),
+   contact_name VARCHAR(255),
+   partner_id BIGINT,
+   active SMALLINT NOT NULL,
+   CONSTRAINT pk_project PRIMARY KEY (id)
+);
+ALTER TABLE project ADD CONSTRAINT FK_PROJECT_ON_PARTNER FOREIGN KEY (partner_id) REFERENCES partner (id);
+ALTER TABLE project ADD CONSTRAINT FK_PROJECT_ON_PROJECT_STATUS FOREIGN KEY (project_status_id) REFERENCES project_status (id);
+
+CREATE TABLE invoice (
+  id BIGINT NOT NULL,
+   human_id VARCHAR(255),
+   title VARCHAR(255),
+   partner_id BIGINT,
+   project_id BIGINT,
+   income SMALLINT NOT NULL,
+   currency INTEGER,
+   net_amount DOUBLE NOT NULL,
+   gross_amount DOUBLE NOT NULL,
+   vat_amount DOUBLE NOT NULL,
+   completion_date TIMESTAMP,
+   create_date TIMESTAMP,
+   payment_deadline TIMESTAMP,
+   planned SMALLINT NOT NULL,
+   file BLOB,
+   CONSTRAINT pk_invoice PRIMARY KEY (id)
+);
+ALTER TABLE invoice ADD CONSTRAINT FK_INVOICE_ON_PARTNER FOREIGN KEY (partner_id) REFERENCES partner (id);
+ALTER TABLE invoice ADD CONSTRAINT FK_INVOICE_ON_PROJECT FOREIGN KEY (project_id) REFERENCES project (id);
+
+CREATE TABLE treasury (
+  id BIGINT NOT NULL,
+   project_id BIGINT,
+   human_id VARCHAR(255),
+   buy_amount DOUBLE NOT NULL,
+   buy_currency INTEGER,
+   sell_amount DOUBLE NOT NULL,
+   sell_currency INTEGER,
+   transaction_date TIMESTAMP,
+   value_date TIMESTAMP,
+   file BLOB,
+   CONSTRAINT pk_treasury PRIMARY KEY (id)
+);
+ALTER TABLE treasury ADD CONSTRAINT FK_TREASURY_ON_PROJECT FOREIGN KEY (project_id) REFERENCES project (id);
+
+CREATE TABLE project_associate (
+  id BIGINT NOT NULL,
+   project_id BIGINT,
+   associate_id BIGINT,
+   CONSTRAINT pk_projectassociate PRIMARY KEY (id)
+);
+ALTER TABLE project_associate ADD CONSTRAINT FK_PROJECTASSOCIATE_ON_ASSOCIATE FOREIGN KEY (associate_id) REFERENCES associate (id);
+ALTER TABLE project_associate ADD CONSTRAINT FK_PROJECTASSOCIATE_ON_PROJECT FOREIGN KEY (project_id) REFERENCES project (id);
+
+CREATE TABLE service_record (
+  id BIGINT NOT NULL,
+   project_id BIGINT,
+   associate_id BIGINT,
+   work_day TIMESTAMP,
+   description VARCHAR(255),
+   details VARCHAR(255),
+   work_hours INTEGER NOT NULL,
+   cost DOUBLE NOT NULL,
+   file BLOB,
+   CONSTRAINT pk_servicerecord PRIMARY KEY (id)
+);
+ALTER TABLE service_record ADD CONSTRAINT FK_SERVICERECORD_ON_ASSOCIATE FOREIGN KEY (associate_id) REFERENCES associate (id);
+ALTER TABLE service_record ADD CONSTRAINT FK_SERVICERECORD_ON_PROJECT FOREIGN KEY (project_id) REFERENCES project (id);
+
+-- //@UNDO
+-- SQL to undo the change goes here.
+
+DROP TABLE service_record;
+DROP TABLE project_associate;
+DROP TABLE treasury;
+DROP TABLE invoice;
+DROP TABLE project;
+DROP TABLE partner;
+DROP TABLE project_status;
+DROP TABLE edocument;
+DROP TABLE associate;
index a47612cac82d79786c24158f462fd9d7528bca18..5ac8726050e030df4a9f6e2f6ba75d613aa171a1 100644 (file)
@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
-        xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+        xmlns="http://maven.apache.org/POM/4.0.0">
     <modelVersion>4.0.0</modelVersion>
     <groupId>hu.user</groupId>
     <artifactId>lis-db</artifactId>
         <artifactId>lis</artifactId>
         <version>0.0.1-SNAPSHOT</version>
     </parent>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.data</groupId>
+            <artifactId>spring-data-mongodb</artifactId>
+            <version>3.4.6</version>
+        </dependency>
+        <dependency>
+            <groupId>org.mongodb</groupId>
+            <artifactId>mongodb-driver-sync</artifactId>
+            <version>4.9.1</version>
+        </dependency>
+
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+            <version>3.0.4</version>
+        </dependency>
+        <dependency>
+            <groupId>com.ibm.db2</groupId>
+            <artifactId>jcc</artifactId>
+            <version>11.5.8.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-annotations</artifactId>
+        </dependency>
+    </dependencies>
 </project>
\ No newline at end of file
index 0d9fc21f09b6a54d17e25c4d28a91b46c1ae834b..a9571e18aeba76c19586b85175ce71aec2ade79f 100644 (file)
@@ -1,14 +1,24 @@
 package hu.user.lis.db;
 
 import lombok.*;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
 
 @Getter
 @Setter
+@Entity
 @Builder
+@Document
 @AllArgsConstructor
 @NoArgsConstructor
 public class Associate {
-    String id;
+    @Id
+    @GeneratedValue(strategy = GenerationType.SEQUENCE)
+    Long id;
     String name;
     String login;
     String password;
diff --git a/lis-db/src/main/java/hu/user/lis/db/EDocument.java b/lis-db/src/main/java/hu/user/lis/db/EDocument.java
new file mode 100644 (file)
index 0000000..17059d8
--- /dev/null
@@ -0,0 +1,28 @@
+package hu.user.lis.db;
+
+import lombok.*;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import java.util.Date;
+
+@Getter
+@Setter
+@Entity
+@Builder
+@Document
+@AllArgsConstructor
+@NoArgsConstructor
+public class EDocument {
+    @Id
+    @GeneratedValue(strategy = GenerationType.SEQUENCE)
+    Long id;
+    Date created;
+    String name;
+    String description;
+    int size;
+    byte[] file;
+}
index ea07d901467262c196098a388f7266b9ea7ab38a..2577a5c45fc530c606a9dc58d9de7ee6bd91cc21 100644 (file)
@@ -1,20 +1,30 @@
 package hu.user.lis.db;
 
 import lombok.*;
+import org.springframework.data.mongodb.core.mapping.Document;
 
+import javax.persistence.*;
 import java.util.Date;
 
 @Getter
 @Setter
+@Entity
 @Builder
+@Document
 @AllArgsConstructor
 @NoArgsConstructor
 public class Invoice {
-    String id;
+    @Id
+    @GeneratedValue(strategy = GenerationType.SEQUENCE)
+    Long id;
     String humanId;
-    String projectId;
     String title;
+    @OneToOne
+    @JoinColumn(name = "partner_id")
     Partner partner;
+    @ManyToOne
+    @JoinColumn(name = "project_id")
+    Project project;
     boolean income;
     Currency currency;
     double netAmount;
index ac903d621470783f269857751a00be9bc997e24c..45f2b63812e7a58bf71f3fbe7608db5d99bd87dc 100644 (file)
@@ -1,14 +1,24 @@
 package hu.user.lis.db;
 
 import lombok.*;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
 
 @Getter
 @Setter
+@Entity
 @Builder
+@Document
 @AllArgsConstructor
 @NoArgsConstructor
 public class Partner {
-    String id;
+    @Id
+    @GeneratedValue(strategy = GenerationType.SEQUENCE)
+    Long id;
     String name;
     String vatNr;
     String address;
index 84a4a9971aa92f26f934a5c432449dd900e85253..42113c62341842283d50a5a16175c8a28ba9f34e 100644 (file)
@@ -1,23 +1,36 @@
 package hu.user.lis.db;
 
 import lombok.*;
+import org.springframework.data.mongodb.core.mapping.Document;
 
+import javax.persistence.*;
 import java.util.List;
 
 @Getter
 @Setter
+@Entity
 @Builder
+@Document
 @AllArgsConstructor
 @NoArgsConstructor
 public class Project {
-    String id;
-    String projectStatusId;
+    @Id
+    @GeneratedValue(strategy = GenerationType.SEQUENCE)
+    Long id;
+    @ManyToOne
+    @JoinColumn(name = "project_status_id")
+    ProjectStatus projectStatus;
     String name;
     String humanId;
     String contactName;
+    @ManyToOne
+    @JoinColumn(name = "partner_id")
     Partner partner;
     boolean active;
+    @OneToMany(mappedBy = "project")
     List<Invoice> incomingInvoices;
+    @OneToMany(mappedBy = "project")
     List<Invoice> outgoingInvoices;
+    @OneToMany(mappedBy = "project")
     List<Treasury> treasuries;
 }
index c66cfd810945248d0cec9a5137786dfb29cfd3e2..b2982fd614868583cb8efce0a99a5064f6b75594 100644 (file)
@@ -1,13 +1,28 @@
 package hu.user.lis.db;
 
 import lombok.*;
+import org.springframework.data.mongodb.core.mapping.Document;
+import org.springframework.data.mongodb.core.mapping.DocumentReference;
+
+import javax.persistence.*;
 
 @Getter
 @Setter
+@Entity
 @Builder
+@Document
 @AllArgsConstructor
 @NoArgsConstructor
 public class ProjectAssociate {
-    String projectId;
-    String associateId;
+    @Id
+    @GeneratedValue(strategy = GenerationType.SEQUENCE)
+    Long id;
+    @ManyToOne
+    @JoinColumn(name = "project_id")
+    @DocumentReference
+    Project project;
+    @ManyToOne
+    @JoinColumn(name = "associate_id")
+    @DocumentReference
+    Associate associate;
 }
index d0ee9abb25f474915b90006cf5ecb61c9a89c678..f45b7f852b349d5771a1343305371d7f6b592e2c 100644 (file)
@@ -2,13 +2,20 @@ package hu.user.lis.db;
 
 import lombok.*;
 
+import javax.persistence.*;
+
 @Getter
 @Setter
 @Builder
+@Entity
+//@Document
 @AllArgsConstructor
 @NoArgsConstructor
+@Table(name = "project_status")
 public class ProjectStatus {
-    String id;
+    @Id
+    @GeneratedValue(strategy = GenerationType.SEQUENCE)
+    Long id;
     String name;
     boolean active;
     int order;
index 0ce1fd71cf84c2f823dbfdc0bbfff5cdc5ce515a..f7ad0226b93da8619edf7c39eeb6a755e50cc513 100644 (file)
@@ -1,17 +1,30 @@
 package hu.user.lis.db;
 
 import lombok.*;
+import org.springframework.data.mongodb.core.mapping.Document;
+import org.springframework.data.mongodb.core.mapping.DocumentReference;
 
+import javax.persistence.*;
 import java.util.Date;
 
 @Getter
 @Setter
+@Entity
 @Builder
+@Document
 @AllArgsConstructor
 @NoArgsConstructor
 public class ServiceRecord {
-    String id;
+    @Id
+    @GeneratedValue(strategy = GenerationType.SEQUENCE)
+    Long id;
+    @ManyToOne
+    @JoinColumn(name = "project_id")
+    @DocumentReference(lazy = true)
     Project project;
+    @ManyToOne
+    @JoinColumn(name = "associate_id")
+    @DocumentReference(lazy = true)
     Associate associate;
     Date workDay;
     String description;
index 7e59c59b9ca06e47191074063b4f1afc4a2390e1..bea7a823e559a36d61a779905b619e715047c554 100644 (file)
@@ -1,16 +1,25 @@
 package hu.user.lis.db;
 
 import lombok.*;
+import org.springframework.data.mongodb.core.mapping.Document;
 
+import javax.persistence.*;
 import java.util.Date;
 
 @Getter
 @Setter
 @Builder
+@Entity
+@Document
 @AllArgsConstructor
 @NoArgsConstructor
 public class Treasury {
-    String id;
+    @Id
+    @GeneratedValue(strategy = GenerationType.SEQUENCE)
+    Long id;
+    @ManyToOne
+    @JoinColumn(name = "project_id")
+    Project project;
     String humanId;
     double buyAmount;
     Currency buyCurrency;
diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectStatusRepository.java b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectStatusRepository.java
new file mode 100644 (file)
index 0000000..7ed8770
--- /dev/null
@@ -0,0 +1,14 @@
+package hu.user.lis.db.repository;
+
+import hu.user.lis.db.ProjectStatus;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.transaction.annotation.Transactional;
+
+public interface ProjectStatusRepository extends JpaRepository<ProjectStatus, Long> {
+    @Modifying
+    @Transactional
+    @Query(value = "TRUNCATE TABLE project_status IMMEDIATE", nativeQuery = true)
+    void truncate();
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/api/AssociateApi.java b/lis-services/src/main/java/hu/user/lis/services/api/AssociateApi.java
new file mode 100644 (file)
index 0000000..9cd7a0f
--- /dev/null
@@ -0,0 +1,22 @@
+package hu.user.lis.services.api;
+
+import hu.user.lis.db.Associate;
+import hu.user.lis.services.nosql.AssociateDbService;
+import hu.user.lis.services.nosql.DbService;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Log4j2
+@RestController
+@RequestMapping("/api/associate")
+public class AssociateApi extends DbApi<Associate> {
+    @Autowired
+    AssociateDbService associateDbService;
+
+    @Override
+    protected DbService<Associate> getDbService() {
+        return associateDbService;
+    }
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/api/DbApi.java b/lis-services/src/main/java/hu/user/lis/services/api/DbApi.java
new file mode 100644 (file)
index 0000000..46a8eca
--- /dev/null
@@ -0,0 +1,41 @@
+package hu.user.lis.services.api;
+
+import hu.user.lis.services.nosql.DbService;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+public abstract class DbApi<T> {
+
+    protected abstract DbService<T> getDbService();
+
+    @GetMapping("/list")
+    public List<T> list() {
+        return getDbService().list();
+    }
+
+    @GetMapping("/get/{id}")
+    public T get(@PathVariable String id) {
+        return getDbService().get(id);
+    }
+
+    @PostMapping("/create")
+    public T create(@RequestBody T entity) {
+        return getDbService().insert(entity);
+    }
+
+    @PutMapping("/update")
+    public void update(@RequestBody T entity) {
+        getDbService().save(entity);
+    }
+
+    @GetMapping("/reset")
+    public void reset() {
+        getDbService().reset();
+    }
+
+    @GetMapping("/generate")
+    public List<T> generate() {
+        return getDbService().generate();
+    }
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/api/GenerateApi.java b/lis-services/src/main/java/hu/user/lis/services/api/GenerateApi.java
new file mode 100644 (file)
index 0000000..66c8f86
--- /dev/null
@@ -0,0 +1,52 @@
+package hu.user.lis.services.api;
+
+import hu.user.lis.services.nosql.*;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Log4j2
+@RestController
+@RequestMapping("/api/generate")
+public class GenerateApi {
+    @Autowired
+    ProjectStatusDbService projectStatusDbService;
+    @Autowired
+    PartnerDbService partnerDbService;
+    @Autowired
+    AssociateDbService associateDbService;
+    @Autowired
+    InvoiceDbService invoiceDbService;
+    @Autowired
+    TreasuryDbService treasuryDbService;
+    @Autowired
+    ProjectDbService projectDbService;
+    @Autowired
+    ProjectAssociateDbService projectAssociateDbService;
+    @Autowired
+    ServiceRecordDbService serviceRecordDbService;
+
+    @GetMapping("/all")
+    public String list() {
+        log.info("projectStatusDbService");
+        projectStatusDbService.generate();
+        log.info("partnerDbService");
+        partnerDbService.generate();
+        log.info("associateDbService");
+        associateDbService.generate();
+        log.info("invoiceDbService");
+        invoiceDbService.generate();
+        log.info("treasuryDbService");
+        treasuryDbService.generate();
+        log.info("projectDbService");
+        projectDbService.generate();
+        log.info("projectAssociateDbService");
+        projectAssociateDbService.generate();
+        log.info("serviceRecordDbService");
+        serviceRecordDbService.generate();
+        return "DONE";
+    }
+
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/api/InvoiceApi.java b/lis-services/src/main/java/hu/user/lis/services/api/InvoiceApi.java
new file mode 100644 (file)
index 0000000..02680bd
--- /dev/null
@@ -0,0 +1,22 @@
+package hu.user.lis.services.api;
+
+import hu.user.lis.db.Invoice;
+import hu.user.lis.services.nosql.DbService;
+import hu.user.lis.services.nosql.InvoiceDbService;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Log4j2
+@RestController
+@RequestMapping("/api/invoice")
+public class InvoiceApi extends DbApi<Invoice> {
+    @Autowired
+    InvoiceDbService invoiceDbService;
+
+    @Override
+    protected DbService<Invoice> getDbService() {
+        return invoiceDbService;
+    }
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/api/PartnerApi.java b/lis-services/src/main/java/hu/user/lis/services/api/PartnerApi.java
new file mode 100644 (file)
index 0000000..c3ce532
--- /dev/null
@@ -0,0 +1,22 @@
+package hu.user.lis.services.api;
+
+import hu.user.lis.db.Partner;
+import hu.user.lis.services.nosql.DbService;
+import hu.user.lis.services.nosql.PartnerDbService;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Log4j2
+@RestController
+@RequestMapping("/api/partner")
+public class PartnerApi extends DbApi<Partner> {
+    @Autowired
+    PartnerDbService partnerDbService;
+
+    @Override
+    protected DbService<Partner> getDbService() {
+        return partnerDbService;
+    }
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/api/ProjectApi.java b/lis-services/src/main/java/hu/user/lis/services/api/ProjectApi.java
new file mode 100644 (file)
index 0000000..99b5033
--- /dev/null
@@ -0,0 +1,22 @@
+package hu.user.lis.services.api;
+
+import hu.user.lis.db.Project;
+import hu.user.lis.services.nosql.DbService;
+import hu.user.lis.services.nosql.ProjectDbService;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Log4j2
+@RestController
+@RequestMapping("/api/project")
+public class ProjectApi extends DbApi<Project> {
+    @Autowired
+    ProjectDbService projectDbService;
+
+    @Override
+    protected DbService<Project> getDbService() {
+        return projectDbService;
+    }
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/api/ProjectAssociateApi.java b/lis-services/src/main/java/hu/user/lis/services/api/ProjectAssociateApi.java
new file mode 100644 (file)
index 0000000..f13e2a2
--- /dev/null
@@ -0,0 +1,22 @@
+package hu.user.lis.services.api;
+
+import hu.user.lis.db.ProjectAssociate;
+import hu.user.lis.services.nosql.DbService;
+import hu.user.lis.services.nosql.ProjectAssociateDbService;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Log4j2
+@RestController
+@RequestMapping("/api/project-associate")
+public class ProjectAssociateApi extends DbApi<ProjectAssociate> {
+    @Autowired
+    ProjectAssociateDbService projectAssociateDbService;
+
+    @Override
+    protected DbService<ProjectAssociate> getDbService() {
+        return projectAssociateDbService;
+    }
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/api/ProjectStatusApi.java b/lis-services/src/main/java/hu/user/lis/services/api/ProjectStatusApi.java
new file mode 100644 (file)
index 0000000..3a0570a
--- /dev/null
@@ -0,0 +1,53 @@
+package hu.user.lis.services.api;
+
+import hu.user.lis.db.ProjectStatus;
+import hu.user.lis.db.repository.ProjectStatusRepository;
+import hu.user.lis.services.data.ProjectStatusService;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@Log4j2
+@RestController
+@RequestMapping("/api/project-status")
+public class ProjectStatusApi {
+    @Autowired
+    ProjectStatusRepository projectStatusRepository;
+    @Autowired
+    ProjectStatusService projectStatusService;
+
+    @GetMapping("/list")
+    public List<ProjectStatus> list() {
+        return projectStatusRepository.findAll();
+    }
+
+    @GetMapping("/get/{id}")
+    public ProjectStatus get(@PathVariable Long id) {
+        return projectStatusRepository.findById(id).orElse(null);
+    }
+
+    @PostMapping("/create")
+    public ProjectStatus create(@RequestBody ProjectStatus entity) {
+        return projectStatusRepository.save(entity);
+    }
+
+    @PutMapping("/update")
+    public void update(@RequestBody ProjectStatus entity) {
+        projectStatusRepository.truncate();
+    }
+
+    @GetMapping("/reset")
+    public void reset() {
+        projectStatusRepository.truncate();
+    }
+
+    @GetMapping("/generate")
+    public List<ProjectStatus> generate() {
+        reset();
+        List<ProjectStatus> result = projectStatusService.getAll();
+        projectStatusRepository.saveAll(result);
+        return result;
+    }
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/api/ServiceRecordApi.java b/lis-services/src/main/java/hu/user/lis/services/api/ServiceRecordApi.java
new file mode 100644 (file)
index 0000000..dcd274b
--- /dev/null
@@ -0,0 +1,22 @@
+package hu.user.lis.services.api;
+
+import hu.user.lis.db.ServiceRecord;
+import hu.user.lis.services.nosql.DbService;
+import hu.user.lis.services.nosql.ServiceRecordDbService;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Log4j2
+@RestController
+@RequestMapping("/api/service-record")
+public class ServiceRecordApi extends DbApi<ServiceRecord> {
+    @Autowired
+    ServiceRecordDbService serviceRecordDbService;
+
+    @Override
+    protected DbService<ServiceRecord> getDbService() {
+        return serviceRecordDbService;
+    }
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/api/TreasuryApi.java b/lis-services/src/main/java/hu/user/lis/services/api/TreasuryApi.java
new file mode 100644 (file)
index 0000000..a43f830
--- /dev/null
@@ -0,0 +1,22 @@
+package hu.user.lis.services.api;
+
+import hu.user.lis.db.Treasury;
+import hu.user.lis.services.nosql.DbService;
+import hu.user.lis.services.nosql.TreasuryDbService;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Log4j2
+@RestController
+@RequestMapping("/api/treasury")
+public class TreasuryApi extends DbApi<Treasury> {
+    @Autowired
+    TreasuryDbService treasuryDbService;
+
+    @Override
+    protected DbService<Treasury> getDbService() {
+        return treasuryDbService;
+    }
+}
index 0121bf90e337279d52465163fd44bb07b3fda06e..7d78d66c32635742fa9113eaa018c3b61bb2c99c 100644 (file)
@@ -7,6 +7,8 @@ import java.util.List;
 public interface AssociateService extends DataService<Associate> {
     List<Associate> getAll();
 
+    void setAll(List<Associate> entities);
+
     Associate createNew();
 
     void add(Associate entity);
@@ -14,4 +16,6 @@ public interface AssociateService extends DataService<Associate> {
     Associate getRandom();
 
     void replace(Associate targetEntity, Associate replacementEntity);
+
+    Associate getById(String id);
 }
index 6fcc976433deb38bf52734e29d7e3f2b6dbebc0f..be5cf898ae9e40e1381104eb37062a2dcbdac7d7 100644 (file)
@@ -2,7 +2,6 @@ package hu.user.lis.services.data;
 
 import hu.user.lis.db.Associate;
 import lombok.extern.log4j.Log4j2;
-import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.RandomUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -27,10 +26,14 @@ public class AssociateServiceImpl extends DataServiceImpl<Associate> implements
         return entities;
     }
 
+    @Override
+    public void setAll(List<Associate> entities) {
+        this.entities = entities;
+    }
+
     @Override
     public Associate createNew() {
-        String id = RandomStringUtils.random(8, "0123456789abcdef");
-        return Associate.builder().id(id).active(true).build();
+        return Associate.builder().active(true).build();
     }
 
     @Override
@@ -45,6 +48,11 @@ public class AssociateServiceImpl extends DataServiceImpl<Associate> implements
         entities.add(replacementEntity);
     }
 
+    @Override
+    public Associate getById(String id) {
+        return getAll().stream().filter(p -> p.getId().equals(id)).findFirst().get();
+    }
+
     @Override
     public Associate getRandom() {
         return getAll().get(RandomUtils.nextInt(0, entities.size()));
@@ -53,7 +61,6 @@ public class AssociateServiceImpl extends DataServiceImpl<Associate> implements
     private List<Associate> generate() {
         List<Associate> result = new ArrayList<>();
         for (int i = 0; i < 10; i++) {
-            String id = RandomStringUtils.random(8, "0123456789abcdef");
             String name = dataGeneratorService.faker().name().fullName();
             String login = "user" + (i + 1);
             String password = "password";
@@ -63,7 +70,6 @@ public class AssociateServiceImpl extends DataServiceImpl<Associate> implements
 
             Associate entity = Associate.builder()
                     .active(true)
-                    .id(id)
                     .name(name)
                     .login(login)
                     .password(password)
@@ -77,64 +83,58 @@ public class AssociateServiceImpl extends DataServiceImpl<Associate> implements
     private List<Associate> generate2() {
         List<Associate> result = new ArrayList<>();
         double monthlyCost = 0;
-        String id = RandomStringUtils.random(8, "0123456789abcdef");
         String name = "Kosztolányi Árpád";
         String login = "user1";
         String password = "password";
         monthlyCost = BigDecimal.valueOf(RandomUtils.nextDouble(300000, 1500000))
                 .setScale(2, RoundingMode.CEILING).doubleValue();
         Associate entity = Associate.builder().monthlyCost(monthlyCost)
-                .active(true).id(id).name(name).login(login).password(password).build();
+                .active(true).name(name).login(login).password(password).build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         name = "Lévai Tibor";
         login = "user2";
         password = "password";
         monthlyCost = BigDecimal.valueOf(RandomUtils.nextDouble(300000, 1500000))
                 .setScale(2, RoundingMode.CEILING).doubleValue();
         entity = Associate.builder().monthlyCost(monthlyCost)
-                .active(true).id(id).name(name).login(login).password(password).build();
+                .active(true).name(name).login(login).password(password).build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         name = "Szabó Marcell";
         login = "user3";
         password = "password";
         monthlyCost = BigDecimal.valueOf(RandomUtils.nextDouble(300000, 1500000))
                 .setScale(2, RoundingMode.CEILING).doubleValue();
         entity = Associate.builder().monthlyCost(monthlyCost)
-                .active(true).id(id).name(name).login(login).password(password).build();
+                .active(true).name(name).login(login).password(password).build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         name = "Gulyás Csaba";
         login = "user4";
         password = "password";
         monthlyCost = BigDecimal.valueOf(RandomUtils.nextDouble(300000, 1500000))
                 .setScale(2, RoundingMode.CEILING).doubleValue();
         entity = Associate.builder().monthlyCost(monthlyCost)
-                .active(true).id(id).name(name).login(login).password(password).build();
+                .active(true).name(name).login(login).password(password).build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         name = "Lévai Csilla";
         login = "user5";
         password = "password";
         monthlyCost = BigDecimal.valueOf(RandomUtils.nextDouble(300000, 1500000))
                 .setScale(2, RoundingMode.CEILING).doubleValue();
         entity = Associate.builder().monthlyCost(monthlyCost)
-                .active(true).id(id).name(name).login(login).password(password).build();
+                .active(true).name(name).login(login).password(password).build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         name = "Vajda Krisztina";
         login = "user6";
         password = "password";
         monthlyCost = BigDecimal.valueOf(RandomUtils.nextDouble(300000, 1500000))
                 .setScale(2, RoundingMode.CEILING).doubleValue();
         entity = Associate.builder().monthlyCost(monthlyCost)
-                .active(true).id(id).name(name).login(login).password(password).build();
+                .active(true).name(name).login(login).password(password).build();
         result.add(entity);
 
         return result;
diff --git a/lis-services/src/main/java/hu/user/lis/services/data/EDocumentService.java b/lis-services/src/main/java/hu/user/lis/services/data/EDocumentService.java
new file mode 100644 (file)
index 0000000..0babafa
--- /dev/null
@@ -0,0 +1,13 @@
+package hu.user.lis.services.data;
+
+import hu.user.lis.db.EDocument;
+
+import java.util.List;
+
+public interface EDocumentService extends DataService<EDocument> {
+    List<EDocument> getAll();
+
+    EDocument createNew();
+
+    void add(EDocument entity);
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/data/EDocumentServiceImpl.java b/lis-services/src/main/java/hu/user/lis/services/data/EDocumentServiceImpl.java
new file mode 100644 (file)
index 0000000..530b619
--- /dev/null
@@ -0,0 +1,36 @@
+package hu.user.lis.services.data;
+
+import hu.user.lis.db.EDocument;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+@Log4j2
+public class EDocumentServiceImpl extends DataServiceImpl<EDocument> implements EDocumentService {
+    @Autowired
+    DataGeneratorService dataGeneratorService;
+    private List<EDocument> entities;
+
+    @Override
+    public List<EDocument> getAll() {
+        if (entities == null) {
+            entities = new ArrayList<>();
+        }
+        return entities;
+    }
+
+    @Override
+    public EDocument createNew() {
+        return EDocument.builder().build();
+    }
+
+    @Override
+    public void add(EDocument entity) {
+        entities.add(entity);
+    }
+
+}
index 34e64f154eb7a0f0f7a854addd6cac2d0ae116d4..3d458e605c69f955ab560eba9c9368e70d0d0286 100644 (file)
@@ -4,19 +4,15 @@ import hu.user.lis.db.Invoice;
 
 import java.util.List;
 
-public interface InvoiceService {
+public interface InvoiceService extends DataService<Invoice> {
     List<Invoice> getAll();
 
+    void setAll(List<Invoice> entities);
+
     Invoice createNew();
 
     void add(Invoice entity);
 
-    Invoice copy(Invoice sourceEntity);
-
-    String toString(Invoice sourceEntity);
-
-    Invoice copy(Invoice sourceEntity, String property, Object value);
-
     void replace(Invoice targetEntity, Invoice replacementEntity);
 
     List<Invoice> getRandom(boolean income);
@@ -26,6 +22,4 @@ public interface InvoiceService {
     Invoice getByHumanId(String id);
 
     List<Invoice> getByHumanIds(String[] ids);
-
-
 }
index 48f2ceea0c6bc460c3482a6cae6cbbf3a43122b5..b7d64856b7802a7ccd6b5945d648bdbe440cb4f6 100644 (file)
@@ -4,9 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import hu.user.lis.db.Currency;
 import hu.user.lis.db.Invoice;
 import hu.user.lis.db.Partner;
-import hu.user.lis.db.Project;
 import lombok.extern.log4j.Log4j2;
-import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.RandomUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -19,7 +17,6 @@ import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 
 @Service
 @Log4j2
@@ -55,10 +52,22 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
         return result;
     }
 
+    @Override
+    public void setAll(List<Invoice> entities) {
+        this.incomingEntities = new ArrayList<>();
+        this.outgoingEntities = new ArrayList<>();
+        entities.forEach(e -> {
+            if (e.isIncome()) {
+                incomingEntities.add(e);
+            } else {
+                outgoingEntities.add(e);
+            }
+        });
+    }
+
     @Override
     public Invoice createNew() {
-        String id = RandomStringUtils.random(8, "0123456789abcdef");
-        return Invoice.builder().id(id).planned(true).build();
+        return Invoice.builder().planned(true).build();
     }
 
     @Override
@@ -76,7 +85,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
         DateFormat humanIdDateFormat = new SimpleDateFormat("yyyy");
 
         for (int i = 0; i < GENERATE_COUNT; i++) {
-            String id = RandomStringUtils.random(8, "0123456789abcdef");
             String title = dataGeneratorService.faker().commerce().productName();
             Partner partner = partnerService.getRandom();
             Date completionDate = dataGeneratorService.faker().date().between(formatter.parse("2010-01-01"), new Date());
@@ -91,7 +99,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             double grossAmount = netAmount * 1.27;
             double vatAmount = grossAmount - netAmount;
             Invoice entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -115,10 +122,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
 
         if (income) {                                                   // csak a bejovo szamlak generalasa
-            String id = RandomStringUtils.random(8, "0123456789abcdef");
             String humanId = "VSz-2023/00070-";                                  // szamla sorszam
             String title = dataGeneratorService.faker().commerce().productName();    // 2022-0027
-            Partner partner = partnerService.getById("001");                   // 001
+            Partner partner = partnerService.getByName("ServerUnite Kft.");                   // 001
             Date completionDate = formatter.parse("2023-02-22");
             Date createDate = formatter.parse("2023-02-22");
             Date paymentDeadline = formatter.parse("2023-03-24");
@@ -127,7 +133,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             double grossAmount = netAmount * 1.27;
             double vatAmount = grossAmount - netAmount;
             Invoice entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -142,10 +147,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "582-SPI1003006-3021";                          // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();   // 2020-0109
-            partner = partnerService.getById("004");               // 004
+            partner = partnerService.getByName("Arrow ECS Kft.");               // 004
             completionDate = formatter.parse("2020-12-22");
             createDate = formatter.parse("2020-12-22");
             paymentDeadline = formatter.parse("2021-02-10");
@@ -154,7 +158,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -169,10 +172,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "582-SPI003118";                                 // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();    // 2020-0109
-            partner = partnerService.getById("004");                 // 004
+            partner = partnerService.getByName("Arrow ECS Kft.");                 // 004
             completionDate = formatter.parse("2020-12-31");
             createDate = formatter.parse("2020-12-31");
             paymentDeadline = formatter.parse("2021-03-31");
@@ -181,7 +183,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -196,10 +197,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "582-SPI003680";                               // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();  // 2020-0109
-            partner = partnerService.getById("004");               // 004
+            partner = partnerService.getByName("Arrow ECS Kft.");               // 004
             completionDate = formatter.parse("2021-03-08");
             createDate = formatter.parse("2021-03-08");
             paymentDeadline = formatter.parse("2021-04-27");
@@ -208,7 +208,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -223,10 +222,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "582-SPI003681";                               // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();  // 2020-0109
-            partner = partnerService.getById("004");               // 004
+            partner = partnerService.getByName("Arrow ECS Kft.");               // 004
             completionDate = formatter.parse("2021-03-08");
             createDate = formatter.parse("2021-03-08");
             paymentDeadline = formatter.parse("2021-04-27");
@@ -235,7 +233,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -250,10 +247,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "582-SPI004090";                               // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();  // 2020-0109
-            partner = partnerService.getById("004");               // 004
+            partner = partnerService.getByName("Arrow ECS Kft.");               // 004
             completionDate = formatter.parse("2021-04-19");
             createDate = formatter.parse("2021-04-19");
             paymentDeadline = formatter.parse("2021-06-08");
@@ -262,7 +258,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -277,10 +272,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "9090010764";                                  // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();  // 2020-0109
-            partner = partnerService.getById("005");               // 005
+            partner = partnerService.getByName("Tech Data - TD Synnex Kft.");               // 005
             completionDate = formatter.parse("2020-12-31");
             createDate = formatter.parse("2020-12-31");
             paymentDeadline = formatter.parse("2021-03-01");
@@ -289,7 +283,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -304,10 +297,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "VSz-2021/00091";                                  // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();      // 2020-0109
-            partner = partnerService.getById("006");                   // 006
+            partner = partnerService.getByName("The IT Solutions Kft.");                   // 006
             completionDate = formatter.parse("2021-02-10");
             createDate = formatter.parse("2021-02-18");
             paymentDeadline = formatter.parse("2021-03-20");
@@ -316,7 +308,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -331,10 +322,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "EURSZLA0177/2022";                           // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                   // 2022-0227
-            partner = partnerService.getById("008");              // 008
+            partner = partnerService.getByName("Clico Hungary Kft.");              // 008
             completionDate = formatter.parse("2022-12-30");
             createDate = formatter.parse("2022-12-30");
             paymentDeadline = formatter.parse("2023-01-31");
@@ -343,7 +333,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -358,10 +347,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "19044";                                       // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                   // 2022-0227
-            partner = partnerService.getById("009");              // 009
+            partner = partnerService.getByName("JamoDat");              // 009
             completionDate = formatter.parse("2022-12-22");
             createDate = formatter.parse("2022-12-22");
             paymentDeadline = formatter.parse("2023-01-26");
@@ -370,7 +358,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;             // Ez a számla ÁFA-mentes !!!!
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -385,10 +372,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "9171058452";                                       // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                   // 2022-0227
-            partner = partnerService.getById("010");              // 010
+            partner = partnerService.getByName("S&T Consulting Kft.");              // 010
             completionDate = formatter.parse("2022-12-30");
             createDate = formatter.parse("2023-01-13");
             paymentDeadline = formatter.parse("2023-02-12");
@@ -397,7 +383,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -412,10 +397,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "9171058628";                                       // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                   // 2022-0227
-            partner = partnerService.getById("010");              // 010
+            partner = partnerService.getByName("S&T Consulting Kft.");              // 010
             completionDate = formatter.parse("2023-01-12");
             createDate = formatter.parse("2023-01-19");
             paymentDeadline = formatter.parse("2023-02-18");
@@ -424,7 +408,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -439,10 +422,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "9171058628";                                       // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                   // 2022-0227
-            partner = partnerService.getById("011");              // 011
+            partner = partnerService.getByName("SHT Kft.");              // 011
             completionDate = formatter.parse("2022-12-23");
             createDate = formatter.parse("2022-12-23");
             paymentDeadline = formatter.parse("2023-01-07");
@@ -451,7 +433,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -466,10 +447,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "2022-SOV/000495";                                       // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                   // 2022-0227
-            partner = partnerService.getById("012");              // 012
+            partner = partnerService.getByName("SoftOne Kft.");              // 012
             completionDate = formatter.parse("2022-12-31");
             createDate = formatter.parse("2022-12-31");
             paymentDeadline = formatter.parse("2023-01-30");
@@ -478,7 +458,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -493,10 +472,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "2022-SOV/000496";                            // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                   // 2022-0227
-            partner = partnerService.getById("012");              // 012
+            partner = partnerService.getByName("SoftOne Kft.");              // 012
             completionDate = formatter.parse("2022-12-31");
             createDate = formatter.parse("2022-12-31");
             paymentDeadline = formatter.parse("2023-01-30");
@@ -505,7 +483,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -520,10 +497,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "E-SYMPR-2022-105";                            // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                   // 2022-0227
-            partner = partnerService.getById("013");              // 013
+            partner = partnerService.getByName("Symport Holding Zrt.");              // 013
             completionDate = formatter.parse("2022-12-28");
             createDate = formatter.parse("2022-12-28");
             paymentDeadline = formatter.parse("2023-01-27");
@@ -532,7 +508,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -547,10 +522,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "17356/23";                                    // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                   // 2023-0018
-            partner = partnerService.getById("014");              // 014
+            partner = partnerService.getByName("Blue Store Kft.");              // 014
             completionDate = formatter.parse("2023-02-06");
             createDate = formatter.parse("2023-02-06");
             paymentDeadline = formatter.parse("2023-03-08");
@@ -559,7 +533,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -574,10 +547,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "2023-SOV/000123";                                     // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();    // 2023-0054
-            partner = partnerService.getById("012");                       // 012
+            partner = partnerService.getByName("SoftOne Kft.");                       // 012
             completionDate = formatter.parse("2023-04-14");
             createDate = formatter.parse("2023-04-17");
             paymentDeadline = formatter.parse("2023-05-17");
@@ -586,7 +558,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -602,10 +573,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             result.add(entity);
 
         } else {
-            String id = RandomStringUtils.random(8, "0123456789abcdef");
             String humanId = "USER-2023-7";                                    // szamla sorszam
             String title = dataGeneratorService.faker().commerce().productName();  // 2022-0027
-            Partner partner = partnerService.getById("002");                  // 002
+            Partner partner = partnerService.getByName("Agrárminisztérium");                  // 002
             Date completionDate = formatter.parse("2023-02-23");
             Date createDate = formatter.parse("2023-02-23");
             Date paymentDeadline = formatter.parse("2023-03-25");
@@ -614,7 +584,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             double grossAmount = netAmount * 1.27;
             double vatAmount = grossAmount - netAmount;
             Invoice entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -629,10 +598,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "2021/0001";                                  // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();      // 2020-0109
-            partner = partnerService.getById("007");                   // 007
+            partner = partnerService.getByName("The IT Solutions Kft.");                   // 007
             completionDate = formatter.parse("2020-12-31");
             createDate = formatter.parse("2021-01-04");
             paymentDeadline = formatter.parse("2021-04-04");
@@ -641,7 +609,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -656,11 +623,10 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-                                               // csak a kimeno szamlak generalasa
-            id = RandomStringUtils.random(8, "0123456789abcdef");
+            // csak a kimeno szamlak generalasa
             humanId = "2021/0069";                                  // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();      // 2020-0109
-            partner = partnerService.getById("007");                   // 007
+            partner = partnerService.getByName("The IT Solutions Kft.");                   // 007
             completionDate = formatter.parse("2021-03-09");
             createDate = formatter.parse("2021-03-10");
             paymentDeadline = formatter.parse("2021-06-08.");
@@ -669,7 +635,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -684,10 +649,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "E-USER-2023-12";                            // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                   // 2022-0227
-            partner = partnerService.getById("017");              // 017
+            partner = partnerService.getByName("MKB Bank Zrt.");              // 017
             completionDate = formatter.parse("2022-12-31");
             createDate = formatter.parse("2023-01-06");
             paymentDeadline = formatter.parse("2023-03-07");
@@ -696,7 +660,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -712,10 +675,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             result.add(entity);
 
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "E-USER-2023-13";                            // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                   // 2022-0227
-            partner = partnerService.getById("017");              // 017
+            partner = partnerService.getByName("MKB Bank Zrt.");              // 017
             completionDate = formatter.parse("2022-12-31");
             createDate = formatter.parse("2023-01-06");
             paymentDeadline = formatter.parse("2023-03-07");
@@ -724,7 +686,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -739,10 +700,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "E-USER-2023-53";                             // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();                // 2023-0018
-            partner = partnerService.getById("015");              // 015
+            partner = partnerService.getByName("HírTV Zrt.");              // 015
             completionDate = formatter.parse("2023-02-08");
             createDate = formatter.parse("2023-02-09.");
             paymentDeadline = formatter.parse("2023-03-08");
@@ -751,7 +711,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -766,10 +725,9 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
                     .build();
             result.add(entity);
 
-            id = RandomStringUtils.random(8, "0123456789abcdef");
             humanId = "E-USER-2023-95";                                     // szamla sorszam
             title = dataGeneratorService.faker().commerce().productName();    // 2023-0054
-            partner = partnerService.getById("016");                       // 016
+            partner = partnerService.getByName("Groupama Biztosító Zrt.");                       // 016
             completionDate = formatter.parse("2023-04-14");
             createDate = formatter.parse("2023-04-17");
             paymentDeadline = formatter.parse("2023-05-17");
@@ -778,7 +736,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
             grossAmount = netAmount * 1.27;
             vatAmount = grossAmount - netAmount;
             entity = Invoice.builder()
-                    .id(id)
                     .humanId(humanId)
                     .title(title)
                     .currency(currency)
@@ -819,7 +776,6 @@ public class InvoiceServiceImpl extends DataServiceImpl<Invoice> implements Invo
     }
 
 
-
     @Override
     public List<Invoice> getRandom(boolean income) {
         getAll();
index faa1783c586243b135dee752f2802800056e831d..5c57be11155ecd8ee9f4f6407124f7382b2a3875 100644 (file)
@@ -8,6 +8,8 @@ import java.util.List;
 public interface PartnerService {
     List<Partner> getAll();
 
+    void setAll(List<Partner> entities);
+
     Partner createNew();
 
     void add(Partner entity);
@@ -23,4 +25,6 @@ public interface PartnerService {
     String toString(Partner sourceEntity) throws JsonProcessingException;
 
     Partner copy(Partner sourceEntity, String property, Object value) throws JsonProcessingException, NoSuchFieldException, IllegalAccessException;
+
+    Partner getByName(String name);
 }
index d0e8e3593af98c9e1d41b38f9d095d7813ded359..0d13a5d88de874c378176e1da52c45f6b4ffcad2 100644 (file)
@@ -36,10 +36,14 @@ public class PartnerServiceImpl extends DataServiceImpl<Partner> implements Part
         return entities;
     }
 
+    @Override
+    public void setAll(List<Partner> entities) {
+        this.entities = entities;
+    }
+
     @Override
     public Partner createNew() {
-        String id = RandomStringUtils.random(8, "0123456789abcdef");
-        return Partner.builder().id(id).active(true).build();
+        return Partner.builder().active(true).build();
     }
 
     @Override
@@ -82,7 +86,7 @@ public class PartnerServiceImpl extends DataServiceImpl<Partner> implements Part
                     address.city(),
                     address.streetName(),
                     address.buildingNumber());
-            Partner partner = Partner.builder().active(true).id(id).name(name).vatNr(vatNr).address(fullAddress).build();
+            Partner partner = Partner.builder().active(true).name(name).vatNr(vatNr).address(fullAddress).build();
             result.add(partner);
         }
         return result;
@@ -91,90 +95,74 @@ public class PartnerServiceImpl extends DataServiceImpl<Partner> implements Part
     private List<Partner> generate2() {
         List<Partner> result = new ArrayList<>();
 
-        String id = "001";
         String name = "ServerUnite Kft.";
 
-        Partner partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1151 Budapest, Mogyoród útja 42.").build();
+        Partner partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1151 Budapest, Mogyoród útja 42.").build();
         result.add(partner);
 
-        id = "002";
         name = "Agrárminisztérium";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1055 Budapest, Kossuth Lajos tér 11.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1055 Budapest, Kossuth Lajos tér 11.").build();
         result.add(partner);
 
-        id = "003";
         name = "DNS Hungária Kft.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1027 Budapest, Kapás u. 11.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1027 Budapest, Kapás u. 11.").build();
         result.add(partner);
 
-        id = "004";
+
         name = "Arrow ECS Kft.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1117 Budapest, Infopark stny. 3. B-épület, V. emelet").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1117 Budapest, Infopark stny. 3. B-épület, V. emelet").build();
         result.add(partner);
 
-        id = "005";
         name = "Tech Data - TD Synnex Kft.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1117 Budapest, Budafoki út 91-93.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1117 Budapest, Budafoki út 91-93.").build();
         result.add(partner);
 
-        id = "006";
         name = "The IT Solutions Kft.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1141 Budapest, Vezér u. 106-108.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1141 Budapest, Vezér u. 106-108.").build();
         result.add(partner);
 
-        id = "007";
         name = "Techwave Hungary Zrt.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1138 Budapest, Dunavirág u. 2-6.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1138 Budapest, Dunavirág u. 2-6.").build();
         result.add(partner);
 
-        id = "008";
         name = "Clico Hungary Kft.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1134 Budapest, Dévai u. 26-28.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1134 Budapest, Dévai u. 26-28.").build();
         result.add(partner);
 
-        id = "009";
         name = "JamoDat";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("4700 Naestved, Salto Skovvange 36, Denmark").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("4700 Naestved, Salto Skovvange 36, Denmark").build();
         result.add(partner);
 
-        id = "010";
         name = "S&T Consulting Kft.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("2040 Budaörs, Puskás Tivadar út 14.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("2040 Budaörs, Puskás Tivadar út 14.").build();
         result.add(partner);
 
-        id = "011";
         name = "SHT Kft.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1047 Budapest, Baross u. 79.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1047 Budapest, Baross u. 79.").build();
         result.add(partner);
 
-        id = "012";
         name = "SoftOne Kft.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1052 Budapest, Deák Ferenc tér 3.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1052 Budapest, Deák Ferenc tér 3.").build();
         result.add(partner);
 
-        id = "013";
         name = "Symport Holding Zrt.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1031 Budapest, Záhony u. 7.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1031 Budapest, Záhony u. 7.").build();
         result.add(partner);
 
-        id = "014";
         name = "Blue Store Kft.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1118 Budapest, Budaörsi út 46.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1118 Budapest, Budaörsi út 46.").build();
         result.add(partner);
 
-        id = "015";
         name = "HírTV Zrt.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1149 Budapest, Angol utca 65-69.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1149 Budapest, Angol utca 65-69.").build();
         result.add(partner);
 
-        id = "016";
         name = "Groupama Biztosító Zrt.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1146 Budapest, Erzsébet királyné útja 1. C-épület").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1146 Budapest, Erzsébet királyné útja 1. C-épület").build();
         result.add(partner);
 
-        id = "017";
         name = "MKB Bank Zrt.";
-        partner = Partner.builder().active(true).id(id).name(name).vatNr(generateVatNumber()).address("1056 Budapest, Váci u. 38.").build();
+        partner = Partner.builder().active(true).name(name).vatNr(generateVatNumber()).address("1056 Budapest, Váci u. 38.").build();
         result.add(partner);
 
         return result;
@@ -217,4 +205,9 @@ public class PartnerServiceImpl extends DataServiceImpl<Partner> implements Part
         return result;
     }
 
+    @Override
+    public Partner getByName(String name) {
+        return getAll().stream().filter(p -> p.getName().equals(name)).findFirst().get();
+    }
+
 }
index dfc738a5acccb75de90fc13a8da90c1d5f49a16e..4a160032afd4f755d7780ae49be0271b5c30dd07 100644 (file)
@@ -1,20 +1,22 @@
 package hu.user.lis.services.data;
 
+import hu.user.lis.db.Associate;
+import hu.user.lis.db.Project;
 import hu.user.lis.db.ProjectAssociate;
 
-import java.util.Collection;
+import java.util.List;
 import java.util.Map;
 
 public interface ProjectAssociateService {
-    ProjectAssociate createNew(String projectId, String associateId);
+    ProjectAssociate createNew(Project project, Associate associate);
 
     void add(ProjectAssociate entity);
 
     void remove(ProjectAssociate entity);
 
-    void update(String projectId, Map<String, Boolean> associates);
+    void update(Project project, Map<Associate, Boolean> associates);
 
     String toString(ProjectAssociate sourceEntity);
 
-    Collection<ProjectAssociate> getAll();
+    List<ProjectAssociate> getAll();
 }
index c67689354da5817388207d395b5510510d612952..2f9f61321fc4f21d287f430d5827fd3ca1c88f73 100644 (file)
@@ -1,6 +1,5 @@
 package hu.user.lis.services.data;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 import hu.user.lis.db.Associate;
 import hu.user.lis.db.Project;
 import hu.user.lis.db.ProjectAssociate;
@@ -17,8 +16,6 @@ import java.util.stream.Collectors;
 @Service
 @Log4j2
 public class ProjectAssociateServiceImpl extends DataServiceImpl<ProjectAssociate> implements ProjectAssociateService {
-    @Autowired
-    ObjectMapper mapper;
     @Autowired
     ProjectService projectService;
     @Autowired
@@ -34,8 +31,8 @@ public class ProjectAssociateServiceImpl extends DataServiceImpl<ProjectAssociat
     }
 
     @Override
-    public ProjectAssociate createNew(String projectId, String associateId) {
-        return ProjectAssociate.builder().projectId(projectId).associateId(associateId).build();
+    public ProjectAssociate createNew(Project project, Associate associate) {
+        return ProjectAssociate.builder().project(project).associate(associate).build();
     }
 
     @Override
@@ -49,12 +46,12 @@ public class ProjectAssociateServiceImpl extends DataServiceImpl<ProjectAssociat
     }
 
     @Override
-    public void update(String projectId, Map<String, Boolean> associates) {
-        List<ProjectAssociate> deleteEntities = entities.stream().filter(pa -> pa.getProjectId().equals(projectId)).collect(Collectors.toList());
+    public void update(Project project, Map<Associate, Boolean> associates) {
+        List<ProjectAssociate> deleteEntities = entities.stream().filter(pa -> pa.getProject().getId().equals(project.getId())).collect(Collectors.toList());
         entities.removeAll(deleteEntities);
-        associates.forEach((associateId, isAssociate) -> {
+        associates.forEach((associate, isAssociate) -> {
             if (isAssociate) {
-                ProjectAssociate projectAssociate = ProjectAssociate.builder().projectId(projectId).associateId(associateId).build();
+                ProjectAssociate projectAssociate = ProjectAssociate.builder().project(project).associate(associate).build();
                 entities.add(projectAssociate);
             }
         });
@@ -67,7 +64,7 @@ public class ProjectAssociateServiceImpl extends DataServiceImpl<ProjectAssociat
             int associatesCount = RandomUtils.nextInt(1, 5);
             for (int i = 0; i < associatesCount; i++) {
                 Associate associate = associateService.getRandom();
-                ProjectAssociate entity = ProjectAssociate.builder().projectId(project.getId()).associateId(associate.getId()).build();
+                ProjectAssociate entity = ProjectAssociate.builder().project(project).associate(associate).build();
                 result.add(entity);
             }
         }
index ab2b69ed729d2280bbb031b75dd7029193ac024f..551e4fee2b0edec63c7e5b0d5dd3190f8e4ebe48 100644 (file)
@@ -7,6 +7,8 @@ import java.util.List;
 public interface ProjectService {
     List<Project> getAll();
 
+    void setAll(List<Project> entities);
+
     Project getById(String id);
 
     List<Project> getByPartner(String id);
index 36bd034805f8eaf6e68af6f733cd395c72a3c61e..091f07e9fc4ec4bf4ede806e06a8faf4aaa94057 100644 (file)
@@ -2,8 +2,8 @@ package hu.user.lis.services.data;
 
 import hu.user.lis.db.Partner;
 import hu.user.lis.db.Project;
+import hu.user.lis.db.ProjectStatus;
 import lombok.extern.log4j.Log4j2;
-import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.RandomUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -29,6 +29,7 @@ public class ProjectServiceImpl extends DataServiceImpl<Project> implements Proj
     TreasuryService treasuryService;
     @Autowired
     ProjectStatusService projectStatusService;
+
     private List<Project> entities;
 
     @Override
@@ -39,6 +40,11 @@ public class ProjectServiceImpl extends DataServiceImpl<Project> implements Proj
         return entities;
     }
 
+    @Override
+    public void setAll(List<Project> entities) {
+        this.entities = entities;
+    }
+
     @Override
     public Project getById(String id) {
         return getAll().stream().filter(p -> p.getId().equals(id)).findFirst().get();
@@ -52,12 +58,10 @@ public class ProjectServiceImpl extends DataServiceImpl<Project> implements Proj
 
     @Override
     public Project createNew() {
-        String id = RandomStringUtils.random(8, "0123456789abcdef");
         String humanId = dataGeneratorService.faker().code().isbn13(true);
-        String projectStatusId = projectStatusService.getAll().get(0).getId();
+        ProjectStatus projectStatus = projectStatusService.getAll().get(0);
         return Project.builder()
-                .projectStatusId(projectStatusId)
-                .id(id)
+                .projectStatus(projectStatus)
                 .humanId(humanId)
                 .incomingInvoices(new ArrayList<>())
                 .outgoingInvoices(new ArrayList<>())
@@ -87,16 +91,14 @@ public class ProjectServiceImpl extends DataServiceImpl<Project> implements Proj
         List<Project> result = new ArrayList<>();
         DateFormat dateFormat = new SimpleDateFormat("yyyy");
         for (int i = 0; i < 20; i++) {
-            String id = RandomStringUtils.random(8, "0123456789abcdef");
-            String projectStatusId = projectStatusService.getAll().get(0).getId();
+            ProjectStatus projectStatus = projectStatusService.getAll().get(0);
             String name = dataGeneratorService.faker().commerce().productName();
             Date dt = dataGeneratorService.faker().date().past(i + 1, TimeUnit.DAYS);
             String humanId = String.format("%s-%s", dateFormat.format(dt), String.format("%04d", i));
             String contactName = dataGeneratorService.faker().name().fullName();
             Partner partner = partnerService.getRandom();
             Project entity = Project.builder()
-                    .id(id)
-                    .projectStatusId(projectStatusId)
+                    .projectStatus(projectStatus)
                     .active(true)
                     .humanId(humanId)
                     .name(name)
@@ -104,7 +106,7 @@ public class ProjectServiceImpl extends DataServiceImpl<Project> implements Proj
                     .partner(partner)
                     .incomingInvoices(invoiceService.getRandom(true))
                     .outgoingInvoices(invoiceService.getRandom(false))
-                    //.treasuries(treasuryService.getRandom())
+                    .treasuries(new ArrayList<>())
                     .build();
             result.add(entity);
         }
@@ -114,15 +116,14 @@ public class ProjectServiceImpl extends DataServiceImpl<Project> implements Proj
     private List<Project> generate2() {
         List<Project> result = new ArrayList<>();
 
-        String id = dataGeneratorService.faker().code().isbn10(true);
-        String projectStatusId = projectStatusService.getAll().get(0).getId();
+        ProjectStatus projectStatus = projectStatusService.getAll().get(0);
         String name = "IBM és HP diszkek szállítása régi szerverbe";
         String humanId = "2022-0027";
         String contactName = dataGeneratorService.faker().name().fullName();
-        Partner partner = partnerService.getById("002");               // 002
+
+        Partner partner = partnerService.getByName("Agrárminisztérium");               // 002
         Project entity = Project.builder()
-                .id(id)
-                .projectStatusId(projectStatusId)
+                .projectStatus(projectStatus)
                 .active(true)
                 .humanId(humanId)
                 .name(name)
@@ -130,18 +131,16 @@ public class ProjectServiceImpl extends DataServiceImpl<Project> implements Proj
                 .partner(partner)
                 .incomingInvoices(invoiceService.getByHumanIds(new String[]{"VSz-2023/00070-"}))   // VSz-2023/00070-
                 .outgoingInvoices(invoiceService.getByHumanIds(new String[]{"USER-2023-7"}))  // USER-2023-7
-                //.treasuries(treasuryService.getRandom())
+                .treasuries(new ArrayList<>())
                 .build();
         result.add(entity);
 
-        id = dataGeneratorService.faker().code().isbn10(true);
         name = "IBM Power szerver garanciakiterjesztése";
         humanId = "2022-0109";
         contactName = dataGeneratorService.faker().name().fullName();
-        partner = partnerService.getById("007");                       // 007
+        partner = partnerService.getByName("Techwave Hungary Zrt.");               // 007
         entity = Project.builder()
-                .id(id)
-                .projectStatusId(projectStatusId)
+                .projectStatus(projectStatus)
                 .active(true)
                 .humanId(humanId)
                 .name(name)
@@ -149,18 +148,16 @@ public class ProjectServiceImpl extends DataServiceImpl<Project> implements Proj
                 .partner(partner)
                 .incomingInvoices(invoiceService.getByHumanIds(new String[]{"582-SPI1003006-3021", "582-SPI003118", "582-SPI003680", "582-SPI003681", "582-SPI004090", "9090010764", "VSz-2021/00091"}))   // 582-SPI1003006-3021, 582-SPI003118, 582-SPI003680, 582-SPI003681, 582-SPI004090, 9090010764, VSz-2021/00091
                 .outgoingInvoices(invoiceService.getByHumanIds(new String[]{"2021/0001", "2021/0069"}))  // 2021/0001, 2021/0069
-                .treasuries(treasuryService.getByHumanIds(new String[]{"014","015"}))
+                .treasuries(treasuryService.getByHumanIds(new String[]{"014", "015"}))
                 .build();
         result.add(entity);
 
-        id = dataGeneratorService.faker().code().isbn10(true);
         name = "Multivendor 2023 évre";
         humanId = "2022-0227";
         contactName = dataGeneratorService.faker().name().fullName();
-        partner = partnerService.getById("017");                       // 017
+        partner = partnerService.getByName("MKB Bank Zrt.");               // 017
         entity = Project.builder()
-                .id(id)
-                .projectStatusId(projectStatusId)
+                .projectStatus(projectStatus)
                 .active(true)
                 .humanId(humanId)
                 .name(name)
@@ -172,14 +169,12 @@ public class ProjectServiceImpl extends DataServiceImpl<Project> implements Proj
                 .build();
         result.add(entity);
 
-        id = dataGeneratorService.faker().code().isbn10(true);
         name = "LTO8 szalagok szállítása";
         humanId = "2023-0018";
         contactName = dataGeneratorService.faker().name().fullName();
-        partner = partnerService.getById("015");                       // 015
+        partner = partnerService.getByName("HírTV Zrt.");               // 015
         entity = Project.builder()
-                .id(id)
-                .projectStatusId(projectStatusId)
+                .projectStatus(projectStatus)
                 .active(true)
                 .humanId(humanId)
                 .name(name)
@@ -187,18 +182,16 @@ public class ProjectServiceImpl extends DataServiceImpl<Project> implements Proj
                 .partner(partner)
                 .incomingInvoices(invoiceService.getByHumanIds(new String[]{"17356/23"}))   // 17356/23
                 .outgoingInvoices(invoiceService.getByHumanIds(new String[]{"E-USER-2023-53"}))  // E-USER-2023-53
-                //.treasuries(treasuryService.getRandom())
+                .treasuries(new ArrayList<>())
                 .build();
         result.add(entity);
 
-        id = dataGeneratorService.faker().code().isbn10(true);
         name = "PowerBuilder Professional licencek szállítása";
         humanId = "2023-0054";
         contactName = dataGeneratorService.faker().name().fullName();
-        partner = partnerService.getById("016");                       // 016
+        partner = partnerService.getByName("Groupama Biztosító Zrt.");               // 016
         entity = Project.builder()
-                .id(id)
-                .projectStatusId(projectStatusId)
+                .projectStatus(projectStatus)
                 .active(true)
                 .humanId(humanId)
                 .name(name)
index cfcfa67d432db173f8f80a4b8e42cded5855bcd0..2a127de3720a8e3cd219f91f706c208bd0e3e3e1 100644 (file)
@@ -7,7 +7,7 @@ import java.util.List;
 public interface ProjectStatusService extends DataService<ProjectStatus> {
     List<ProjectStatus> getAll();
 
-    ProjectStatus getById(String id);
+    ProjectStatus getById(Object id);
 
     ProjectStatus createNew();
 
index 2ee101c2e25682bed758f044ef1d6d90b350de3c..3bb19662f15090cd0e3d65fad142ea2d4bdd79ef 100644 (file)
@@ -2,50 +2,52 @@ package hu.user.lis.services.data;
 
 import hu.user.lis.db.ProjectStatus;
 import lombok.extern.log4j.Log4j2;
-import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.RandomUtils;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.Comparator;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.stream.Collectors;
 
 @Service
 @Log4j2
 public class ProjectStatusServiceImpl extends DataServiceImpl<ProjectStatus> implements ProjectStatusService {
-    private Map<String, ProjectStatus> entities;
+    private List<ProjectStatus> entities;
 
     @Override
     public List<ProjectStatus> getAll() {
         if (entities == null) {
+
+            //projectStatusRepository.findAll()
             entities = generate();
         }
-        return entities.values().stream().sorted(Comparator.comparing(ProjectStatus::getOrder)).collect(Collectors.toList());
+        return entities.stream().sorted(Comparator.comparing(ProjectStatus::getOrder)).collect(Collectors.toList());
     }
 
     @Override
-    public ProjectStatus getById(String id) {
-        return entities.get(id);
+    public ProjectStatus getById(Object id) {
+        return entities.stream().filter(e -> e.getId().equals(id)).findFirst().get();
     }
 
     @Override
     public ProjectStatus createNew() {
-        String id = RandomStringUtils.random(8, "0123456789abcdef");
-        ProjectStatus result = ProjectStatus.builder().id(id).active(true).order(entities.size() + 1).build();
-        entities.put(result.getId(), result);
+        ProjectStatus result = ProjectStatus.builder().active(true).order(entities.size() + 1).build();
+        entities.add(result);
         return result;
     }
 
     @Override
     public void add(ProjectStatus entity) {
-        entities.put(entity.getId(), entity);
+        entities.add(entity);
     }
 
     @Override
     public void replace(ProjectStatus targetEntity, ProjectStatus replacementEntity) {
-        entities.put(replacementEntity.getId(), replacementEntity);
+        ProjectStatus entity = getById(targetEntity.getId());
+        int i = entities.indexOf(entity);
+        entities.remove(i);
+        entities.add(i, replacementEntity);
     }
 
     @Override
@@ -53,18 +55,17 @@ public class ProjectStatusServiceImpl extends DataServiceImpl<ProjectStatus> imp
         return getAll().get(RandomUtils.nextInt(0, entities.size()));
     }
 
-    private void createStatus(String name, Map<String, ProjectStatus> entities) {
+    private void createStatus(String name, List<ProjectStatus> entities) {
         ProjectStatus entity = ProjectStatus.builder()
                 .active(true)
-                .id(RandomStringUtils.random(8, "0123456789abcdef"))
                 .name(name)
                 .order(entities.size() + 1)
                 .build();
-        entities.put(entity.getId(), entity);
+        entities.add(entity);
     }
 
-    private Map<String, ProjectStatus> generate() {
-        Map<String, ProjectStatus> result = new HashMap<>();
+    private List<ProjectStatus> generate() {
+        List<ProjectStatus> result = new ArrayList<>();
         createStatus("Új", result);
         createStatus("Terv", result);
         createStatus("Készül az ajánlat", result);
index a74541d25eaeeeff39fc31b26480f227dff096bf..c9d50cdd0ab1fd6cd6a655873890afc1a40e0ea2 100644 (file)
@@ -5,7 +5,7 @@ import hu.user.lis.db.ServiceRecord;
 
 import java.util.List;
 
-public interface ServiceRecordService {
+public interface ServiceRecordService extends DataService<ServiceRecord> {
     List<ServiceRecord> getAll();
 
     ServiceRecord getById(String id);
@@ -18,13 +18,7 @@ public interface ServiceRecordService {
 
     void add(ServiceRecord entity);
 
-    ServiceRecord copy(ServiceRecord sourceEntity);
-
     void calculateCost(ServiceRecord entity);
 
     void replace(ServiceRecord targetEntity, ServiceRecord replacementEntity);
-
-    String toString(ServiceRecord sourceEntity);
-
-    ServiceRecord copy(ServiceRecord sourceEntity, String property, Object value);
 }
index b278322ffc11dc078b46e8c5e578e3ec471daf55..f99368bea4e47c40cea7817bb5af4c7e4559bf92 100644 (file)
@@ -1,10 +1,8 @@
 package hu.user.lis.services.data;
 
-import hu.user.lis.db.Associate;
 import hu.user.lis.db.Project;
 import hu.user.lis.db.ServiceRecord;
 import lombok.extern.log4j.Log4j2;
-import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.RandomUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -12,8 +10,8 @@ import org.springframework.stereotype.Service;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
 
 @Service
 @Log4j2
@@ -23,6 +21,8 @@ public class ServiceRecordServiceImpl extends DataServiceImpl<ServiceRecord> imp
     @Autowired
     ProjectService projectService;
     @Autowired
+    ProjectAssociateService projectAssociateService;
+    @Autowired
     AssociateService associateService;
     private List<ServiceRecord> entities;
 
@@ -42,16 +42,14 @@ public class ServiceRecordServiceImpl extends DataServiceImpl<ServiceRecord> imp
 
     @Override
     public List<ServiceRecord> getByProject(String id) {
-        return getAll().stream().filter(p -> p.getProject().getId().equals(id)).collect(Collectors.toList());
+//        return getAll().stream().filter(p -> p.getProject().getId().equals(id)).collect(Collectors.toList());
+        return null;
     }
 
 
     @Override
     public ServiceRecord createNew() {
-        String id = RandomStringUtils.random(8, "0123456789abcdef");
-        return ServiceRecord.builder()
-                .id(id)
-                .build();
+        return ServiceRecord.builder().build();
     }
 
     @Override
@@ -69,8 +67,10 @@ public class ServiceRecordServiceImpl extends DataServiceImpl<ServiceRecord> imp
     public void calculateCost(ServiceRecord entity) {
         double cost = 0;
         try {
-            cost = (entity.getAssociate().getMonthlyCost() * entity.getWorkHours()) / (21 * 8);
-            entity.setCost(cost);
+            if (Objects.nonNull(entity.getAssociate()) && entity.getWorkHours() > 0) {
+                cost = (entity.getAssociate().getMonthlyCost() * entity.getWorkHours()) / (21 * 8);
+                entity.setCost(cost);
+            }
         } catch (Exception e) {
             log.catching(e);
         }
@@ -85,42 +85,50 @@ public class ServiceRecordServiceImpl extends DataServiceImpl<ServiceRecord> imp
 
     private List<ServiceRecord> generate() {
         List<ServiceRecord> result = new ArrayList<>();
-
-        projectService.getAll().forEach(p -> {
-            int serviceRecordCount = RandomUtils.nextInt(3, 10);
-            for (int i = 0; i < serviceRecordCount; i++) {
-                String id = RandomStringUtils.random(8, "0123456789abcdef");
-                Date workDay = dataGeneratorService.faker().date().past(i * 10 + 1, TimeUnit.DAYS);
-                Associate associate = associateService.getRandom();
-                String description = dataGeneratorService.faker().lorem().sentence(10);
-                int workHours = RandomUtils.nextInt(1, 9);
-                ServiceRecord entity = ServiceRecord.builder()
-                        .associate(associate)
-                        .project(p)
-                        .workDay(workDay)
-                        .workHours(workHours)
-                        .description(description)
-                        .id(id)
-                        .build();
-                calculateCost(entity);
-                result.add(entity);
-
-                id = RandomStringUtils.random(8, "0123456789abcdef");
-                entity = ServiceRecord.builder()
-                        .associate(associate)
-                        .project(p)
-                        .workDay(workDay)
-                        .workHours(workHours)
-                        .description(description)
-                        .id(id)
-                        .build();
-                calculateCost(entity);
-                result.add(entity);
-
-
-            }
-
-        });
+        Date workDay = dataGeneratorService.faker().date().past(10 + 1, TimeUnit.DAYS);
+        String description = dataGeneratorService.faker().lorem().sentence(10);
+        int workHours = RandomUtils.nextInt(1, 9);
+        ServiceRecord entity = ServiceRecord.builder()
+                .associate(associateService.getRandom())
+                .project(projectService.getRandom())
+                .workDay(workDay)
+                .workHours(workHours)
+                .description(description)
+                .build();
+        calculateCost(entity);
+        result.add(entity);
+
+//        projectService.getAll().forEach(p -> {
+//            int serviceRecordCount = RandomUtils.nextInt(3, 10);
+//
+//            List<ProjectAssociate> projectAssociates = projectAssociateService.getAll().stream().filter(e -> e.getProject().getId().equals(p.getId())).collect(Collectors.toList());
+//            projectAssociates.forEach(pa -> {
+//                for (int i = 0; i < serviceRecordCount; i++) {
+//                    Date workDay = dataGeneratorService.faker().date().past(i * 10 + 1, TimeUnit.DAYS);
+//                    String description = dataGeneratorService.faker().lorem().sentence(10);
+//                    int workHours = RandomUtils.nextInt(1, 9);
+//                    ServiceRecord entity = ServiceRecord.builder()
+//                            .associate(pa.getAssociate())
+//                            .project(pa.getProject())
+//                            .workDay(workDay)
+//                            .workHours(workHours)
+//                            .description(description)
+//                            .build();
+//                    calculateCost(entity);
+//                    result.add(entity);
+//
+//                    entity = ServiceRecord.builder()
+//                            .associate(pa.getAssociate())
+//                            .project(pa.getProject())
+//                            .workDay(workDay)
+//                            .workHours(workHours)
+//                            .description(description)
+//                            .build();
+//                    calculateCost(entity);
+//                    result.add(entity);
+//                }
+//            });
+//        });
 
         return result;
     }
index 5e9f7752ec25c84ad01a8cdf2b83e493d7bd2c66..678cd6f5caa170993b51e62d988b89c07a947a8e 100644 (file)
@@ -25,10 +25,9 @@ public class SupplierServiceImpl extends DataServiceImpl<Supplier> implements Su
     private List<Supplier> generate() {
         List<Supplier> result = new ArrayList<>();
         for (int i = 0; i < 100; i++) {
-            String id = RandomStringUtils.random(8, "0123456789abcdef");
             String name = dataGeneratorService.faker().name().fullName();
             String zipCode = RandomStringUtils.random(4, "0123456789");
-            Supplier supplier = Supplier.builder().id(id).name(name).zipCode(zipCode).build();
+            Supplier supplier = Supplier.builder().name(name).zipCode(zipCode).build();
             result.add(supplier);
         }
         return result;
index 6f29fbc3d2a962f65867b29ddd7e430650c7479b..12702c2ba5e43782125424ff05bbd3d5e11c4159 100644 (file)
@@ -41,8 +41,7 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
 
     @Override
     public Treasury createNew() {
-        String id = RandomStringUtils.random(8, "0123456789abcdef");
-        return Treasury.builder().id(id).build();
+        return Treasury.builder().build();
     }
 
     private List<Treasury> generate() throws ParseException {
@@ -65,7 +64,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
             double buyAmount = RandomUtils.nextFloat(500, 100000);
             double sellAmount = RandomUtils.nextFloat(500, 100000);
             Treasury entity = Treasury.builder()
-                    .id(id)
                     .buyCurrency(buyCurrency)
                     .sellCurrency(sellCurrency)
                     .transactionDate(transactionDate)
@@ -83,7 +81,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         List<Treasury> result = new ArrayList<>();
         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
 
-        String id = RandomStringUtils.random(8, "0123456789abcdef");
         String humanId = "001";
         Date transactionDate = formatter.parse("2023-01-09");
         Date valueDate = formatter.parse("2023-01-09");
@@ -92,7 +89,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         double buyAmount = 12065.0;
         double sellAmount = 0.0;
         Treasury entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -103,7 +99,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "002";
         transactionDate = formatter.parse("2023-01-25");
         valueDate = formatter.parse("2023-01-25");
@@ -112,7 +107,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 390.0;
         sellAmount = 0.0;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -123,7 +117,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "003";
         transactionDate = formatter.parse("2023-01-27");
         valueDate = formatter.parse("2023-01-27");
@@ -132,7 +125,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 66686.33;
         sellAmount = 0.0;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -143,7 +135,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "004";
         transactionDate = formatter.parse("2023-01-27");
         valueDate = formatter.parse("2023-01-27");
@@ -152,7 +143,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 3016.38;
         sellAmount = 0.0;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -163,7 +153,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "005";
         transactionDate = formatter.parse("2023-01-30");
         valueDate = formatter.parse("2023-01-30");
@@ -172,7 +161,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 20204.75;
         sellAmount = 0.0;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -183,7 +171,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "006";
         transactionDate = formatter.parse("2023-01-30");
         valueDate = formatter.parse("2023-01-30");
@@ -192,7 +179,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 56502.34;
         sellAmount = 0.0;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -203,7 +189,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "007";
         transactionDate = formatter.parse("2023-02-06");
         valueDate = formatter.parse("2023-02-06");
@@ -212,7 +197,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 2672749.00;
         sellAmount = 0.0;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -223,7 +207,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "008";
         transactionDate = formatter.parse("2023-02-10");
         valueDate = formatter.parse("2023-02-10");
@@ -232,7 +215,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 28573.73;
         sellAmount = 0.0;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -243,7 +225,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "009";
         transactionDate = formatter.parse("2023-02-10");
         valueDate = formatter.parse("2023-02-10");
@@ -252,7 +233,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 38.10;
         sellAmount = 0.0;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -263,7 +243,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "010";
         transactionDate = formatter.parse("2023-03-29");
         valueDate = formatter.parse("2023-03-29");
@@ -272,7 +251,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 0.0;
         sellAmount = 199089.20;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -283,7 +261,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "011";
         transactionDate = formatter.parse("2023-03-31");
         valueDate = formatter.parse("2023-03-31");
@@ -292,7 +269,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 0.0;
         sellAmount = 85871.39;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -303,7 +279,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "012";
         transactionDate = formatter.parse("2023-05-17");
         valueDate = formatter.parse("2023-05-17");
@@ -312,7 +287,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 0.0;
         sellAmount = 18411.19;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -323,7 +297,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "013";
         transactionDate = formatter.parse("2023-05-17");
         valueDate = formatter.parse("2023-05-17");
@@ -332,7 +305,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 0.0;
         sellAmount = 17928.59;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -343,7 +315,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "014";
         transactionDate = formatter.parse("2020-10-15");
         valueDate = formatter.parse("2021-03-25");
@@ -352,7 +323,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 224113.70;
         sellAmount = 78439795.00;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
@@ -363,7 +333,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
                 .build();
         result.add(entity);
 
-        id = RandomStringUtils.random(8, "0123456789abcdef");
         humanId = "015";
         transactionDate = formatter.parse("2020-10-15");
         valueDate = formatter.parse("2021-04-15");
@@ -372,7 +341,6 @@ public class TreasuryServiceImpl extends DataServiceImpl<Treasury> implements Tr
         buyAmount = 64955.00;
         sellAmount = 23513710.00;
         entity = Treasury.builder()
-                .id(id)
                 .humanId(humanId)
                 .buyCurrency(buyCurrency)
                 .sellCurrency(sellCurrency)
diff --git a/lis-services/src/main/java/hu/user/lis/services/nosql/AssociateDbService.java b/lis-services/src/main/java/hu/user/lis/services/nosql/AssociateDbService.java
new file mode 100644 (file)
index 0000000..20dff6f
--- /dev/null
@@ -0,0 +1,36 @@
+package hu.user.lis.services.nosql;
+
+import hu.user.lis.db.Associate;
+import hu.user.lis.services.data.AssociateService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class AssociateDbService extends DbService<Associate> {
+    public static final String ID = "id";
+    public static final String NAME = "name";
+    public static final String ACTIVE = "active";
+    public static final String LOGIN = "login";
+    public static final String PASSWORD = "password";
+    public static final String MONTHLY_COST = "monthlyCost";
+    @Autowired
+    AssociateService associateService;
+
+    @Override
+    protected Class<Associate> getEntityClass() {
+        return Associate.class;
+    }
+
+    @Override
+    protected List<Associate> generateEntities() {
+        return associateService.getAll();
+    }
+
+    @Override
+    protected void afterGenerateEntities(List<Associate> entities) {
+        associateService.setAll(entities);
+    }
+
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/nosql/DbService.java b/lis-services/src/main/java/hu/user/lis/services/nosql/DbService.java
new file mode 100644 (file)
index 0000000..f95feb1
--- /dev/null
@@ -0,0 +1,65 @@
+package hu.user.lis.services.nosql;
+
+import com.mongodb.client.MongoCollection;
+import org.bson.Document;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public abstract class DbService<T> {
+    @Autowired
+    MongoTemplate mongoTemplate;
+
+    protected abstract Class<T> getEntityClass();
+
+    public List<T> list() {
+        return mongoTemplate.findAll(getEntityClass());
+    }
+
+    public List<T> list(Query query) {
+        return mongoTemplate.find(query, getEntityClass());
+    }
+
+    public long count(Query query) {
+        return mongoTemplate.count(query, getEntityClass());
+    }
+
+    public T get(String id) {
+        return mongoTemplate.findById(id, getEntityClass());
+    }
+
+    public T insert(T entity) {
+        mongoTemplate.insert(entity);
+        return entity;
+    }
+
+    public T save(T entity) {
+        return mongoTemplate.save(entity);
+    }
+
+    public void reset() {
+        String collectionName = mongoTemplate.getCollectionName(getEntityClass());
+        MongoCollection<Document> collection = mongoTemplate.getCollection(collectionName);
+        if (collection != null) {
+            collection.drop();
+        }
+    }
+
+    public List<T> generate() {
+        reset();
+        List<T> result = generateEntities();
+        mongoTemplate.insertAll(result);
+        afterGenerateEntities(result);
+        return result;
+    }
+
+    protected abstract List<T> generateEntities();
+
+    protected void afterGenerateEntities(List<T> entities) {
+    }
+
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/nosql/InvoiceDbService.java b/lis-services/src/main/java/hu/user/lis/services/nosql/InvoiceDbService.java
new file mode 100644 (file)
index 0000000..b42cf57
--- /dev/null
@@ -0,0 +1,29 @@
+package hu.user.lis.services.nosql;
+
+import hu.user.lis.db.Invoice;
+import hu.user.lis.services.data.InvoiceService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class InvoiceDbService extends DbService<Invoice> {
+    @Autowired
+    InvoiceService invoiceService;
+
+    @Override
+    protected Class<Invoice> getEntityClass() {
+        return Invoice.class;
+    }
+
+    @Override
+    protected List<Invoice> generateEntities() {
+        return invoiceService.getAll();
+    }
+
+    @Override
+    protected void afterGenerateEntities(List<Invoice> entities) {
+        invoiceService.setAll(entities);
+    }
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/nosql/PartnerDbService.java b/lis-services/src/main/java/hu/user/lis/services/nosql/PartnerDbService.java
new file mode 100644 (file)
index 0000000..cc8299a
--- /dev/null
@@ -0,0 +1,33 @@
+package hu.user.lis.services.nosql;
+
+import hu.user.lis.db.Partner;
+import hu.user.lis.services.data.PartnerService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class PartnerDbService extends DbService<Partner> {
+    public static final String ID = "id";
+    public static final String NAME = "name";
+    public static final String VAT_NR = "vatNr";
+    public static final String ADDRESS = "address";
+    @Autowired
+    PartnerService partnerService;
+
+    @Override
+    protected Class<Partner> getEntityClass() {
+        return Partner.class;
+    }
+
+    @Override
+    protected List<Partner> generateEntities() {
+        return partnerService.getAll();
+    }
+
+    @Override
+    protected void afterGenerateEntities(List<Partner> entities) {
+        partnerService.setAll(entities);
+    }
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/nosql/ProjectAssociateDbService.java b/lis-services/src/main/java/hu/user/lis/services/nosql/ProjectAssociateDbService.java
new file mode 100644 (file)
index 0000000..4108fd0
--- /dev/null
@@ -0,0 +1,25 @@
+package hu.user.lis.services.nosql;
+
+import hu.user.lis.db.ProjectAssociate;
+import hu.user.lis.services.data.ProjectAssociateService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class ProjectAssociateDbService extends DbService<ProjectAssociate> {
+    @Autowired
+    ProjectAssociateService projectAssociateService;
+
+    @Override
+    protected Class<ProjectAssociate> getEntityClass() {
+        return ProjectAssociate.class;
+    }
+
+    @Override
+    protected List<ProjectAssociate> generateEntities() {
+        return projectAssociateService.getAll();
+    }
+
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/nosql/ProjectDbService.java b/lis-services/src/main/java/hu/user/lis/services/nosql/ProjectDbService.java
new file mode 100644 (file)
index 0000000..b65d903
--- /dev/null
@@ -0,0 +1,29 @@
+package hu.user.lis.services.nosql;
+
+import hu.user.lis.db.Project;
+import hu.user.lis.services.data.ProjectService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class ProjectDbService extends DbService<Project> {
+    @Autowired
+    ProjectService projectService;
+
+    @Override
+    protected Class<Project> getEntityClass() {
+        return Project.class;
+    }
+
+    @Override
+    protected List<Project> generateEntities() {
+        return projectService.getAll();
+    }
+
+    @Override
+    protected void afterGenerateEntities(List<Project> entities) {
+        projectService.setAll(entities);
+    }
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/nosql/ProjectStatusDbService.java b/lis-services/src/main/java/hu/user/lis/services/nosql/ProjectStatusDbService.java
new file mode 100644 (file)
index 0000000..c65e4a4
--- /dev/null
@@ -0,0 +1,29 @@
+package hu.user.lis.services.nosql;
+
+import hu.user.lis.db.ProjectStatus;
+import hu.user.lis.services.data.ProjectStatusService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class ProjectStatusDbService extends DbService<ProjectStatus> {
+    public final String ID = "id";
+    public final String NAME = "name";
+    public final String ACTIVE = "active";
+    public final String ORDER = "order";
+    @Autowired
+    ProjectStatusService projectStatusService;
+
+    @Override
+    protected Class<ProjectStatus> getEntityClass() {
+        return ProjectStatus.class;
+    }
+
+    @Override
+    protected List<ProjectStatus> generateEntities() {
+        return projectStatusService.getAll();
+    }
+
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/nosql/ServiceRecordDbService.java b/lis-services/src/main/java/hu/user/lis/services/nosql/ServiceRecordDbService.java
new file mode 100644 (file)
index 0000000..7c8a550
--- /dev/null
@@ -0,0 +1,28 @@
+package hu.user.lis.services.nosql;
+
+import hu.user.lis.db.ServiceRecord;
+import hu.user.lis.services.data.ServiceRecordService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class ServiceRecordDbService extends DbService<ServiceRecord> {
+    public static final String ID = "id";
+    public static final String PROJECT_ID = "projectId";
+    public static final String ASSOCIATE_ID = "associateId";
+    @Autowired
+    ServiceRecordService serviceRecordService;
+
+    @Override
+    protected Class<ServiceRecord> getEntityClass() {
+        return ServiceRecord.class;
+    }
+
+    @Override
+    protected List<ServiceRecord> generateEntities() {
+        return serviceRecordService.getAll();
+    }
+
+}
diff --git a/lis-services/src/main/java/hu/user/lis/services/nosql/TreasuryDbService.java b/lis-services/src/main/java/hu/user/lis/services/nosql/TreasuryDbService.java
new file mode 100644 (file)
index 0000000..7fd02ca
--- /dev/null
@@ -0,0 +1,24 @@
+package hu.user.lis.services.nosql;
+
+import hu.user.lis.db.Treasury;
+import hu.user.lis.services.data.TreasuryService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class TreasuryDbService extends DbService<Treasury> {
+    @Autowired
+    TreasuryService treasuryService;
+
+    @Override
+    protected Class<Treasury> getEntityClass() {
+        return Treasury.class;
+    }
+
+    @Override
+    protected List<Treasury> generateEntities() {
+        return treasuryService.getAll();
+    }
+}
index c5bba742fbcc002744b2c13ac91b267b3743f7b9..88b44f820cc31b38524c7e0b6e8088101a6cab26 100644 (file)
@@ -2,7 +2,6 @@ package hu.user.lis.ui.converter;
 
 import hu.user.lis.db.ProjectStatus;
 import hu.user.lis.services.data.ProjectStatusService;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.zkoss.bind.BindContext;
@@ -11,26 +10,31 @@ import org.zkoss.zul.ListModel;
 import org.zkoss.zul.Selectbox;
 import org.zkoss.zul.ext.Selectable;
 
+import java.util.Objects;
+
 @Component
-public class ProjectStatusConverter implements Converter<Object, String, Selectbox> {
+public class ProjectStatusConverter implements Converter<Object, ProjectStatus, Selectbox> {
     @Autowired
     ProjectStatusService projectStatusService;
 
     @Override
-    public Object coerceToUi(String id, Selectbox box, BindContext bindContext) {
-        if (StringUtils.isBlank(id)) {
+    public Object coerceToUi(ProjectStatus projectStatus, Selectbox box, BindContext bindContext) {
+        if (Objects.isNull(projectStatus)) {
             return IGNORED_VALUE;
         }
-        ProjectStatus projectStatus = projectStatusService.getById(id);
         final ListModel<?> model = box.getModel();
         ((Selectable<Object>) model).clearSelection();
-        ((Selectable<Object>) model).addToSelection(projectStatus);
+        for (int i = 0; i < model.getSize(); i++) {
+            ProjectStatus status = (ProjectStatus) model.getElementAt(i);
+            if (status.getId().equals(projectStatus.getId())) {
+                return i;
+            }
+        }
         return IGNORED_VALUE;
     }
 
     @Override
-    public String coerceToBean(Object order, Selectbox bandbox, BindContext bindContext) {
-        ProjectStatus projectStatus = projectStatusService.getAll().get((Integer) order);
-        return projectStatus.getId();
+    public ProjectStatus coerceToBean(Object order, Selectbox bandbox, BindContext bindContext) {
+        return projectStatusService.getAll().get((Integer) order);
     }
 }
\ No newline at end of file
index 4ab32411b00e2099b6bdea82cd6f045c45401a04..d64042485867dec9877ca48152e1153c971faa90 100644 (file)
@@ -1,19 +1,21 @@
 package hu.user.lis.ui.data;
 
 import hu.user.lis.db.Associate;
-import hu.user.lis.services.data.AssociateService;
+import hu.user.lis.services.nosql.AssociateDbService;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
 import org.springframework.context.annotation.Scope;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Component;
 import org.zkoss.bind.BindUtils;
 import org.zkoss.zul.FieldComparator;
 
-import java.util.Comparator;
 import java.util.List;
-import java.util.stream.Collectors;
 
 @Component
 @Log4j2
@@ -21,37 +23,32 @@ import java.util.stream.Collectors;
 public class AssociateSelectorDataModel extends CachedDataModel<Associate> {
     static private final int SEARCH_LIMIT = 10;
     @Autowired
-    AssociateService associateService;
+    AssociateDbService associateDbService;
     private String partialName;
 
-    private boolean filter(Associate associate) {
-        if (StringUtils.isBlank(partialName)) {
-            return true;
-        } else {
-            if (associate.getName().toLowerCase().startsWith(partialName.toLowerCase())) {
-                return true;
-            }
+    private Query filter() {
+        Query result = new Query();
+        if (StringUtils.isNotBlank(partialName)) {
+            result.addCriteria(Criteria.where(AssociateDbService.NAME).regex("/^" + partialName + "/i"));
         }
-        return false;
+        result.addCriteria(Criteria.where(AssociateDbService.ACTIVE).is(true));
+        return result;
     }
 
     @Override
-    protected List<Associate> getResultSet(long offset, int limit, FieldComparator sortComparator) {
-        List<Associate> result = associateService.getAll().stream()
-                .sorted(Comparator.comparing(Associate::getName))
-                .filter(s -> filter(s))
-                .limit(SEARCH_LIMIT)
-                .collect(Collectors.toList());
+    protected List<Associate> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
+        Query query = filter();
+        query.with(Sort.by(Sort.Direction.ASC, AssociateDbService.NAME));
+        query.with(PageRequest.of(page, pageSize));
+        List<Associate> result = associateDbService.list(query);
         return result;
     }
 
     @Override
     public int getResultSetCount() {
-        int result = (int) associateService.getAll().stream()
-                .filter(s -> filter(s))
-                .limit(SEARCH_LIMIT)
-                .count();
-        return result;
+        Query query = filter();
+        int result = (int) associateDbService.count(query);
+        return result > SEARCH_LIMIT ? SEARCH_LIMIT : result;
     }
 
     public void search(String partialName) {
index 7c73dff083ca653a5da70ab13072c49d8ced97dc..54ae8f41ebfdf4f3afaa73db9ea7f2066f11561e 100644 (file)
@@ -2,25 +2,28 @@ package hu.user.lis.ui.data;
 
 import hu.user.lis.db.Associate;
 import hu.user.lis.services.data.AssociateService;
-import lombok.Getter;
+import hu.user.lis.services.nosql.AssociateDbService;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
 import org.springframework.context.annotation.Scope;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Component;
-import org.zkoss.bind.BindUtils;
 import org.zkoss.zul.FieldComparator;
 
-import java.util.Comparator;
 import java.util.List;
-import java.util.stream.Collectors;
 
 @Component
 @Log4j2
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 public class AssociatesDataModel extends CachedDataModel<Associate> {
-    @Getter
+    @Autowired
+    AssociateDbService associateDbService;
     @Autowired
     AssociateService associateService;
     private String partialName;
@@ -28,57 +31,44 @@ public class AssociatesDataModel extends CachedDataModel<Associate> {
     private boolean filterShowInActive;
     private boolean filterShowActive;
 
-
-    private boolean canExecuteSearch() {
-        boolean result = listAll || filterShowActive || filterShowInActive ||
-                StringUtils.isNotBlank(partialName);
-        log.info("Can execute search: {}", result);
-        return result;
-    }
-
-    private boolean filter(Associate associate) {
+    private Query filter() {
+        Query result = new Query();
         if (listAll) {
-            return true;
+            result.addCriteria(Criteria.where(AssociateDbService.ID).gt(0));
+            return result;
         }
-
-        boolean result = true;
         if (StringUtils.isNotBlank(partialName)) {
-            if (!associate.getName().toLowerCase().startsWith(partialName.toLowerCase())) {
-                result = false;
-            }
+            result.addCriteria(Criteria.where(AssociateDbService.NAME).regex("/^" + partialName + "/i"));
         }
-        if (!filterShowActive && associate.isActive()) {
-            result = false;
+        if (filterShowActive && !filterShowInActive) {
+            result.addCriteria(Criteria.where(AssociateDbService.ACTIVE).is(true));
         }
-
-        if (!filterShowInActive && !associate.isActive()) {
-            result = false;
+        if (filterShowInActive && !filterShowActive) {
+            result.addCriteria(Criteria.where(AssociateDbService.ACTIVE).is(false));
         }
-
         return result;
     }
 
     @Override
-    protected List<Associate> getResultSet(long offset, int limit, FieldComparator sortComparator) {
-        List<Associate> result = null;
-        if (canExecuteSearch()) {
-            result = associateService.getAll().stream()
-                    .filter(s -> filter(s))
-                    .sorted(Comparator.comparing(Associate::getName, String.CASE_INSENSITIVE_ORDER))
-                    .collect(Collectors.toList());
+    protected List<Associate> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
+        Query query = filter();
+        if (sortComparator != null) {
+            String orderBy = sortComparator.getRawOrderBy();
+            Sort.Direction direction = sortComparator.isAscending() ? Sort.Direction.ASC : Sort.Direction.DESC;
+            query.with(Sort.by(direction, orderBy));
         }
+
+        Pageable pageable = PageRequest.of(page, pageSize);
+        query.with(pageable);
+
+        List<Associate> result = associateDbService.list(query);
         return result;
     }
 
     @Override
     public int getResultSetCount() {
-        int result = 0;
-        if (canExecuteSearch()) {
-            result = (int) associateService.getAll().stream()
-                    .filter(s -> filter(s))
-                    .count();
-        }
-        return result;
+        Query query = filter();
+        return (int) associateDbService.count(query);
     }
 
     public void search(String partialName) {
@@ -88,24 +78,45 @@ public class AssociatesDataModel extends CachedDataModel<Associate> {
         this.filterShowInActive = true;
         this.partialName = partialName;
         super.reset();
-        BindUtils.postNotifyChange(null, null, this, "*");
     }
 
+    public void limitedSarch(String partialName) {
+        log.info("Litited searching associate using filters: name LIKE {}", partialName);
+        listAll = false;
+        this.filterShowActive = true;
+        this.filterShowInActive = false;
+        this.partialName = partialName;
+        super.reset();
+    }
 
     public void search(boolean filterShowActive, boolean filterShowInActive) {
         log.info("Searching associate using filters: filterShowActive {}, filterShowInActive {}",
                 filterShowActive, filterShowInActive);
+        listAll = false;
         this.filterShowActive = filterShowActive;
         this.filterShowInActive = filterShowInActive;
-        listAll = false;
         super.reset();
-        BindUtils.postNotifyChange(null, null, this, "*");
     }
 
     public void listAll() {
         log.info("List all associates");
         listAll = true;
         super.reset();
-        BindUtils.postNotifyChange(null, null, this, "*");
+    }
+
+    public Associate createNew() {
+        return associateService.createNew();
+    }
+
+    public void addNew(Associate entity) {
+        associateDbService.insert(entity);
+    }
+
+    public Associate copy(Associate selectedEntity) {
+        return associateService.copy(selectedEntity);
+    }
+
+    public Associate save(Associate selectedEntity) {
+        return associateDbService.save(selectedEntity);
     }
 }
index 2c15a11957bffbd22f872b4338a8107a33aec0be..5fdaa3169ca959373908b571410fbbc6bb5944de 100644 (file)
@@ -2,8 +2,10 @@ package hu.user.lis.ui.data;
 
 import lombok.extern.log4j.Log4j2;
 import org.springframework.stereotype.Component;
+import org.zkoss.bind.BindUtils;
 import org.zkoss.zul.FieldComparator;
 import org.zkoss.zul.ListModelList;
+import org.zkoss.zul.event.ListDataEvent;
 
 import java.util.Comparator;
 import java.util.HashMap;
@@ -12,7 +14,10 @@ import java.util.List;
 @Component
 @Log4j2
 public abstract class CachedDataModel<T> extends ListModelList<T> {
-    private int cacheSize = 10;
+    public static final String NATURAL = "natural";
+    public static final String ASCENDING = "ascending";
+    public static final String DESCENDING = "descending";
+    private int cacheSize = 100;
     private int cacheStart;
     private int cacheEnd;
     private int resultSetSize = -1;
@@ -31,6 +36,8 @@ public abstract class CachedDataModel<T> extends ListModelList<T> {
         this.cacheEnd = 0;
 
         clearCache();
+        fireEvent(ListDataEvent.STRUCTURE_CHANGED, -1, -1);
+        BindUtils.postNotifyChange(null, null, this, "*");
     }
 
     public void clearCache() {
@@ -93,12 +100,14 @@ public abstract class CachedDataModel<T> extends ListModelList<T> {
             }
 
             log.info("Query result from {} to {}", startPos, endPos);
-            List<T> resList = getResultSet(startPos, endPos - startPos, sortComparator);
+
+            int limit = endPos - startPos;
+            int page = (int) Math.ceil(this.resultSetSize / limit);
+            List<T> resList = getResultSet(page, limit, sortComparator);
 
             if (resList != null) {
                 log.info("Got {} records", resList.size());
                 for (int c = 0; c < resList.size(); c++) {
-                    cache.put(startPos + c, resList.get(c));
                     cache.put(startPos + c, resList.get(c));
                     // logger.debug("CachedListMode.cached idx: " +
                     // (startPos + c));
@@ -108,17 +117,24 @@ public abstract class CachedDataModel<T> extends ListModelList<T> {
 
             cacheStart = startPos + 1;
             cacheEnd = cacheStart + (cache.size() == 0 ? 0 : (cache.size() - 1));
-//                     BindUtils.postNotifyChange(null, null, this, "*");
-
         } catch (Exception e) {
             log.error("", e);
         }
     }
 
-    abstract protected List<T> getResultSet(long offset, int limit, FieldComparator sortComparator);
+    abstract protected List<T> getResultSet(int page, int pageSize, FieldComparator sortComparator);
 
     abstract public int getResultSetCount();
 
+    @Override
+    public String getSortDirection(Comparator comparator) {
+        FieldComparator fieldCmpr = (FieldComparator) comparator;
+        if (sortComparator == null) {
+            return NATURAL;
+        }
+        String sortDirection = sortComparator.isAscending() ? ASCENDING : DESCENDING;
+        return fieldCmpr.getRawOrderBy().equals(sortComparator.getRawOrderBy()) ? sortDirection : NATURAL;
+    }
 
     @Override
     public void sort(Comparator<T> cmpr, boolean ascending) {
index ce8613cdf5311a8d6a8eecfef045e79e746d280a..8a7351a0c58f8b1512a689438069efe84eb03a20 100644 (file)
@@ -10,6 +10,7 @@ import org.zkoss.lang.Strings;
 @Builder
 @Log4j2
 public class FormDocument extends JSONObject {
+    
     private Object data;
 
     public FormDocument setData(Object data) {
index 934772ea8b12ba0e0f9e28ca705f023ce724cd2f..98b119c29dd56e6db9134b52b0b112db92161249 100644 (file)
@@ -8,7 +8,8 @@ import lombok.Setter;
 @Getter
 @Setter
 @Builder
-public class IncomeMargin {
+public class
+IncomeMargin {
     Currency currency;
     Double amount;
 }
index a4bddaa1fff0f4e823c86ba988446aef87c5a9ef..1d2deb573a27fa732e981d741dd3637027501634 100644 (file)
@@ -17,7 +17,6 @@ import java.util.stream.Collectors;
 @Log4j2
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 public class IncomeMarginsDataModel extends ArrayList<IncomeMargin> {
-
     public void recalculate(Project project) {
         clear();
         Map<Currency, Double> balances = new HashMap<>();
index 8c2131aeddf028fe7ea480316d585bb75e74e34b..4542b193282be33d03d7441079882c22e9a20570 100644 (file)
@@ -20,9 +20,9 @@ import java.util.stream.Collectors;
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 public class PartnerSelectorDataModel extends CachedDataModel<Partner> {
     static private final int SEARCH_LIMIT = 10;
-    private String partialName;
     @Autowired
     PartnerService partnerService;
+    private String partialName;
 
     private boolean filter(Partner partner) {
         if (StringUtils.isBlank(partialName)) {
@@ -36,7 +36,7 @@ public class PartnerSelectorDataModel extends CachedDataModel<Partner> {
     }
 
     @Override
-    protected List<Partner> getResultSet(long offset, int limit, FieldComparator sortComparator) {
+    protected List<Partner> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
         List<Partner> result = partnerService.getAll().stream()
                 .sorted(Comparator.comparing(Partner::getName))
                 .filter(s -> filter(s))
index 6dc7031259c06ca792f1219f99d27f2f8cf57a8c..0eaa649524db14ec0e1cfc7c473734017f3973f4 100644 (file)
@@ -2,99 +2,82 @@ package hu.user.lis.ui.data;
 
 import hu.user.lis.db.Partner;
 import hu.user.lis.services.data.PartnerService;
-import lombok.Getter;
+import hu.user.lis.services.nosql.AssociateDbService;
+import hu.user.lis.services.nosql.PartnerDbService;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
 import org.springframework.context.annotation.Scope;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Component;
-import org.zkoss.bind.BindUtils;
 import org.zkoss.zul.FieldComparator;
 
-import java.util.Comparator;
 import java.util.List;
-import java.util.stream.Collectors;
 
 @Component
 @Log4j2
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 public class PartnersDataModel extends CachedDataModel<Partner> {
+    @Autowired
+    PartnerDbService partnerDbService;
+    @Autowired
+    PartnerService partnerService;
     private String partialName;
     private String partialAddress;
     private String partialVatNr;
     private boolean listAll;
-
-    @Getter
-    @Autowired
-    PartnerService partnerService;
     private boolean filterShowInActive;
     private boolean filterShowActive;
 
 
-    private boolean canExecuteSearch() {
-        boolean result = listAll || filterShowActive || filterShowInActive ||
-                StringUtils.isNotBlank(partialName) ||
-                StringUtils.isNotBlank(partialVatNr) ||
-                StringUtils.isNotBlank(partialAddress);
-        log.info("Can execute search: {}", result);
-        return result;
-    }
-
-    private boolean filter(Partner partner) {
+    private Query filter() {
+        Query result = new Query();
         if (listAll) {
-            return true;
+            result.addCriteria(Criteria.where(PartnerDbService.ID).gt(0));
+            return result;
         }
-
-        boolean result = true;
         if (StringUtils.isNotBlank(partialName)) {
-            if (!partner.getName().toLowerCase().startsWith(partialName.toLowerCase())) {
-                result = false;
-            }
+            result.addCriteria(Criteria.where(PartnerDbService.NAME).regex("/^" + partialName + "/i"));
         }
         if (StringUtils.isNotBlank(partialVatNr)) {
-            if (!partner.getVatNr().toLowerCase().startsWith(partialVatNr.toLowerCase())) {
-                result = false;
-            }
+            result.addCriteria(Criteria.where(PartnerDbService.VAT_NR).regex("/^" + partialVatNr + "/i"));
         }
         if (StringUtils.isNotBlank(partialAddress)) {
-            if (!partner.getAddress().toLowerCase().startsWith(partialAddress.toLowerCase())) {
-                result = false;
-            }
+            result.addCriteria(Criteria.where(PartnerDbService.ADDRESS).regex("/^" + partialAddress + "/i"));
         }
-
-        if (!filterShowActive && partner.isActive()) {
-            result = false;
+        if (filterShowActive && !filterShowInActive) {
+            result.addCriteria(Criteria.where(AssociateDbService.ACTIVE).is(true));
         }
-
-        if (!filterShowInActive && !partner.isActive()) {
-            result = false;
+        if (filterShowInActive && !filterShowActive) {
+            result.addCriteria(Criteria.where(AssociateDbService.ACTIVE).is(false));
         }
-
         return result;
     }
 
     @Override
-    protected List<Partner> getResultSet(long offset, int limit, FieldComparator sortComparator) {
-        List<Partner> result = null;
-        if (canExecuteSearch()) {
-            result = partnerService.getAll().stream()
-                    .filter(s -> filter(s))
-                    .sorted(Comparator.comparing(Partner::getName, String.CASE_INSENSITIVE_ORDER))
-                    .collect(Collectors.toList());
+    protected List<Partner> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
+        Query query = filter();
+        if (sortComparator != null) {
+            String orderBy = sortComparator.getRawOrderBy();
+            Sort.Direction direction = sortComparator.isAscending() ? Sort.Direction.ASC : Sort.Direction.DESC;
+            query.with(Sort.by(direction, orderBy));
         }
+
+        Pageable pageable = PageRequest.of(page, pageSize);
+        query.with(pageable);
+        List<Partner> result = partnerDbService.list(query);
         return result;
     }
 
     @Override
     public int getResultSetCount() {
-        int result = 0;
-        if (canExecuteSearch()) {
-            result = (int) partnerService.getAll().stream()
-                    .filter(s -> filter(s))
-                    .count();
-        }
-        return result;
+        Query query = filter();
+        return (int) partnerDbService.count(query);
     }
 
     public void search(String partialName, String partialVatNr, String partialAddress) {
@@ -105,7 +88,6 @@ public class PartnersDataModel extends CachedDataModel<Partner> {
         this.partialVatNr = partialVatNr;
         this.partialAddress = partialAddress;
         super.reset();
-        BindUtils.postNotifyChange(null, null, this, "*");
     }
 
 
@@ -116,13 +98,27 @@ public class PartnersDataModel extends CachedDataModel<Partner> {
         this.filterShowInActive = filterShowInActive;
         listAll = false;
         super.reset();
-        BindUtils.postNotifyChange(null, null, this, "*");
     }
 
     public void listAll() {
         log.info("List all partners");
         listAll = true;
         super.reset();
-        BindUtils.postNotifyChange(null, null, this, "*");
+    }
+
+    public Partner createNew() {
+        return partnerService.createNew();
+    }
+
+    public void addNew(Partner entity) {
+        partnerDbService.insert(entity);
+    }
+
+    public Partner copy(Partner selectedEntity) {
+        return partnerService.copy(selectedEntity);
+    }
+
+    public Partner save(Partner selectedEntity) {
+        return partnerDbService.save(selectedEntity);
     }
 }
index 854ec0d2e4dd98565f7a8cf925b384d8c3fdbd75..b52a6a6b2f9f71abf7ce6d1708e33cdad05325e0 100644 (file)
@@ -12,7 +12,6 @@ import org.springframework.stereotype.Component;
 import org.zkoss.bind.BindUtils;
 import org.zkoss.zul.FieldComparator;
 
-import java.util.Comparator;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -35,7 +34,7 @@ public class ProjectAssociatesDataModel extends CachedDataModel<ProjectAssociate
     private boolean filter(ProjectAssociate projectAssociate) {
         boolean result = true;
         if (StringUtils.isNotBlank(projectId)) {
-            if (!projectAssociate.getProjectId().equals(projectId)) {
+            if (!projectAssociate.getProject().getId().equals(projectId)) {
                 result = false;
             }
         }
@@ -43,12 +42,11 @@ public class ProjectAssociatesDataModel extends CachedDataModel<ProjectAssociate
     }
 
     @Override
-    protected List<ProjectAssociate> getResultSet(long offset, int limit, FieldComparator sortComparator) {
+    protected List<ProjectAssociate> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
         List<ProjectAssociate> result = null;
         if (canExecuteSearch()) {
             result = projectAssociateService.getAll().stream()
                     .filter(s -> filter(s))
-                    .sorted(Comparator.comparing(ProjectAssociate::getAssociateId))
                     .collect(Collectors.toList());
         }
         return result;
index 39a7117ea7bb3239f06032026b4e03c35066e52f..69b5d85d66ff7e2e7846ab69909ed02208f95a22 100644 (file)
@@ -43,7 +43,7 @@ public class ProjectSelectorDataModel extends CachedDataModel<Project> {
     }
 
     @Override
-    protected List<Project> getResultSet(long offset, int limit, FieldComparator sortComparator) {
+    protected List<Project> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
         List<Project> result = projectService.getAll().stream()
                 .sorted(Comparator.comparing(Project::getName))
                 .filter(s -> filter(s))
index 745337ed7f9a8d5f8af67779163cc23464eef35f..f0cc368113ec057a97224690669aaca90906ae24 100644 (file)
@@ -2,7 +2,7 @@ package hu.user.lis.ui.data;
 
 import hu.user.lis.db.ProjectStatus;
 import hu.user.lis.services.data.ProjectStatusService;
-import lombok.Getter;
+import hu.user.lis.services.nosql.ProjectStatusDbService;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@@ -12,18 +12,27 @@ import org.zkoss.bind.BindUtils;
 import org.zkoss.zul.FieldComparator;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Component
 @Log4j2
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 public class ProjectStatusDataModel extends CachedDataModel<ProjectStatus> {
-    @Getter
     @Autowired
     ProjectStatusService projectStatusService;
+    @Autowired
+    ProjectStatusDbService projectStatusDbService;
+    private boolean activeOnly;
 
     @Override
-    protected List<ProjectStatus> getResultSet(long offset, int limit, FieldComparator sortComparator) {
-        return projectStatusService.getAll();
+    protected List<ProjectStatus> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
+        List<ProjectStatus> result;
+        if (activeOnly) {
+            result = projectStatusService.getAll().stream().filter(e -> e.isActive()).collect(Collectors.toList());
+        } else {
+            result = projectStatusService.getAll();
+        }
+        return result;
     }
 
     @Override
@@ -33,6 +42,13 @@ public class ProjectStatusDataModel extends CachedDataModel<ProjectStatus> {
 
     public void listAll() {
         super.reset();
+        this.activeOnly = false;
+        BindUtils.postNotifyChange(null, null, this, "*");
+    }
+
+    public void listActive() {
+        super.reset();
+        this.activeOnly = true;
         BindUtils.postNotifyChange(null, null, this, "*");
     }
 
index b64d739e6e3b2d13d5c9d62472c44a6224584766..f16eb13dee40971f920deccc484833a4b2de68d6 100644 (file)
@@ -63,7 +63,7 @@ public class ProjectsDataModel extends CachedDataModel<Project> {
     }
 
     @Override
-    protected List<Project> getResultSet(long offset, int limit, FieldComparator sortComparator) {
+    protected List<Project> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
         List<Project> result = null;
         if (canExecuteSearch()) {
             result = projectService.getAll().stream()
index f5d437774326afc67efc631e593ebffee0a9e430..e8cef38d01bd4bda6ec72afe05801d440e187f2d 100644 (file)
@@ -4,38 +4,52 @@ import hu.user.lis.db.Associate;
 import hu.user.lis.db.Project;
 import hu.user.lis.db.ServiceRecord;
 import hu.user.lis.services.data.ServiceRecordService;
-import lombok.Getter;
+import hu.user.lis.services.nosql.ServiceRecordDbService;
 import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
 import org.springframework.context.annotation.Scope;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
 import org.springframework.stereotype.Component;
-import org.zkoss.bind.BindUtils;
 import org.zkoss.bind.annotation.Init;
 import org.zkoss.zk.ui.util.Clients;
 import org.zkoss.zul.FieldComparator;
 
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 
 @Component
 @Log4j2
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 public class ServiceRecordsDataModel extends CachedDataModel<ServiceRecord> {
-    @Getter
     @Autowired
     ServiceRecordService serviceRecordService;
+    @Autowired
+    ServiceRecordDbService serviceRecordDbService;
     private boolean listAll;
-    private Project filterProject;
-    private Associate filterAssociate;
+    private Long filterProjectId;
+    private Long filterAssociateId;
     private boolean groupByAssociate;
 
-    public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) {
-        Map<Object, Boolean> map = new ConcurrentHashMap<>();
-        return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
+    private Query filter() {
+        Query result = new Query();
+        if (listAll) {
+            result.addCriteria(Criteria.where(ServiceRecordDbService.ID).gt(0));
+            return result;
+        }
+        if (Objects.nonNull(filterProjectId)) {
+            result.addCriteria(Criteria.where(ServiceRecordDbService.PROJECT_ID).is(filterProjectId));
+        }
+        if (Objects.nonNull(filterAssociateId)) {
+            result.addCriteria(Criteria.where(ServiceRecordDbService.ASSOCIATE_ID).is(filterAssociateId));
+        }
+        return result;
     }
 
     @Init
@@ -44,50 +58,26 @@ public class ServiceRecordsDataModel extends CachedDataModel<ServiceRecord> {
         log.info("Initialized");
     }
 
-    private boolean canExecuteSearch() {
-        boolean result = listAll || Objects.nonNull(filterProject) || Objects.nonNull(filterAssociate);
-        log.info("Can execute search: {}", result);
-        return result;
-    }
-
-    private boolean filter(ServiceRecord entity) {
-        if (listAll) {
-            return true;
-        }
-        boolean result = true;
-        if (Objects.nonNull(filterProject)) {
-            if (!entity.getProject().getId().equals(filterProject.getId())) {
-                result = false;
-            }
-        }
-        if (Objects.nonNull(filterAssociate)) {
-            if (!entity.getAssociate().getId().equals(filterAssociate.getId())) {
-                result = false;
-            }
-        }
-        return result;
-    }
-
     @Override
-    protected List<ServiceRecord> getResultSet(long offset, int limit, FieldComparator sortComparator) {
-        List<ServiceRecord> result = null;
-        if (canExecuteSearch()) {
-            if (groupByAssociate) {
-                result = getGroupedServiceRecords().values().stream().collect(Collectors.toList());
-            } else {
-                result = serviceRecordService.getAll().stream()
-                        .filter(s -> filter(s))
-                        .sorted(Comparator.comparing(ServiceRecord::getWorkDay))
-                        .collect(Collectors.toList());
-            }
+    protected List<ServiceRecord> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
+        Query query = filter();
+        if (sortComparator != null) {
+            String orderBy = sortComparator.getRawOrderBy();
+            Sort.Direction direction = sortComparator.isAscending() ? Sort.Direction.ASC : Sort.Direction.DESC;
+            query.with(Sort.by(direction, orderBy));
         }
+        Pageable pageable = PageRequest.of(page, pageSize);
+        query.with(pageable);
+        List<ServiceRecord> result = serviceRecordDbService.list(query);
         return result;
     }
 
-    Map<String, ServiceRecord> getGroupedServiceRecords() {
-        Map<String, ServiceRecord> grouped = new HashMap<>();
+    Map<Long, ServiceRecord> getGroupedServiceRecords() {
+        Map<Long, ServiceRecord> grouped = new HashMap<>();
+        Query query = filter();
+        List<ServiceRecord> allEntities = serviceRecordDbService.list(query);
 
-        serviceRecordService.getAll().stream().filter(s -> filter(s)).forEach(s -> {
+        allEntities.stream().forEach(s -> {
             if (grouped.containsKey(s.getAssociate().getId())) {
                 ServiceRecord serviceRecord = grouped.get(s.getAssociate().getId());
                 serviceRecord.setCost(serviceRecord.getCost() + s.getCost());
@@ -103,43 +93,45 @@ public class ServiceRecordsDataModel extends CachedDataModel<ServiceRecord> {
 
     @Override
     public int getResultSetCount() {
-        int result = 0;
-        if (canExecuteSearch()) {
-
-            if (groupByAssociate) {
-                Map<String, ServiceRecord> grouped = getGroupedServiceRecords();
-                result = grouped.size();
-            } else {
-                result = (int) serviceRecordService.getAll().stream()
-                        .filter(s -> filter(s))
-                        .count();
-            }
-        }
-        return result;
+        Query query = filter();
+        return (int) serviceRecordDbService.count(query);
     }
 
     public void listAll() {
         log.info("List all service records");
         listAll = true;
         super.reset();
-        BindUtils.postNotifyChange(null, null, this, "*");
     }
 
     public void search(Project project, boolean groupByAssociate) {
-        log.info("Searching project using filter {} grouping {}", project, groupByAssociate);
-        this.groupByAssociate = groupByAssociate;
-        this.filterProject = project;
+        log.info("Searching project using filter {} grouping {}", project.getId(), groupByAssociate);
         listAll = false;
+        this.groupByAssociate = groupByAssociate;
+        this.filterProjectId = project.getId();
         super.reset();
-        BindUtils.postNotifyChange(null, null, this, "*");
     }
 
     public void search(Project project, Associate associate) {
-        log.info("Searching project using filter {} {}", project, associate);
-        this.filterAssociate = associate;
-        this.filterProject = project;
+        this.filterProjectId = project == null ? null : project.getId();
+        this.filterAssociateId = associate == null ? null : associate.getId();
         listAll = false;
+        log.info("Searching project using filter {} {}", this.filterProjectId, this.filterAssociateId);
         super.reset();
-        BindUtils.postNotifyChange(null, null, this, "*");
+    }
+
+    public ServiceRecord createNew() {
+        return serviceRecordService.createNew();
+    }
+
+    public void addNew(ServiceRecord entity) {
+        serviceRecordDbService.insert(entity);
+    }
+
+    public ServiceRecord copy(ServiceRecord selectedEntity) {
+        return serviceRecordService.copy(selectedEntity);
+    }
+
+    public ServiceRecord save(ServiceRecord selectedEntity) {
+        return serviceRecordDbService.save(selectedEntity);
     }
 }
index 44888c572438ec81230055b1426b323c36c10bed..cd3f7eedf0f8058dc2ae8661cedf41f8d62a44ea 100644 (file)
@@ -19,12 +19,11 @@ import java.util.stream.Collectors;
 @Log4j2
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 public class SuppliersDataModel extends CachedDataModel<Supplier> {
+    @Autowired
+    SupplierService supplierService;
     private String partialName;
     private String partialZipCode;
     private boolean listAll;
-    @Autowired
-    SupplierService supplierService;
-
 
     private boolean canExecuteSearch() {
         boolean result = StringUtils.isNotBlank(partialName) || StringUtils.isNotBlank(partialZipCode) || listAll;
@@ -52,7 +51,7 @@ public class SuppliersDataModel extends CachedDataModel<Supplier> {
     }
 
     @Override
-    protected List<Supplier> getResultSet(long offset, int limit, FieldComparator sortComparator) {
+    protected List<Supplier> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
         List<Supplier> result = null;
         if (canExecuteSearch()) {
             result = supplierService.getAll().stream()
index 983f80fe5277306efb913908c6d3eaacc6b7a32a..7b9b897bebebefb20b19bc8a5b188dd06a73ff73 100644 (file)
@@ -20,9 +20,9 @@ import java.util.stream.Collectors;
 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
 public class SuppliersSimpleDataModel extends CachedDataModel<Supplier> {
     static private final int SEARCH_LIMIT = 10;
-    private String partialName;
     @Autowired
     SupplierService supplierService;
+    private String partialName;
 
     private boolean filter(Supplier supplier) {
         if (StringUtils.isBlank(partialName)) {
@@ -36,7 +36,7 @@ public class SuppliersSimpleDataModel extends CachedDataModel<Supplier> {
     }
 
     @Override
-    protected List<Supplier> getResultSet(long offset, int limit, FieldComparator sortComparator) {
+    protected List<Supplier> getResultSet(int page, int pageSize, FieldComparator sortComparator) {
         List<Supplier> result = supplierService.getAll().stream()
                 .sorted(Comparator.comparing(Supplier::getName))
                 .filter(s -> filter(s))
index 9fb45938a29abd08d7d59d6b66540d327372593c..02820d561d99acead9508f3293cf1c677f012d7e 100644 (file)
@@ -52,8 +52,8 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
     SessionSettings sessionSettings;
     private Project formDocument;
     private Project origDocument;
-    private Map<String, Boolean> origAssociates;
-    private Map<String, Boolean> formAssociates;
+    private Map<Associate, Boolean> origAssociates;
+    private Map<Associate, Boolean> formAssociates;
     @WireVariable
     private PartnerSelectorDataModel partnerSelectorDataModel;
     @WireVariable
@@ -66,6 +66,9 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
     private ServiceRecordsDataModel serviceRecordsDataModel;
     @WireVariable
     private ProjectStatusDataModel projectStatusDataModel;
+    @Getter
+    @WireVariable
+    private ProjectStatusService projectStatusServiceImpl;
     @WireVariable
     private ProjectStatusConverter projectStatusConverter;
     @WireVariable
@@ -80,8 +83,8 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
 
     @Init
     public void init() {
-        eventBus.register(this);
         projectStatusDataModel.listAll();
+        eventBus.register(this);
         log.info("Initialized");
     }
 
@@ -102,7 +105,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
                 origDocument = projectServiceImpl.getById(id);
                 formDocument = projectServiceImpl.copy(origDocument);
             }
-            
+
             if (Objects.isNull(data)) {
                 formDocument = projectServiceImpl.createNew();
                 log.info("Loading new entity {} to editor", formDocument.getId());
@@ -144,7 +147,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
             } else {
                 args = ImmutableMap.of("origDocument", origDocument, "formDocument", formDocument);
             }
-            projectAssociateServiceImpl.update(formDocument.getId(), formAssociates);
+            projectAssociateServiceImpl.update(formDocument, formAssociates);
         }
 
         eventBus.showProjectsList(args);
@@ -419,14 +422,14 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen
             Associate associate = associatesDataModel.getElementAt(i);
             boolean exists = projectAssociateServiceImpl.getAll().stream()
                     .anyMatch(
-                            pa -> pa.getProjectId().equals(formDocument.getId()) &&
-                                    pa.getAssociateId().equals(associate.getId())
+                            pa -> pa.getProject().getId().equals(formDocument.getId()) &&
+                                    pa.getAssociate().getId().equals(associate.getId())
                     );
             if (exists) {
                 log.info("{} is on project {}", associate.getName(), formDocument.getName());
             }
-            formAssociates.put(associate.getId(), exists);
-            origAssociates.put(associate.getId(), exists);
+            formAssociates.put(associate, exists);
+            origAssociates.put(associate, exists);
         }
     }
 
index 0c4a58fd36372f1c4fc6fbec4b6022e1d1b80b30..7ea7ee7ca05c204d4e1c852ae28b5b92eebc9978 100644 (file)
@@ -51,11 +51,6 @@ public class AssociatesViewModel {
         }
     }
 
-    @Command
-    @NotifyChange("selectedEntity")
-    public void search() {
-    }
-
     @Command
     @NotifyChange("selectedEntity")
     public void onListSelection() {
@@ -74,13 +69,13 @@ public class AssociatesViewModel {
     @Command
     public void onAdd() {
         String page = "~./associate-editor.zul";
-        Associate newEntity = associatesDataModel.getAssociateService().createNew();
+        Associate newEntity = associatesDataModel.createNew();
         Window editorWindow = (Window) Executions.createComponents(page, null,
                 Collections.singletonMap("formDocument", newEntity));
         editorWindow.addEventListener("onClose", e -> {
             if (e.getData() != null) {
                 log.info("Associate popup result {}", e.getData());
-                associatesDataModel.getAssociateService().add(newEntity);
+                associatesDataModel.addNew(newEntity);
                 associatesDataModel.clearSelection();
                 refresh();
                 associatesDataModel.addToSelection(newEntity);
@@ -97,7 +92,7 @@ public class AssociatesViewModel {
             return;
         }
         String page = "~./associate-editor.zul";
-        Associate editEntity = associatesDataModel.getAssociateService().copy(selectedEntity);
+        Associate editEntity = associatesDataModel.copy(selectedEntity);
         Map<String, Object> arg = new HashMap<>();
         arg.put("origDocument", selectedEntity);
         arg.put("formDocument", editEntity);
@@ -107,7 +102,7 @@ public class AssociatesViewModel {
                 log.info("Partner popup result {}", e.getData());
                 Associate modifiedEntity = (Associate) e.getData();
                 associatesDataModel.clearSelection();
-                associatesDataModel.getAssociateService().replace(selectedEntity, modifiedEntity);
+                associatesDataModel.save(modifiedEntity);
                 refresh();
                 associatesDataModel.addToSelection(modifiedEntity);
                 selectedEntity = modifiedEntity;
index a6ecd8853a81b2a3aeb19e5f267170e3477e277a..b81f636d5ed922013f1f8f2e5c11682cd8712b4b 100644 (file)
@@ -78,13 +78,13 @@ public class PartnersViewModel extends AsyncBaseModel {
     @Command
     public void onAdd() {
         String page = "~./partner-editor.zul";
-        Partner newEntity = partnersDataModel.getPartnerService().createNew();
+        Partner newEntity = partnersDataModel.createNew();
         Window editorWindow = (Window) Executions.createComponents(page, null,
                 Collections.singletonMap("formDocument", newEntity));
         editorWindow.addEventListener("onClose", e -> {
             if (e.getData() != null) {
                 log.info("Partner popup result {}", e.getData());
-                partnersDataModel.getPartnerService().add(newEntity);
+                partnersDataModel.add(newEntity);
                 partnersDataModel.clearSelection();
                 refresh();
                 partnersDataModel.addToSelection(newEntity);
@@ -110,7 +110,7 @@ public class PartnersViewModel extends AsyncBaseModel {
             return;
         }
         String page = "~./partner-editor.zul";
-        Partner editEntity = partnersDataModel.getPartnerService().copy(selectedPartner);
+        Partner editEntity = partnersDataModel.copy(selectedPartner);
         Map<String, Object> arg = new HashMap<>();
         arg.put("origDocument", selectedPartner);
         arg.put("formDocument", editEntity);
@@ -120,7 +120,7 @@ public class PartnersViewModel extends AsyncBaseModel {
                 log.info("Partner popup result {}", e.getData());
                 Partner modifiedEntity = (Partner) e.getData();
                 partnersDataModel.clearSelection();
-                partnersDataModel.getPartnerService().replace(selectedPartner, modifiedEntity);
+                partnersDataModel.save(modifiedEntity);
                 refresh();
                 partnersDataModel.addToSelection(modifiedEntity);
                 selectedPartner = modifiedEntity;
index 88cac06b58a9b3e44b34f944e2abd4404d73941b..97eff6070fbf0ee6dcb8a128741c2df066800b1a 100644 (file)
@@ -1,8 +1,6 @@
 package hu.user.lis.ui.view;
 
 import hu.user.lis.db.Project;
-import hu.user.lis.db.ProjectStatus;
-import hu.user.lis.services.data.ProjectStatusService;
 import hu.user.lis.ui.Constants;
 import hu.user.lis.ui.data.ProjectsDataModel;
 import hu.user.lis.ui.event.EventBus;
@@ -31,8 +29,6 @@ public class ProjectsViewModel extends AsyncBaseModel implements EventListener {
     ProjectsDataModel projectsDataModel;
     @WireVariable
     EventBus eventBus;
-    @WireVariable
-    private ProjectStatusService projectStatusServiceImpl;
     @Getter
     private Project selectedProject;
     private boolean filterShowInActive;
@@ -53,10 +49,6 @@ public class ProjectsViewModel extends AsyncBaseModel implements EventListener {
         log.info("Initialized");
     }
 
-    public ProjectStatus getProjectStatus(String id) {
-        return projectStatusServiceImpl.getById(id);
-    }
-
     private void refresh() {
         projectsDataModel.clearSelection();
         selectedProject = null;
index 4befd0f2cde8b3e42d748dd18de43574ded8149b..f77889c76fdbc599fc5cd8359ab4df363b4ac8db 100644 (file)
@@ -113,13 +113,13 @@ public class ServiceRecordsViewModel implements EventListener {
     @Command
     public void onAdd() {
         String page = "~./service-record-editor.zul";
-        ServiceRecord newEntity = serviceRecordsDataModel.getServiceRecordService().createNew();
+        ServiceRecord newEntity = serviceRecordsDataModel.createNew();
         Window editorWindow = (Window) Executions.createComponents(page, null,
                 Collections.singletonMap("formDocument", newEntity));
         editorWindow.addEventListener("onClose", e -> {
             if (e.getData() != null) {
                 log.info("Partner popup result {}", e.getData());
-                serviceRecordsDataModel.getServiceRecordService().add(newEntity);
+                serviceRecordsDataModel.add(newEntity);
                 serviceRecordsDataModel.clearSelection();
                 refresh();
                 serviceRecordsDataModel.addToSelection(newEntity);
@@ -136,7 +136,7 @@ public class ServiceRecordsViewModel implements EventListener {
             return;
         }
         String page = "~./service-record-editor.zul";
-        ServiceRecord editEntity = serviceRecordsDataModel.getServiceRecordService().copy(selectedEntity);
+        ServiceRecord editEntity = serviceRecordsDataModel.copy(selectedEntity);
         Map<String, Object> arg = ImmutableMap.of("origDocument", selectedEntity, "formDocument", editEntity);
         Window editorWindow = (Window) Executions.createComponents(page, null, arg);
         editorWindow.addEventListener("onClose", e -> {
@@ -144,7 +144,7 @@ public class ServiceRecordsViewModel implements EventListener {
                 log.info("Partner popup result {}", e.getData());
                 ServiceRecord modifiedEntity = (ServiceRecord) e.getData();
                 serviceRecordsDataModel.clearSelection();
-                serviceRecordsDataModel.getServiceRecordService().replace(selectedEntity, modifiedEntity);
+                serviceRecordsDataModel.save(modifiedEntity);
                 refresh();
                 serviceRecordsDataModel.addToSelection(modifiedEntity);
                 selectedEntity = modifiedEntity;
index d446f2c57ec5b0293593c641c61a8abbda28a82e..66e46a86326312fdfc81642ff00acf9ae241b612 100644 (file)
             </north>
             <center border="none" flex="true">
                 <listbox vflex="true" model="@load(vm.associatesDataModel)"
-                         autopaging="true" pagingPosition="top" multiple="false"
+                         autopaging="true" mold="paging" pagingPosition="top" multiple="false"
                          onSelect="@command('onListSelection')" onDoubleClick="@command('onEdit')"
                          onAfterRender="@command('onAfterRenderList')">
                     <listhead sizable="true">
-                        <listheader label="Név" align="left"/>
-                        <listheader label="Login" align="left"/>
-                        <listheader label="Aktív" align="left"/>
+                        <listheader label="Név" sort="auto(name)" align="left"/>
+                        <listheader label="Login" sort="auto(login)" align="left"/>
+                        <listheader label="Aktív" sort="auto(active)" align="left"/>
                     </listhead>
                     <template name="model">
                         <listitem>
index 94ecda65c37d5f269a98e482afcd88727a529dc6..a2cda008b9a2c996d124ec7278cb66c14c67a37d 100644 (file)
             </north>
             <center border="none" flex="true">
                 <listbox id="partnersList" vflex="true" model="@load(vm.partnersDataModel)"
-                         autopaging="true" pagingPosition="top" multiple="false"
+                         autopaging="true" mold="paging" pagingPosition="top" multiple="false"
                          onSelect="@command('onListSelection')" onDoubleClick="@command('onEdit')"
                          onAfterRender="@command('onAfterRenderPartners')">
                     <listhead sizable="true">
-                        <listheader label="Név" align="left"/>
-                        <listheader label="Adószám" align="left"/>
-                        <listheader label="Cím" align="left"/>
-                        <listheader label="Aktív" align="left"/>
+                        <listheader label="Név" sort="auto(name)" align="left"/>
+                        <listheader label="Adószám" sort="auto(vatNr)" align="left"/>
+                        <listheader label="Cím" sort="auto(address)" align="left"/>
+                        <listheader label="Aktív" sort="auto(active)" align="left"/>
                     </listhead>
                     <template name="model">
                         <listitem>
index affb6660f14deb6314241211bae34fc2d3f3b70e..20ce3d9135d64c9670945eef3181ce89e11ce867 100644 (file)
                                                 <row>
                                                     <vlayout>
                                                         <label value="Státusz"/>
-                                                        <selectbox model="@load(vm.projectStatusDataModel)"
+                                                        <!--                                                        <combobox model="@load(vm.projectStatusDataModel)"-->
+                                                        <!--                                                                  width="100%" readonly="true"-->
+                                                        <!--                                                                  selectedItem="@bind(vm.formDocument.projectStatus) @validator(vm)"-->
+                                                        <!--                                                                  forward="onOK=submit.onClick, onCancel=cancel.onClick">-->
+                                                        <!--                                                            <template name="model">-->
+                                                        <!--                                                                <comboitem label="${each.name}"/>-->
+                                                        <!--                                                            </template>-->
+                                                        <!--                                                        </combobox>-->
+                                                        <selectbox model="@load(vm.projectStatusServiceImpl.getAll())"
                                                                    width="100%"
-                                                                   selectedIndex="@bind(vm.formDocument.projectStatusId) @converter(vm.projectStatusConverter) @validator(vm)"
+                                                                   selectedIndex="@bind(vm.formDocument.projectStatus) @converter(vm.projectStatusConverter) @validator(vm)"
                                                                    forward="onOK=submit.onClick, onCancel=cancel.onClick">
                                                             <template name="model">
                                                                 ${each.name}
index 699c05c0b10265139dcaddd12b95d3951ab7c02f..ae0ddfe4cdb9d4f6465af51b149c848df73e2301 100644 (file)
@@ -32,7 +32,7 @@
                         <listitem>
                             <listcell label="@load(each.humanId)"/>
                             <listcell label="@load(each.partner.name)"/>
-                            <listcell label="@load(vm.getProjectStatus(each.projectStatusId).name)"/>
+                            <listcell label="@load(each.projectStatus.name)"/>
                             <listcell label="@load(each.name)"/>
                             <listcell label="@load(each.contactName)"/>
                             <listcell>
index 04b65c4ffc6de2710596179f85776eec4d1fc27a..bb7e002234ef9975af66feffc5dd6ab2443b9565 100644 (file)
             </north>
             <center border="none" flex="true">
                 <listbox vflex="true" model="@load(vm.serviceRecordsDataModel)"
-                         autopaging="true" pagingPosition="top" onSelect="@command('onListSelection')"
+                         autopaging="true" mold="paging" pagingPosition="top" onSelect="@command('onListSelection')"
                          onDoubleClick="@command('onEdit')">
                     <listhead sizable="true">
-                        <listheader label="Projekt azonosító" align="left"/>
-                        <listheader label="Projekt név" align="left"/>
-                        <listheader label="Partner név" align="left"/>
-                        <listheader label="Munkatárs" align="left"/>
-                        <listheader label="Munkanap" align="left"/>
-                        <listheader label="Leírás" align="left"/>
-                        <listheader label="Óraszám" align="right" style="text-align: center"/>
+                        <listheader label="Projekt azonosító" sort="auto(project.humanId)" align="left"/>
+                        <listheader label="Projekt név" sort="auto(project.name)" align="left"/>
+                        <listheader label="Partner név" sort="auto(partner.name)" align="left"/>
+                        <listheader label="Munkatárs" sort="auto(name)" align="left"/>
+                        <listheader label="Munkanap" sort="auto(workDay)" align="left"/>
+                        <listheader label="Leírás" sort="auto(description)" align="left"/>
+                        <listheader label="Óraszám" sort="auto(workHours)" align="right" style="text-align: center"/>
                         <listheader label="Aláírt" align="left"/>
                     </listhead>
                     <template name="model">