Skip to content
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<org.mapstruct.version>1.2.0.Final</org.mapstruct.version>
<org.projectlombok.version>1.16.18</org.projectlombok.version>
<final-name>commonapi-v1.0</final-name>
<environment>dev</environment>
<environment>test</environment>
<target-properties>target/classes/application.properties</target-properties>
<source-properties>src/main/environment/common_${environment}.properties</source-properties>
<hostname-dev>10.208.122.32</hostname-dev>
Expand Down
12 changes: 6 additions & 6 deletions src/main/environment/common_test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ spring.jpa.database=default
##--------------------------------------------## Primary db-------------------------------------------------------------------


encDbUserName=zFlYsp9Z0s+lRvLM15A3g/Ba0w8VGs/1usuW7EsGF3k=
encDbPass=JGGAGn5wTlrbTLUHY+5BzfBa0w8VGs/1usuW7EsGF3k=
spring.datasource.url=jdbc:mysql://10.208.122.38:3306/db_iemr?autoReconnect=true&useSSL=false
encDbUserName=<Enter your AMRIT DB username>
encDbPass=<Enter your AMRIT DB password>
spring.datasource.url=<Enter AMRIT DB URL here>
spring.datasource.driver-class-name=com.mysql.jdbc.Driver



encDbUserNameSec=zFlYsp9Z0s+lRvLM15A3g/Ba0w8VGs/1usuW7EsGF3k=
encDbPassSec=JGGAGn5wTlrbTLUHY+5BzfBa0w8VGs/1usuW7EsGF3k=
secondary.datasource.url=jdbc:mysql://10.208.122.38:3306/db_reporting?autoReconnect=true&useSSL=false
encDbUserNameSec=<Enter your secondary DB username>
encDbPassSec=<Enter your secondary DB password>
secondary.datasource.url=<Enter secondary DB URL here>
secondary.datasource.driver-class-name=com.mysql.jdbc.Driver
##-------------------------------------------------------------# KM config--------------------------------------------------

Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/iemr/common/config/PrimaryDBConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
Expand All @@ -41,7 +40,6 @@
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.iemr.common.utils.CryptoUtil;
import com.iemr.common.utils.config.ConfigProperties;

@Configuration
Expand All @@ -50,8 +48,6 @@
"com.iemr.common.repo", "com.iemr.common.notification.agent", "com.iemr.common.covidVaccination" })
public class PrimaryDBConfig {

@Autowired
private CryptoUtil cryptoUtil;
Logger logger = LoggerFactory.getLogger(this.getClass().getName());

@Primary
Expand All @@ -73,8 +69,8 @@ public DataSource dataSource() {
org.apache.tomcat.jdbc.pool.DataSource datasource = new org.apache.tomcat.jdbc.pool.DataSource();
datasource.setPoolProperties(p);

datasource.setUsername(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbUserName")));
datasource.setPassword(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbPass")));
datasource.setUsername(ConfigProperties.getPropertyByName("encDbUserName"));
datasource.setPassword(ConfigProperties.getPropertyByName("encDbPass"));

return datasource;
}
Expand Down
9 changes: 2 additions & 7 deletions src/main/java/com/iemr/common/config/SecondaryDBConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
Expand All @@ -40,7 +39,6 @@
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.iemr.common.utils.CryptoUtil;
import com.iemr.common.utils.config.ConfigProperties;

@Configuration
Expand All @@ -49,9 +47,6 @@
"com.iemr.common.secondary.repository.callreport" })
public class SecondaryDBConfig {

@Autowired
private CryptoUtil cryptoUtil;

Logger logger = LoggerFactory.getLogger(this.getClass().getName());

@Bean(name = "secondaryDataSource")
Expand All @@ -72,8 +67,8 @@ public DataSource dataSource() {
org.apache.tomcat.jdbc.pool.DataSource datasource = new org.apache.tomcat.jdbc.pool.DataSource();
datasource.setPoolProperties(p);

datasource.setUsername(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbUserNameSec")));
datasource.setPassword(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbPassSec")));
datasource.setUsername(ConfigProperties.getPropertyByName("encDbUserNameSec"));
datasource.setPassword(ConfigProperties.getPropertyByName("encDbPassSec"));

return datasource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@
package com.iemr.common.service.door_to_door_app;

import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -51,15 +47,11 @@
import com.iemr.common.data.door_to_door_app.V_doortodooruserdetails;
import com.iemr.common.model.user.LoginRequestModel;
import com.iemr.common.repo.door_to_door_app.V_doortodooruserdetailsRepo;
import com.iemr.common.utils.CryptoUtil;
import com.iemr.common.utils.mapper.InputMapper;

@Service
@PropertySource("classpath:application.properties")
public class DoorToDoorServiceImpl implements DoorToDoorService {

@Autowired
private CryptoUtil cryptoUtil;

@Value("${avniRegistrationLimit}")
private String avniRegistrationLimit;
Expand Down Expand Up @@ -232,7 +224,7 @@ public String get_NCD_TB_HRP_Suspected_Status(RequestParser rp) throws Exception

@Override
public void scheduleJobForRegisterAvniBeneficiary() throws Exception {

RestTemplate restTemplate = new RestTemplate();
Integer updateCount = 0;
Long id = null;
Expand All @@ -241,61 +233,53 @@ public void scheduleJobForRegisterAvniBeneficiary() throws Exception {
Long benId = null;
Integer count = 0;
try {
ArrayList<Object[]> list = v_doortodooruserdetailsRepo
.getAvniBeneficiary(avniRegistrationLimit !=null ? Integer.parseInt(avniRegistrationLimit) : 10);

if(list !=null && list.size()>0)
{

for (Object[] obj : list) {
id = obj[0] != null ? ((BigInteger) obj[0]).longValue() : null;
json = obj[1] != null ? obj[1].toString() : null;
extId = obj[2] != null ? obj[2].toString() : null;
benId = obj[3] != null ? ((BigInteger) obj[3]).longValue() : null;
count = v_doortodooruserdetailsRepo.checkIfAvniIdExists(extId);
if (count > 0)
logger.info("Beneficiary with Avni Id " + extId + " already exists");
else {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
headers.add("Content-Type", "application/json");
headers.add("AUTHORIZATION", amritUserAuthenticate());
HttpEntity<Object> requestReg = new HttpEntity<Object>(json, headers);
ResponseEntity<String> response = restTemplate.exchange(everwellRegisterBenficiary, HttpMethod.POST,
requestReg, String.class);

if (response.getStatusCodeValue() == 200 & response.hasBody()) {
logger.info("registration api response " + response.getBody());
String responseStr = response.getBody();
JsonObject jsnOBJ = new JsonObject();
JsonParser jsnParser = new JsonParser();
JsonElement jsnElmnt = jsnParser.parse(responseStr);
jsnOBJ = jsnElmnt.getAsJsonObject();
JsonObject jsonData = jsnOBJ.getAsJsonObject("data");
benId = Long.parseLong(jsonData.get("beneficiaryID").getAsString());
updateCount = v_doortodooruserdetailsRepo.updateAvniBenId(id, benId);
logger.info("Beneficiary Id "+benId+" registered successfully");
ArrayList<Object[]> list = v_doortodooruserdetailsRepo
.getAvniBeneficiary(avniRegistrationLimit != null ? Integer.parseInt(avniRegistrationLimit) : 10);

if (list != null && list.size() > 0) {

for (Object[] obj : list) {
id = obj[0] != null ? ((BigInteger) obj[0]).longValue() : null;
json = obj[1] != null ? obj[1].toString() : null;
extId = obj[2] != null ? obj[2].toString() : null;
benId = obj[3] != null ? ((BigInteger) obj[3]).longValue() : null;
count = v_doortodooruserdetailsRepo.checkIfAvniIdExists(extId);
if (count > 0)
logger.info("Beneficiary with Avni Id " + extId + " already exists");
else {
MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
headers.add("Content-Type", "application/json");
headers.add("AUTHORIZATION", amritUserAuthenticate());
HttpEntity<Object> requestReg = new HttpEntity<Object>(json, headers);
ResponseEntity<String> response = restTemplate.exchange(everwellRegisterBenficiary,
HttpMethod.POST, requestReg, String.class);

if (response.getStatusCodeValue() == 200 & response.hasBody()) {
logger.info("registration api response " + response.getBody());
String responseStr = response.getBody();
JsonObject jsnOBJ = new JsonObject();
JsonParser jsnParser = new JsonParser();
JsonElement jsnElmnt = jsnParser.parse(responseStr);
jsnOBJ = jsnElmnt.getAsJsonObject();
JsonObject jsonData = jsnOBJ.getAsJsonObject("data");
benId = Long.parseLong(jsonData.get("beneficiaryID").getAsString());
updateCount = v_doortodooruserdetailsRepo.updateAvniBenId(id, benId);
logger.info("Beneficiary Id " + benId + " registered successfully");
}
}
}
}
}
}
else
logger.info("No new records found");
}catch(Exception e)
{
} else
logger.info("No new records found");
} catch (Exception e) {
logger.error(e.getLocalizedMessage());
}

}

public String amritUserAuthenticate() {
String authorization = "";
/*
* StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
* encryptor.setAlgorithm("PBEWithMD5AndDES");
* encryptor.setPassword("dev-env-secret");
*/
String amritUser = cryptoUtil.decrypt(amritUserName);
String amritPass = cryptoUtil.decrypt(amritPassword);
String amritUser = amritUserName;
String amritPass = amritPassword;
LoginRequestModel loginCredentials = new LoginRequestModel(amritUser, amritPass);
loginCredentials.setDoLogout(true);
MultiValueMap<String, String> headersLogin = new LinkedMultiValueMap<String, String>();
Expand Down
58 changes: 27 additions & 31 deletions src/main/java/com/iemr/common/service/email/EmailServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,13 @@
import com.iemr.common.repository.email.StockAlertDataRepo;
import com.iemr.common.repository.feedback.FeedbackRepository;
import com.iemr.common.service.beneficiary.IEMRSearchUserService;
import com.iemr.common.utils.CryptoUtil;
import com.iemr.common.utils.config.ConfigProperties;
import com.iemr.common.utils.http.HttpUtils;
import com.iemr.common.utils.mapper.InputMapper;

@Service
public class EmailServiceImpl implements EmailService {

@Autowired
private CryptoUtil cryptoUtil;


private InputMapper inputMapper = new InputMapper();
@Autowired
private JavaMailSender javaMailSender;
Expand Down Expand Up @@ -444,27 +440,27 @@ public void publishEmail() {
} else {
dataList = new ArrayList<>();
dataList.add(stockAlertData);
if(stockAlertData !=null && stockAlertData.getEmailid() !=null)
dataMap.put(stockAlertData.getEmailid(), dataList);
if (stockAlertData != null && stockAlertData.getEmailid() != null)
dataMap.put(stockAlertData.getEmailid(), dataList);
}
}
} else {
logger.info("No Alert emails to be sent");
}
int sendMail=0;
int sendMail = 0;
for (Entry<String, List<StockAlertData>> entry : dataMap.entrySet()) {
logger.info(entry.getKey() + ": key");
logger.info(entry.getValue().toString() + ": value");
try {
byte[] bytes = ExcelHelper.InventoryDataToExcel(entry.getValue());
ByteArrayDataSource byteArrayOutputStream = new ByteArrayDataSource(bytes, "application/vnd.ms-excel");
sendMail=sendEmailWithAttachment(entry.getKey(),byteArrayOutputStream);
if(sendMail ==1)
logger.info("Email successfully sent to "+entry.getKey());
else
logger.info("Error while sending email to "+entry.getKey());
}catch(Exception e)
{
byte[] bytes = ExcelHelper.InventoryDataToExcel(entry.getValue());
ByteArrayDataSource byteArrayOutputStream = new ByteArrayDataSource(bytes,
"application/vnd.ms-excel");
sendMail = sendEmailWithAttachment(entry.getKey(), byteArrayOutputStream);
if (sendMail == 1)
logger.info("Email successfully sent to " + entry.getKey());
else
logger.info("Error while sending email to " + entry.getKey());
} catch (Exception e) {
logger.info(e.getLocalizedMessage());
}
}
Expand Down Expand Up @@ -506,24 +502,24 @@ public void publishEmail() {
int sendEmailWithAttachment(String recipient, ByteArrayDataSource attachment) throws Exception {
try {
// Creating a mime message
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(host);
mailSender.setPort(Integer.parseInt(port));
String decryptSender = cryptoUtil.decrypt(sender);
String decryptPass = cryptoUtil.decrypt(password);
mailSender.setUsername(decryptSender);
mailSender.setPassword(decryptPass);
Properties props = mailSender.getJavaMailProperties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost(host);
mailSender.setPort(Integer.parseInt(port));

String decryptSender = sender;
String decryptPass = password;

mailSender.setUsername(decryptSender);
mailSender.setPassword(decryptPass);
Properties props = mailSender.getJavaMailProperties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper mimeMessageHelper;
mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
mimeMessageHelper.setFrom(sender);
mimeMessageHelper.setTo(recipient);
mimeMessageHelper.setText("Sample");
mimeMessageHelper.setText("Sample");
mimeMessageHelper.setSubject(subject);
mimeMessageHelper.addAttachment("InventoryStockAlert.xlsx", attachment);

Expand All @@ -533,7 +529,7 @@ int sendEmailWithAttachment(String recipient, ByteArrayDataSource attachment) th
}

catch (Exception e) {
throw new Exception("Error while Sending Mail to "+recipient+" : " + e.getLocalizedMessage());
throw new Exception("Error while Sending Mail to " + recipient + " : " + e.getLocalizedMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@
import com.iemr.common.repository.everwell.EverwellFetchAndSync;
import com.iemr.common.repository.location.LocationDistrictRepository;
import com.iemr.common.repository.location.LocationStateRepository;
import com.iemr.common.utils.CryptoUtil;
import com.iemr.common.utils.mapper.InputMapper;
import com.iemr.common.utils.response.OutputResponse;

@Service
@PropertySource("classpath:application.properties")
public class EverwellRegistrationServiceImpl implements EverwellRegistrationService {
@Autowired
private CryptoUtil cryptoUtil;

private InputMapper inputMapper = new InputMapper();

Expand Down Expand Up @@ -147,14 +144,14 @@ public void registerBeneficiary() {
try {

// 1097 user authentication
String amritUser = cryptoUtil.decrypt(amritUserName);
String amritPass = cryptoUtil.decrypt(amritPassword);

String amritUser = amritUserName;
String amritPass = amritPassword;
LoginRequestModel loginCredentials1097 = new LoginRequestModel(amritUser, amritPass);

MultiValueMap<String, String> headersLogin = new LinkedMultiValueMap<String, String>();
headersLogin.add("Content-Type", "application/json");
//headersLogin.add("AUTHORIZATION", "");
// headersLogin.add("AUTHORIZATION", "");

logger.info("AMRIT login request OBj " + loginCredentials1097.toString());

Expand Down
Loading