From 388eba19b8e0e9185a36e94f7bbd1a76ae1cab0a Mon Sep 17 00:00:00 2001 From: elgekko Date: Thu, 6 Jul 2023 17:35:57 +0200 Subject: [PATCH] Sort and cache --- KB.md | 1 + TODO.txt | 15 +- lis-app/src/main/resources/application.yaml | 2 +- .../src/main/java/hu/user/lis/db/Invoice.java | 3 + .../src/main/java/hu/user/lis/db/Project.java | 19 +- .../main/java/hu/user/lis/db/Treasury.java | 2 + .../AssociateRepositorySearchImpl.java | 2 + .../repository/PartnerRepositorySearch.java | 4 +- .../PartnerRepositorySearchImpl.java | 43 ++-- .../ProjectAssociateRepository.java | 6 +- .../lis/db/repository/ProjectRepository.java | 6 + .../ProjectRepositorySearchImpl.java | 2 + .../repository/ProjectStatusRepository.java | 2 + .../ServiceRecordRepositorySearchImpl.java | 8 +- .../java/hu/user/lis/services/api/DbApi.java | 17 +- .../hu/user/lis/services/api/GenerateApi.java | 9 + .../hu/user/lis/services/api/ProjectApi.java | 40 ++++ .../lis/services/data/InvoiceService.java | 5 +- .../lis/services/data/InvoiceServiceImpl.java | 17 +- .../lis/services/data/ProjectServiceImpl.java | 16 +- .../lis/services/data/TreasuryService.java | 3 +- .../services/data/TreasuryServiceImpl.java | 9 +- .../user/lis/ui/config/WebSecurityConfig.java | 17 +- .../ui/converter/ProjectStatusConverter.java | 6 +- .../hu/user/lis/ui/data/CachedDataModel.java | 61 ++---- .../lis/ui/data/CachedSpringDataModel.java | 2 + .../lis/ui/data/IncomeMarginsDataModel.java | 6 +- .../hu/user/lis/ui/data/InvoiceDataModel.java | 31 +++ .../lis/ui/data/PartnerSelectorDataModel.java | 12 +- .../user/lis/ui/data/PartnersDataModel.java | 20 +- .../ui/data/ProjectAssociatesDataModel.java | 37 +--- .../lis/ui/data/ProjectStatusDataModel.java | 4 + .../user/lis/ui/data/ProjectsDataModel.java | 52 ++++- .../lis/ui/data/ServiceRecordsDataModel.java | 9 +- .../user/lis/ui/data/TreasuryDataModel.java | 32 +++ .../lis/ui/editor/PartnerEditorModel.java | 7 +- .../lis/ui/editor/ProjectEditorModel.java | 185 ++++++++++-------- .../java/hu/user/lis/ui/event/EventBus.java | 2 +- .../hu/user/lis/ui/view/IndexViewModel.java | 4 +- .../hu/user/lis/ui/view/LoginViewModel.java | 19 ++ .../user/lis/ui/view/ProjectsViewModel.java | 7 +- .../lis/ui/view/ServiceRecordsViewModel.java | 11 +- .../user/lis/ui/view/SettingsViewModel.java | 11 +- lis-ui/src/main/resources/metainfo/zk/zk.xml | 25 +++ lis-ui/src/main/resources/web/index.zul | 8 +- lis-ui/src/main/resources/web/login.zul | 67 ++++--- .../src/main/resources/web/project-editor.zul | 2 +- lis-ui/src/main/resources/web/projects.zul | 12 +- .../main/resources/web/service-records.zul | 6 +- lis-ui/src/main/resources/web/settings.zul | 3 +- .../resources/web/static/css/webclient.css | 6 +- 51 files changed, 551 insertions(+), 344 deletions(-) create mode 100644 lis-ui/src/main/java/hu/user/lis/ui/data/InvoiceDataModel.java create mode 100644 lis-ui/src/main/java/hu/user/lis/ui/data/TreasuryDataModel.java create mode 100644 lis-ui/src/main/java/hu/user/lis/ui/view/LoginViewModel.java diff --git a/KB.md b/KB.md index 4aa1b8f..51658e8 100644 --- a/KB.md +++ b/KB.md @@ -60,6 +60,7 @@ https://www.zkoss.org/wiki/ZK_Spring_Essentials/Working_with_ZK_Spring/Working_w (To enable remove @SpringBootApplication with exludes and @ComponentScan) https://www.baeldung.com/get-user-in-spring-security https://www.baeldung.com/spring-security-authentication-provider +https://www.zkoss.org/wiki/ZK_Developer%27s_Reference/Security_Tips/SSO_Redirect_Handling ##### ZK Style diff --git a/TODO.txt b/TODO.txt index c64c820..5e7706e 100644 --- a/TODO.txt +++ b/TODO.txt @@ -54,15 +54,8 @@ 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 +* auth/ldap ldap:fds.in.useribm.hu:389,ldaps:fds.useribm.hu:636 - -db persist -- servicerecord: - project generalas - generalas - project szuro - -auth/ldap autorizacio nav szamla erkeztetes camunda: egy felasznalohoz jon be, projekthez lehessen csatolni, projektszanot ellenorizze @@ -81,11 +74,5 @@ szamla erkeztetes camunda: egy felasznalohoz jon be, projekthez lehessen csatoln - 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 diff --git a/lis-app/src/main/resources/application.yaml b/lis-app/src/main/resources/application.yaml index 3f2d8e4..507a9d2 100644 --- a/lis-app/src/main/resources/application.yaml +++ b/lis-app/src/main/resources/application.yaml @@ -9,7 +9,7 @@ spring: jpa: hibernate: use-new-id-generator-mappings: false - show-sql: true + show-sql: false properties: hibernate: format_sql: true diff --git a/lis-db/src/main/java/hu/user/lis/db/Invoice.java b/lis-db/src/main/java/hu/user/lis/db/Invoice.java index 0b9eccd..4ee7af1 100644 --- a/lis-db/src/main/java/hu/user/lis/db/Invoice.java +++ b/lis-db/src/main/java/hu/user/lis/db/Invoice.java @@ -1,5 +1,6 @@ package hu.user.lis.db; +import com.fasterxml.jackson.annotation.JsonIncludeProperties; import lombok.*; import javax.persistence.*; @@ -19,9 +20,11 @@ public class Invoice { String title; @OneToOne @JoinColumn(name = "partner_id") + @JsonIncludeProperties({"id"}) Partner partner; @ManyToOne @JoinColumn(name = "project_id") + @JsonIncludeProperties({"id"}) Project project; boolean income; Currency currency; diff --git a/lis-db/src/main/java/hu/user/lis/db/Project.java b/lis-db/src/main/java/hu/user/lis/db/Project.java index 16cea07..ff1d8da 100644 --- a/lis-db/src/main/java/hu/user/lis/db/Project.java +++ b/lis-db/src/main/java/hu/user/lis/db/Project.java @@ -1,9 +1,10 @@ package hu.user.lis.db; +import com.fasterxml.jackson.annotation.JsonIncludeProperties; import lombok.*; import javax.persistence.*; -import java.util.List; +import java.util.Set; @Getter @Setter @@ -23,12 +24,16 @@ public class Project { String contactName; @ManyToOne @JoinColumn(name = "partner_id") + @JsonIncludeProperties({"id"}) Partner partner; boolean active; - @OneToMany(mappedBy = "project") - List incomingInvoices; - @OneToMany(mappedBy = "project") - List outgoingInvoices; - @OneToMany(mappedBy = "project") - List treasuries; + @OneToMany(mappedBy = "project", fetch = FetchType.EAGER) + @JsonIncludeProperties({"id"}) + Set incomingInvoices; + @OneToMany(mappedBy = "project", fetch = FetchType.EAGER) + @JsonIncludeProperties({"id"}) + Set outgoingInvoices; + @OneToMany(mappedBy = "project", fetch = FetchType.EAGER) + @JsonIncludeProperties({"id"}) + Set treasuries; } diff --git a/lis-db/src/main/java/hu/user/lis/db/Treasury.java b/lis-db/src/main/java/hu/user/lis/db/Treasury.java index 5b2f7ce..60114e6 100644 --- a/lis-db/src/main/java/hu/user/lis/db/Treasury.java +++ b/lis-db/src/main/java/hu/user/lis/db/Treasury.java @@ -1,5 +1,6 @@ package hu.user.lis.db; +import com.fasterxml.jackson.annotation.JsonIncludeProperties; import lombok.*; import javax.persistence.*; @@ -17,6 +18,7 @@ public class Treasury { Long id; @ManyToOne @JoinColumn(name = "project_id") + @JsonIncludeProperties({"id"}) Project project; String humanId; double buyAmount; diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepositorySearchImpl.java b/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepositorySearchImpl.java index 1cafe75..90d2dbf 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepositorySearchImpl.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/AssociateRepositorySearchImpl.java @@ -3,6 +3,7 @@ package hu.user.lis.db.repository; import hu.user.lis.db.Associate; import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.query.QueryUtils; import org.springframework.stereotype.Repository; import javax.persistence.EntityManager; @@ -41,6 +42,7 @@ public class AssociateRepositorySearchImpl implements AssociateRepositorySearch Root root = cq.from(Associate.class); cq.where(getPredicates(cb, root, partialName, filterShowActive, filterShowInActive)); + cq.orderBy(QueryUtils.toOrders(pageable.getSort(), root, cb)); TypedQuery query = entityManager.createQuery(cq); query.setMaxResults(pageable.getPageSize()); query.setFirstResult(pageable.getPageSize() * pageable.getPageNumber()); diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearch.java b/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearch.java index 8ef30ed..9e07be7 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearch.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearch.java @@ -6,7 +6,7 @@ import org.springframework.data.domain.Pageable; import java.util.List; public interface PartnerRepositorySearch { - List search(String partialName, String partialVatNr, String partialAddress, boolean filterShowActive, boolean filterShowInActive, Pageable pageable); + List search(String partialSearch, boolean filterShowActive, boolean filterShowInActive, Pageable pageable); - long count(String partialName, String partialVatNr, String partialAddress, boolean filterShowActive, boolean filterShowInActive); + long count(String ppartialSearch, boolean filterShowActive, boolean filterShowInActive); } diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearchImpl.java b/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearchImpl.java index 7266539..67e57f0 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearchImpl.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/PartnerRepositorySearchImpl.java @@ -3,6 +3,7 @@ package hu.user.lis.db.repository; import hu.user.lis.db.Partner; import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.query.QueryUtils; import org.springframework.stereotype.Repository; import javax.persistence.EntityManager; @@ -20,22 +21,16 @@ public class PartnerRepositorySearchImpl implements PartnerRepositorySearch { @PersistenceContext EntityManager entityManager; - Predicate[] getPredicates(CriteriaBuilder cb, Root root, String partialName, - String partialVatNr, String partialAddress, boolean filterShowActive, boolean filterShowInActive) { + Predicate[] getPredicates(CriteriaBuilder cb, Root root, String partialSearch, boolean filterShowActive, boolean filterShowInActive) { List predicates = new ArrayList<>(); - List orPredicates = new ArrayList<>(); - if (StringUtils.isNotBlank(partialName)) { - orPredicates.add(cb.like(root.get("name"), "%" + partialName + "%")); - } - if (StringUtils.isNotBlank(partialVatNr)) { - orPredicates.add(cb.like(root.get("vat_nr"), "%" + partialVatNr + "%")); - } - if (StringUtils.isNotBlank(partialAddress)) { - orPredicates.add(cb.like(root.get("address"), "%" + partialAddress + "%")); - } - if (orPredicates.size() > 0) { + if (StringUtils.isNotBlank(partialSearch)) { + List orPredicates = new ArrayList<>(); + orPredicates.add(cb.like(cb.lower(root.get("name")), "%" + partialSearch.toLowerCase() + "%")); + orPredicates.add(cb.like(cb.lower(root.get("vat_nr")), "%" + partialSearch.toLowerCase() + "%")); + orPredicates.add(cb.like(cb.lower(root.get("address")), "%" + partialSearch.toLowerCase() + "%")); predicates.add(cb.or(orPredicates.toArray(new Predicate[]{}))); } + if (filterShowActive && !filterShowInActive) { predicates.add(cb.isTrue(root.get("active"))); } @@ -45,26 +40,14 @@ public class PartnerRepositorySearchImpl implements PartnerRepositorySearch { return predicates.toArray(new Predicate[]{}); } - Predicate[] getPredicates(CriteriaBuilder cb, Root root, String partialName, boolean filterShowActive) { - List predicates = new ArrayList<>(); - if (StringUtils.isNotBlank(partialName)) { - predicates.add(cb.like(root.get("name"), "%" + partialName + "%")); - } - if (filterShowActive) { - predicates.add(cb.isTrue(root.get("active"))); - } else { - predicates.add(cb.isFalse(root.get("active"))); - } - return predicates.toArray(new Predicate[]{}); - } - @Override - public List search(String partialName, String partialVatNr, String partialAddress, boolean filterShowActive, boolean filterShowInActive, Pageable pageable) { + public List search(String partialSearch, boolean filterShowActive, boolean filterShowInActive, Pageable pageable) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Partner.class); Root root = cq.from(Partner.class); - cq.where(getPredicates(cb, root, partialName, partialVatNr, partialAddress, filterShowActive, filterShowInActive)); + cq.where(getPredicates(cb, root, partialSearch, filterShowActive, filterShowInActive)); + cq.orderBy(QueryUtils.toOrders(pageable.getSort(), root, cb)); TypedQuery query = entityManager.createQuery(cq); query.setMaxResults(pageable.getPageSize()); query.setFirstResult(pageable.getPageSize() * pageable.getPageNumber()); @@ -72,13 +55,13 @@ public class PartnerRepositorySearchImpl implements PartnerRepositorySearch { } @Override - public long count(String partialName, String partialVatNr, String partialAddress, boolean filterShowActive, boolean filterShowInActive) { + public long count(String partialSearch, boolean filterShowActive, boolean filterShowInActive) { CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Long.class); Root root = cq.from(Partner.class); cq.select(cb.count(root)); - cq.where(getPredicates(cb, root, partialName, partialVatNr, partialAddress, filterShowActive, filterShowInActive)); + cq.where(getPredicates(cb, root, partialSearch, filterShowActive, filterShowInActive)); return entityManager.createQuery(cq).getSingleResult(); } diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectAssociateRepository.java b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectAssociateRepository.java index 721c76c..eace4a2 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectAssociateRepository.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectAssociateRepository.java @@ -1,12 +1,12 @@ package hu.user.lis.db.repository; import hu.user.lis.db.ProjectAssociate; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ProjectAssociateRepository extends JpaRepository { - Page findAllByProjectId(Long projectId, Pageable pageable); + List findAllByProjectId(Long projectId); Long countByProjectId(Long projectId); diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepository.java b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepository.java index a5868ea..9fcbfaa 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepository.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepository.java @@ -3,6 +3,12 @@ package hu.user.lis.db.repository; import hu.user.lis.db.Project; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ProjectRepository extends JpaRepository, ProjectRepositorySearch { + List findByHumanIdLikeOrderByHumanIdDesc(String yearSearch); + + Project findFirstByHumanIdLikeOrderByHumanIdDesc(String yearSearch); + } diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearchImpl.java b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearchImpl.java index 6d7a4ef..9c252ee 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearchImpl.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/ProjectRepositorySearchImpl.java @@ -3,6 +3,7 @@ package hu.user.lis.db.repository; import hu.user.lis.db.Project; import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.query.QueryUtils; import org.springframework.stereotype.Repository; import javax.persistence.EntityManager; @@ -46,6 +47,7 @@ public class ProjectRepositorySearchImpl implements ProjectRepositorySearch { Root root = cq.from(Project.class); cq.where(getPredicates(cb, root, partialSearch, filterShowActive, filterShowInActive)); + cq.orderBy(QueryUtils.toOrders(pageable.getSort(), root, cb)); TypedQuery query = entityManager.createQuery(cq); query.setMaxResults(pageable.getPageSize()); query.setFirstResult(pageable.getPageSize() * pageable.getPageNumber()); 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 index 471419d..c3087e4 100644 --- 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 @@ -10,4 +10,6 @@ public interface ProjectStatusRepository extends JpaRepository findByActiveIsTrue(Sort sort); long countByActiveIsTrue(); + + ProjectStatus findByOrder(int order); } diff --git a/lis-db/src/main/java/hu/user/lis/db/repository/ServiceRecordRepositorySearchImpl.java b/lis-db/src/main/java/hu/user/lis/db/repository/ServiceRecordRepositorySearchImpl.java index 8d89ebe..e330623 100644 --- a/lis-db/src/main/java/hu/user/lis/db/repository/ServiceRecordRepositorySearchImpl.java +++ b/lis-db/src/main/java/hu/user/lis/db/repository/ServiceRecordRepositorySearchImpl.java @@ -1,7 +1,9 @@ package hu.user.lis.db.repository; import hu.user.lis.db.ServiceRecord; +import lombok.extern.log4j.Log4j2; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.query.QueryUtils; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; @@ -14,6 +16,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +@Log4j2 public class ServiceRecordRepositorySearchImpl implements ServiceRecordRepositorySearch { @PersistenceContext EntityManager entityManager; @@ -21,10 +24,10 @@ public class ServiceRecordRepositorySearchImpl implements ServiceRecordRepositor Predicate[] getPredicates(CriteriaBuilder cb, Root root, Long filterProjectId, Long filterAssociateId) { List predicates = new ArrayList<>(); if (Objects.nonNull(filterProjectId)) { - predicates.add(cb.equal(root.join("project").get("id"), filterProjectId)); + predicates.add(cb.equal(root.get("project"), filterProjectId)); } if (Objects.nonNull(filterAssociateId)) { - predicates.add(cb.equal(root.join("associate").get("id"), filterAssociateId)); + predicates.add(cb.equal(root.get("associate"), filterAssociateId)); } return predicates.toArray(new Predicate[]{}); } @@ -36,6 +39,7 @@ public class ServiceRecordRepositorySearchImpl implements ServiceRecordRepositor Root root = cq.from(ServiceRecord.class); cq.where(getPredicates(cb, root, filterProjectId, filterAssociateId)); + cq.orderBy(QueryUtils.toOrders(pageable.getSort(), root, cb)); TypedQuery query = entityManager.createQuery(cq); query.setMaxResults(pageable.getPageSize()); query.setFirstResult(pageable.getPageSize() * pageable.getPageNumber()); 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 index b7280b3..e8ddd6e 100644 --- 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 @@ -1,6 +1,8 @@ package hu.user.lis.services.api; import hu.user.lis.services.data.DataService; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -9,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestBody; import java.util.List; + public abstract class DbApi, S extends DataService> { protected abstract S getService(); @@ -20,6 +23,11 @@ public abstract class DbApi, S extends DataS return getRepository().findAll(); } + @GetMapping("/page") + public Page page(Pageable pageable) { + return getRepository().findAll(pageable); + } + @GetMapping("/get/{id}") public T get(@PathVariable long id) { return getRepository().findById(id).orElse(null); @@ -37,7 +45,12 @@ public abstract class DbApi, S extends DataS @GetMapping("/generate") public List generate() { - deleteAll(); - return getRepository().saveAll(getService().getAll()); + List result = getRepository().saveAll(getService().getAll()); + afterSave(result); + return result; + } + + protected void afterSave(List entities) { + } } 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 index 01e9383..4126745 100644 --- 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 @@ -29,6 +29,15 @@ public class GenerateApi { @GetMapping("/all") public String list() { + serviceRecordApi.deleteAll(); + projectAssociateApi.deleteAll(); + treasuryApi.deleteAll(); + invoiceApi.deleteAll(); + associateApi.deleteAll(); + projectApi.deleteAll(); + partnerApi.deleteAll(); + projectStatusApi.deleteAll(); + log.info("projectStatus"); projectStatusApi.generate(); log.info("partner"); 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 index a57f179..2baadf5 100644 --- 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 @@ -1,13 +1,21 @@ package hu.user.lis.services.api; +import hu.user.lis.db.Invoice; import hu.user.lis.db.Project; +import hu.user.lis.db.Treasury; +import hu.user.lis.db.repository.InvoiceRepository; import hu.user.lis.db.repository.ProjectRepository; +import hu.user.lis.db.repository.TreasuryRepository; import hu.user.lis.services.data.ProjectService; 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; +import java.util.List; +import java.util.Objects; +import java.util.Set; + @Log4j2 @RestController @RequestMapping("/api/project") @@ -16,6 +24,10 @@ public class ProjectApi extends DbApi entities) { + entities.forEach(p -> { + Set incomingInvoices = p.getIncomingInvoices(); + if (Objects.nonNull(incomingInvoices)) { + incomingInvoices.forEach(i -> { + i.setProject(p); + invoiceRepository.save(i); + }); + } + + Set outgoingInvoices = p.getOutgoingInvoices(); + if (Objects.nonNull(outgoingInvoices)) { + outgoingInvoices.forEach(i -> { + i.setProject(p); + invoiceRepository.save(i); + }); + } + + Set treasuries = p.getTreasuries(); + treasuries.forEach(t -> { + t.setProject(p); + treasuryRepository.save(t); + }); + }); + } + } diff --git a/lis-services/src/main/java/hu/user/lis/services/data/InvoiceService.java b/lis-services/src/main/java/hu/user/lis/services/data/InvoiceService.java index cacadd4..a2043c9 100644 --- a/lis-services/src/main/java/hu/user/lis/services/data/InvoiceService.java +++ b/lis-services/src/main/java/hu/user/lis/services/data/InvoiceService.java @@ -3,6 +3,7 @@ package hu.user.lis.services.data; import hu.user.lis.db.Invoice; import java.util.List; +import java.util.Set; public interface InvoiceService extends DataService { void setAll(List entities); @@ -13,11 +14,11 @@ public interface InvoiceService extends DataService { void replace(Invoice targetEntity, Invoice replacementEntity); - List getRandom(boolean income); + Set getRandom(boolean income); Invoice getById(String id); Invoice getByHumanId(String id); - List getByHumanIds(String[] ids); + Set getByHumanIds(String[] ids); } diff --git a/lis-services/src/main/java/hu/user/lis/services/data/InvoiceServiceImpl.java b/lis-services/src/main/java/hu/user/lis/services/data/InvoiceServiceImpl.java index b7d6485..1c6cc2e 100644 --- a/lis-services/src/main/java/hu/user/lis/services/data/InvoiceServiceImpl.java +++ b/lis-services/src/main/java/hu/user/lis/services/data/InvoiceServiceImpl.java @@ -1,6 +1,5 @@ package hu.user.lis.services.data; -import com.fasterxml.jackson.databind.ObjectMapper; import hu.user.lis.db.Currency; import hu.user.lis.db.Invoice; import hu.user.lis.db.Partner; @@ -12,10 +11,7 @@ import org.springframework.stereotype.Service; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.concurrent.TimeUnit; @Service @@ -26,8 +22,7 @@ public class InvoiceServiceImpl extends DataServiceImpl implements Invo DataGeneratorService dataGeneratorService; @Autowired PartnerService partnerService; - @Autowired - ObjectMapper mapper; + private List incomingEntities; private List outgoingEntities; @@ -765,8 +760,8 @@ public class InvoiceServiceImpl extends DataServiceImpl implements Invo } @Override - public List getByHumanIds(String[] ids) { - List result = new ArrayList<>(); + public Set getByHumanIds(String[] ids) { + Set result = new HashSet<>(); for (String i : ids) { result.add(getByHumanId(i)); @@ -777,10 +772,10 @@ public class InvoiceServiceImpl extends DataServiceImpl implements Invo @Override - public List getRandom(boolean income) { + public Set getRandom(boolean income) { getAll(); int count = RandomUtils.nextInt(2, 5); - List result = new ArrayList<>(); + Set result = new HashSet<>(); for (int i = 0; i < count; i++) { if (income) { int index = RandomUtils.nextInt(0, incomingEntities.size()); diff --git a/lis-services/src/main/java/hu/user/lis/services/data/ProjectServiceImpl.java b/lis-services/src/main/java/hu/user/lis/services/data/ProjectServiceImpl.java index 091f07e..e099ccc 100644 --- a/lis-services/src/main/java/hu/user/lis/services/data/ProjectServiceImpl.java +++ b/lis-services/src/main/java/hu/user/lis/services/data/ProjectServiceImpl.java @@ -12,6 +12,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -58,14 +59,13 @@ public class ProjectServiceImpl extends DataServiceImpl implements Proj @Override public Project createNew() { - String humanId = dataGeneratorService.faker().code().isbn13(true); +// String humanId = dataGeneratorService.faker().code().isbn13(true); ProjectStatus projectStatus = projectStatusService.getAll().get(0); return Project.builder() .projectStatus(projectStatus) - .humanId(humanId) - .incomingInvoices(new ArrayList<>()) - .outgoingInvoices(new ArrayList<>()) - .treasuries(new ArrayList<>()) + .incomingInvoices(new HashSet<>()) + .outgoingInvoices(new HashSet<>()) + .treasuries(new HashSet<>()) .active(true) .build(); } @@ -106,7 +106,7 @@ public class ProjectServiceImpl extends DataServiceImpl implements Proj .partner(partner) .incomingInvoices(invoiceService.getRandom(true)) .outgoingInvoices(invoiceService.getRandom(false)) - .treasuries(new ArrayList<>()) + .treasuries(new HashSet<>()) .build(); result.add(entity); } @@ -131,7 +131,7 @@ public class ProjectServiceImpl extends DataServiceImpl 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(new ArrayList<>()) + .treasuries(new HashSet<>()) .build(); result.add(entity); @@ -182,7 +182,7 @@ public class ProjectServiceImpl extends DataServiceImpl 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(new ArrayList<>()) + .treasuries(new HashSet<>()) .build(); result.add(entity); diff --git a/lis-services/src/main/java/hu/user/lis/services/data/TreasuryService.java b/lis-services/src/main/java/hu/user/lis/services/data/TreasuryService.java index 8b97885..c91e7bc 100644 --- a/lis-services/src/main/java/hu/user/lis/services/data/TreasuryService.java +++ b/lis-services/src/main/java/hu/user/lis/services/data/TreasuryService.java @@ -3,6 +3,7 @@ package hu.user.lis.services.data; import hu.user.lis.db.Treasury; import java.util.List; +import java.util.Set; public interface TreasuryService extends DataService { Treasury createNew(); @@ -11,5 +12,5 @@ public interface TreasuryService extends DataService { Treasury getByHumanId(String id); - List getByHumanIds(String[] ids); + Set getByHumanIds(String[] ids); } diff --git a/lis-services/src/main/java/hu/user/lis/services/data/TreasuryServiceImpl.java b/lis-services/src/main/java/hu/user/lis/services/data/TreasuryServiceImpl.java index 12702c2..7b8d1da 100644 --- a/lis-services/src/main/java/hu/user/lis/services/data/TreasuryServiceImpl.java +++ b/lis-services/src/main/java/hu/user/lis/services/data/TreasuryServiceImpl.java @@ -11,10 +11,7 @@ import org.springframework.stereotype.Service; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.concurrent.TimeUnit; @Service @@ -373,8 +370,8 @@ public class TreasuryServiceImpl extends DataServiceImpl implements Tr } @Override - public List getByHumanIds(String[] ids) { - List result = new ArrayList<>(); + public Set getByHumanIds(String[] ids) { + Set result = new HashSet<>(); for (String i : ids) { result.add(getByHumanId(i)); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java b/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java index bde12a7..8fb3891 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/config/WebSecurityConfig.java @@ -9,6 +9,8 @@ import org.springframework.security.config.annotation.authentication.builders.Au import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint; +import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import static hu.user.lis.ui.view.IndexViewModel.NAVIGATION; @@ -17,11 +19,11 @@ import static hu.user.lis.ui.view.IndexViewModel.NAVIGATION; public class WebSecurityConfig extends WebSecurityConfigurerAdapter { public static final String ZUL_FILES = "/zkau/web/**/*.zul"; - - public static final String[] ZK_RESOURCES = {"/zkau/web/**/js/**", "/zkau/web/**/zul/css/**", "/zkau/web/**/img/**"}; - // allow desktop cleanup after logout or when reloading login page public static final String REMOVE_DESKTOP_REGEX = "/zkau\\?dtid=.*&cmd_0=rmDesktop&.*"; + + + public static final String[] ZK_RESOURCES = {"/zkau/web/**/js/**", "/zkau/web/**/zul/css/**", "/zkau/web/**/img/**", "/zkau/web/**/static/**"}; @Autowired LocalAuthProvider localAuthProvider; @@ -37,14 +39,19 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET, ZK_RESOURCES).permitAll() // allow zk resources .regexMatchers(HttpMethod.GET, REMOVE_DESKTOP_REGEX).permitAll() // allow desktop cleanup .requestMatchers(req -> "rmDesktop".equals(req.getParameter("cmd_0"))).permitAll() // allow desktop cleanup from ZATS - .mvcMatchers("/", "/login", "/logout").permitAll() + .mvcMatchers("/", "/login", "/logout", "/api/**").permitAll() //mvcMatchers(navigation).hasRole("USER") .anyRequest().authenticated() .and() .formLogin() .loginPage("/login").defaultSuccessUrl("/partners") .and() - .logout().logoutUrl("/logout").logoutSuccessUrl("/"); + .logout().logoutUrl("/logout").logoutSuccessUrl("/") + .and() + .exceptionHandling() + .defaultAuthenticationEntryPointFor( + new Http403ForbiddenEntryPoint(), + new AntPathRequestMatcher("/zkau", "POST")); } @Autowired diff --git a/lis-ui/src/main/java/hu/user/lis/ui/converter/ProjectStatusConverter.java b/lis-ui/src/main/java/hu/user/lis/ui/converter/ProjectStatusConverter.java index 88b44f8..75b10f8 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/converter/ProjectStatusConverter.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/converter/ProjectStatusConverter.java @@ -1,7 +1,7 @@ package hu.user.lis.ui.converter; import hu.user.lis.db.ProjectStatus; -import hu.user.lis.services.data.ProjectStatusService; +import hu.user.lis.db.repository.ProjectStatusRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.zkoss.bind.BindContext; @@ -15,7 +15,7 @@ import java.util.Objects; @Component public class ProjectStatusConverter implements Converter { @Autowired - ProjectStatusService projectStatusService; + ProjectStatusRepository projectStatusRepository; @Override public Object coerceToUi(ProjectStatus projectStatus, Selectbox box, BindContext bindContext) { @@ -35,6 +35,6 @@ public class ProjectStatusConverter implements Converter extends ListModelList { public static final String NATURAL = "natural"; public static final String ASCENDING = "ascending"; public static final String DESCENDING = "descending"; - private int cacheSize = 100; + private int CACHE_SIZE = 100; private int cacheStart; private int cacheEnd; private int resultSetSize = -1; @@ -83,14 +83,12 @@ public abstract class CachedDataModel extends ListModelList { return this.resultSetSize; } -// private void loadCache(int forIndex) { +// protected void loadCache(int forIndex) { // try { -// int halfSize = this.cacheSize / 2; -// int rowLimit = this.cacheSize; // 200 +// int halfSize = this.CACHE_SIZE / 2; +// int rowLimit = this.CACHE_SIZE; // int startPos = 0; -// if ((forIndex - halfSize) > 0) { // forIndex=60 startPos=0 -// // cache=0-200, forIndex=150 -// // startPos=50 cache=50-250 +// if ((forIndex - halfSize) > 0) { // startPos = (forIndex - halfSize); // } // @@ -103,21 +101,19 @@ public abstract class CachedDataModel extends ListModelList { // log.info("Result item count is {}", resultSetSize); // } // -// log.info("Query result from {} to {}", startPos, endPos); -// // int limit = endPos - startPos; -// int page = (int) Math.ceil(this.resultSetSize / limit); +// +// // (int) Math.ceil(this.resultSetSize / limit); +// int page = forIndex == 0 ? 0 : (int) Math.ceil(limit / forIndex); +// log.info("Query result from {} to {} for item {} | page {} pageSize {}", startPos, endPos, forIndex, page, limit); // List 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)); -// // logger.debug("CachedListMode.cached idx: " + -// // (startPos + c)); // } // } -// // logger.debug("CachedListMode.cacheSize: " + cache.size()); // // cacheStart = startPos + 1; // cacheEnd = cacheStart + (cache.size() == 0 ? 0 : (cache.size() - 1)); @@ -126,45 +122,26 @@ public abstract class CachedDataModel extends ListModelList { // } // } - private void loadCache(int forIndex) { - try { - int halfSize = this.cacheSize / 2; - int rowLimit = this.cacheSize; // 200 - int startPos = 0; - if ((forIndex - halfSize) > 0) { // forIndex=60 startPos=0 - // cache=0-200, forIndex=150 - // startPos=50 cache=50-250 - startPos = (forIndex - halfSize); - } - - int endPos = (startPos + rowLimit); - endPos = ((this.resultSetSize < 0) || (endPos <= this.resultSetSize)) ? endPos : this.resultSetSize; - + protected void loadCache(int forIndex) { + try { + int page = forIndex == 0 ? 0 : (int) Math.ceil(forIndex / CACHE_SIZE); + log.info("{} query result for item {} | page {} pageSize {}", getClass().getSimpleName(), forIndex, page, CACHE_SIZE); if (this.resultSetSize < 0) { this.resultSetSize = getResultSetCount(); - log.info("Result item count is {}", resultSetSize); + log.info("Result item total count is {}", resultSetSize); } - - int limit = endPos - startPos; - - // (int) Math.ceil(this.resultSetSize / limit); - int page = forIndex == 0 ? 0 : (int) Math.ceil(limit / forIndex); - log.info("Query result from {} to {} | page {} pageSize {}", startPos, endPos, page, limit); - List resList = getResultSet(page, limit, sortComparator); + List resList = getResultSet(page, CACHE_SIZE, sortComparator); if (resList != null) { log.info("Got {} records", resList.size()); + cacheStart = forIndex; for (int c = 0; c < resList.size(); c++) { - cache.put(startPos + c, resList.get(c)); - // logger.debug("CachedListMode.cached idx: " + - // (startPos + c)); + cache.put(forIndex + c, resList.get(c)); + cacheEnd++; } } - // logger.debug("CachedListMode.cacheSize: " + cache.size()); - cacheStart = startPos + 1; - cacheEnd = cacheStart + (cache.size() == 0 ? 0 : (cache.size() - 1)); } catch (Exception e) { log.error("", e); } @@ -187,7 +164,7 @@ public abstract class CachedDataModel extends ListModelList { @Override public void sort(Comparator cmpr, boolean ascending) { sortComparator = (FieldComparator) cmpr; - log.info("Sort {} {}", sortComparator.getOrderBy(), ascending); +// log.info("Sort {} {}", sortComparator.getOrderBy(), ascending); reset(); } } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/CachedSpringDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/CachedSpringDataModel.java index 632204f..0fc1153 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/CachedSpringDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/CachedSpringDataModel.java @@ -21,7 +21,9 @@ public abstract class CachedSpringDataModel extends CachedDataModel { Sort.Direction direction = sortComparator.isAscending() ? Sort.Direction.ASC : Sort.Direction.DESC; pageable = PageRequest.of(page, pageSize, Sort.by(direction, orderBy)); } + log.info("{} {}", getClass().getSimpleName(), pageable); return pageable; } + } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/IncomeMarginsDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/IncomeMarginsDataModel.java index 1d2deb5..e674fd5 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/IncomeMarginsDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/IncomeMarginsDataModel.java @@ -20,21 +20,21 @@ public class IncomeMarginsDataModel extends ArrayList { public void recalculate(Project project) { clear(); Map balances = new HashMap<>(); - List outgoingInvoices = project.getOutgoingInvoices(); + Set outgoingInvoices = project.getOutgoingInvoices(); if (Objects.nonNull(outgoingInvoices)) { for (Invoice invoice : outgoingInvoices) { addBalance(balances, invoice.getCurrency(), invoice.getNetAmount()); } } - List incomingInvoices = project.getIncomingInvoices(); + Set incomingInvoices = project.getIncomingInvoices(); if (Objects.nonNull(incomingInvoices)) { for (Invoice invoice : incomingInvoices) { substractBalance(balances, invoice.getCurrency(), invoice.getNetAmount()); } } - List treasuries = project.getTreasuries(); + Set treasuries = project.getTreasuries(); if (Objects.nonNull(treasuries)) { for (Treasury treasury : treasuries) { substractBalance(balances, treasury.getSellCurrency(), treasury.getSellAmount()); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/InvoiceDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/InvoiceDataModel.java new file mode 100644 index 0000000..53cbd05 --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/InvoiceDataModel.java @@ -0,0 +1,31 @@ +package hu.user.lis.ui.data; + +import hu.user.lis.db.Invoice; +import hu.user.lis.db.Project; +import hu.user.lis.db.repository.InvoiceRepository; +import hu.user.lis.services.data.InvoiceService; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.persistence.EntityExistsException; + +@Component +@Log4j2 +public class InvoiceDataModel { + + @Autowired + InvoiceService invoiceService; + @Autowired + InvoiceRepository invoiceRepository; + + public Invoice copy(Invoice entity) { + return invoiceRepository.findById(entity.getId()).orElseThrow(EntityExistsException::new); + } + + public Invoice createNew(Project formDocument) { + Invoice result = invoiceService.createNew(); + result.setProject(formDocument); + return result; + } +} diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/PartnerSelectorDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/PartnerSelectorDataModel.java index 689b750..8149566 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/PartnerSelectorDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/PartnerSelectorDataModel.java @@ -22,28 +22,28 @@ public class PartnerSelectorDataModel extends CachedSpringDataModel { @Autowired PartnerRepository partnerRepository; - private String partialName; + private String partialSearch; @Override public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { Pageable pageable = createPageable(page, pageSize, sortComparator); - List result = StringUtils.isBlank(partialName) ? partnerRepository.findAll() : - partnerRepository.search(partialName, partialName, partialName, true, false, pageable); + List result = StringUtils.isBlank(partialSearch) ? partnerRepository.findAll() : + partnerRepository.search(partialSearch, true, false, pageable); return result; } @Override public int getResultSetCount() { - int result = StringUtils.isBlank(partialName) ? + int result = StringUtils.isBlank(partialSearch) ? (int) partnerRepository.count() : - (int) partnerRepository.count(partialName, partialName, partialName, true, false); + (int) partnerRepository.count(partialSearch, true, false); return result > SEARCH_LIMIT ? SEARCH_LIMIT : result; } public void search(String partialName) { log.info("Searching partner using filter {}", partialName); - this.partialName = partialName; + this.partialSearch = partialName; super.reset(); } } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/PartnersDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/PartnersDataModel.java index 23b3e2c..c5f62c3 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/PartnersDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/PartnersDataModel.java @@ -23,11 +23,7 @@ public class PartnersDataModel extends CachedSpringDataModel { @Autowired PartnerService partnerService; - private String partialName; - - private String partialAddress; - - private String partialVatNr; + private String partialSearch; private boolean listAll; @@ -40,24 +36,22 @@ public class PartnersDataModel extends CachedSpringDataModel { public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { Pageable pageable = createPageable(page, pageSize, sortComparator); List result = listAll ? partnerRepository.findAll() : - partnerRepository.search(partialName, partialVatNr, partialAddress, filterShowActive, filterShowInActive, pageable); + partnerRepository.search(partialSearch, filterShowActive, filterShowInActive, pageable); return result; } @Override public int getResultSetCount() { long result = listAll ? partnerRepository.count() : - partnerRepository.count(partialName, partialVatNr, partialAddress, filterShowActive, filterShowInActive); + partnerRepository.count(partialSearch, filterShowActive, filterShowInActive); return (int) result; } - public void search(String partialName, String partialVatNr, String partialAddress) { - log.info("Searching partner using filters: name LIKE {}, VAT number LIKE {}, Address LIKE {}", - partialName, partialVatNr, partialAddress); + public void search(String partialSearch) { + log.info("Searching partner using filters: name or VAT number or Address LIKE {}", + partialSearch); listAll = false; - this.partialName = partialName; - this.partialVatNr = partialVatNr; - this.partialAddress = partialAddress; + this.partialSearch = partialSearch; super.reset(); } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectAssociatesDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectAssociatesDataModel.java index b9498e7..afb8a1c 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectAssociatesDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectAssociatesDataModel.java @@ -2,48 +2,27 @@ package hu.user.lis.ui.data; import hu.user.lis.db.ProjectAssociate; import hu.user.lis.db.repository.ProjectAssociateRepository; -import hu.user.lis.services.data.ProjectAssociateService; 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.Pageable; import org.springframework.stereotype.Component; -import org.zkoss.zul.FieldComparator; import java.util.List; +import java.util.Objects; @Component @Log4j2 -@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) -public class ProjectAssociatesDataModel extends CachedSpringDataModel { +public class ProjectAssociatesDataModel { @Autowired ProjectAssociateRepository projectAssociateRepository; - @Autowired - ProjectAssociateService projectAssociateService; - - private Long projectId; - - - @Override - public List getResultSet(int page, int pageSize, FieldComparator sortComparator) { - Pageable pageable = createPageable(page, pageSize, sortComparator); - List result = projectAssociateRepository.findAllByProjectId(projectId, pageable).getContent(); + public List search(Long projectId) { + List result = null; + if (Objects.nonNull(projectId)) { + log.info("Searching project associate using filter: projectId LIKE {}", projectId); + result = projectAssociateRepository.findAllByProjectId(projectId); + } return result; } - @Override - public int getResultSetCount() { - long result = projectAssociateRepository.countByProjectId(projectId); - return (int) result; - } - - public void search(Long projectId) { - log.info("Searching project associate using filter: projectId LIKE {}", projectId); - this.projectId = projectId; - super.reset(); - } - } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectStatusDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectStatusDataModel.java index f1ce273..abf2ce6 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectStatusDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectStatusDataModel.java @@ -86,4 +86,8 @@ public class ProjectStatusDataModel extends CachedSpringDataModel public void save(ProjectStatus entity) { projectStatusRepository.save(entity); } + + public ProjectStatus getDefault() { + return projectStatusRepository.findByOrder(1); + } } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectsDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectsDataModel.java index 8f6a15b..4869f78 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectsDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/ProjectsDataModel.java @@ -1,8 +1,8 @@ package hu.user.lis.ui.data; import hu.user.lis.db.Project; +import hu.user.lis.db.ProjectStatus; import hu.user.lis.db.repository.ProjectRepository; -import hu.user.lis.services.data.ProjectService; import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -11,7 +11,13 @@ import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; import org.zkoss.zul.FieldComparator; +import javax.persistence.EntityNotFoundException; +import java.lang.reflect.Field; +import java.text.DecimalFormat; +import java.time.Year; +import java.util.HashSet; import java.util.List; +import java.util.Objects; @Component @Log4j2 @@ -21,7 +27,7 @@ public class ProjectsDataModel extends CachedSpringDataModel { ProjectRepository projectRepository; @Autowired - ProjectService projectService; + ProjectStatusDataModel projectStatusDataModel; private String partialName; @@ -70,18 +76,54 @@ public class ProjectsDataModel extends CachedSpringDataModel { } public Project createNew() { - return projectService.createNew(); + String yearSearch = String.format("%s-%%", Year.now().getValue()); + Project lastInYear = projectRepository.findFirstByHumanIdLikeOrderByHumanIdDesc(yearSearch); + int sortOrder = Integer.parseInt(lastInYear.getHumanId().split("-")[1]); + DecimalFormat decFormat = new DecimalFormat("0000"); + String humanId = String.format("%s-%s", Year.now().getValue(), decFormat.format(++sortOrder)); + ProjectStatus projectStatus = projectStatusDataModel.getDefault(); + return Project.builder() + .projectStatus(projectStatus) + .humanId(humanId) + .incomingInvoices(new HashSet<>()) + .outgoingInvoices(new HashSet<>()) + .treasuries(new HashSet<>()) + .active(true) + .build(); } public void addNew(Project entity) { projectRepository.save(entity); } - public Project copy(Project selectedEntity) { - return projectService.copy(selectedEntity); + public Project copy(Project entity) { + return projectRepository.findById(entity.getId()).orElseThrow(EntityNotFoundException::new); + } + + public Project copy(Project entity, String property, Object value) { + Project result = copy(entity); + setPropertyValue(result, property, value); + return result; + } + + public void setPropertyValue(Project entity, String property, Object value) { + if (Objects.isNull(property)) { + return; + } + try { + Field field = entity.getClass().getDeclaredField(property); + field.setAccessible(true); + field.set(entity, value); + } catch (Exception e) { + log.catching(e); + } } public Project save(Project selectedEntity) { return projectRepository.save(selectedEntity); } + + public Project getById(Long id) { + return projectRepository.findById(id).orElseThrow(EntityNotFoundException::new); + } } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/data/ServiceRecordsDataModel.java b/lis-ui/src/main/java/hu/user/lis/ui/data/ServiceRecordsDataModel.java index 62e8f86..9476356 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/data/ServiceRecordsDataModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/data/ServiceRecordsDataModel.java @@ -19,6 +19,7 @@ import javax.persistence.EntityNotFoundException; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Component @Log4j2 @@ -41,6 +42,9 @@ public class ServiceRecordsDataModel extends CachedSpringDataModel getResultSet(int page, int pageSize, FieldComparator sortComparator) { + if (groupByAssociate) { + return getGroupedServiceRecords().values().stream().collect(Collectors.toList()); + } Pageable pageable = createPageable(page, pageSize, sortComparator); List result = listAll ? serviceRecordRepository.findAll(pageable).toList() : serviceRecordRepository.search(filterProjectId, filterAssociateId, pageable); @@ -56,7 +60,7 @@ public class ServiceRecordsDataModel extends CachedSpringDataModel origAssociates; - private Map formAssociates; + + @WireVariable + private ProjectsDataModel projectsDataModel; + @WireVariable private PartnerSelectorDataModel partnerSelectorDataModel; + @WireVariable - private InvoiceService invoiceServiceImpl; + private InvoiceDataModel invoiceDataModel; + @WireVariable - private ProjectService projectServiceImpl; + private TreasuryDataModel treasuryDataModel; + @WireVariable - private TreasuryService treasuryServiceImpl; + private ProjectService projectServiceImpl; + @WireVariable private ServiceRecordsDataModel serviceRecordsDataModel; + @WireVariable private ProjectStatusDataModel projectStatusDataModel; - @Getter + @WireVariable - private ProjectStatusService projectStatusServiceImpl; + private IncomeMarginsDataModel incomeMarginsDataModel; + @WireVariable - private ProjectStatusConverter projectStatusConverter; + private ProjectAssociatesDataModel projectAssociatesDataModel; + @WireVariable - private IncomeMarginsDataModel incomeMarginsDataModel; + private ProjectStatusConverter projectStatusConverter; + @WireVariable private EventBus eventBus; + + private Project formDocument; + + private Project origDocument; + + private Map origAssociates; + + private Map formAssociates; + private boolean formInvalid = true; + private Invoice selectedIncomingInvoice; + private Invoice selectedOutgoingInvoice; + private Treasury selectedTreasury; + private String partialAssociateName; @Init @@ -93,31 +112,21 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen if (Constants.SET_PROJECT_EDITOR_DATA.equals(evt.getName())) { log.info("Got event {}", Constants.SET_PROJECT_EDITOR_DATA); Object data = evt.getData(); - if (data instanceof Map) { - Map mapData = (Map) evt.getData(); - origDocument = (Project) mapData.get("origDocument"); - formDocument = (Project) mapData.get("formDocument"); - } - - if (data instanceof String) { - String id = (String) data; - log.info("Loading entity {} to editor", id); - origDocument = projectServiceImpl.getById(id); - formDocument = projectServiceImpl.copy(origDocument); - } - if (Objects.isNull(data)) { - formDocument = projectServiceImpl.createNew(); + formDocument = projectsDataModel.createNew(); log.info("Loading new entity {} to editor", formDocument.getId()); + } else { + Long id = (Long) data; + Clients.evalJavaScript(String.format("pushNav('/project/%d')", id)); + log.info("Loading entity {} to editor", id); + formDocument = projectsDataModel.getById(id); + origDocument = projectsDataModel.getById(id); } - if (Objects.nonNull(formDocument)) { - Clients.evalJavaScript(String.format("pushNav('/project/%s')", formDocument.getId())); - serviceRecordsDataModel.search(formDocument, true); - associatesDataModel.listAll(); - incomeMarginsDataModel.recalculate(formDocument); - BindUtils.postNotifyChange(this, "formDocument"); - } + serviceRecordsDataModel.search(formDocument, true); + initAssociates(); + incomeMarginsDataModel.recalculate(formDocument); + BindUtils.postNotifyChange(this, "formDocument"); } } @@ -137,20 +146,10 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen @Command public void onEndEdit(@BindingParam("target") Window target, @BindingParam("select") boolean select) { - if (select && formInvalid) { - return; - } - Map args = null; - if (select) { - if (Objects.isNull(origDocument)) { - args = ImmutableMap.of("formDocument", formDocument); - } else { - args = ImmutableMap.of("origDocument", origDocument, "formDocument", formDocument); - } - projectAssociateServiceImpl.update(formDocument, formAssociates); + if (select && !formInvalid) { + projectsDataModel.save(formDocument); + eventBus.showProjectsList(ImmutableMap.of("formDocument", formDocument)); } - - eventBus.showProjectsList(args); } @Command @@ -190,17 +189,35 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen Object value = ctx.getProperty().getValue(); log.info("Validating caused by {} {} {}", target.getId(), property, value); try { - Project newData = projectServiceImpl.copy(formDocument, property, value); + + Project newData = getEntityToValidate(property, value); validate(newData); } catch (Exception e) { log.catching(e); } } + private Project getEntityToValidate() { + return getEntityToValidate(null, null); + } + + private Project getEntityToValidate(String property, Object value) { + Project newData; + if (Objects.isNull(origDocument)) { + if (Objects.nonNull(property)) { + projectsDataModel.setPropertyValue(formDocument, property, value); + } + newData = formDocument; + } else { + newData = projectsDataModel.copy(formDocument, property, value); + } + return newData; + } + private void validate(Project newData) { incomeMarginsDataModel.recalculate(formDocument); updateFormInvalid(false); - if (!Objects.isNull(origDocument)) { + if (Objects.nonNull(origDocument)) { boolean invalid = projectServiceImpl.toString(origDocument).equals(projectServiceImpl.toString(newData)) && !isAssociatesChanged(); updateFormInvalid(invalid); @@ -219,7 +236,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen @Command public void onAddIncoming() { String page = "~./incoming-invoice-editor.zul"; - Invoice editEntity = invoiceServiceImpl.createNew(); + Invoice editEntity = invoiceDataModel.createNew(formDocument); editEntity.setIncome(true); Window editorWindow = (Window) Executions.createComponents(page, null, Collections.singletonMap("formDocument", editEntity)); @@ -229,7 +246,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen selectedIncomingInvoice = editEntity; BindUtils.postNotifyChange(this, "selectedIncomingInvoice"); BindUtils.postNotifyChange(this.formDocument, "incomingInvoices"); - validate(projectServiceImpl.copy(formDocument)); + validate(getEntityToValidate()); } }); editorWindow.doModal(); @@ -239,7 +256,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen @Command public void onEditIncoming() throws JsonProcessingException { String page = "~./incoming-invoice-editor.zul"; - Invoice editEntity = invoiceServiceImpl.copy(selectedIncomingInvoice); + Invoice editEntity = invoiceDataModel.copy(selectedIncomingInvoice); Map arg = new HashMap<>(); arg.put("origDocument", selectedIncomingInvoice); arg.put("formDocument", editEntity); @@ -247,14 +264,13 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen editorWindow.addEventListener("onClose", e -> { if (e.getData() != null) { Invoice modifiedEntity = (Invoice) e.getData(); - List incomingInvoices = formDocument.getIncomingInvoices(); - int index = incomingInvoices.indexOf(selectedIncomingInvoice); + Set incomingInvoices = formDocument.getIncomingInvoices(); incomingInvoices.remove(selectedIncomingInvoice); - incomingInvoices.add(index, modifiedEntity); + incomingInvoices.add(modifiedEntity); selectedIncomingInvoice = modifiedEntity; BindUtils.postNotifyChange(this, "selectedIncomingInvoice"); BindUtils.postNotifyChange(this.formDocument, "incomingInvoices"); - validate(projectServiceImpl.copy(formDocument)); + validate(getEntityToValidate()); } }); editorWindow.doModal(); @@ -270,13 +286,12 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen selectedIncomingInvoice = null; BindUtils.postNotifyChange(this, "selectedIncomingInvoice"); BindUtils.postNotifyChange(this.formDocument, "incomingInvoices"); - validate(projectServiceImpl.copy(formDocument)); } @Command public void onAddOutgoing() { String page = "~./outgoing-invoice-editor.zul"; - Invoice editEntity = invoiceServiceImpl.createNew(); + Invoice editEntity = invoiceDataModel.createNew(formDocument); Window editorWindow = (Window) Executions.createComponents(page, null, Collections.singletonMap("formDocument", editEntity)); editorWindow.addEventListener("onClose", e -> { @@ -285,7 +300,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen selectedOutgoingInvoice = editEntity; BindUtils.postNotifyChange(this, "selectedOutgoingInvoice"); BindUtils.postNotifyChange(this.formDocument, "outgoingInvoices"); - validate(projectServiceImpl.copy(formDocument)); + validate(getEntityToValidate()); } }); editorWindow.doModal(); @@ -295,7 +310,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen @Command public void onEditOutgoing() throws JsonProcessingException { String page = "~./outgoing-invoice-editor.zul"; - Invoice editEntity = invoiceServiceImpl.copy(selectedOutgoingInvoice); + Invoice editEntity = invoiceDataModel.copy(selectedOutgoingInvoice); Map arg = new HashMap<>(); arg.put("origDocument", selectedOutgoingInvoice); arg.put("formDocument", editEntity); @@ -303,14 +318,13 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen editorWindow.addEventListener("onClose", e -> { if (e.getData() != null) { Invoice modifiedEntity = (Invoice) e.getData(); - List outgoingInvoices = formDocument.getOutgoingInvoices(); - int index = outgoingInvoices.indexOf(selectedOutgoingInvoice); + Set outgoingInvoices = formDocument.getOutgoingInvoices(); outgoingInvoices.remove(selectedOutgoingInvoice); - outgoingInvoices.add(index, modifiedEntity); + outgoingInvoices.add(modifiedEntity); selectedOutgoingInvoice = modifiedEntity; BindUtils.postNotifyChange(this, "selectedOutgoingInvoice"); BindUtils.postNotifyChange(this.formDocument, "outgoingInvoices"); - validate(projectServiceImpl.copy(formDocument)); + validate(getEntityToValidate()); } }); editorWindow.doModal(); @@ -326,13 +340,12 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen selectedOutgoingInvoice = null; BindUtils.postNotifyChange(this, "selectedOutgoingInvoice"); BindUtils.postNotifyChange(this.formDocument, "outgoingInvoices"); - validate(projectServiceImpl.copy(formDocument)); } @Command public void onAddTreasury() { String page = "~./treasury-editor.zul"; - Treasury editEntity = treasuryServiceImpl.createNew(); + Treasury editEntity = treasuryDataModel.createNew(formDocument); Window editorWindow = (Window) Executions.createComponents(page, null, Collections.singletonMap("formDocument", editEntity)); editorWindow.addEventListener("onClose", e -> { @@ -341,7 +354,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen selectedTreasury = editEntity; BindUtils.postNotifyChange(this, "selectedTreasury"); BindUtils.postNotifyChange(this.formDocument, "treasuries"); - validate(projectServiceImpl.copy(formDocument)); + validate(getEntityToValidate()); } }); editorWindow.doModal(); @@ -351,20 +364,19 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen @Command public void onEditTreasury() { String page = "~./treasury-editor.zul"; - Treasury editEntity = treasuryServiceImpl.copy(selectedTreasury); + Treasury editEntity = treasuryDataModel.copy(selectedTreasury); Map arg = ImmutableMap.of("origDocument", selectedTreasury, "formDocument", editEntity); Window editorWindow = (Window) Executions.createComponents(page, null, arg); editorWindow.addEventListener("onClose", e -> { if (e.getData() != null) { Treasury modifiedEntity = (Treasury) e.getData(); - List treasuries = formDocument.getTreasuries(); - int index = treasuries.indexOf(selectedTreasury); + Set treasuries = formDocument.getTreasuries(); treasuries.remove(selectedTreasury); - treasuries.add(index, modifiedEntity); + treasuries.add(modifiedEntity); selectedTreasury = modifiedEntity; BindUtils.postNotifyChange(this, "selectedTreasury"); BindUtils.postNotifyChange(this.formDocument, "treasuries"); - validate(projectServiceImpl.copy(formDocument)); + validate(getEntityToValidate()); } }); editorWindow.doModal(); @@ -380,7 +392,6 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen selectedTreasury = null; BindUtils.postNotifyChange(this, "selectedTreasury"); BindUtils.postNotifyChange(this.formDocument, "treasuries"); - validate(projectServiceImpl.copy(formDocument)); } private void updateFormInvalid(boolean invalid) { @@ -416,11 +427,20 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen @Command @NotifyChange("formAssociates") public void onAfterRenderAssociates() { + } + + @NotifyChange("formAssociates") + private void initAssociates() { + associatesDataModel.listAll(); formAssociates = new HashMap<>(); origAssociates = new HashMap<>(); + if (Objects.isNull(formDocument.getId())) { + return; + } + List projectAssociates = projectAssociatesDataModel.search(formDocument.getId()); for (int i = 0; i < associatesDataModel.getSize(); i++) { Associate associate = associatesDataModel.getElementAt(i); - boolean exists = projectAssociateServiceImpl.getAll().stream() + boolean exists = projectAssociates.stream() .anyMatch( pa -> pa.getProject().getId().equals(formDocument.getId()) && pa.getAssociate().getId().equals(associate.getId()) @@ -428,9 +448,10 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen if (exists) { log.info("{} is on project {}", associate.getName(), formDocument.getName()); } - formAssociates.put(associate, exists); - origAssociates.put(associate, exists); + formAssociates.put(associate.getId(), exists); + origAssociates.put(associate.getId(), exists); } + BindUtils.postNotifyChange(this, "formAssociates"); } private boolean isAssociatesChanged() { @@ -441,7 +462,7 @@ public class ProjectEditorModel extends AbstractValidator implements EventListen @Command public void onAssociateChecked() { log.info("Associate checked"); - validate(projectServiceImpl.copy(formDocument)); + validate(origDocument); } } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java b/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java index 9e9f041..21559db 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/event/EventBus.java @@ -43,7 +43,7 @@ public class EventBus { getQueue().publish(new Event(Constants.SET_SERVICE_RECORDS_LIST_DATA, null, data)); } - public void setProjectEditorData(Object data) { + public void setProjectEditorData(Long data) { getQueue().publish(new Event(Constants.SET_PROJECT_EDITOR_DATA, null, data)); } diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java index 1080759..e9ad059 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/IndexViewModel.java @@ -77,7 +77,7 @@ public class IndexViewModel implements EventListener { String id = path.split("/")[2]; selectPage(PROJECT_EDITOR); // eventBus.setProjectEditorData(Collections.singletonMap("id", id)); - eventBus.setProjectEditorData(id); + eventBus.setProjectEditorData(Long.parseLong(id)); } else { if (NAVIGATION.containsKey(path)) { setPage(NAVIGATION.get(path)); @@ -102,7 +102,7 @@ public class IndexViewModel implements EventListener { } if (Constants.SHOW_PROJECT_EDITOR.equals(event.getName())) { selectPage(PROJECT_EDITOR); - eventBus.setProjectEditorData(event.getData()); + eventBus.setProjectEditorData((Long) event.getData()); } if (Constants.SHOW_PROJECTS_LIST.equals(event.getName())) { selectPage(PROJECTS_LIST); diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/LoginViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/LoginViewModel.java new file mode 100644 index 0000000..b2075f9 --- /dev/null +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/LoginViewModel.java @@ -0,0 +1,19 @@ +package hu.user.lis.ui.view; + +import lombok.Getter; +import lombok.extern.log4j.Log4j2; +import org.springframework.boot.info.BuildProperties; +import org.zkoss.zk.ui.select.annotation.VariableResolver; +import org.zkoss.zk.ui.select.annotation.WireVariable; + +@Log4j2 +@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class) +@Getter +public class LoginViewModel { + @WireVariable + BuildProperties buildProperties; + + public LoginViewModel() { + + } +} diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java index 2459dd6..bd4dd88 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/ProjectsViewModel.java @@ -77,8 +77,6 @@ public class ProjectsViewModel extends AsyncBaseModel implements EventListener { @Command public void onAdd() { - Project newEntity = projectsDataModel.createNew(); -// eventBus.showProjectEditor(ImmutableMap.of("formDocument", newEntity)); eventBus.showProjectEditor(null); } @@ -87,9 +85,8 @@ public class ProjectsViewModel extends AsyncBaseModel implements EventListener { if (Objects.isNull(selectedProject)) { return; } -// Project editEntity = projectsDataModel.getProjectService().copy(selectedProject); -// eventBus.showProjectEditor(ImmutableMap.of("origDocument", selectedProject, "formDocument", editEntity)); - eventBus.showProjectEditor(selectedProject.getId()); + Project editEntity = projectsDataModel.copy(selectedProject); + eventBus.showProjectEditor(editEntity.getId()); } public boolean isFilterShowInActive() { diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java index 0b7e927..68fa6ab 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/ServiceRecordsViewModel.java @@ -15,10 +15,7 @@ import org.zkoss.bind.BindContext; import org.zkoss.bind.BindUtils; import org.zkoss.bind.annotation.*; import org.zkoss.zk.ui.Executions; -import org.zkoss.zk.ui.event.Event; -import org.zkoss.zk.ui.event.EventListener; -import org.zkoss.zk.ui.event.InputEvent; -import org.zkoss.zk.ui.event.OpenEvent; +import org.zkoss.zk.ui.event.*; import org.zkoss.zk.ui.select.annotation.VariableResolver; import org.zkoss.zk.ui.select.annotation.WireVariable; import org.zkoss.zk.ui.util.Clients; @@ -172,6 +169,12 @@ public class ServiceRecordsViewModel implements EventListener { serviceRecordsDataModel.listAll(); } + @Command + public void onSort(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) { + SortEvent evt = (SortEvent) ctx.getTriggerEvent(); + //evt.stopPropagation(); + } + @Override public void onEvent(Event evt) throws Exception { if (Constants.SET_SERVICE_RECORDS_LIST_DATA.equals(evt.getName())) { diff --git a/lis-ui/src/main/java/hu/user/lis/ui/view/SettingsViewModel.java b/lis-ui/src/main/java/hu/user/lis/ui/view/SettingsViewModel.java index 4bba82d..28d7ddd 100644 --- a/lis-ui/src/main/java/hu/user/lis/ui/view/SettingsViewModel.java +++ b/lis-ui/src/main/java/hu/user/lis/ui/view/SettingsViewModel.java @@ -4,10 +4,8 @@ import hu.user.lis.db.ProjectStatus; import hu.user.lis.ui.data.ProjectStatusDataModel; import lombok.Getter; import lombok.extern.log4j.Log4j2; -import org.zkoss.bind.BindContext; +import org.zkoss.bind.annotation.BindingParam; import org.zkoss.bind.annotation.Command; -import org.zkoss.bind.annotation.ContextParam; -import org.zkoss.bind.annotation.ContextType; import org.zkoss.bind.annotation.Init; import org.zkoss.zk.ui.select.annotation.VariableResolver; import org.zkoss.zk.ui.select.annotation.WireVariable; @@ -60,14 +58,11 @@ public class SettingsViewModel extends AsyncBaseModel { } @Command - public void onActiveChecked(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) { -// CheckEvent evt = (CheckEvent) ctx.getTriggerEvent(); -// ProjectStatus entity = (ProjectStatus) evt.getData(); -// projectStatusDataModel.save(entity); + public void onActiveChecked(@BindingParam("entity") ProjectStatus entity) { + projectStatusDataModel.save(entity); } public void setSelectedProjectStatus(ProjectStatus selectedProjectStatus) { - log.info("Sekected {}", selectedProjectStatus.getName()); this.selectedProjectStatus = selectedProjectStatus; } } diff --git a/lis-ui/src/main/resources/metainfo/zk/zk.xml b/lis-ui/src/main/resources/metainfo/zk/zk.xml index 861c2fa..04e41f1 100644 --- a/lis-ui/src/main/resources/metainfo/zk/zk.xml +++ b/lis-ui/src/main/resources/metainfo/zk/zk.xml @@ -5,6 +5,31 @@ 300 /timeout + + + ajax + 403 + /login + + + ajax + 410 + /timeout + server-push + + + + + + + + + + + + + + diff --git a/lis-ui/src/main/resources/web/index.zul b/lis-ui/src/main/resources/web/index.zul index 9482f5b..560d215 100644 --- a/lis-ui/src/main/resources/web/index.zul +++ b/lis-ui/src/main/resources/web/index.zul @@ -3,9 +3,9 @@