From 75b90cee2b5b19497ac1a69ec42501c8a387c257 Mon Sep 17 00:00:00 2001 From: Benoit DUMONT Date: Wed, 6 Nov 2024 21:42:30 +0100 Subject: [PATCH] Fixed issue when creating datalib with upload file. --- .../crud/testdata/CreateTestDataLib.java | 32 ++++++++++++++----- .../D2/include/en/changelog_4.19_en.adoc | 1 + 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/source/src/main/java/org/cerberus/core/servlet/crud/testdata/CreateTestDataLib.java b/source/src/main/java/org/cerberus/core/servlet/crud/testdata/CreateTestDataLib.java index 9970b375a..ece1a6501 100644 --- a/source/src/main/java/org/cerberus/core/servlet/crud/testdata/CreateTestDataLib.java +++ b/source/src/main/java/org/cerberus/core/servlet/crud/testdata/CreateTestDataLib.java @@ -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 { @@ -196,17 +198,29 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re List 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); @@ -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); } } diff --git a/source/src/main/resources/documentation/D2/include/en/changelog_4.19_en.adoc b/source/src/main/resources/documentation/D2/include/en/changelog_4.19_en.adoc index f32133004..604c8706a 100644 --- a/source/src/main/resources/documentation/D2/include/en/changelog_4.19_en.adoc +++ b/source/src/main/resources/documentation/D2/include/en/changelog_4.19_en.adoc @@ -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]