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 @@ ...@@ -29,6 +29,14 @@
<artifactId>spring-boot-starter-integration</artifactId> <artifactId>spring-boot-starter-integration</artifactId>
</dependency> </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> <dependency>
<groupId>org.springframework.integration</groupId> <groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-mongodb</artifactId> <artifactId>spring-integration-mongodb</artifactId>
...@@ -56,6 +64,15 @@ ...@@ -56,6 +64,15 @@
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </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> <dependency>
<groupId>mysql</groupId> <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId> <artifactId>mysql-connector-java</artifactId>
......
...@@ -2,6 +2,8 @@ package com.voter.verification.dao; ...@@ -2,6 +2,8 @@ package com.voter.verification.dao;
import java.util.List; 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.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
...@@ -22,27 +24,33 @@ public class VoterDAOImpl implements VoterDAO { ...@@ -22,27 +24,33 @@ public class VoterDAOImpl implements VoterDAO {
@Autowired @Autowired
private MongoTemplate mongoTemplate; 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 @Override
public Voter saveOrUpdateVoterInfo(Voter voterObj) { public Voter saveOrUpdateVoterInfo(Voter voterObj) {
Voter voterSavedObj = null; Voter voterSavedObj = null;
Query query = new Query(); 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 { try {
Update update = new Update(); Update update = new Update();
update.set("personId" , voterObj.getpersonId()); update.set("personId" , voterObj.getPersonId());
update.set("personAge" , voterObj.getpersonAge()); update.set("personAge" , voterObj.getPersonAge());
update.set("personName", voterObj.getpersonName()); update.set("personName", voterObj.getPersonName());
update.set("personAddress", voterObj.getpersonAddress()); update.set("personAddress", voterObj.getPersonAddress());
update.set("state", voterObj.getState()); update.set("state", voterObj.getState());
voterSavedObj = mongoTemplate.findAndModify(query, update, Voter.class); voterSavedObj = mongoTemplate.findAndModify(query, update, Voter.class);
if(voterSavedObj == null ) { if(voterSavedObj == null ) {
voterSavedObj = mongoTemplate.save(voterObj); voterSavedObj = mongoTemplate.save(voterObj);
} }
System.out.println("Updated the information ... " + voterSavedObj.toString()); logger.info("Updated the information ... " + voterSavedObj.toString());
} catch(Exception ex) { } catch(Exception ex) {
ex.printStackTrace(); logger.error("Error while saving the voter information", ex);
} }
return voterSavedObj; return voterSavedObj;
} }
......
...@@ -4,7 +4,14 @@ import java.io.Serializable; ...@@ -4,7 +4,14 @@ import java.io.Serializable;
import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Document;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Document(collection = "voterinformation") @Document(collection = "voterinformation")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Voter implements Serializable { public class Voter implements Serializable {
/** /**
...@@ -19,68 +26,4 @@ public class Voter implements Serializable { ...@@ -19,68 +26,4 @@ public class Voter implements Serializable {
private String state; private String state;
private String emailId; private String emailId;
private String referenceId; 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; ...@@ -11,6 +11,9 @@ import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult; 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.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder; import org.springframework.messaging.support.MessageBuilder;
...@@ -19,6 +22,7 @@ import org.springframework.stereotype.Component; ...@@ -19,6 +22,7 @@ import org.springframework.stereotype.Component;
import com.voter.verification.dao.VoterDAO; import com.voter.verification.dao.VoterDAO;
import com.voter.verification.model.Voter; import com.voter.verification.model.Voter;
import com.voter.verification.model.VoterInformation; import com.voter.verification.model.VoterInformation;
import com.voter.verification.vo.VoterVO;
/** /**
* Service activator to consume & apply business logic to transform from JSON to * Service activator to consume & apply business logic to transform from JSON to
...@@ -32,6 +36,8 @@ public class VoterServiceActivator { ...@@ -32,6 +36,8 @@ public class VoterServiceActivator {
@Autowired @Autowired
private VoterDAO voterDAO; private VoterDAO voterDAO;
private Logger logger = LogManager.getLogger(VoterServiceActivator.class);
/** /**
* Service activator method to receive the input message * Service activator method to receive the input message
...@@ -39,25 +45,36 @@ public class VoterServiceActivator { ...@@ -39,25 +45,36 @@ public class VoterServiceActivator {
* @param inputMesg * @param inputMesg
* @return * @return
*/ */
public Message<VoterInformation> mapPersonToVoter(Message<Voter> personMsg) { public Message<VoterInformation> mapPersonToVoter(Message<VoterVO> personMsg) {
System.out.println("Inside service activator... " + personMsg.getPayload()); logger.info("Inside service activator... " + personMsg.getPayload());
Voter voterInput = personMsg.getPayload(); VoterVO voterInput = personMsg.getPayload();
Voter voterObjSaved = null; Voter voterObjSaved = null;
boolean isPersonEligible = false; boolean isPersonEligible = false;
if (voterInput.getpersonAge() >= 18) { if (voterInput.getPersonAge() >= 18) {
isPersonEligible = true; 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*/ /** Saving the information using DAO Layer*/
voterObjSaved = voterDAO.saveOrUpdateVoterInfo(voterInput); voterObjSaved = voterDAO.saveOrUpdateVoterInfo(dbInput);
System.out.println("Voter information has been successfully saved or updated!...."+voterObjSaved.toString()); logger.info("Voter information has been successfully saved or updated!...."+voterObjSaved.toString());
VoterInformation voterInfo = new VoterInformation(); VoterInformation voterInfo = new VoterInformation();
voterInfo.setVoterId(voterInput.getpersonId()); voterInfo.setVoterId(dbInput.getPersonId());
voterInfo.setVoterName(voterInput.getpersonName()); voterInfo.setVoterName(dbInput.getPersonName());
voterInfo.setVoterAddress(voterInput.getpersonAddress()); voterInfo.setVoterAddress(dbInput.getPersonAddress());
voterInfo.setVoterProvince(voterInput.getState()); voterInfo.setVoterProvince(dbInput.getState());
voterInfo.setEligible(isPersonEligible); voterInfo.setEligible(isPersonEligible);
voterInfo.setVoterAge(voterInput.getpersonAge()); voterInfo.setVoterAge(voterInput.getPersonAge());
voterInfo.setReferenceId(voterInput.getReferenceId()); voterInfo.setReferenceId(voterInput.getReferenceId());
voterInfo.setEmailId(voterInput.getEmailId()); 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 @@ ...@@ -57,7 +57,7 @@
<int:json-to-object-transformer <int:json-to-object-transformer
id="jsonStringToPersonTrnsfrmer.eligible.person.id" id="jsonStringToPersonTrnsfrmer.eligible.person.id"
object-mapper="getMapper" object-mapper="getMapper"
type="com.voter.verification.model.Voter" type="com.voter.verification.vo.VoterVO"
input-channel="requestChannel" input-channel="requestChannel"
output-channel="person.mapper.voting.out" /> output-channel="person.mapper.voting.out" />
......
{ {
"personId" : 4, "personId" : 12,
"personName":"RK D", "personName":"Mahesh Nisum",
"personAge":35, "personAge":17,
"personAddress":"DNo 7-6-69/204, Kousalya Colony, Bachupally-500090, Hyderabad", "personAddress":"Nisum Technologies, Kondapur, Hyderabad.",
"state":"Telangana", "state":"Telangana",
"emailId":"raghunathbj13@gmail.com", "emailId":"mahesh.9818@gmail.com",
"referenceId":"DGN31147076" "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