-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
224 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
exec/src/main/java/com/google/fhir/gateway/ResourceValidatorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.google.fhir.gateway; | ||
|
||
import com.google.fhir.gateway.interfaces.ResourceValidator; | ||
import com.google.fhir.gateway.validators.ImmunizationResourceValidator; | ||
import com.google.fhir.gateway.validators.PatientResourceValidator; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Objects; | ||
|
||
@Component | ||
public class ResourceValidatorFactory { | ||
public ResourceValidator getValidator(String resourceType) { | ||
|
||
String resourceTypeData = ""; | ||
if (Objects.equals(resourceType, "Patient")) { | ||
resourceTypeData = FHIRResourceTypesData.PATIENT.name(); | ||
} else if (Objects.equals(resourceType, "Immunization")) { | ||
resourceTypeData = FHIRResourceTypesData.IMMUNIZATION.name(); | ||
}else { | ||
resourceTypeData = resourceType; | ||
} | ||
|
||
if (Objects.equals(resourceTypeData, FHIRResourceTypesData.PATIENT.name())){ | ||
return new PatientResourceValidator(); | ||
}else if (Objects.equals(resourceTypeData, FHIRResourceTypesData.IMMUNIZATION.name())){ | ||
return new ImmunizationResourceValidator(); | ||
}else { | ||
return null; // or throw an exception here depending on your needs. | ||
} | ||
|
||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
exec/src/main/java/com/google/fhir/gateway/interfaces/ResourceValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.google.fhir.gateway.interfaces; | ||
|
||
import jakarta.servlet.http.HttpServletRequest; | ||
import retrofit2.Call; | ||
|
||
public interface ResourceValidator { | ||
Call<Object> getResource(String role, String targetUrl); | ||
Call<Object> createResource(String role, String targetUrl, HttpServletRequest requestBody); | ||
Call<Object> updateResource(String role, String targetUrl , HttpServletRequest requestBody); | ||
Call<Object> deleteResource(String role, String targetUrl); | ||
} | ||
|
62 changes: 62 additions & 0 deletions
62
exec/src/main/java/com/google/fhir/gateway/validators/ImmunizationResourceValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.google.fhir.gateway.validators; | ||
|
||
import com.google.fhir.gateway.ApiServiceImpl; | ||
import com.google.fhir.gateway.interfaces.AccessChecker; | ||
import com.google.fhir.gateway.interfaces.AccessDecision; | ||
import com.google.fhir.gateway.interfaces.RequestDetailsReader; | ||
import com.google.fhir.gateway.interfaces.ResourceValidator; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import retrofit2.Call; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class ImmunizationResourceValidator implements AccessChecker, ResourceValidator { | ||
|
||
private final ApiServiceImpl apiService = new ApiServiceImpl(); | ||
|
||
@Override | ||
public AccessDecision checkAccess(RequestDetailsReader requestDetails) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Call<Object> getResource(String role, String targetUrl) { | ||
return apiService.getResource(targetUrl); | ||
} | ||
|
||
@Override | ||
public Call<Object> createResource(String role, String targetUrl, HttpServletRequest requestBody) { | ||
return apiService.createResource(targetUrl, readRequestBody(requestBody)); | ||
} | ||
|
||
@Override | ||
public Call<Object> updateResource(String role, String targetUrl, HttpServletRequest requestBody) { | ||
return apiService.updateResource(targetUrl, readRequestBody(requestBody)); | ||
} | ||
|
||
@Override | ||
public Call<Object> deleteResource(String role, String targetUrl) { | ||
return apiService.deleteResource(targetUrl); | ||
} | ||
|
||
private String readRequestBody(HttpServletRequest request) { | ||
|
||
try{ | ||
|
||
StringBuilder stringBuilder = new StringBuilder(); | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream(), "utf-8"))) { | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
stringBuilder.append(line); | ||
} | ||
} | ||
return stringBuilder.toString(); | ||
|
||
}catch (IOException e) { | ||
e.printStackTrace(); | ||
return null; // or throw an exception here depending on your needs. | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
exec/src/main/java/com/google/fhir/gateway/validators/PatientResourceValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.google.fhir.gateway.validators; | ||
|
||
import com.google.fhir.gateway.ApiServiceImpl; | ||
import com.google.fhir.gateway.interfaces.AccessChecker; | ||
import com.google.fhir.gateway.interfaces.AccessDecision; | ||
import com.google.fhir.gateway.interfaces.RequestDetailsReader; | ||
import com.google.fhir.gateway.interfaces.ResourceValidator; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import retrofit2.Call; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
public class PatientResourceValidator implements AccessChecker, ResourceValidator { | ||
|
||
private final ApiServiceImpl apiService = new ApiServiceImpl(); | ||
|
||
@Override | ||
public AccessDecision checkAccess(RequestDetailsReader requestDetails) { | ||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public Call<Object> getResource(String role, String targetUrl) { | ||
return apiService.getResource(targetUrl); | ||
} | ||
|
||
@Override | ||
public Call<Object> createResource(String role, String targetUrl, HttpServletRequest requestBody) { | ||
return apiService.createResource(targetUrl, readRequestBody(requestBody)); | ||
} | ||
|
||
@Override | ||
public Call<Object> updateResource(String role, String targetUrl, HttpServletRequest requestBody) { | ||
return apiService.updateResource(targetUrl, readRequestBody(requestBody)); | ||
} | ||
|
||
@Override | ||
public Call<Object> deleteResource(String role, String targetUrl) { | ||
return apiService.deleteResource(targetUrl); | ||
} | ||
|
||
private String readRequestBody(HttpServletRequest request) { | ||
|
||
try{ | ||
|
||
StringBuilder stringBuilder = new StringBuilder(); | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream(), "utf-8"))) { | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
stringBuilder.append(line); | ||
} | ||
} | ||
return stringBuilder.toString(); | ||
|
||
}catch (IOException e) { | ||
e.printStackTrace(); | ||
return null; // or throw an exception here depending on your needs. | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters