Skip to content
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
<dependency>
<groupId>com.mysql</groupId>
Expand Down
7 changes: 7 additions & 0 deletions src/main/environment/common_ci.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ spring.datasource.username=@env.DATABASE_IDENTITY_USERNAME@
spring.datasource.password=@env.DATABASE_IDENTITY_PASSWORD@
spring.datasource.driver-class-name=com.mysql.jdbc.Driver


secondary.datasource.url=@env.DATABASE_URL@
secondary.datasource.username=@env.DATABASE_USERNAME@
secondary.datasource.password=@env.DATABASE_PASSWORD@
secondary.datasource.driver-class-name=com.mysql.jdbc.Driver


#ELK logging file name
logging.path=logs/
logging.file.name=@env.IDENTITY_API_LOGGING_FILE_NAME@
Expand Down
7 changes: 7 additions & 0 deletions src/main/environment/common_docker.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ spring.datasource.username=${DATABASE_IDENTITY_USERNAME}
spring.datasource.password=${DATABASE_IDENTITY_PASSWORD}
spring.datasource.driver-class-name=com.mysql.jdbc.Driver


secondary.datasource.url=${DATABASE_URL}
secondary.datasource.username=${DATABASE_USERNAME}
secondary.datasource.password=${DATABASE_PASSWORD}
secondary.datasource.driver-class-name=com.mysql.jdbc.Driver


#ELK logging file name
logging.path=logs/
logging.file.name=${IDENTITY_API_LOGGING_FILE_NAME}
Expand Down
6 changes: 6 additions & 0 deletions src/main/environment/common_example.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.jdbc.Driver


secondary.datasource.url=jdbc:mysql://localhost:3306/db_iemr
secondary.datasource.username=root
secondary.datasource.password=root123

Check failure

Code scanning / SonarCloud

Database passwords should not be disclosed High

Make sure this database password gets changed and removed from the code. See more on SonarQube Cloud
secondary.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

jwt.secret=my-32-character-ultra-secure-and-ultra-long-secret
logging.path=logs/
logging.file.name=logs/identity-api.log
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/com/iemr/common/identity/config/PrimaryDBConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* AMRIT – Accessible Medical Records via Integrated Technology
* Integrated EHR (Electronic Health Records) Solution
*
* Copyright (C) "Piramal Swasthya Management and Research Institute"
*
* This file is part of AMRIT.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.config;

import com.iemr.common.identity.utils.config.ConfigProperties;
import jakarta.persistence.EntityManagerFactory;
import org.apache.tomcat.jdbc.pool.DataSource;
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", basePackages = {"com.iemr.common.identity.domain.identity",
"com.iemr.common.identity.repo","com.iemr.common.identity.data.rmnch",})
public class PrimaryDBConfig {

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

@Primary
@Bean(name = "dataSource")
@ConfigurationProperties(prefix = "spring.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(ConfigProperties.getPropertyByName("spring.datasource.username"));
datasource.setPassword(ConfigProperties.getPropertyByName("spring.datasource.password"));

return datasource;
}

@Primary
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder,
@Qualifier("dataSource") DataSource dataSource) {
return builder.dataSource(dataSource).packages("com.iemr.common.identity.domain.identity","com.iemr.common.identity.data.rmnch").persistenceUnit("db_identity").build();
}

@Primary
@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(
@Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* AMRIT – Accessible Medical Records via Integrated Technology
* Integrated EHR (Electronic Health Records) Solution
*
* Copyright (C) "Piramal Swasthya Management and Research Institute"
*
* This file is part of AMRIT.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.config;

import com.iemr.common.identity.utils.config.ConfigProperties;
import jakarta.persistence.EntityManagerFactory;
import org.apache.tomcat.jdbc.pool.DataSource;
import org.apache.tomcat.jdbc.pool.PoolConfiguration;
import org.apache.tomcat.jdbc.pool.PoolProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(entityManagerFactoryRef = "secondaryEntityManagerFactory",
transactionManagerRef = "secondaryTransactionManager", basePackages = {"com.iemr.common.identity.domain.iemr"})
public class SecondaryDBConfig {

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);

datasource.setUsername(ConfigProperties.getPropertyByName("secondary.datasource.username"));
datasource.setPassword(ConfigProperties.getPropertyByName("secondary.datasource.password"));


return datasource;
}

@Bean(name = "secondaryEntityManagerFactory")
public LocalContainerEntityManagerFactoryBean barEntityManagerFactory(EntityManagerFactoryBuilder builder,
@Qualifier("secondaryDataSource") DataSource dataSource) {
return builder.dataSource(dataSource).packages("com.iemr.common.identity.domain.iemr").persistenceUnit("db_iemr").build();
}

@Bean(name = "secondaryTransactionManager")
public PlatformTransactionManager barTransactionManager(
@Qualifier("secondaryEntityManagerFactory") EntityManagerFactory secondaryEntityManagerFactory) {
return new JpaTransactionManager(secondaryEntityManagerFactory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

import co.elastic.clients.elasticsearch.ElasticsearchClient;

import com.iemr.common.identity.domain.MBeneficiarymapping;
import com.iemr.common.identity.domain.identity.MBeneficiarymapping;
import com.iemr.common.identity.service.elasticsearch.ElasticsearchIndexingService;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.math.BigInteger;
import java.sql.Timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.math.BigInteger;
import java.sql.Timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.math.BigInteger;
import java.sql.Timestamp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.io.Serializable;
import java.math.BigInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.io.Serializable;
import java.math.BigInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.io.Serializable;
import java.math.BigInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.io.Serializable;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;

import org.json.JSONObject;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand All @@ -39,8 +37,6 @@
import jakarta.persistence.Table;
import jakarta.persistence.Transient;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.annotations.Expose;

import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.io.Serializable;
import java.math.BigInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.io.Serializable;
import java.math.BigInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.io.Serializable;
import java.math.BigInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.io.Serializable;
import java.math.BigInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.io.Serializable;
import java.math.BigInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.sql.Timestamp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
package com.iemr.common.identity.domain;
package com.iemr.common.identity.domain.identity;

import java.util.ArrayList;
import java.util.List;
Expand Down
Loading
Loading