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

verify link and manual mail for pending foreign item #4

Merged
merged 2 commits into from
Aug 24, 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@SpringBootApplication
@ComponentScan(basePackages = { "dev.sunbirdrc.registry.middleware", "dev.sunbirdrc.claim"})
@EnableAsync
public class ClaimsApplication {
public static void main(String[] args) {
SpringApplication.run(ClaimsApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ public class PropertyMapper {

@Value("${regulator.table.name}")
private String regulatorTableName;

@Value("${student.foreign.verification.table.name}")
private String studentForeignVerificationTableName;

@Value("${claim.url}")
private String claimUrl;

@Value("${registry.shard.id}")
private String registryShardId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.*;

import javax.imageio.ImageIO;
import javax.xml.bind.DatatypeConverter;
Expand Down Expand Up @@ -119,10 +116,12 @@ public ResponseEntity<String> sendCertificateMail(@RequestBody CertificateMailDt
return new ResponseEntity<>("Mail is sending", HttpStatus.OK);
}

@RequestMapping(value = "/api/v1/sendPendingForeignItemMail", method = RequestMethod.POST)
@RequestMapping(value = "/api/v1/sendPendingForeignItemMail/{claimId}", method = RequestMethod.GET)
public ResponseEntity<String> sendPendingItemMail(@RequestHeader HttpHeaders headers,
@RequestBody PendingMailDTO pendingMailDTO) {
emailService.sendManualPendingMail(pendingMailDTO);
return new ResponseEntity<>("Mail is sending", HttpStatus.OK);
@PathVariable String claimId) {

emailService.collectAndSendForeignCoucilMailManually(claimId);

return new ResponseEntity<>("Sending manual foreign pending item mail", HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package dev.sunbirdrc.claim.controller;

import dev.sunbirdrc.claim.service.ClaimService;
import dev.sunbirdrc.claim.service.StudentForeignVerificationService;
import dev.sunbirdrc.claim.status.Status;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/outside")
public class OutsideStudentController {

@Autowired
private StudentForeignVerificationService foreignVerificationService;

@Autowired
private ClaimService claimService;

@GetMapping("/foreignStudent/{id}")
public ResponseEntity<String> getForeignStudentVerificationDetail(@PathVariable String id) {
String template = foreignVerificationService.generatePendingMailContent(id);

if (!StringUtils.isEmpty(template)) {
return new ResponseEntity<>(template, HttpStatus.OK);
} else {
return ResponseEntity.notFound().build();
}
}

@GetMapping("/foreignStudent/verify/{id}/{status}")
public ResponseEntity<String> verifyForeignStudentVerification(@PathVariable String id,
@PathVariable Status status) {

claimService.updateForeignStudentStatus(id, status);

return new ResponseEntity<>("Foreign student verification updated", HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class PendingMailDTO {
private String regulatorEmail;
private String credType;
private String registrationNumber;
private String verifyLink;
}
11 changes: 11 additions & 0 deletions java/claim/src/main/java/dev/sunbirdrc/claim/entity/Claim.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ public void setCredType(String credType) {
@Column
private String attestorUserId;

@Column
private String foreignStudentStatus;

public String getForeignStudentStatus() {
return foreignStudentStatus;
}

public void setForeignStudentStatus(String foreignStudentStatus) {
this.foreignStudentStatus = foreignStudentStatus;
}

@PrePersist
protected void onCreate() {
createdAt = new Date();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package dev.sunbirdrc.claim.entity;


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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class StudentForeignVerification {
private String title;
private String name;
private String registrationType;
private String registrationNumber;
private String refNo;
private String phoneNumber;
private String passingYear;
private String passingMonth;
private String osOwner;
private String osid;
private String nursingCollage;
private String mothersName;
private String joiningYear;
private String joiningMonth;
private String gender;
private String finalYearRollNo;
private String fathersName;
private String examBody;
private String email;
private String dateOfBirth;
private String date;
private String courseName;
private String council;
private String candidatePic;
private String barCode;
private String aadhaarNo;


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface ClaimRepository extends JpaRepository<Claim, String> {
List<Claim> findByAttestorEntity(String entity);

List<Claim> findByRequestorName(String requestorName);

List<Claim> findByEntityId(String entityId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dev.sunbirdrc.claim.repository;

import dev.sunbirdrc.claim.entity.StudentForeignVerification;
import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

public class StudentForeignVerificationRowMapper implements RowMapper<StudentForeignVerification> {
@Override
public StudentForeignVerification mapRow(ResultSet rs, int rowNum) throws SQLException {
return new StudentForeignVerification(
rs.getString("title"),
rs.getString("name"),
rs.getString("registrationType"),
rs.getString("registrationNumber"),
rs.getString("refNo"),
rs.getString("phoneNumber"),
rs.getString("passingYear"),
rs.getString("passingMonth"),
rs.getString("osOwner"),
rs.getString("osid"),
rs.getString("nursingCollage"),
rs.getString("mothersName"),
rs.getString("joiningYear"),
rs.getString("joiningMonth"),
rs.getString("gender"),
rs.getString("finalYearRollNo"),
rs.getString("fathersName"),
rs.getString("examBody"),
rs.getString("email"),
rs.getString("dateOfBirth"),
rs.getString("date"),
rs.getString("courseName"),
rs.getString("council"),
rs.getString("candidatePic"),
rs.getString("barCode"),
rs.getString("aadhaarNo")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package dev.sunbirdrc.claim.service;

import dev.sunbirdrc.claim.config.PropertyMapper;
import dev.sunbirdrc.claim.controller.EmailController;
import dev.sunbirdrc.claim.dto.PendingMailDTO;
import dev.sunbirdrc.claim.entity.Regulator;
import dev.sunbirdrc.claim.exception.ClaimMailException;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;

import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AsyncMailSender {
private static final Logger logger = LoggerFactory.getLogger(AsyncMailSender.class);
@Autowired
private JavaMailSender mailSender;

@Autowired
private PropertyMapper propertyMapper;

@Autowired
private Configuration freeMarkerConfiguration;

/**
* @param pendingMailDTOList
* @param regulatorList
*/
@Async
public void sendPendingMailToRegulatorList(@NonNull List<PendingMailDTO> pendingMailDTOList,
List<Regulator> regulatorList) {

for (Regulator regulator : regulatorList) {
try {
MimeMessage mimeMessage = mailSender.createMimeMessage();

MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);

mimeMessageHelper.setSubject(propertyMapper.getForeignPendingItemSubject());
mimeMessageHelper.setFrom(new InternetAddress(propertyMapper.getSimpleMailMessageFrom(),
"Auto generated mail for pending item"));
mimeMessageHelper.setTo(regulator.getEmail());
mimeMessageHelper.setText(generatePendingMailContent(pendingMailDTOList, regulator.getName()), true);

mailSender.send(mimeMessageHelper.getMimeMessage());
} catch (Exception e) {
logger.error("Exception while sending mail: ", e);
throw new ClaimMailException("Exception while composing and sending mail with OTP");
}
}
}

/**
* @param pendingMailDTOList
* @param regulatorName
* @return
*/
private String generatePendingMailContent(@NonNull List<PendingMailDTO> pendingMailDTOList,
@NonNull String regulatorName) {
String processedTemplateString = null;

Map<String, Object> mailMap = new HashMap<>();
mailMap.put("candidates", pendingMailDTOList);
mailMap.put("regulatorName", regulatorName);

try {
freeMarkerConfiguration.setClassForTemplateLoading(this.getClass(), "/templates/");
Template template = freeMarkerConfiguration.getTemplate("pending-item-mail.ftl");
processedTemplateString = FreeMarkerTemplateUtils.processTemplateIntoString(template, mailMap);

} catch (TemplateException e) {
logger.error("TemplateException while creating auto mail template for foreing pending item ", e);
throw new ClaimMailException("Error while creating auto mail template for foreing pending item");
} catch (IOException e) {
logger.error("IOException while creating auto mail template for foreing pending item ", e);
throw new ClaimMailException("Error while creating auto mail template for foreing pending item");
}
return processedTemplateString;
}

/**
* @param pendingMailDTO
* @param regulatorName
* @param regulatorEmail
*/
@Async
public void sendManualPendingMail(PendingMailDTO pendingMailDTO, @NonNull String regulatorName,
@NonNull String regulatorEmail) {

try {
MimeMessage mimeMessage = mailSender.createMimeMessage();

MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);

mimeMessageHelper.setSubject(propertyMapper.getForeignPendingItemSubject());
mimeMessageHelper.setFrom(new InternetAddress(propertyMapper.getSimpleMailMessageFrom(),
"Pending action item"));
mimeMessageHelper.setTo(regulatorEmail);
mimeMessageHelper.setText(generateManualForeignPendingMailContent(pendingMailDTO, regulatorName), true);

mailSender.send(mimeMessageHelper.getMimeMessage());
} catch (Exception e) {
logger.error("Exception while sending mail: ", e);
throw new ClaimMailException("Exception while composing and sending mail with OTP");
}

}

/**
* @param pendingMailDTO
* @param foreignRegulatorName
* @return
*/
private String generateManualForeignPendingMailContent(PendingMailDTO pendingMailDTO, String foreignRegulatorName) {
String processedTemplateString = null;

Map<String, Object> mailMap = new HashMap<>();
mailMap.put("candidate", pendingMailDTO);
mailMap.put("regulatorName", foreignRegulatorName);

try {
freeMarkerConfiguration.setClassForTemplateLoading(this.getClass(), "/templates/");
Template template = freeMarkerConfiguration.getTemplate("manual-pending-item-mail.ftl");
processedTemplateString = FreeMarkerTemplateUtils.processTemplateIntoString(template, mailMap);

} catch (TemplateException e) {
logger.error("TemplateException while creating manual mail template for foreing pending item ", e);
throw new ClaimMailException("Error while creating manual mail template for foreing pending item");
} catch (IOException e) {
logger.error("IOException while creating manual mail template for foreing pending item ", e);
throw new ClaimMailException("Error while creating manual mail template for foreing pending item");
}
return processedTemplateString;
}
}
Loading