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

Auto and manual pending item for foreign student #3

Merged
merged 8 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions java/claim/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-vision</artifactId>
Expand Down Expand Up @@ -154,6 +158,14 @@
<artifactId>json</artifactId>
<version>20210307</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.sunbirdrc.claim.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@Data
public class PropertyMapper {
@Value("${simple.mail.message.from}")
private String simpleMailMessageFrom;

@Value("${foreign.pending.item.subject}")
private String foreignPendingItemSubject;

@Value("${up.council.name}")
private String upCouncilName;

@Value("${regulator.table.name}")
private String regulatorTableName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ public class AttributeNames {
public static final String CONTENT = "content";
public static final String TOTAL_PAGES = "totalPages";
public static final String TOTAL_ELEMENTS = "totalElements";

public static final String JPG = "JPG";
public static final String JPEG = "JPEG";
public static final String PNG = "PNG";
public static final String GIF = "GIF";
public static final String PDF = "PDF";
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package dev.sunbirdrc.claim.controller;

import dev.sunbirdrc.claim.dto.BarCode;
import dev.sunbirdrc.claim.dto.CertificateMailDto;
import dev.sunbirdrc.claim.dto.MailDto;
import dev.sunbirdrc.claim.dto.PendingMailDTO;
import dev.sunbirdrc.claim.service.EmailService;
import net.sourceforge.barbecue.Barcode;
import net.sourceforge.barbecue.BarcodeFactory;
Expand Down Expand Up @@ -111,5 +113,16 @@ private String prepareBody(String idLink, String name, String credType) {
return body;
}

@RequestMapping(value = "/api/v1/sendCertificateMail", method = RequestMethod.POST)
public ResponseEntity<String> sendCertificateMail(@RequestBody CertificateMailDto certificateMailDto) {
emailService.sendCertificateMail(certificateMailDto);
return new ResponseEntity<>("Mail is sending", HttpStatus.OK);
}

@RequestMapping(value = "/api/v1/sendPendingForeignItemMail", method = RequestMethod.POST)
public ResponseEntity<String> sendPendingItemMail(@RequestHeader HttpHeaders headers,
@RequestBody PendingMailDTO pendingMailDTO) {
emailService.sendManualPendingMail(pendingMailDTO);
return new ResponseEntity<>("Mail is sending", HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ public ResponseEntity<Resource> downloadFile(
ByteArrayResource resource = fileService.downloadFile(fileName);
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_DISPOSITION, "filename=\"" + fileName + "\"");
return ResponseEntity.ok().
contentType(MediaType.APPLICATION_PDF).
headers(headers).body(resource);

try {
MediaType mediaType = fileService.getFileMediaType(fileName);

return ResponseEntity.ok()
.contentType(mediaType)
.headers(headers).body(resource);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.EXPECTATION_FAILED);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.sunbirdrc.claim.dto;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CertificateMailDto {
private String name;
private String certificate;
private String emailAddress;

private String credentialsType;

private String certificateBase64;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.sunbirdrc.claim.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PendingMailDTO {
private String name;
private String emailAddress;
private String council;
private String itemName;
private String refNo;
private String regulatorName;
private String regulatorEmail;
private String credType;
private String registrationNumber;
}
32 changes: 32 additions & 0 deletions java/claim/src/main/java/dev/sunbirdrc/claim/entity/Regulator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package dev.sunbirdrc.claim.entity;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Regulator {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private String ID;
@Column
private String name;
@Column
private String phoneNumber;
@Column
private String council;
@Column
private String email;
@Column
private String osOwner;
@Column
private String osid;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.sunbirdrc.claim.exception;

public class ClaimMailException extends RuntimeException {
public ClaimMailException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package dev.sunbirdrc.claim.quartz;

import lombok.extern.slf4j.Slf4j;
import org.quartz.CronTrigger;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.SimpleTrigger;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.Date;

@Slf4j
@Component
public class JobCreator {

/**
* Create Quartz Job.
*
* @param jobClass Class whose executeInternal() method needs to be called.
* @param isDurable Job needs to be persisted even after completion. if true, job will be persisted, not otherwise.
* @param context Spring application context.
* @param jobName Job name.
* @param jobGroup Job group.
* @return JobDetail object
*/
public JobDetail createJob(Class<? extends QuartzJobBean> jobClass, boolean isDurable,
ApplicationContext context, String jobName, String jobGroup) {
JobDetailFactoryBean factoryBean = new JobDetailFactoryBean();
factoryBean.setJobClass(jobClass);
factoryBean.setDurability(isDurable);
factoryBean.setApplicationContext(context);
factoryBean.setName(jobName);
factoryBean.setGroup(jobGroup);

// set job data map
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put(jobName + jobGroup, jobClass.getName());
factoryBean.setJobDataMap(jobDataMap);

factoryBean.afterPropertiesSet();

return factoryBean.getObject();
}

/**
* Create cron trigger.
*
* @param triggerName Trigger name.
* @param startTime Trigger start time.
* @param cronExpression Cron expression.
* @param misFireInstruction Misfire instruction (what to do in case of misfire happens).
* @return {@link CronTrigger}
*/
public CronTrigger createCronTrigger(String triggerName, Date startTime, String cronExpression, int misFireInstruction) {
CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean();
factoryBean.setName(triggerName);
factoryBean.setStartTime(startTime);
factoryBean.setCronExpression(cronExpression);
factoryBean.setMisfireInstruction(misFireInstruction);
try {
factoryBean.afterPropertiesSet();
} catch (ParseException e) {
log.error(e.getMessage(), e);
}
return factoryBean.getObject();
}

/**
* Create simple trigger.
*
* @param triggerName Trigger name.
* @param startTime Trigger start time.
* @param repeatTime Job repeat period mills
* @param misFireInstruction Misfire instruction (what to do in case of misfire happens).
* @return {@link SimpleTrigger}
*/
public SimpleTrigger createSimpleTrigger(String triggerName, Date startTime, Long repeatTime, int misFireInstruction) {
SimpleTriggerFactoryBean factoryBean = new SimpleTriggerFactoryBean();
factoryBean.setName(triggerName);
factoryBean.setStartTime(startTime);
factoryBean.setRepeatInterval(repeatTime);
factoryBean.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
factoryBean.setMisfireInstruction(misFireInstruction);
factoryBean.afterPropertiesSet();
return factoryBean.getObject();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.sunbirdrc.claim.quartz;

import dev.sunbirdrc.claim.service.EmailService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class MailingJobExecutor extends QuartzJobBean {

@Autowired
private EmailService emailService;

@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
log.info(">>>>>>>>>>>> Mail for foreign council job started :: " + new Date(System.currentTimeMillis()) + " <<<<<<<<<<<<<<<<");

emailService.sendForeignPendingItemMail();

log.info(">>>>>>>>>>>> Mail for foreign council has been completed :: " + new Date(System.currentTimeMillis()) + " <<<<<<<<<<<<<<<<");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package dev.sunbirdrc.claim.quartz;

import org.quartz.JobDetail;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.quartz.QuartzProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import javax.sql.DataSource;
import java.util.Properties;

@Configuration
public class SchedulerConfig {
@Autowired
private DataSource dataSource;

@Autowired
private ApplicationContext applicationContext;

@Autowired
private QuartzProperties quartzProperties;

@Autowired
private JobCreator jobCreator;

/**
* create scheduler factory
*/
@Bean
public SchedulerFactoryBean schedulerFactoryBean(@Qualifier("searchJobTrigger") Trigger searchJobTrigger) {

SchedulerJobFactory jobFactory = new SchedulerJobFactory();
jobFactory.setApplicationContext(applicationContext);

Properties properties = new Properties();
properties.putAll(quartzProperties.getProperties());

SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setOverwriteExistingJobs(true);
factory.setDataSource(dataSource);
factory.setQuartzProperties(properties);
factory.setJobFactory(jobFactory);
factory.setTriggers(searchJobTrigger);
return factory;
}

@Bean(name = "searchJobTrigger")
public CronTriggerFactoryBean sampleJobTrigger(@Qualifier("quartzJobDetail") JobDetail jobDetail,
@Value("${samplejob.frequency}") String frequency) {
return createCronTrigger(jobDetail, frequency);
}

private static CronTriggerFactoryBean createCronTrigger(JobDetail jobDetail, String cronExpression) {
CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean();
factoryBean.setJobDetail(jobDetail);
factoryBean.setCronExpression(cronExpression);
factoryBean.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
return factoryBean;
}

@Bean
public JobDetail quartzJobDetail() {
return jobCreator.createJob(MailingJobExecutor.class, true, applicationContext, "Send mail", "Mail Event Group");
}
}
Loading