From 935ab8b9c517740216567df72b1bb175dd935948 Mon Sep 17 00:00:00 2001 From: Bennett Date: Sun, 29 Mar 2026 23:51:52 +0300 Subject: [PATCH 1/2] release: Fix error sending notification --- .../flextuma/core/services/BaseService.java | 60 ++++++++++++------- .../services/NotificationService.java | 27 ++++++++- .../services/DashboardServiceTest.java | 1 - 3 files changed, 63 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/flexcodelabs/flextuma/core/services/BaseService.java b/src/main/java/com/flexcodelabs/flextuma/core/services/BaseService.java index 71822e0..8777d07 100644 --- a/src/main/java/com/flexcodelabs/flextuma/core/services/BaseService.java +++ b/src/main/java/com/flexcodelabs/flextuma/core/services/BaseService.java @@ -446,7 +446,7 @@ protected void onPostSave(T entity) { } protected void initializeAssociationsForResponse(Object entity, int depth) { - if (entity == null || depth < 0) { + if (!shouldProcessEntity(entity, depth)) { return; } @@ -456,33 +456,50 @@ protected void initializeAssociationsForResponse(Object entity, int depth) { return; } + processAssociations(entity, managedType, depth); + } + + private boolean shouldProcessEntity(Object entity, int depth) { + return entity != null && depth >= 0; + } + + private void processAssociations(Object entity, ManagedType managedType, int depth) { BeanWrapper wrapper = new BeanWrapperImpl(entity); for (Attribute attribute : managedType.getAttributes()) { - if (!attribute.isAssociation() || !wrapper.isReadableProperty(attribute.getName())) { + if (!isProcessableAssociation(attribute, wrapper)) { continue; } Object value = wrapper.getPropertyValue(attribute.getName()); - if (value == null) { - continue; + if (value != null) { + Hibernate.initialize(value); + processAssociationValue(value, depth); } + } + } - Hibernate.initialize(value); - if (depth == 0) { - continue; - } + private boolean isProcessableAssociation(Attribute attribute, BeanWrapper wrapper) { + return attribute.isAssociation() && wrapper.isReadableProperty(attribute.getName()); + } - if (value instanceof Collection collection) { - for (Object item : collection) { - initializeSingularAssociations(item, depth - 1); - } - continue; - } + private void processAssociationValue(Object value, int depth) { + if (depth == 0) { + return; + } + if (value instanceof Collection collection) { + processCollectionAssociations(collection, depth); + } else { initializeSingularAssociations(value, depth - 1); } } + private void processCollectionAssociations(Collection collection, int depth) { + for (Object item : collection) { + initializeSingularAssociations(item, depth - 1); + } + } + private void initializeSingularAssociations(Object entity, int depth) { if (entity == null || depth < 0) { return; @@ -496,18 +513,17 @@ private void initializeSingularAssociations(Object entity, int depth) { BeanWrapper wrapper = new BeanWrapperImpl(entity); for (Attribute attribute : managedType.getAttributes()) { - if (!attribute.isAssociation() || attribute.isCollection() || !wrapper.isReadableProperty(attribute.getName())) { + if (!attribute.isAssociation() || attribute.isCollection() + || !wrapper.isReadableProperty(attribute.getName())) { continue; } Object value = wrapper.getPropertyValue(attribute.getName()); - if (value == null) { - continue; - } - - Hibernate.initialize(value); - if (depth > 0) { - initializeSingularAssociations(value, depth - 1); + if (value != null) { + Hibernate.initialize(value); + if (depth > 0) { + initializeSingularAssociations(value, depth - 1); + } } } } diff --git a/src/main/java/com/flexcodelabs/flextuma/modules/notification/services/NotificationService.java b/src/main/java/com/flexcodelabs/flextuma/modules/notification/services/NotificationService.java index 27035ad..503a5ea 100644 --- a/src/main/java/com/flexcodelabs/flextuma/modules/notification/services/NotificationService.java +++ b/src/main/java/com/flexcodelabs/flextuma/modules/notification/services/NotificationService.java @@ -3,6 +3,7 @@ import java.util.Map; import java.util.Optional; +import org.hibernate.Hibernate; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -146,6 +147,28 @@ private SmsLog processAndSaveSms(User user, SmsConnector connector, String phone } } - return logRepository.save(log); + SmsLog savedLog = logRepository.save(log); + initializeForResponse(savedLog); + return savedLog; } -} \ No newline at end of file + + private void initializeForResponse(SmsLog smsLog) { + Hibernate.initialize(smsLog); + + if (smsLog.getCreatedBy() != null) { + Hibernate.initialize(smsLog.getCreatedBy()); + } + + if (smsLog.getUpdatedBy() != null) { + Hibernate.initialize(smsLog.getUpdatedBy()); + } + + if (smsLog.getConnector() != null) { + Hibernate.initialize(smsLog.getConnector()); + } + + if (smsLog.getTemplate() != null) { + Hibernate.initialize(smsLog.getTemplate()); + } + } +} diff --git a/src/test/java/com/flexcodelabs/flextuma/modules/dashboard/services/DashboardServiceTest.java b/src/test/java/com/flexcodelabs/flextuma/modules/dashboard/services/DashboardServiceTest.java index c1c9412..e6a01f6 100644 --- a/src/test/java/com/flexcodelabs/flextuma/modules/dashboard/services/DashboardServiceTest.java +++ b/src/test/java/com/flexcodelabs/flextuma/modules/dashboard/services/DashboardServiceTest.java @@ -27,7 +27,6 @@ import com.flexcodelabs.flextuma.core.entities.finance.Wallet; import com.flexcodelabs.flextuma.core.entities.sms.SmsConnector; import com.flexcodelabs.flextuma.core.entities.sms.SmsLog; -import com.flexcodelabs.flextuma.core.enums.SmsCampaignStatus; import com.flexcodelabs.flextuma.core.enums.SmsLogStatus; import com.flexcodelabs.flextuma.core.helpers.CurrentUserResolver; import com.flexcodelabs.flextuma.core.repositories.SmsCampaignRepository; From 12eb367669004d9b30bcee93d354539e4806bd7d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 29 Mar 2026 20:52:43 +0000 Subject: [PATCH 2/2] Release v0.0.34 [skip ci] --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2648032..d258db5 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ plugins { } group = 'com.flexcodelabs' -version = '0.0.33' +version = '0.0.34' description = 'Flextuma App' java {