Skip to content

Commit

Permalink
Fixed issue when creating datalib with upload file.
Browse files Browse the repository at this point in the history
  • Loading branch information
vertigo17 committed Nov 6, 2024
1 parent 11181ef commit 75b90ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
}
}
} catch (FileUploadException e) {
e.printStackTrace();
LOG.warn(e, e);
} catch (Exception e) {
LOG.warn(e, e);
}

try {
Expand Down Expand Up @@ -196,17 +198,29 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re

List<TestDataLibData> tdldList = new ArrayList<>();
TestDataLib dataLibWithUploadedFile = (TestDataLib) ansItem.getItem();

// Getting list of SubData from JSON Call
if (fileData.get("subDataList") != null) {
JSONArray objSubDataArray = new JSONArray(fileData.get("subDataList"));
tdldList = getSubDataFromParameter(request, appContext, dataLibWithUploadedFile.getTestDataLibID(), objSubDataArray, (file != null && activateAutoSubdata != null && activateAutoSubdata.equals("1")));

if (file != null) {
String fileName;
ans = libService.uploadFile(dataLibWithUploadedFile.getTestDataLibID(), file);
if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
fileName = file.getName();
dataLibWithUploadedFile.setCsvUrl(File.separator + dataLibWithUploadedFile.getTestDataLibID() + File.separator + fileName);
lib.setTestDataLibID(dataLibWithUploadedFile.getTestDataLibID());
ans = libService.update(lib);
finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, ans);
}
}

// Getting list of SubData from JSON Call
if (fileData.get("subDataList") != null) {
JSONArray objSubDataArray = new JSONArray(fileData.get("subDataList"));
tdldList = getSubDataFromParameter(request, appContext, dataLibWithUploadedFile.getTestDataLibID(), objSubDataArray, (file != null && activateAutoSubdata != null && activateAutoSubdata.equals("1")));
}

if (file != null && activateAutoSubdata != null && activateAutoSubdata.equals("1")) {
String firstLine = "";
String secondLine = "";
try (BufferedReader reader = new BufferedReader(new FileReader(parameterService.getParameterStringByKey(Parameter.VALUE_cerberus_testdatalibfile_path, "", null) + lib.getCsvUrl()));) {
try (BufferedReader reader = new BufferedReader(new FileReader(parameterService.getParameterStringByKey(Parameter.VALUE_cerberus_testdatalibfile_path, "", null) + dataLibWithUploadedFile.getCsvUrl()));) {
firstLine = reader.readLine();
secondLine = reader.readLine();
LOG.debug(firstLine);
Expand Down Expand Up @@ -257,9 +271,11 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
response.getWriter().print(jsonResponse);
response.getWriter().flush();
} catch (JSONException ex) {
LOG.warn(ex);
LOG.warn(ex, ex);
response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
response.getWriter().flush();
} catch (Exception e) {
LOG.warn(e, e);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [ENGINE] Fixed NPE when making a control on non successful service answer.
* [GUI] Fixed an issue when adding an environment to an existing application.
* [GUI] Environments with empty system, country or environment can be deleted.
* [GUI] Error when creating datalib with file upload.

*Improvements / New features*
[square]
Expand Down

0 comments on commit 75b90ce

Please sign in to comment.