Skip to content

Commit b804de1

Browse files
authored
Merge pull request #384 from PSMRI/rebase-3.7.0
Rebase 3.7.0
2 parents 02f209d + f3364e9 commit b804de1

54 files changed

Lines changed: 2065 additions & 303 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/swagger-json.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Sync Swagger to AMRIT-Docs
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
swagger-sync:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 20
12+
13+
steps:
14+
- name: Checkout API repo
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Java 17
18+
uses: actions/setup-java@v4
19+
with:
20+
distribution: temurin
21+
java-version: 17
22+
cache: maven
23+
24+
- name: Build API (skip tests)
25+
run: mvn -B clean package -DskipTests
26+
27+
- name: Install jq
28+
run: sudo apt-get update && sudo apt-get install -y jq
29+
30+
- name: Run API in swagger profile
31+
run: |
32+
mvn spring-boot:run \
33+
-Dspring-boot.run.profiles=swagger \
34+
-Dspring-boot.run.arguments=--server.port=9090 \
35+
> app.log 2>&1 &
36+
echo $! > api_pid.txt
37+
38+
- name: Wait for API & fetch Swagger
39+
run: |
40+
for i in {1..40}; do
41+
CODE=$(curl --connect-timeout 2 --max-time 5 -s -o swagger_raw.json -w "%{http_code}" http://localhost:9090/v3/api-docs || true)
42+
43+
if [ "$CODE" = "200" ]; then
44+
jq . swagger_raw.json > common-api.json || {
45+
echo "Swagger JSON invalid"
46+
cat swagger_raw.json
47+
exit 1
48+
}
49+
50+
if [ "$(jq '.paths | length' common-api.json)" -eq 0 ]; then
51+
echo "Swagger paths empty – failing"
52+
exit 1
53+
fi
54+
55+
echo "Swagger generated successfully"
56+
exit 0
57+
fi
58+
59+
echo "Waiting for API... ($i)"
60+
sleep 4
61+
done
62+
63+
echo "Swagger not generated"
64+
cat app.log || true
65+
exit 1
66+
67+
- name: Stop API
68+
if: always()
69+
run: |
70+
# Graceful shutdown of the process group
71+
sleep 5
72+
# Force kill the process group if still running
73+
if [ -f api_pid.txt ]; then
74+
PID=$(cat api_pid.txt)
75+
kill -TERM -- -"$PID" 2>/dev/null || true
76+
sleep 2
77+
kill -9 -- -"$PID" 2>/dev/null || true
78+
fi
79+
# Fallback: kill any remaining java process on port 9090
80+
fuser -k 9090/tcp 2>/dev/null || true
81+
82+
- name: Checkout AMRIT-Docs
83+
uses: actions/checkout@v4
84+
with:
85+
repository: PSMRI/AMRIT-Docs
86+
token: ${{ secrets.DOCS_REPO_TOKEN }}
87+
path: amrit-docs
88+
fetch-depth: 0
89+
90+
- name: Copy Swagger JSON
91+
run: |
92+
mkdir -p amrit-docs/docs/swagger
93+
cp common-api.json amrit-docs/docs/swagger/common-api.json
94+
95+
# Use a fixed branch name for PRs to avoid accumulating stale PRs.
96+
# This ensures only one open PR is updated per run; delete-branch: true cleans up after merge.
97+
- name: Create Pull Request
98+
uses: peter-evans/create-pull-request@v8
99+
with:
100+
token: ${{ secrets.DOCS_REPO_TOKEN }}
101+
path: amrit-docs
102+
branch: auto/swagger-update-common-api
103+
base: main
104+
commit-message: "chore(docs): auto-update Common-API swagger"
105+
title: "chore(docs): auto-update Common-API swagger"
106+
delete-branch: true
107+
body: |
108+
This PR automatically updates Common-API Swagger JSON
109+
from the latest main branch build.

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"java.compile.nullAnalysis.mode": "automatic"
3+
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# AMRIT - Common Service
2-
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) ![branch parameter](https://github.com/PSMRI/Common-API/actions/workflows/sast-and-package.yml/badge.svg)
2+
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
3+
[![DeepWiki](https://img.shields.io/badge/DeepWiki-PSMRI/Common--API-blue)](https://deepwiki.com/PSMRI/Common-API)
34

45

56
Common API is a microservice whch acts as a gateway for AMRIT. There are many APIs that are exposed by Common-API. It contains APIs of common integrators like c-Zentrix, Everwell, Openkm and some master APIs like location master, alerts, notification,language and location messages.
@@ -87,4 +88,3 @@ If you encounter any issues, bugs, or have feature requests, please file them in
8788
8889
We’d love to have you join our community discussions and get real-time support!
8990
Join our [Discord server](https://discord.gg/FVQWsf5ENS) to connect with contributors, ask questions, and stay updated.
90-

pom.xml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.iemr.common-API</groupId>
88
<artifactId>common-api</artifactId>
9-
<version>3.6.0</version>
9+
<version>3.7.0</version>
1010
<packaging>war</packaging>
1111

1212
<name>Common-API</name>
@@ -54,6 +54,12 @@
5454
</repository>
5555
</repositories>
5656
<dependencies>
57+
58+
<dependency>
59+
<groupId>com.h2database</groupId>
60+
<artifactId>h2</artifactId>
61+
<scope>runtime</scope>
62+
</dependency>
5763

5864
<dependency>
5965
<groupId>org.springframework.boot</groupId>
@@ -520,6 +526,32 @@
520526
<build>
521527
<finalName>${artifactId}-${version}</finalName>
522528
<plugins>
529+
<plugin>
530+
<groupId>io.github.git-commit-id</groupId>
531+
<artifactId>git-commit-id-maven-plugin</artifactId>
532+
<version>9.0.2</version>
533+
<executions>
534+
<execution>
535+
<id>get-the-git-infos</id>
536+
<goals>
537+
<goal>revision</goal>
538+
</goals>
539+
<phase>initialize</phase>
540+
</execution>
541+
</executions>
542+
<configuration>
543+
<generateGitPropertiesFile>true</generateGitPropertiesFile>
544+
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
545+
<includeOnlyProperties>
546+
<property>^git.branch$</property>
547+
<property>^git.commit.id.abbrev$</property>
548+
<property>^git.build.version$</property>
549+
<property>^git.build.time$</property>
550+
</includeOnlyProperties>
551+
<failOnNoGitDirectory>false</failOnNoGitDirectory>
552+
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
553+
</configuration>
554+
</plugin>
523555
<plugin>
524556
<groupId>org.apache.maven.plugins</groupId>
525557
<artifactId>maven-jar-plugin</artifactId>

src/main/environment/common_ci.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ km-base-path=@env.KM_API_BASE_PATH@
1919
km-root-path=/okm:personal/users/
2020
km-guest-user=@env.KM_GUEST_USER@
2121
km-guest-password=@env.KM_GUEST_PASSWORD@
22+
tempFilePath=@env.TEMP_FILE_PATH@
2223

2324
# CTI Config
2425
cti-server-ip=@env.CTI_SERVER_IP@
@@ -202,5 +203,9 @@ platform.feedback.ratelimit.day-limit=@env.PLATFORM_FEEDBACK_RATELIMIT_DAY_LIMIT
202203
platform.feedback.ratelimit.user-day-limit=@env.PLATFORM_FEEDBACK_RATELIMIT_USER_DAY_LIMIT@
203204
platform.feedback.ratelimit.fail-window-minutes=@env.PLATFORM_FEEDBACK_RATELIMIT_FAIL_WINDOW_MINUTES@
204205
platform.feedback.ratelimit.backoff-minutes=@env.PLATFORM_FEEDBACK_RATELIMIT_BACKOFF_MINUTES@
206+
otp.ratelimit.enabled=@env.OTP_RATELIMIT_ENABLED@
207+
otp.ratelimit.minute-limit=@env.OTP_RATELIMIT_MINUTE_LIMIT@
208+
otp.ratelimit.hour-limit=@env.OTP_RATELIMIT_HOUR_LIMIT@
209+
otp.ratelimit.day-limit=@env.OTP_RATELIMIT_DAY_LIMIT@
205210
generateBeneficiaryIDs-api-url=@env.GEN_BENEFICIARY_IDS_API_URL@
206211

src/main/environment/common_docker.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ everwellRegisterBenficiary = ${COMMON_API_BASE_URL}/beneficiary/create
126126
## LungAssessment credentials
127127
lungAssessmentEmail = ${SWAASA_EMAIL}
128128
lungAssessmentPassword =${SWAASA_PASSWORD}
129-
129+
tempFilePath=${TEMP_FILE_PATH}
130130

131131
## SWASSA APIs
132132
lungAssessmentAdminLogin = ${SWAASA_BASE_URL}/api/adminLogin
@@ -206,4 +206,8 @@ platform.feedback.ratelimit.day-limit=${PLATFORM_FEEDBACK_RATELIMIT_DAY_LIMIT}
206206
platform.feedback.ratelimit.user-day-limit=${PLATFORM_FEEDBACK_RATELIMIT_USER_DAY_LIMIT}
207207
platform.feedback.ratelimit.fail-window-minutes=${PLATFORM_FEEDBACK_RATELIMIT_FAIL_WINDOW_MINUTES}
208208
platform.feedback.ratelimit.backoff-minutes=${PLATFORM_FEEDBACK_RATELIMIT_BACKOFF_MINUTES}
209+
otp.ratelimit.enabled=${OTP_RATELIMIT_ENABLED}
210+
otp.ratelimit.minute-limit=${OTP_RATELIMIT_MINUTE_LIMIT}
211+
otp.ratelimit.hour-limit=${OTP_RATELIMIT_HOUR_LIMIT}
212+
otp.ratelimit.day-limit=${OTP_RATELIMIT_DAY_LIMIT}
209213
generateBeneficiaryIDs-api-url={GEN_BENEFICIARY_IDS_API_URL}

src/main/environment/common_example.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ km-root-path=/okm:personal/users/
2525
km-guest-user=guest
2626
km-guest-password=guest
2727

28+
tempFilePath=/opt/openkm
29+
2830
# CTI Config
2931
cti-server-ip=10.208.122.99
3032
cti-logger_base_url=http://10.208.122.99/logger
@@ -224,5 +226,10 @@ platform.feedback.ratelimit.user-day-limit=50
224226
platform.feedback.ratelimit.fail-window-minutes=5
225227
platform.feedback.ratelimit.backoff-minutes=15
226228

229+
# --- OTP Rate Limiting (per mobile number) ---
230+
otp.ratelimit.minute-limit=3
231+
otp.ratelimit.hour-limit=10
232+
otp.ratelimit.day-limit=20
233+
227234
### generate Beneficiary IDs URL
228235
generateBeneficiaryIDs-api-url=/generateBeneficiaryController/generateBeneficiaryIDs

src/main/java/com/iemr/common/config/PrimaryDBConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
4040
import org.springframework.transaction.PlatformTransactionManager;
4141
import org.springframework.transaction.annotation.EnableTransactionManagement;
42+
import org.springframework.context.annotation.Profile;
4243

4344
import com.iemr.common.utils.config.ConfigProperties;
4445

@@ -47,7 +48,8 @@
4748
@Configuration
4849
@EnableTransactionManagement
4950
@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", basePackages = { "com.iemr.common.repository",
50-
"com.iemr.common.repo", "com.iemr.common.notification.agent", "com.iemr.common.covidVaccination", "com.iemr.common.repository.everwell.*", "com.iemr.common.data.grievance", "com.iemr.common.repository.users" })
51+
"com.iemr.common.repo", "com.iemr.common.notification.agent", "com.iemr.common.covidVaccination", "com.iemr.common.repository.everwell.*", "com.iemr.common.data.grievance", "com.iemr.common.repository.users" })
52+
@Profile("!swagger")
5153
public class PrimaryDBConfig {
5254

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

src/main/java/com/iemr/common/config/SecondaryDBConfig.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@
4343

4444
import jakarta.persistence.EntityManagerFactory;
4545

46+
import org.springframework.context.annotation.Profile;
47+
4648
@Configuration
4749
@EnableTransactionManagement
4850
@EnableJpaRepositories(entityManagerFactoryRef = "secondaryEntityManagerFactory", transactionManagerRef = "secondaryTransactionManager", basePackages = {
49-
"com.iemr.common.secondary.repository.callreport" })
51+
"com.iemr.common.secondary.repository.callreport" })
52+
@Profile("!swagger")
5053
public class SecondaryDBConfig {
5154

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

src/main/java/com/iemr/common/config/SwaggerConfig.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.springframework.context.annotation.Bean;
44
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.core.env.Environment;
56

67
import io.swagger.v3.oas.models.Components;
78
import io.swagger.v3.oas.models.OpenAPI;
@@ -11,14 +12,23 @@
1112

1213
@Configuration
1314
public class SwaggerConfig {
14-
15-
@Bean
16-
public OpenAPI customOpenAPI() {
17-
return new OpenAPI().info(new
18-
Info().title("Common API").version("version").description("A microservice for the creation and management of beneficiaries."))
19-
.addSecurityItem(new SecurityRequirement().addList("my security"))
20-
.components(new Components().addSecuritySchemes("my security",
21-
new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer")));
15+
private static final String DEFAULT_SERVER_URL = "http://localhost:9090";
16+
17+
@Bean
18+
public OpenAPI customOpenAPI(Environment env) {
19+
String devUrl = env.getProperty("api.dev.url", DEFAULT_SERVER_URL);
20+
String uatUrl = env.getProperty("api.uat.url", DEFAULT_SERVER_URL);
21+
String demoUrl = env.getProperty("api.demo.url", DEFAULT_SERVER_URL);
22+
return new OpenAPI()
23+
.info(new Info().title("Common API").version("version").description("A microservice for the creation and management of beneficiaries."))
24+
.addSecurityItem(new SecurityRequirement().addList("my security"))
25+
.components(new Components().addSecuritySchemes("my security",
26+
new SecurityScheme().name("my security").type(SecurityScheme.Type.HTTP).scheme("bearer")))
27+
.servers(java.util.Arrays.asList(
28+
new io.swagger.v3.oas.models.servers.Server().url(devUrl).description("Dev"),
29+
new io.swagger.v3.oas.models.servers.Server().url(uatUrl).description("UAT"),
30+
new io.swagger.v3.oas.models.servers.Server().url(demoUrl).description("Demo")
31+
));
2232
}
2333

2434
}

0 commit comments

Comments
 (0)