diff --git a/src/main/java/com/iemr/common/CommonApplication.java b/src/main/java/com/iemr/common/CommonApplication.java index c93f50f5..c5911738 100644 --- a/src/main/java/com/iemr/common/CommonApplication.java +++ b/src/main/java/com/iemr/common/CommonApplication.java @@ -8,30 +8,20 @@ import com.iemr.common.utils.IEMRApplBeans; -/** - * @author VI314759 - * - */ @SpringBootApplication public class CommonApplication extends SpringBootServletInitializer { - /** - * @return - */ + @Bean public IEMRApplBeans instantiateBeans() { return new IEMRApplBeans(); } - /** - * @param args - */ public static void main(String[] args) { - SpringApplication.run(commonApplication, args); + SpringApplication.run(CommonApplication.class, args); } protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(new Class[] { CommonApplication.class }); } - private static Class commonApplication = CommonApplication.class; } diff --git a/src/main/java/com/iemr/common/config/PrimaryDBConfig.java b/src/main/java/com/iemr/common/config/PrimaryDBConfig.java index ef07fabb..db702b80 100644 --- a/src/main/java/com/iemr/common/config/PrimaryDBConfig.java +++ b/src/main/java/com/iemr/common/config/PrimaryDBConfig.java @@ -28,7 +28,7 @@ @EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", basePackages = { "com.iemr.common.repository", "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()); @@ -52,8 +52,6 @@ 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"))); diff --git a/src/main/java/com/iemr/common/config/SecondaryDBConfig.java b/src/main/java/com/iemr/common/config/SecondaryDBConfig.java index 980da8b4..55906c73 100644 --- a/src/main/java/com/iemr/common/config/SecondaryDBConfig.java +++ b/src/main/java/com/iemr/common/config/SecondaryDBConfig.java @@ -9,7 +9,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; import org.springframework.context.annotation.Bean; @@ -25,60 +24,49 @@ @Configuration @EnableTransactionManagement -@EnableJpaRepositories( - entityManagerFactoryRef = "secondaryEntityManagerFactory", - transactionManagerRef = "secondaryTransactionManager", - basePackages = { "com.iemr.common.secondary.repository.callreport" } -) +@EnableJpaRepositories(entityManagerFactoryRef = "secondaryEntityManagerFactory", transactionManagerRef = "secondaryTransactionManager", basePackages = { + "com.iemr.common.secondary.repository.callreport" }) public class SecondaryDBConfig { - + @Autowired private CryptoUtil cryptoUtil; - + Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + @Bean(name = "secondaryDataSource") - @ConfigurationProperties(prefix = "secondary.datasource") - public DataSource dataSource() { - PoolConfiguration p = new PoolProperties(); - p.setMaxActive(30); - p.setMaxIdle(15); - p.setMinIdle(5); - p.setInitialSize(5); - p.setMaxWait(10000); - p.setMinEvictableIdleTimeMillis(15000); - p.setRemoveAbandoned(true); - p.setLogAbandoned(true); - p.setRemoveAbandonedTimeout(600); - p.setTestOnBorrow(true); - p.setValidationQuery("SELECT 1"); - org.apache.tomcat.jdbc.pool.DataSource datasource = new org.apache.tomcat.jdbc.pool.DataSource(); - datasource.setPoolProperties(p); - + @ConfigurationProperties(prefix = "secondary.datasource") + public DataSource dataSource() { + PoolConfiguration p = new PoolProperties(); + p.setMaxActive(30); + p.setMaxIdle(15); + p.setMinIdle(5); + p.setInitialSize(5); + p.setMaxWait(10000); + p.setMinEvictableIdleTimeMillis(15000); + p.setRemoveAbandoned(true); + p.setLogAbandoned(true); + p.setRemoveAbandonedTimeout(600); + p.setTestOnBorrow(true); + p.setValidationQuery("SELECT 1"); + 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"))); + + return datasource; + } + + @Bean(name = "secondaryEntityManagerFactory") + public LocalContainerEntityManagerFactoryBean barEntityManagerFactory(EntityManagerFactoryBuilder builder, + @Qualifier("secondaryDataSource") DataSource dataSource) { + return builder.dataSource(dataSource).packages("common.iemr.common.secondary.data.report") + .persistenceUnit("db_reporting").build(); + } - datasource.setUsername(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbUserNameSec"))); - datasource.setPassword(cryptoUtil.decrypt(ConfigProperties.getPropertyByName("encDbPassSec"))); - - return datasource; - } - - @Bean(name = "secondaryEntityManagerFactory") - public LocalContainerEntityManagerFactoryBean - barEntityManagerFactory( - EntityManagerFactoryBuilder builder, - @Qualifier("secondaryDataSource") DataSource dataSource - ) { - return - builder - .dataSource(dataSource) - .packages("common.iemr.common.secondary.data.report") - .persistenceUnit("db_reporting") - .build(); - } - @Bean(name = "secondaryTransactionManager") - public PlatformTransactionManager barTransactionManager( - @Qualifier("secondaryEntityManagerFactory") EntityManagerFactory - secondaryEntityManagerFactory - ) { - return new JpaTransactionManager(secondaryEntityManagerFactory); - } + @Bean(name = "secondaryTransactionManager") + public PlatformTransactionManager barTransactionManager( + @Qualifier("secondaryEntityManagerFactory") EntityManagerFactory secondaryEntityManagerFactory) { + return new JpaTransactionManager(secondaryEntityManagerFactory); + } } diff --git a/src/main/java/com/iemr/common/config/encryption/SecurePassword.java b/src/main/java/com/iemr/common/config/encryption/SecurePassword.java index d15dbbcb..c8844ce5 100644 --- a/src/main/java/com/iemr/common/config/encryption/SecurePassword.java +++ b/src/main/java/com/iemr/common/config/encryption/SecurePassword.java @@ -11,10 +11,8 @@ import org.springframework.stereotype.Service; @Service -public class SecurePassword -{ - public String generateStrongPassword(String password) throws NoSuchAlgorithmException, InvalidKeySpecException - { +public class SecurePassword { + public String generateStrongPassword(String password) throws NoSuchAlgorithmException, InvalidKeySpecException { int iterations = 1000; char[] chars = password.toCharArray(); byte[] salt = getSalt(); @@ -25,31 +23,26 @@ public String generateStrongPassword(String password) throws NoSuchAlgorithmExce return iterations + ":" + toHex(salt) + ":" + toHex(hash); } - private byte[] getSalt() throws NoSuchAlgorithmException - { + private byte[] getSalt() throws NoSuchAlgorithmException { SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); byte[] salt = new byte[16]; sr.nextBytes(salt); return salt; } - private String toHex(byte[] array) throws NoSuchAlgorithmException - { + private String toHex(byte[] array) { BigInteger bi = new BigInteger(1, array); String hex = bi.toString(16); int paddingLength = array.length * 2 - hex.length(); - if (paddingLength > 0) - { + if (paddingLength > 0) { return String.format(new StringBuilder().append("%0").append(paddingLength).append("d").toString(), - new Object[] - { Integer.valueOf(0) }) + hex; + new Object[] { Integer.valueOf(0) }) + hex; } return hex; } public boolean validatePassword(String originalPassword, String storedPassword) - throws NoSuchAlgorithmException, InvalidKeySpecException - { + throws NoSuchAlgorithmException, InvalidKeySpecException { String[] parts = storedPassword.split(":"); int iterations = Integer.parseInt(parts[0]); byte[] salt = fromHex(parts[1]); @@ -60,18 +53,15 @@ public boolean validatePassword(String originalPassword, String storedPassword) byte[] testHash = skf.generateSecret(spec).getEncoded(); int diff = hash.length ^ testHash.length; - for (int i = 0; (i < hash.length) && (i < testHash.length); i++) - { + for (int i = 0; (i < hash.length) && (i < testHash.length); i++) { diff |= hash[i] ^ testHash[i]; } return diff == 0; } - private byte[] fromHex(String hex) throws NoSuchAlgorithmException - { + private byte[] fromHex(String hex) { byte[] bytes = new byte[hex.length() / 2]; - for (int i = 0; i < bytes.length; i++) - { + for (int i = 0; i < bytes.length; i++) { bytes[i] = ((byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16)); } return bytes; diff --git a/src/main/java/com/iemr/common/config/prototype/BeneficiaryOccupation.java b/src/main/java/com/iemr/common/config/prototype/BeneficiaryOccupation.java index abc26f25..e65f292d 100644 --- a/src/main/java/com/iemr/common/config/prototype/BeneficiaryOccupation.java +++ b/src/main/java/com/iemr/common/config/prototype/BeneficiaryOccupation.java @@ -1,14 +1,6 @@ package com.iemr.common.config.prototype; -import lombok.Data; - -@Data -/** - * @author VI314759 - * - */ -public class BeneficiaryOccupation -{ +public class BeneficiaryOccupation { private Long occupationID; private String occupationType; private Boolean deleted; @@ -17,8 +9,60 @@ public class BeneficiaryOccupation private String key; private String operation; - public BeneficiaryOccupation() - { + public Long getOccupationID() { + return occupationID; + } + + public String getOccupationType() { + return occupationType; + } + + public Boolean getDeleted() { + return deleted; + } + + public String getCreatedby() { + return createdby; + } + + public String getModifiedby() { + return modifiedby; + } + + public String getKey() { + return key; + } + + public String getOperation() { + return operation; + } + public void setOccupationID(Long occupationID) { + this.occupationID = occupationID; } + + public void setOccupationType(String occupationType) { + this.occupationType = occupationType; + } + + public void setDeleted(Boolean deleted) { + this.deleted = deleted; + } + + public void setCreatedby(String createdby) { + this.createdby = createdby; + } + + public void setModifiedby(String modifiedby) { + this.modifiedby = modifiedby; + } + + public void setKey(String key) { + this.key = key; + } + + public void setOperation(String operation) { + this.operation = operation; + } + } diff --git a/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java b/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java index 3128ffa4..954e4608 100644 --- a/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java +++ b/src/main/java/com/iemr/common/config/quartz/QuartzConfig.java @@ -25,12 +25,8 @@ public class QuartzConfig { private final Logger log = LoggerFactory.getLogger(this.getClass().getName()); - - // @Autowired - // private DataSource dataSource; - - // @Autowired(required = true) - // private ConfigProperties configProperties; + private static final String quartzJobGroup = "spring-quartz"; + private static final String quartzJobDefaultSchedule = "0 0 0 31 12 ? *"; @Autowired private PlatformTransactionManager transactionManager; @@ -91,23 +87,22 @@ public JobDetailFactoryBean processMQJobForUnblock() { JobDetailFactoryBean jobDetailFactory; jobDetailFactory = new JobDetailFactoryBean(); jobDetailFactory.setJobClass(ScheduleJobServiceForUnblock.class); - jobDetailFactory.setGroup("spring-quartz"); + jobDetailFactory.setGroup(quartzJobGroup); return jobDetailFactory; } @Bean public CronTriggerFactoryBean processMQTriggerForUnblock() { Boolean startJob = ConfigProperties.getBoolean("start-unblock-scheduler"); - CronTriggerFactoryBean cronTriggerFactoryBean = null; - String scheduleConfig = "0 0 0 31 12 ? *"; + CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean(); + ; + String scheduleConfig = quartzJobDefaultSchedule; if (startJob) { scheduleConfig = ConfigProperties.getPropertyByName("cron-scheduler-unblock"); } - cronTriggerFactoryBean = new CronTriggerFactoryBean(); cronTriggerFactoryBean.setJobDetail(processMQJobForUnblock().getObject()); - cronTriggerFactoryBean.setCronExpression(scheduleConfig); - cronTriggerFactoryBean.setGroup("spring-quartz"); + cronTriggerFactoryBean.setGroup(quartzJobGroup); return cronTriggerFactoryBean; } @@ -117,23 +112,22 @@ public JobDetailFactoryBean processMQJobForSMS() { JobDetailFactoryBean jobDetailFactory; jobDetailFactory = new JobDetailFactoryBean(); jobDetailFactory.setJobClass(ScheduleJobServiceForSMS.class); - jobDetailFactory.setGroup("spring-quartz"); + jobDetailFactory.setGroup(quartzJobGroup); return jobDetailFactory; } @Bean public CronTriggerFactoryBean processMQTriggerForSMS() { Boolean startJob = ConfigProperties.getBoolean("start-sms-scheduler"); - CronTriggerFactoryBean cronTriggerFactoryBean = null; - String scheduleConfig = "0 0 0 31 12 ? *"; + CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean(); + ; + String scheduleConfig = quartzJobDefaultSchedule; if (startJob) { scheduleConfig = ConfigProperties.getPropertyByName("cron-scheduler-sms"); } - cronTriggerFactoryBean = new CronTriggerFactoryBean(); cronTriggerFactoryBean.setJobDetail(processMQJobForSMS().getObject()); - cronTriggerFactoryBean.setCronExpression(scheduleConfig); - cronTriggerFactoryBean.setGroup("spring-quartz"); + cronTriggerFactoryBean.setGroup(quartzJobGroup); return cronTriggerFactoryBean; } @@ -143,23 +137,21 @@ public JobDetailFactoryBean processMQJobForEmail() { JobDetailFactoryBean jobDetailFactory; jobDetailFactory = new JobDetailFactoryBean(); jobDetailFactory.setJobClass(ScheduleJobServiceForEmail.class); - jobDetailFactory.setGroup("spring-quartz"); + jobDetailFactory.setGroup(quartzJobGroup); return jobDetailFactory; } @Bean public CronTriggerFactoryBean processMQTriggerForEmail() { Boolean startJob = ConfigProperties.getBoolean("start-email-scheduler"); - CronTriggerFactoryBean cronTriggerFactoryBean = null; - String scheduleConfig = "0 0 0 31 12 ? *"; + CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean(); + String scheduleConfig = quartzJobDefaultSchedule; if (startJob) { scheduleConfig = ConfigProperties.getPropertyByName("cron-scheduler-email"); } - cronTriggerFactoryBean = new CronTriggerFactoryBean(); cronTriggerFactoryBean.setJobDetail(processMQJobForEmail().getObject()); - cronTriggerFactoryBean.setCronExpression(scheduleConfig); - cronTriggerFactoryBean.setGroup("spring-quartz"); + cronTriggerFactoryBean.setGroup(quartzJobGroup); return cronTriggerFactoryBean; } @@ -169,23 +161,21 @@ public JobDetailFactoryBean processMQJobForRegistration() { JobDetailFactoryBean jobDetailFactory; jobDetailFactory = new JobDetailFactoryBean(); jobDetailFactory.setJobClass(ScheduleForEverwellRegistration.class); - jobDetailFactory.setGroup("spring-quartz"); + jobDetailFactory.setGroup(quartzJobGroup); return jobDetailFactory; } @Bean public CronTriggerFactoryBean processMQTriggerForRegistration() { Boolean startJob = ConfigProperties.getBoolean("start-registration-scheduler"); - CronTriggerFactoryBean cronTriggerFactoryBean = null; - String scheduleConfig = "0 0 0 31 12 ? *"; + CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean(); + String scheduleConfig = quartzJobDefaultSchedule; if (startJob) { scheduleConfig = ConfigProperties.getPropertyByName("cron-scheduler-registration"); } - cronTriggerFactoryBean = new CronTriggerFactoryBean(); cronTriggerFactoryBean.setJobDetail(processMQJobForRegistration().getObject()); - cronTriggerFactoryBean.setCronExpression(scheduleConfig); - cronTriggerFactoryBean.setGroup("spring-quartz"); + cronTriggerFactoryBean.setGroup(quartzJobGroup); return cronTriggerFactoryBean; } @@ -195,23 +185,21 @@ public JobDetailFactoryBean processMQJobForEverwellDataSync() { JobDetailFactoryBean jobDetailFactory; jobDetailFactory = new JobDetailFactoryBean(); jobDetailFactory.setJobClass(ScheduleForEverwellDataSync.class); - jobDetailFactory.setGroup("spring-quartz"); + jobDetailFactory.setGroup(quartzJobGroup); return jobDetailFactory; } @Bean public CronTriggerFactoryBean processMQTriggerForEverwellDataSync() { Boolean startJob = ConfigProperties.getBoolean("start-everwelldatasync-scheduler"); - CronTriggerFactoryBean cronTriggerFactoryBean = null; - String scheduleConfig = "0 0 0 31 12 ? *"; + CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean(); + String scheduleConfig = quartzJobDefaultSchedule; if (startJob) { scheduleConfig = ConfigProperties.getPropertyByName("cron-scheduler-everwelldatasync"); } - cronTriggerFactoryBean = new CronTriggerFactoryBean(); cronTriggerFactoryBean.setJobDetail(processMQJobForEverwellDataSync().getObject()); - cronTriggerFactoryBean.setCronExpression(scheduleConfig); - cronTriggerFactoryBean.setGroup("spring-quartz"); + cronTriggerFactoryBean.setGroup(quartzJobGroup); return cronTriggerFactoryBean; } @@ -221,23 +209,21 @@ public JobDetailFactoryBean processMQJobForCtiDataSync() { JobDetailFactoryBean jobDetailFactory; jobDetailFactory = new JobDetailFactoryBean(); jobDetailFactory.setJobClass(ScheduleForCzentrixCall.class); - jobDetailFactory.setGroup("spring-quartz"); + jobDetailFactory.setGroup(quartzJobGroup); return jobDetailFactory; } @Bean public CronTriggerFactoryBean processMQTriggerForCtiDataSync() { Boolean startJob = ConfigProperties.getBoolean("start-ctidatasync-scheduler"); - CronTriggerFactoryBean cronTriggerFactoryBean = null; - String scheduleConfig = "0 0 0 31 12 ? *"; + CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean(); + String scheduleConfig = quartzJobDefaultSchedule; if (startJob) { scheduleConfig = ConfigProperties.getPropertyByName("cron-scheduler-ctidatasync"); } - cronTriggerFactoryBean = new CronTriggerFactoryBean(); cronTriggerFactoryBean.setJobDetail(processMQJobForCtiDataSync().getObject()); - cronTriggerFactoryBean.setCronExpression(scheduleConfig); - cronTriggerFactoryBean.setGroup("spring-quartz"); + cronTriggerFactoryBean.setGroup(quartzJobGroup); return cronTriggerFactoryBean; } @@ -247,23 +233,21 @@ public JobDetailFactoryBean processMQJobForAvniRegistration() { JobDetailFactoryBean jobDetailFactory; jobDetailFactory = new JobDetailFactoryBean(); jobDetailFactory.setJobClass(ScheduleJobServiceForAvniRegistration.class); - jobDetailFactory.setGroup("spring-quartz"); + jobDetailFactory.setGroup(quartzJobGroup); return jobDetailFactory; } @Bean public CronTriggerFactoryBean processMQTriggerForAvniRegistration() { Boolean startJob = ConfigProperties.getBoolean("start-avni-scheduler"); - CronTriggerFactoryBean cronTriggerFactoryBean = null; - String scheduleConfig = "0 0 0 31 12 ? *"; + CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean(); + String scheduleConfig = quartzJobDefaultSchedule; if (startJob) { scheduleConfig = ConfigProperties.getPropertyByName("cron-avni-registration"); } - cronTriggerFactoryBean = new CronTriggerFactoryBean(); cronTriggerFactoryBean.setJobDetail(processMQJobForAvniRegistration().getObject()); - cronTriggerFactoryBean.setCronExpression(scheduleConfig); - cronTriggerFactoryBean.setGroup("spring-quartz"); + cronTriggerFactoryBean.setGroup(quartzJobGroup); return cronTriggerFactoryBean; } @@ -273,26 +257,23 @@ public JobDetailFactoryBean processMQJobForNHMDashboardData() { JobDetailFactoryBean jobDetailFactory; jobDetailFactory = new JobDetailFactoryBean(); jobDetailFactory.setJobClass(ScheduleJobForNHMDashboardData.class); - jobDetailFactory.setGroup("spring-quartz"); + jobDetailFactory.setGroup(quartzJobGroup); return jobDetailFactory; } @Bean public CronTriggerFactoryBean processMQTriggerForNHMDashboardData() { Boolean startJob = ConfigProperties.getBoolean("start-nhmdashboard-scheduler"); - CronTriggerFactoryBean cronTriggerFactoryBean = null; - String scheduleConfig = "0 0 0 31 12 ? *"; + CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean(); + String scheduleConfig = quartzJobDefaultSchedule; if (startJob) { scheduleConfig = ConfigProperties.getPropertyByName("cron-scheduler-nhmdashboard"); } - cronTriggerFactoryBean = new CronTriggerFactoryBean(); cronTriggerFactoryBean.setJobDetail(processMQJobForNHMDashboardData().getObject()); - cronTriggerFactoryBean.setCronExpression(scheduleConfig); - cronTriggerFactoryBean.setGroup("spring-quartz"); + cronTriggerFactoryBean.setGroup(quartzJobGroup); return cronTriggerFactoryBean; - } } diff --git a/src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java b/src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java index 441356a4..ee66f182 100644 --- a/src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java +++ b/src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java @@ -17,16 +17,15 @@ public class ScheduleJobForNHMDashboardData implements Job { private final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); @Autowired - private NHM_DashboardService nhm_DashboardService; + private NHM_DashboardService nhmDashboardService; @Override public void execute(JobExecutionContext arg0) throws JobExecutionException { logger.info("Started job for NHM dashboard data pull from cti " + arg0.getClass().getName()); try { - String s = nhm_DashboardService.pull_NHM_Data_CTI(); + String s = nhmDashboardService.pull_NHM_Data_CTI(); logger.info(s); } catch (Exception e) { - // TODO Auto-generated catch block logger.error(e.getLocalizedMessage()); } logger.info("Completed job for NHM dashboard data pull from cti " + arg0.getClass().getName()); diff --git a/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java b/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java index aa602574..b10fb705 100644 --- a/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java +++ b/src/main/java/com/iemr/common/controller/beneficiary/BeneficiaryRegistrationController.java @@ -3,7 +3,6 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; -// import javax.transaction.Transactional; import javax.ws.rs.core.MediaType; import org.json.JSONArray; @@ -32,7 +31,6 @@ import com.iemr.common.service.beneficiary.IEMRSearchUserService; import com.iemr.common.service.beneficiary.RegisterBenificiaryService; import com.iemr.common.service.beneficiary.SexualOrientationService; -import com.iemr.common.service.callhandling.CalltypeService; import com.iemr.common.service.directory.DirectoryService; import com.iemr.common.service.location.LocationService; import com.iemr.common.service.reports.CallReportsService; @@ -62,6 +60,7 @@ public class BeneficiaryRegistrationController { private InputMapper inputMapper = new InputMapper(); private final Logger logger = LoggerFactory.getLogger(this.getClass().getName()); + private static final String AUTHORIZATION = "authorization"; private RegisterBenificiaryService registerBenificiaryService; private IEMRBeneficiaryTypeService iemrBeneficiaryTypeService; private IEMRSearchUserService iemrSearchUserService; @@ -78,7 +77,6 @@ public class BeneficiaryRegistrationController { private BenRelationshipTypeService benRelationshipTypeService; private BeneficiaryOccupationService beneficiaryOccupationService; private GovtIdentityTypeService govtIdentityTypeService; - private CalltypeService calltypeService; @Autowired public void setBenRelationshipTypeService(BenRelationshipTypeService benRelationshipTypeService) { @@ -155,11 +153,6 @@ public void setSexualOrientationService(SexualOrientationService sexualOrientati this.sexualOrientationService = sexualOrientationService; } - @Autowired - public void setCalltypeService(CalltypeService calltypeService) { - this.calltypeService = calltypeService; - } - @Autowired public void setGovtIdentityTypeService(GovtIdentityTypeService govtIdentityTypeService) { this.govtIdentityTypeService = govtIdentityTypeService; @@ -189,8 +182,6 @@ public String createBeneficiary( logger.info("Create beneficiary request " + beneficiaryModel); try { - // BeneficiaryModel beneficiaryModel = - // inputMapper.gson().fromJson(createRequest, BeneficiaryModel.class); response.setResponse(registerBenificiaryService.save(beneficiaryModel, httpRequest)); } catch (Exception e) { logger.error("create beneficiary failed with error " + e.getMessage(), e); @@ -201,36 +192,6 @@ public String createBeneficiary( return response.toString(); } - // @ApiOperation(value = "Creates a new beneficiary") - // @CrossOrigin() - // @RequestMapping(value = "/createV1", method = RequestMethod.POST, produces = - // "application/json", - // consumes = "application/json", headers = "Authorization") - // @Transactional - // - // public String createBeneficiaryV1(@RequestBody BeneficiaryModel - // beneficiaryModel, HttpServletRequest httpRequest) - // { - // OutputResponse response = new OutputResponse(); - // - // logger.info("Create beneficiary request " + beneficiaryModel); - // try - // { - // - // // BeneficiaryModel beneficiaryModel = - // inputMapper.gson().fromJson(createRequest, BeneficiaryModel.class); - // response.setResponse(registerBenificiaryService.save(beneficiaryModel, - // httpRequest)); - // } catch (Exception e) - // { - // logger.error("create beneficiary failed with error " + e.getMessage(), e); - // response.setError(e); - // } - // - // logger.info("create beneficiary response " + response.toString()); - // return response.toString(); - // } - /** * @param beneficiaryType * @return @@ -263,8 +224,7 @@ public String getBeneficiaryRelation() { OutputResponse response = new OutputResponse(); logger.info("Get relationship request"); try { - Iterable iBeneficiaryTypes; - iBeneficiaryTypes = this.iemrBeneficiaryTypeService.getRelations(); + Iterable iBeneficiaryTypes = this.iemrBeneficiaryTypeService.getRelations(); } catch (Exception e) { logger.error("get relationships failed with error " + e.getMessage(), e); response.setError(e); @@ -281,7 +241,7 @@ public String searchUser(@PathVariable("id") String beneficiaryId, HttpServletRe logger.info("serach user beneficiaryId:" + beneficiaryId); OutputResponse response = new OutputResponse(); - String auth = httpRequest.getHeader("authorization"); + String auth = httpRequest.getHeader(AUTHORIZATION); try { List iBeneficiary = this.iemrSearchUserService.userExitsCheckWithId(beneficiaryId, auth, false); @@ -302,7 +262,7 @@ public String searchUserByID( HttpServletRequest httpRequest) { OutputResponse response = new OutputResponse(); - String auth = httpRequest.getHeader("authorization"); + String auth = httpRequest.getHeader(AUTHORIZATION); logger.info("Search user by ID request " + request); try { BeneficiaryModel benificiaryDetails = InputMapper.gson().fromJson(request, BeneficiaryModel.class); @@ -347,7 +307,7 @@ public String searchUserByPhone( @ApiParam("{\"phoneNo\":\"String\",\"pageNo\":\"Integer\",\"rowsPerPage\":\"Integer\"}") @RequestBody String request, HttpServletRequest httpRequest) { OutputResponse response = new OutputResponse(); - String auth = httpRequest.getHeader("authorization"); + String auth = httpRequest.getHeader(AUTHORIZATION); logger.info("Serach user by phone no request " + request); try { JSONObject requestObj = new JSONObject(request); @@ -377,7 +337,7 @@ public String searchBeneficiary( HttpServletRequest httpRequest) { logger.info("searchBeneficiary request " + request); OutputResponse output = new OutputResponse(); - String auth = httpRequest.getHeader("authorization"); + String auth = httpRequest.getHeader(AUTHORIZATION); try { output.setResponse(iemrSearchUserService.findBeneficiary(request, auth)); } catch (NumberFormatException ne) { @@ -419,7 +379,6 @@ public String getRegistrationData() { logger.error("get user registration data failed with error " + e.getMessage(), e); } logger.info("get user registration data response " + response.toString()); - // return beneficiaryRegistrationData.toString(); return response.toString(); } @@ -454,14 +413,12 @@ public String getRegistrationDataV1( logger.error("get user registration data failed with error " + e.getMessage(), e); } logger.info("get user registration data response " + response.toString()); - // return beneficiaryRegistrationData.toString(); return response.toString(); } @CrossOrigin() @ApiOperation(value = "Updating beneficiary details") @RequestMapping(value = "/update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON, headers = "Authorization") - // @Transactional public String updateBenefciary( @ApiParam("{\"beneficiaryRegID\":\"Long\",\"firstName\":\"String\",\"lastName\":\"String\"," + "\"dOB\":\"Timestamp\",\"ageUnits\":\"String\",\"fatherName\":\"String\",\"spouseName\":\"String\"," @@ -477,7 +434,7 @@ public String updateBenefciary( + "\"changeInFamilyDetails\":\"Boolean\"}") @RequestBody String benificiaryRequest, HttpServletRequest httpRequest) { OutputResponse response = new OutputResponse(); - String auth = httpRequest.getHeader("authorization"); + String auth = httpRequest.getHeader(AUTHORIZATION); Integer updateCount = 0; try { BeneficiaryModel benificiaryDetails = inputMapper.gson().fromJson(benificiaryRequest, @@ -509,9 +466,8 @@ public String updateBenefciary( @RequestMapping(value = "/getBeneficiariesByPhoneNo", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON, headers = "Authorization") public String getBeneficiariesByPhone(@ApiParam("{\"phoneNo\":\"String\"}") @RequestBody String request, HttpServletRequest httpRequest) { - // String response = "[]"; OutputResponse response = new OutputResponse(); - String auth = httpRequest.getHeader("authorization"); + String auth = httpRequest.getHeader(AUTHORIZATION); logger.info("getBeneficiariesByPhoneNo request " + request); try { BenPhoneMap benPhoneMap = inputMapper.gson().fromJson(request, BenPhoneMap.class); @@ -522,20 +478,18 @@ public String getBeneficiariesByPhone(@ApiParam("{\"phoneNo\":\"String\"}") @Req response.setError(e); logger.error("getBeneficiariesByPhoneNo failed with error " + e.getMessage(), e); } -// logger.info("getBeneficiariesByPhoneNo response " + response.toString()); return response.toString(); } @CrossOrigin() @ApiOperation(value = "Update beneficiary community or education") @RequestMapping(value = "/updateCommunityorEducation", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON, headers = "Authorization") - // @Transactional public String updateBenefciaryCommunityorEducation( @ApiParam("{\"beneficiaryRegID\":\"Long\",\"i_bendemographics\":{\"communityID\":\"Integer\"," + "\"educationID\":\"Integer\"}}") @RequestBody String benificiaryRequest, HttpServletRequest httpRequest) { OutputResponse response = new OutputResponse(); - String auth = httpRequest.getHeader("authorization"); + String auth = httpRequest.getHeader(AUTHORIZATION); Integer updateCount = 0; try { BeneficiaryModel benificiaryDetails = inputMapper.gson().fromJson(benificiaryRequest, @@ -551,12 +505,7 @@ public String updateBenefciaryCommunityorEducation( responseObj.put("updateCount", updateCount); response.setResponse(responseObj.toString()); } - } -// catch (JSONException e) { -// logger.error("Update beneficiary failed with error " + e.getMessage(), e); -// response.setError(e); -// } - catch (Exception e) { + } catch (Exception e) { logger.error("Update beneficiary failed with error " + e.getMessage(), e); response.setError(e); } @@ -582,9 +531,6 @@ public String getBeneficiaryIDs( logger.error(e.getMessage()); response.setError(e); } - /** - * sending the response... - */ return response.toString(); }