Notification Code.
This commit is contained in:
@@ -15,7 +15,9 @@ import java.util.zip.ZipOutputStream;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import net.gepafin.tendermanagement.entities.*;
|
||||
import net.gepafin.tendermanagement.enums.DocumentSourceTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.NotificationTypeEnum;
|
||||
import net.gepafin.tendermanagement.enums.VersionActionTypeEnum;
|
||||
import net.gepafin.tendermanagement.model.request.NotificationReq;
|
||||
import net.gepafin.tendermanagement.model.request.VersionHistoryRequest;
|
||||
import net.gepafin.tendermanagement.model.response.*;
|
||||
import net.gepafin.tendermanagement.repositories.*;
|
||||
@@ -108,6 +110,18 @@ public class CallDao {
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
private NotificationDao notificationDao;
|
||||
|
||||
@Autowired
|
||||
private BeneficiaryRepository beneficiaryRepository;
|
||||
|
||||
@Autowired
|
||||
private NotificationTypeRepository notificationTypeRepository;
|
||||
|
||||
@Autowired
|
||||
private UserWithCompanyRepository userWithCompanyRepository;
|
||||
|
||||
public CallResponse createCallStep1(CreateCallRequestStep1 createCallRequest, UserEntity userEntity) {
|
||||
createCallRequest.setRegionId(userEntity.getRoleEntity().getRegion().getId());
|
||||
CallEntity callEntity = convertToCallEntity(createCallRequest, userEntity);
|
||||
@@ -828,13 +842,36 @@ public class CallDao {
|
||||
validateStatusChange(currentStatus, statusReq);
|
||||
callEntity.setStatus(statusReq.getValue());
|
||||
callEntity = callRepository.save(callEntity);
|
||||
|
||||
|
||||
//Creating notification.
|
||||
List<Long> userIds = beneficiaryRepository.findUserIdsByHubIdAndBeneficiaryId(callEntity.getHub().getId());
|
||||
Map<String, String> placeholders = new HashMap<>();
|
||||
placeholders.put("{{call_name}}", callEntity.getName());
|
||||
userIds.forEach(userId -> {
|
||||
NotificationReq notificationReq = createNotificationReq(NotificationTypeEnum.CALL_CREATED.getValue(), placeholders, userId);
|
||||
List<Long> companyIds = userWithCompanyRepository.findActiveCompanyIdsByUserId(notificationReq.getUserId());
|
||||
notificationReq.setCompanyIds(companyIds);
|
||||
notificationDao.sendNotification(notificationReq);
|
||||
});
|
||||
|
||||
/** This code is responsible for adding a version history log for the "update call status" operation **/
|
||||
loggingUtil.addVersionHistory(VersionHistoryRequest.builder().request(request).actionType(VersionActionTypeEnum.UPDATE).oldData(oldCallEntity).newData(callEntity).build());
|
||||
|
||||
|
||||
return convertToCallResponseBean(callEntity);
|
||||
}
|
||||
|
||||
public NotificationReq createNotificationReq(String notificationType, Map<String, String> placeholders, Long userId) {
|
||||
// Create NotificationReq object
|
||||
NotificationReq notificationReq = new NotificationReq();
|
||||
NotificationTypeEntity notificationTypeEntity = notificationTypeRepository.findByNotificationNameAndIsDeletedFalse(notificationType);
|
||||
notificationReq.setNotificationType(notificationType);
|
||||
String message = Utils.replacePlaceholders(notificationTypeEntity.getJsonTemplate(), placeholders);
|
||||
notificationReq.setMessage(message);
|
||||
notificationReq.setUserId(userId);
|
||||
return notificationReq;
|
||||
}
|
||||
|
||||
|
||||
private void validateStatusChange(CallStatusEnum currentStatus, CallStatusEnum newStatus) {
|
||||
if (currentStatus == newStatus) {
|
||||
throw new CustomValidationException(Status.VALIDATION_ERROR,
|
||||
|
||||
Reference in New Issue
Block a user