Commit 01ea8fb8 authored by rjosula's avatar rjosula

1. Added Logger&lombok dependency into pom.xml

2. Added VO instead of model entity into Integration XML
3. Added Lombok related data, all arguementconstr, defaultConstruct
4. Removed the sysout and added log info
parent 12c3e860
......@@ -29,6 +29,14 @@
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mongodb</artifactId>
......@@ -56,6 +64,15 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
......
......@@ -2,6 +2,8 @@ package com.voter.verification.dao;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
......@@ -22,27 +24,33 @@ public class VoterDAOImpl implements VoterDAO {
@Autowired
private MongoTemplate mongoTemplate;
private Logger logger = LogManager.getLogger(VoterDAOImpl.class);
/**
* Save or update the Voter information based on the personId criteria
* If person Id exists it will update else will create a new record.
*/
@Override
public Voter saveOrUpdateVoterInfo(Voter voterObj) {
Voter voterSavedObj = null;
Query query = new Query();
query.addCriteria(Criteria.where("personId").is(Integer.valueOf(voterObj.getpersonId())));
query.addCriteria(Criteria.where("personId").is(Integer.valueOf(voterObj.getPersonId())));
try {
Update update = new Update();
update.set("personId" , voterObj.getpersonId());
update.set("personAge" , voterObj.getpersonAge());
update.set("personName", voterObj.getpersonName());
update.set("personAddress", voterObj.getpersonAddress());
update.set("personId" , voterObj.getPersonId());
update.set("personAge" , voterObj.getPersonAge());
update.set("personName", voterObj.getPersonName());
update.set("personAddress", voterObj.getPersonAddress());
update.set("state", voterObj.getState());
voterSavedObj = mongoTemplate.findAndModify(query, update, Voter.class);
if(voterSavedObj == null ) {
voterSavedObj = mongoTemplate.save(voterObj);
}
System.out.println("Updated the information ... " + voterSavedObj.toString());
logger.info("Updated the information ... " + voterSavedObj.toString());
} catch(Exception ex) {
ex.printStackTrace();
logger.error("Error while saving the voter information", ex);
}
return voterSavedObj;
}
......
......@@ -4,7 +4,14 @@ import java.io.Serializable;
import org.springframework.data.mongodb.core.mapping.Document;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Document(collection = "voterinformation")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Voter implements Serializable {
/**
......@@ -19,68 +26,4 @@ public class Voter implements Serializable {
private String state;
private String emailId;
private String referenceId;
public int getpersonId() {
return personId;
}
public void setpersonId(int personId) {
this.personId = personId;
}
public String getpersonName() {
return personName;
}
public void setpersonName(String personName) {
this.personName = personName;
}
public int getpersonAge() {
return personAge;
}
public void setpersonAge(int personAge) {
this.personAge = personAge;
}
public String getpersonAddress() {
return personAddress;
}
public void setpersonAddress(String personAddress) {
this.personAddress = personAddress;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public Voter() {
}
public String getEmailId() {
return emailId;
}
public void setEmailId(String emailId) {
this.emailId = emailId;
}
public String getReferenceId() {
return referenceId;
}
public void setReferenceId(String referenceId) {
this.referenceId = referenceId;
}
public Voter(int personId, String personName, int personAge, String personAddress, String state, String emailId,
String referenceId) {
super();
this.personId = personId;
this.personName = personName;
this.personAge = personAge;
this.personAddress = personAddress;
this.state = state;
this.emailId = emailId;
this.referenceId = referenceId;
}
@Override
public String toString() {
return "Voter [personId=" + personId + ", personName=" + personName + ", personAge=" + personAge
+ ", personAddress=" + personAddress + ", state=" + state + ", emailId=" + emailId + ", referenceId="
+ referenceId + "]";
}
}
......@@ -11,6 +11,9 @@ import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
......@@ -19,6 +22,7 @@ import org.springframework.stereotype.Component;
import com.voter.verification.dao.VoterDAO;
import com.voter.verification.model.Voter;
import com.voter.verification.model.VoterInformation;
import com.voter.verification.vo.VoterVO;
/**
* Service activator to consume & apply business logic to transform from JSON to
......@@ -32,6 +36,8 @@ public class VoterServiceActivator {
@Autowired
private VoterDAO voterDAO;
private Logger logger = LogManager.getLogger(VoterServiceActivator.class);
/**
* Service activator method to receive the input message
......@@ -39,25 +45,36 @@ public class VoterServiceActivator {
* @param inputMesg
* @return
*/
public Message<VoterInformation> mapPersonToVoter(Message<Voter> personMsg) {
System.out.println("Inside service activator... " + personMsg.getPayload());
Voter voterInput = personMsg.getPayload();
public Message<VoterInformation> mapPersonToVoter(Message<VoterVO> personMsg) {
logger.info("Inside service activator... " + personMsg.getPayload());
VoterVO voterInput = personMsg.getPayload();
Voter voterObjSaved = null;
boolean isPersonEligible = false;
if (voterInput.getpersonAge() >= 18) {
if (voterInput.getPersonAge() >= 18) {
isPersonEligible = true;
}
Voter dbInput = new Voter();
/**
* This is to copy properties from source voterInput to dbInput destination
*/
try {
BeanUtils.copyProperties(dbInput, voterInput);
} catch(Exception ex) {
logger.error("Error occured while copying the properties ", ex);
}
/** Saving the information using DAO Layer*/
voterObjSaved = voterDAO.saveOrUpdateVoterInfo(voterInput);
System.out.println("Voter information has been successfully saved or updated!...."+voterObjSaved.toString());
voterObjSaved = voterDAO.saveOrUpdateVoterInfo(dbInput);
logger.info("Voter information has been successfully saved or updated!...."+voterObjSaved.toString());
VoterInformation voterInfo = new VoterInformation();
voterInfo.setVoterId(voterInput.getpersonId());
voterInfo.setVoterName(voterInput.getpersonName());
voterInfo.setVoterAddress(voterInput.getpersonAddress());
voterInfo.setVoterProvince(voterInput.getState());
voterInfo.setVoterId(dbInput.getPersonId());
voterInfo.setVoterName(dbInput.getPersonName());
voterInfo.setVoterAddress(dbInput.getPersonAddress());
voterInfo.setVoterProvince(dbInput.getState());
voterInfo.setEligible(isPersonEligible);
voterInfo.setVoterAge(voterInput.getpersonAge());
voterInfo.setVoterAge(voterInput.getPersonAge());
voterInfo.setReferenceId(voterInput.getReferenceId());
voterInfo.setEmailId(voterInput.getEmailId());
......
package com.voter.verification.vo;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
@Data
@Setter
@Getter
public class VoterVO {
private int personId;
private String personName;
private int personAge;
private String personAddress;
private String state;
private String emailId;
private String referenceId;
}
......@@ -57,7 +57,7 @@
<int:json-to-object-transformer
id="jsonStringToPersonTrnsfrmer.eligible.person.id"
object-mapper="getMapper"
type="com.voter.verification.model.Voter"
type="com.voter.verification.vo.VoterVO"
input-channel="requestChannel"
output-channel="person.mapper.voting.out" />
......
{
"personId" : 4,
"personName":"RK D",
"personAge":35,
"personAddress":"DNo 7-6-69/204, Kousalya Colony, Bachupally-500090, Hyderabad",
"personId" : 12,
"personName":"Mahesh Nisum",
"personAge":17,
"personAddress":"Nisum Technologies, Kondapur, Hyderabad.",
"state":"Telangana",
"emailId":"raghunathbj13@gmail.com",
"emailId":"mahesh.9818@gmail.com",
"referenceId":"DGN31147076"
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment