Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : using blaze MultiSelect View #363

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import org.gradle.plugins.ide.eclipse.model.SourceFolder
buildscript {
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
classpath "org.owasp:dependency-check-gradle:${owasp_plugin_version}"
Expand Down Expand Up @@ -67,6 +68,11 @@ dependencies {
runtimeOnly "org.postgresql:postgresql"
implementation "org.liquibase:liquibase-core"

// Blaze Persistance
implementation('com.blazebit:blaze-persistence-integration-spring-data-3.3')
implementation('com.blazebit:blaze-persistence-integration-hibernate-6.2')
implementation('com.blazebit:blaze-persistence-integration-entity-view-spring-6.0')

implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:${springdoc_openapi_version}"
runtimeOnly "io.micrometer:micrometer-registry-prometheus"

Expand All @@ -92,6 +98,12 @@ dependencies {
testAnnotationProcessor("org.mapstruct.extensions.spring:mapstruct-spring-extensions:1.1.1")
}

dependencyManagement {
imports {
mavenBom "com.blazebit:blaze-persistence-bom:${blaze_persistence_version}"
}
}

tasks.withType(JavaCompile).configureEach {
options.compilerArgs += [
'-Amapstruct.suppressGeneratorTimestamp=true',
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ spotless_version=6.25.0
jacoco_min_coverage_required=0.84

spring_boot_version=3.4.0-M1
blaze_persistence_version=1.6.12
spring_dependency_management_version=1.1.6
springdoc_openapi_version=2.6.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2014 - 2024 Blazebit.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.learning.mfscreener.config.db;

import com.blazebit.persistence.Criteria;
import com.blazebit.persistence.CriteriaBuilderFactory;
import com.blazebit.persistence.integration.view.spring.EnableEntityViews;
import com.blazebit.persistence.spi.CriteriaBuilderConfiguration;
import com.blazebit.persistence.spring.data.repository.config.EnableBlazeRepositories;
import com.blazebit.persistence.view.EntityViewManager;
import com.blazebit.persistence.view.spi.EntityViewConfiguration;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceUnit;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;

@Configuration(proxyBeanMethods = false)
@EnableEntityViews(basePackages = {"com.learning.mfscreener.models.entityviews"})
@EnableBlazeRepositories(basePackages = "com.learning.mfscreener.repository")
public class BlazePersistenceConfiguration {

@PersistenceUnit
private EntityManagerFactory entityManagerFactory;

@Bean
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@Lazy(false)
CriteriaBuilderFactory createCriteriaBuilderFactory() {
CriteriaBuilderConfiguration config = Criteria.getDefault();
return config.createCriteriaBuilderFactory(entityManagerFactory);
}

@Bean
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@Lazy(false)
EntityViewManager createEntityViewManager(
CriteriaBuilderFactory cbf, EntityViewConfiguration entityViewConfiguration) {
return entityViewConfiguration.createEntityViewManager(cbf);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.learning.mfscreener.models.entityviews;

import com.blazebit.persistence.view.EntityView;
import com.blazebit.persistence.view.IdMapping;
import com.learning.mfscreener.entities.InvestorInfoEntity;
import java.time.LocalDateTime;

/**
* EntityView for {@link com.learning.mfscreener.entities.InvestorInfoEntity}
*/
@EntityView(InvestorInfoEntity.class)
public interface InvestorInfoEntityView {
String getCreatedBy();

LocalDateTime getCreatedDate();

String getLastModifiedBy();

LocalDateTime getLastModifiedDate();

@IdMapping
Long getId();

String getEmail();

String getName();

String getMobile();

String getAddress();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.learning.mfscreener.models.entityviews;

import com.blazebit.persistence.view.EntityView;
import com.blazebit.persistence.view.FetchStrategy;
import com.blazebit.persistence.view.IdMapping;
import com.blazebit.persistence.view.Mapping;
import com.learning.mfscreener.entities.CasTypeEnum;
import com.learning.mfscreener.entities.FileTypeEnum;
import com.learning.mfscreener.entities.UserCASDetailsEntity;
import java.time.LocalDateTime;
import java.util.List;

/**
* EntityView for {@link com.learning.mfscreener.entities.UserCASDetailsEntity}
*/
@EntityView(UserCASDetailsEntity.class)
public interface UserCASDetailsEntityView {
String getCreatedBy();

LocalDateTime getCreatedDate();

String getLastModifiedBy();

LocalDateTime getLastModifiedDate();

@IdMapping
Long getId();

CasTypeEnum getCasTypeEnum();

FileTypeEnum getFileTypeEnum();

InvestorInfoEntityView getInvestorInfoEntity();

@Mapping(fetch = FetchStrategy.MULTISET)
List<UserFolioDetailsEntityView> getFolioEntities();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.learning.mfscreener.models.entityviews;

import com.blazebit.persistence.view.EntityView;
import com.blazebit.persistence.view.FetchStrategy;
import com.blazebit.persistence.view.IdMapping;
import com.blazebit.persistence.view.Mapping;
import com.learning.mfscreener.entities.UserFolioDetailsEntity;
import java.time.LocalDateTime;
import java.util.List;

/**
* EntityView for {@link com.learning.mfscreener.entities.UserFolioDetailsEntity}
*/
@EntityView(UserFolioDetailsEntity.class)
public interface UserFolioDetailsEntityView {
String getCreatedBy();

LocalDateTime getCreatedDate();

String getLastModifiedBy();

LocalDateTime getLastModifiedDate();

@IdMapping
Long getId();

String getFolio();

String getAmc();

String getPan();

String getKyc();

@Mapping(fetch = FetchStrategy.MULTISET)
List<UserSchemeDetailsEntityView> getSchemeEntities();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.learning.mfscreener.models.entityviews;

import com.blazebit.persistence.view.EntityView;
import com.blazebit.persistence.view.FetchStrategy;
import com.blazebit.persistence.view.IdMapping;
import com.blazebit.persistence.view.Mapping;
import com.learning.mfscreener.entities.UserSchemeDetailsEntity;
import java.time.LocalDateTime;
import java.util.List;

/**
* EntityView for {@link com.learning.mfscreener.entities.UserSchemeDetailsEntity}
*/
@EntityView(UserSchemeDetailsEntity.class)
public interface UserSchemeDetailsEntityView {
String getCreatedBy();

LocalDateTime getCreatedDate();

String getLastModifiedBy();

LocalDateTime getLastModifiedDate();

@IdMapping
Long getId();

String getScheme();

String getIsin();

String getAdvisor();

String getRtaCode();

String getRta();

String getType();

Long getAmfi();

String getMyopen();

String getClose();

String getCloseCalculated();

@Mapping(fetch = FetchStrategy.MULTISET)
List<UserTransactionDetailsEntityView> getTransactionEntities();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.learning.mfscreener.models.entityviews;

import com.blazebit.persistence.view.EntityView;
import com.blazebit.persistence.view.IdMapping;
import com.learning.mfscreener.entities.UserTransactionDetailsEntity;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
* EntityView for {@link com.learning.mfscreener.entities.UserTransactionDetailsEntity}
*/
@EntityView(UserTransactionDetailsEntity.class)
public interface UserTransactionDetailsEntityView {
String getCreatedBy();

LocalDateTime getCreatedDate();

String getLastModifiedBy();

LocalDateTime getLastModifiedDate();

@IdMapping
Long getId();

LocalDate getTransactionDate();

String getDescription();

Double getAmount();

Double getUnits();

Double getNav();

Double getBalance();

String getType();

String getDividendRate();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.learning.mfscreener.repository;

import com.learning.mfscreener.models.entityviews.UserCASDetailsEntityView;

public interface CustomUserCASDetailsEntityRepository {

UserCASDetailsEntityView findByInvestorEmailAndName(String email, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import org.springframework.stereotype.Repository;

@Repository
public interface UserCASDetailsEntityRepository extends JpaRepository<UserCASDetailsEntity, Long> {
public interface UserCASDetailsEntityRepository
extends JpaRepository<UserCASDetailsEntity, Long>, CustomUserCASDetailsEntityRepository {
rajadilipkolli marked this conversation as resolved.
Show resolved Hide resolved

@Query(
nativeQuery = true,
Expand Down Expand Up @@ -58,11 +59,4 @@ SELECT SUM(balance) AS balanceUnits,
""")
List<PortfolioDetailsProjection> getPortfolioDetails(
@Param("pan") String panNumber, @Param("asOfDate") LocalDate asOfDate);

@Query(
"""
select u from UserCASDetailsEntity u join fetch u.folioEntities join fetch u.investorInfoEntity as i
where i.email = :email and i.name = :name
""")
UserCASDetailsEntity findByInvestorEmailAndName(@Param("email") String email, @Param("name") String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.learning.mfscreener.repository.impl;

import com.blazebit.persistence.CriteriaBuilderFactory;
import com.blazebit.persistence.view.EntityViewManager;
import com.blazebit.persistence.view.EntityViewSetting;
import com.learning.mfscreener.entities.UserCASDetailsEntity;
import com.learning.mfscreener.models.entityviews.UserCASDetailsEntityView;
import com.learning.mfscreener.repository.CustomUserCASDetailsEntityRepository;
import jakarta.persistence.EntityManager;

public class CustomUserCASDetailsEntityRepositoryImpl implements CustomUserCASDetailsEntityRepository {

private final EntityManager entityManager;

private final CriteriaBuilderFactory criteriaBuilderFactory;

private final EntityViewManager entityViewManager;

public CustomUserCASDetailsEntityRepositoryImpl(
EntityManager entityManager,
CriteriaBuilderFactory criteriaBuilderFactory,
EntityViewManager entityViewManager) {
this.entityManager = entityManager;
this.criteriaBuilderFactory = criteriaBuilderFactory;
this.entityViewManager = entityViewManager;
}

@Override
public UserCASDetailsEntityView findByInvestorEmailAndName(String email, String name) {
return entityViewManager
.applySetting(
EntityViewSetting.create(UserCASDetailsEntityView.class),
criteriaBuilderFactory.create(entityManager, UserCASDetailsEntity.class))
.where("investorInfoEntity.email")
.eq(email)
.where("investorInfoEntity.name")
.eq(name) // Adding condition for the name
.getSingleResult();
}
}
Loading
Loading