Skip to content
56 changes: 56 additions & 0 deletions NMSReportingSuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,62 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
</dependency>


<!-- ActiveMQ Dependencies -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>5.15.9</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.15.9</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<version>5.15.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${springframework.version}</version>
</dependency>


<!-- ActiveMQ Dependencies -->
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
<version>5.15.16</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.15.16</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<version>5.15.16</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.15.16</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>javax.jms-api</artifactId>
<version>2.0.1</version>
</dependency>


<!--Number formatter for excel reports-->
<dependency>
<groupId>com.ibm.icu</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
Expand All @@ -33,6 +34,9 @@ public class EtlNotificationServiceImpl implements EtlNotificationService {
@Autowired
private NoticeDao noticeDao;

@Autowired
private JmsTemplate jmsTemplate;

public final String getNoticeTypeAsMonthlyReports = "MONTHLY_REPORTS";
public final String getNoticeTypeAsQuarterReports = "QUARTERLY_NOTICE";
public final String getNoticeTypeAsYearlyReports = "YEARLY_NOTICE";
Expand Down Expand Up @@ -213,18 +217,21 @@ private void addGeneratedReportNotifications(List<Notice> notices, List<String>
@Override
@Transactional
public boolean scheduledNotification() {
if (isAutoGenerate()){
try {
dailyNotifications();
} catch (Exception e) {
LOGGER.error("Error occurred while processing daily failed ETL: ", e);
if (isAutoGenerate()) {
try {
jmsTemplate.convertAndSend("etl-notification", "PROCESS_DAILY_NOTIFICATIONS");
LOGGER.info("Successfully sent PROCESS_DAILY_NOTIFICATIONS to etl-notification queue.");
} catch (Exception e) {
LOGGER.error("Error occurred while sending message to etl-notification queue: ", e);
return false;
}
return true;
}
LOGGER.info("Finished dailyFailedEtlForTheDay method");
return true;
}
LOGGER.info("Auto-generation is disabled. Skipping scheduled notification.");
return false;
}


private java.sql.Date getYesterdayDate() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.beehyv.nmsreporting.config;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.converter.MessageConverter;
import org.springframework.jms.support.converter.SimpleMessageConverter;

import javax.jms.ConnectionFactory;
import javax.jms.Queue;

import java.util.Arrays;

import static com.beehyv.nmsreporting.utils.Global.getPropertyValueApp;

@Configuration
@EnableJms
@ComponentScan(basePackages = {"com.beehyv.nmsreporting.listeners", "com.beehyv.nmsreporting.otherpackages"})
public class ActiveMQConfig {

private static final String activeMqUrl = getPropertyValueApp("activeMqUrl");


@Bean
public ActiveMQConnectionFactory connectionFactory() {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
factory.setBrokerURL(activeMqUrl);
factory.setTrustAllPackages(false);
factory.setTrustedPackages(Arrays.asList(
"com.beehyv.nmsreporting.model",
"com.beehyv.nmsreporting.entity",
"java.util",
"java.lang"
));
return factory;
}

@Bean
public JmsTemplate jmsTemplate() {
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(connectionFactory());
template.setMessageConverter(messageConverter());
return template;
}

@Bean
public MessageConverter messageConverter() {
return new SimpleMessageConverter();
}

@Bean
public JmsListenerContainerFactory<?> jmsListenerContainerFactory(ConnectionFactory connectionFactory) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
// Optional: Configure additional settings
factory.setConcurrency("1-5"); // 1-5 concurrent consumers
factory.setRecoveryInterval(1000L); // 1 second recovery interval
return factory;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.beehyv.nmsreporting.entity;

import java.io.Serializable;
import java.util.Date;


public class ReportMessage implements Serializable {
private static final long serialVersionUID = 1L;
private String reportType;
private Date fromDate;
private Date toDate;
private boolean isWeekly;

public ReportMessage() {}

public ReportMessage(String reportType, Date fromDate, Date toDate, boolean isWeekly) {
this.reportType = reportType;
this.fromDate = fromDate;
this.toDate = toDate;
this.isWeekly = isWeekly;
}

public String getReportType() {
return reportType;
}

public void setReportType(String reportType) {
this.reportType = reportType;
}

public Date getFromDate() {
return fromDate;
}

public void setFromDate(Date fromDate) {
this.fromDate = fromDate;
}

public Date getToDate() {
return toDate;
}

public void setToDate(Date toDate) {
this.toDate = toDate;
}

public boolean isWeekly() {
return isWeekly;
}

public void setWeekly(boolean weekly) {
isWeekly = weekly;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;

import static com.beehyv.nmsreporting.utils.Global.isAutoGenerate;

Expand All @@ -19,18 +20,19 @@ public class AshaSmsAutoTargetFileGeneration {
@Autowired
AshaTargetFileService ashaTargetFileService;

@Autowired
private JmsTemplate jmsTemplate;

public void processTargetFile() {

if (isAutoGenerate()) {
try {
TargetFileNotification targetFileNotification = ashaTargetFileService.generateTargetFile();
if (targetFileNotification != null) {
smsNotificationService.sendNotificationRequest(targetFileNotification);
} else {
LOGGER.error("Failed to generate target file.");
}

jmsTemplate.convertAndSend("target-file-queue", "PROCESS_TARGET_FILE");

LOGGER.info("Published target file processing event to 'target-file-queue'.");
} catch (Exception e) {
LOGGER.error("Error processing target file: {}", e.getMessage(), e);
LOGGER.error("Failed to publish target file processing event: {}", e.getMessage(), e);
}
}
}
Expand Down
Loading