Skip to content
23 changes: 23 additions & 0 deletions NMSReportingSuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,29 @@ 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>
Comment thread
dinesh-beehyv marked this conversation as resolved.


<!--Number formatter for excel reports-->
<dependency>
<groupId>com.ibm.icu</groupId>
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); // Don't trust all packages for security
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.");
}
// You can publish a simple text message...
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

import com.beehyv.nmsreporting.business.AdminService;
import com.beehyv.nmsreporting.business.EmailService;
import com.beehyv.nmsreporting.entity.ReportMessage;
import com.beehyv.nmsreporting.enums.ReportType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.transaction.annotation.Transactional;

import javax.jms.Destination;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Queue;

import static com.beehyv.nmsreporting.enums.ReportType.maCourse;
import static com.beehyv.nmsreporting.utils.Global.isAutoGenerate;
Expand All @@ -20,27 +27,39 @@ public class AutoReportEmailGeneration {
@Autowired
AdminService adminService;

@Autowired
private JmsTemplate jmsTemplate;

@Autowired
EmailService emailService;


private static final Logger LOGGER = LoggerFactory.getLogger(AutoReportEmailGeneration.class);



public boolean executeInternal() {
if(isAutoGenerate()) {
Calendar aCalendar = Calendar.getInstance();
aCalendar.add(Calendar.MONTH, -1);
aCalendar.set(Calendar.DATE, 1);
aCalendar.set(Calendar.MILLISECOND, 0);
aCalendar.set(Calendar.SECOND, 0);
aCalendar.set(Calendar.MINUTE, 0);
aCalendar.set(Calendar.HOUR_OF_DAY, 0);
if (!isAutoGenerate()) {
LOGGER.info("Auto-generation is disabled. Skipping report generation.");
return false;
}
try {

Date fromDate = aCalendar.getTime();
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
calendar.set(Calendar.DATE, 1);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
Date fromDate = calendar.getTime();
calendar.add(Calendar.MONTH, 1);
Date toDate = calendar.getTime();

LOGGER.info("Starting report generation preprocessing for period from {} to {}", fromDate, toDate);

aCalendar.add(Calendar.MONTH, 1);

Date toDate = aCalendar.getTime();

Date startDate = new Date(0);
/*adminService.getCircleWiseAnonymousFiles(fromDate,toDate);*/
System.out.println("Report generation started");
adminService.createFiles(maCourse.getReportType());
adminService.createFolders(ReportType.maAnonymous.getReportType());
adminService.createFiles(ReportType.maInactive.getReportType());
Expand All @@ -51,52 +70,69 @@ public boolean executeInternal() {
adminService.createFiles(ReportType.motherRejected.getReportType());
adminService.createFiles(ReportType.childRejected.getReportType());

LOGGER.info("Preprocessing complete. Files and folders created.");


adminService.createMotherImportRejectedFiles(1,false);
System.out.println("Mother_Rejection Monthly reports generated");
adminService.createChildImportRejectedFiles(1,false);
System.out.println("Child_Rejection Monthly reports generated");
adminService.getCircleWiseAnonymousFiles(fromDate, toDate);
System.out.println("MA_Anonymous reports generated");
adminService.getCumulativeCourseCompletionFiles(toDate);
System.out.println("MA_Course_Completion reports generated");
adminService.getCumulativeInactiveFiles(toDate);
System.out.println("MA_Inactive reports generated");
adminService.porcessKilkariSixWeekNoAnswerFiles(fromDate, toDate);
System.out.println("KilkariSixWeekNoAnswer reports generated");
adminService.processKilkariLowListenershipDeactivationFiles(fromDate, toDate);
System.out.println("LowListenershipDeactivation reports generated");
adminService.getKilkariSelfDeactivationFiles(fromDate, toDate);
System.out.println("KilkariSelfDeactivation reports generated");
adminService.processKilkariLowUsageFiles(fromDate, toDate);
System.out.println("KilkariLowUsage reports generated");
System.out.println("Report generation done");
publishReportEvent("Mother_Rejected", "mother-rejected", fromDate, toDate, false);
publishReportEvent("Child_Rejected", "child-rejected", fromDate, toDate, false);
publishReportEvent("MA_ANONYMOUS", "ma-anonymous-queue", fromDate, toDate, false);
publishReportEvent("MA_Course_Completion", "ma-course-completion", fromDate, toDate, false);
publishReportEvent("MA_Inactive", "ma-inactive-reports", fromDate, toDate, false);
publishReportEvent("KilkariSixWeekNoAnswer", "kilkar-sixWeek-NoAnswer", fromDate, toDate, false);
publishReportEvent("LowListenershipDeactivation", "low-listenership-deactivation", fromDate, toDate, false);
publishReportEvent("KilkariSelfDeactivation", "kilkari-self-deactivation", fromDate, toDate, false);
publishReportEvent("KilkariLowUsage", "kilkari-low-usage", fromDate, toDate, false);

LOGGER.info("Report generation events published successfully.");
return true;
} catch (Exception e) {
LOGGER.error("Error during report generation processing: ", e);
return false;
}
return false;
}


private void publishReportEvent(String reportType, String queueName, Date fromDate, Date toDate, boolean isWeekly) {
ReportMessage reportMessage = new ReportMessage(reportType, fromDate, toDate, isWeekly);
try {
jmsTemplate.convertAndSend(queueName, reportMessage);
LOGGER.info("Published report event: {} to queue: {}", reportType, queueName);
} catch (Exception e) {
LOGGER.error("Failed to publish report event {} to queue {}: ", reportType, queueName, e);
}
}



public boolean executeWeekly() {
if(isAutoGenerate()) {
Calendar aCalendar = Calendar.getInstance();
aCalendar.add(Calendar.DAY_OF_WEEK, -(aCalendar.get(Calendar.DAY_OF_WEEK) - 1));
Date toDate = aCalendar.getTime();
if (!isAutoGenerate()) {
LOGGER.info("Auto-generation is disabled. Skipping weekly report generation.");
return false;
}
try {
Calendar calendar = Calendar.getInstance();
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
calendar.add(Calendar.DAY_OF_WEEK, -(dayOfWeek - 1));
Date weekStartDate = calendar.getTime();

Date toDate = new Date();

LOGGER.info("Weekly report generation: weekStartDate = {}, toDate = {}", weekStartDate, toDate);


// adminService.createFiles(ReportType.flwRejected.getReportType());
adminService.createFiles(ReportType.motherRejected.getReportType());
adminService.createFiles(ReportType.childRejected.getReportType());

// adminService.createFlwImportRejectedFiles(toDate);
// System.out.println("FLW_Rejection reports generated");
adminService.createMotherImportRejectedFiles(1,true);
System.out.println("Mother_Rejection reports generated");
adminService.createChildImportRejectedFiles(1,true);
System.out.println("Child_Rejection reports generated");
LOGGER.info("Weekly report generation preprocessing complete. Files and folders created.");
publishReportEvent("Mother_Rejected", "mother-rejected", weekStartDate, toDate, true);
publishReportEvent("Child_Rejected", "child-rejected", weekStartDate, toDate, true);

LOGGER.info("Weekly report generation events published successfully.");
return true;
} catch (Exception e) {
LOGGER.error("Error during weekly report generation processing: ", e);
return false;
}
return false;
}

public HashMap sendFirstMail() {
Expand Down
Loading