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 views #287

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -0,0 +1,39 @@
package com.learning.mfscreener.repository;

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 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();
}
Comment on lines +10 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class declaration, fields, and constructor are correctly implemented, ensuring proper dependency management. The method findByInvestorEmailAndName uses EntityViewManager and CriteriaBuilderFactory effectively to query UserCASDetailsEntity based on email and name. However, consider handling NoResultException that getSingleResult() may throw if no entity matches the criteria.

public UserCASDetailsEntityView findByInvestorEmailAndName(String email, String name) {
    try {
        return entityViewManager
                .applySetting(
                        EntityViewSetting.create(UserCASDetailsEntityView.class),
                        criteriaBuilderFactory.create(entityManager, UserCASDetailsEntity.class))
                .where("investorInfoEntity.email")
                .eq(email)
                .where("investorInfoEntity.name")
                .eq(name)
                .getSingleResult();
    } catch (jakarta.persistence.NoResultException e) {
        return null; // Or handle accordingly
    }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface UserCASDetailsEntityRepository extends JpaRepository<UserCASDetailsEntity, Long> {
public interface UserCASDetailsEntityRepository
extends JpaRepository<UserCASDetailsEntity, Long>, CustomUserCASDetailsEntityRepository {

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

@Transactional(readOnly = true)
@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
Expand Up @@ -14,6 +14,8 @@
import com.learning.mfscreener.mapper.CasDetailsMapper;
import com.learning.mfscreener.models.MFSchemeDTO;
import com.learning.mfscreener.models.PortfolioDetailsDTO;
import com.learning.mfscreener.models.entityviews.UserCASDetailsEntityView;
import com.learning.mfscreener.models.entityviews.UserFolioDetailsEntityView;
import com.learning.mfscreener.models.portfolio.CasDTO;
import com.learning.mfscreener.models.portfolio.UserFolioDTO;
import com.learning.mfscreener.models.portfolio.UserSchemeDTO;
Expand Down Expand Up @@ -101,7 +103,8 @@ UploadResponseHolder findDelta(String email, String name, CasDTO casDTO) {
List<UserTransactionDetailsEntity> userTransactionDetailsEntityList =
this.userTransactionDetailsEntityRepository.findAllTransactionsByEmailAndName(email, name);

UserCASDetailsEntity userCASDetailsEntity = casDetailsEntityRepository.findByInvestorEmailAndName(email, name);
UserCASDetailsEntityView userCASDetailsEntityView =
casDetailsEntityRepository.findByInvestorEmailAndName(email, name);

if (userTransactionDTOListCount == userTransactionDetailsEntityList.size()) {
log.info("No new transactions are added");
Expand All @@ -112,16 +115,16 @@ UploadResponseHolder findDelta(String email, String name, CasDTO casDTO) {
AtomicInteger transactionsCounter = new AtomicInteger();

// Verify if new folios are added
List<String> existingFolios = userCASDetailsEntity.getFolioEntities().stream()
.map(UserFolioDetailsEntity::getFolio)
List<String> existingFolios = userCASDetailsEntityView.getFolioEntities().stream()
.map(UserFolioDetailsEntityView::getFolio)
.toList();

folioDTOList.forEach(userFolioDTO -> {
String folio = userFolioDTO.folio();
if (!existingFolios.contains(folio)) {
log.info("New folio: {} created that is not present in the database", folio);
userCASDetailsEntity.addFolioEntity(
casDetailsMapper.mapUserFolioDTOToUserFolioDetailsEntity(userFolioDTO));
// userCASDetailsEntityView.addFolioEntity(
// casDetailsMapper.mapUserFolioDTOToUserFolioDetailsEntity(userFolioDTO));
folioCounter.incrementAndGet();
int newTransactions = userFolioDTO.schemes().stream()
.map(UserSchemeDTO::transactions)
Expand Down Expand Up @@ -184,7 +187,8 @@ UploadResponseHolder findDelta(String email, String name, CasDTO casDTO) {
});
}
});
userCASDetailsEntity.setFolioEntities(existingUserFolioDetailsEntityList);
// TODO
// userCASDetailsEntityView.setFolioEntities(existingUserFolioDetailsEntityList);
Comment on lines +214 to +215
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TODO comment indicates unfinished work or a placeholder for future implementation. It's crucial to track these tasks to ensure they are completed or addressed in subsequent updates.

Would you like assistance in implementing the functionality mentioned in the TODO comment, or should it be tracked as an issue for future resolution?


// Check if all new transactions are added as part of adding schemes
if (userTransactionDTOListCount == (userTransactionDetailsEntityList.size() + transactionsCounter.get())) {
Expand Down Expand Up @@ -244,7 +248,7 @@ UploadResponseHolder findDelta(String email, String name, CasDTO casDTO) {
});
}
}
return new UploadResponseHolder(userCASDetailsEntity, folioCounter.get(), transactionsCounter.get());
return new UploadResponseHolder(null, folioCounter.get(), transactionsCounter.get());
}

public PortfolioResponse getPortfolioByPAN(String panNumber, LocalDate asOfDate) {
Expand Down
Loading