Skip to content
Open
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
3 changes: 3 additions & 0 deletions src/main/java/com/iemr/tm/repo/nurse/BenVisitDetailRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public List<Object[]> getBeneficiaryVisitDetails(@Param("benRegID") Long benRegI
@Query(nativeQuery = true, value = " SELECT FileUID from t_kmfilemanager where KmFileManagerID = :fileID ")
public String getFileUUID(@Param("fileID") int fileID);

@Query(nativeQuery = true, value = " SELECT FileName from t_kmfilemanager where KmFileManagerID = :fileID ")
public String getFileName(@Param("fileID") int fileID);

// get file uuid from file id
@Transactional
@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
*/
package com.iemr.tm.service.common.transaction;

import java.net.URL;
import java.net.HttpURLConnection;
import java.io.InputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -554,14 +558,16 @@

// end

public String getOpenKMDocURL(String requestOBJ, String Authorization) throws JSONException {
public String getOpenKMDocURL(String requestOBJ, String Authorization) throws Exception {

Check warning on line 561 in src/main/java/com/iemr/tm/service/common/transaction/CommonServiceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace generic exceptions with specific library exceptions or a custom exception.

See more on https://sonarcloud.io/project/issues?id=PSMRI_TM-API&issues=AZ1oBodwzsBjmD1pomI0&open=AZ1oBodwzsBjmD1pomI0&pullRequest=146

Check failure on line 561 in src/main/java/com/iemr/tm/service/common/transaction/CommonServiceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 37 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=PSMRI_TM-API&issues=AZ1oBodwzsBjmD1pomI2&open=AZ1oBodwzsBjmD1pomI2&pullRequest=146

Check warning on line 561 in src/main/java/com/iemr/tm/service/common/transaction/CommonServiceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this local variable to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=PSMRI_TM-API&issues=AZ1oBodwzsBjmD1pomIz&open=AZ1oBodwzsBjmD1pomIz&pullRequest=146
RestTemplate restTemplate = new RestTemplate();
HttpServletRequest requestHeader = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
.getRequest();
String fileUUID = null;
JSONObject obj = new JSONObject(requestOBJ);
if (obj.has("fileID")) {

Check failure on line 567 in src/main/java/com/iemr/tm/service/common/transaction/CommonServiceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "fileID" 3 times.

See more on https://sonarcloud.io/project/issues?id=PSMRI_TM-API&issues=AZ1oBodwzsBjmD1pomI1&open=AZ1oBodwzsBjmD1pomI1&pullRequest=146
fileUUID = benVisitDetailRepo.getFileUUID(obj.getInt("fileID"));
int fileID = obj.getInt("fileID");
fileUUID = benVisitDetailRepo.getFileUUID(fileID);
String fileName = benVisitDetailRepo.getFileName(fileID);

logger.info("fileUUID for fileID " + obj.getInt("fileID") + " is " + fileUUID);
logger.info("openkmDocUrl is " + openkmDocUrl);
Expand All @@ -586,7 +592,22 @@
String fileUrl = dataObj.getString("response");
// Fix malformed URL: https://user:pass@https://host -> https://user:pass@host
fileUrl = fileUrl.replaceAll("@https?://", "@");
return fileUrl;
// Download file from OpenKM and return as base64
URL url = new URL(fileUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (url.getUserInfo() != null) {
String basicAuth = "Basic " + Base64.getEncoder().encodeToString(url.getUserInfo().getBytes());
conn.setRequestProperty("Authorization", basicAuth);
}
try (InputStream is = conn.getInputStream()) {
byte[] fileBytes = is.readAllBytes();
JSONObject result = new JSONObject();
result.put("fileContent", Base64.getEncoder().encodeToString(fileBytes));
result.put("fileName", fileName != null ? fileName : "download");
return result.toString();
} finally {
conn.disconnect();
}
}
}
return dataVal.toString();
Expand Down
Loading