From c5ccf97ff7ad5474b381eab77777dbaa585e5e44 Mon Sep 17 00:00:00 2001 From: "dalia.florinda" Date: Thu, 15 Jan 2026 13:34:43 +0100 Subject: [PATCH 1/2] fix upload file --- .../com/olympus/hermione/services/FileService.java | 12 ++++++++++-- .../hermione/services/ScenarioExecutionService.java | 12 +++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/olympus/hermione/services/FileService.java b/src/main/java/com/olympus/hermione/services/FileService.java index 45e8285..2ffa9b1 100644 --- a/src/main/java/com/olympus/hermione/services/FileService.java +++ b/src/main/java/com/olympus/hermione/services/FileService.java @@ -157,8 +157,16 @@ public class FileService { // Normalizza il path rimuovendo eventuali separatori doppi o tripli String normalizedPath = filePath.replaceAll("[\\\\/]+", "/"); - // Costruisci il path completo del file - Path file = Paths.get(uploadDir, normalizedPath); + // Check if path is absolute (starts with drive letter or uploadDir) + // If absolute, use it directly; otherwise, combine with uploadDir + Path file; + if (normalizedPath.matches("^[A-Za-z]:/.*") || normalizedPath.startsWith(uploadDir)) { + // Already absolute path - use directly (backward compatibility) + file = Paths.get(normalizedPath); + } else { + // Relative path - combine with uploadDir + file = Paths.get(uploadDir, normalizedPath); + } logger.info("Upload directory: {}", uploadDir); logger.info("Normalized relative path: {}", normalizedPath); diff --git a/src/main/java/com/olympus/hermione/services/ScenarioExecutionService.java b/src/main/java/com/olympus/hermione/services/ScenarioExecutionService.java index 2af1511..b4d3ec0 100644 --- a/src/main/java/com/olympus/hermione/services/ScenarioExecutionService.java +++ b/src/main/java/com/olympus/hermione/services/ScenarioExecutionService.java @@ -341,8 +341,9 @@ public class ScenarioExecutionService { if (scenarioExecutionInput.getInputs().containsKey("Folder")) { folder_name = scenarioExecutionInput.getInputs().get("Folder"); } + // Save only relative path (folder + filename) without uploadDir scenarioExecutionInput.getInputs().put("SingleFileUpload", - uploadDir + folder_name + "/" + scenarioExecutionInput.getInputs().get("SingleFileUpload")); + folder_name + "/" + scenarioExecutionInput.getInputs().get("SingleFileUpload")); } scenarioExecution.setScenarioExecutionInput(scenarioExecutionInput); @@ -633,20 +634,21 @@ public class ScenarioExecutionService { List results = mongoTemplate.find(query, ScenarioExecution.class); - // Remove MultiFileUpload from inputs if present + // Keep MultiFileUpload flag to show download button in frontend results.forEach(execution -> { if (execution.getScenarioExecutionInput() != null && execution.getScenarioExecutionInput().getInputs() != null && execution.getScenarioExecutionInput().getInputs().containsKey("MultiFileUpload")) { - execution.getScenarioExecutionInput().getInputs().put("MultiFileUpload", null); - // Also remove from execSharedMap if it exists + // Set a placeholder value instead of null to indicate file presence + execution.getScenarioExecutionInput().getInputs().put("MultiFileUpload", "uploaded"); + if (execution.getExecSharedMap() != null && execution.getExecSharedMap().get("user_input") != null) { HashMap userInput = (HashMap) execution.getExecSharedMap().get("user_input"); if (userInput.containsKey("MultiFileUpload")) { - userInput.put("MultiFileUpload", null); + userInput.put("MultiFileUpload", "uploaded"); } } } From 996b125c7cdaee2f1bed0a2421079e26bcd0cdb7 Mon Sep 17 00:00:00 2001 From: Emanuele Ferrelli Date: Fri, 16 Jan 2026 09:22:24 +0100 Subject: [PATCH 2/2] Update openSearch step --- .../stepSolvers/OpenSearchQuerySolver.java | 220 +++++++++--------- 1 file changed, 110 insertions(+), 110 deletions(-) diff --git a/src/main/java/com/olympus/hermione/stepSolvers/OpenSearchQuerySolver.java b/src/main/java/com/olympus/hermione/stepSolvers/OpenSearchQuerySolver.java index d0a8bba..bb5421a 100644 --- a/src/main/java/com/olympus/hermione/stepSolvers/OpenSearchQuerySolver.java +++ b/src/main/java/com/olympus/hermione/stepSolvers/OpenSearchQuerySolver.java @@ -24,26 +24,26 @@ import ch.qos.logback.classic.Logger; public class OpenSearchQuerySolver extends StepSolver { private String opensearch_base_url; - // private String opensearch_project; + private String opensearch_project; private String opensearch_query; private String opensearch_search_type; - private Integer opensearch_k; + private Integer opensearch_topk; private Integer opensearch_max_context_chars; private Double opensearch_vector_weight; private Double opensearch_entity_weight; private String opensearch_output_variable; // Optional Ks* filter fields - // private String opensearch_ks_application_name; - // private String opensearch_ks_doctype; - // private String opensearch_ks_doc_source; - // private String opensearch_ks_file_source; - // private String opensearch_ks_document_id; - // private String opensearch_ks_project_name; - // private String opensearch_ks_knowledge_path; + private String opensearch_ks_application_name; + private String opensearch_ks_doctype; + private String opensearch_ks_doc_source; + private String opensearch_ks_file_source; + private String opensearch_ks_document_id; + private String opensearch_ks_project_name; + private String opensearch_ks_knowledge_path; // Optional tags filter (as JSON string) - // private String opensearch_tags; + private String opensearch_tags; Logger logger = (Logger) LoggerFactory.getLogger(OpenSearchQuerySolver.class); @@ -59,12 +59,12 @@ public class OpenSearchQuerySolver extends StepSolver { } // Project (required) - // if(this.step.getAttributes().get("opensearch_project") != null){ - // this.opensearch_project = (String) this.step.getAttributes().get("opensearch_project"); - // logger.info("opensearch_project: " + this.opensearch_project); - // } else { - // throw new IllegalArgumentException("opensearch_project is required"); - // } + if(this.step.getAttributes().get("opensearch_project") != null){ + this.opensearch_project = (String) this.step.getAttributes().get("opensearch_project"); + logger.info("opensearch_project: " + this.opensearch_project); + } else { + throw new IllegalArgumentException("opensearch_project is required"); + } // Query (required) if(this.step.getAttributes().get("opensearch_query") != null){ @@ -83,17 +83,17 @@ public class OpenSearchQuerySolver extends StepSolver { logger.info("opensearch_search_type: " + this.opensearch_search_type); // K (number of results, default: 5) - if(this.step.getAttributes().get("opensearch_k") != null){ + if(this.step.getAttributes().get("opensearch_topk") != null){ Object kValue = this.step.getAttributes().get("opensearch_k"); if(kValue instanceof Integer){ - this.opensearch_k = (Integer) kValue; + this.opensearch_topk = (Integer) kValue; } else { - this.opensearch_k = Integer.parseInt(kValue.toString()); + this.opensearch_topk = Integer.parseInt(kValue.toString()); } } else { - this.opensearch_k = 5; + this.opensearch_topk = 5; } - logger.info("opensearch_k: " + this.opensearch_k); + logger.info("opensearch_topk: " + this.opensearch_topk); // Max context chars (default: 4000) if(this.step.getAttributes().get("opensearch_max_context_chars") != null){ @@ -143,69 +143,69 @@ public class OpenSearchQuerySolver extends StepSolver { logger.info("opensearch_output_variable: " + this.opensearch_output_variable); // Load optional Ks* filter fields - // if(this.step.getAttributes().get("opensearch_ks_application_name") != null){ - // this.opensearch_ks_application_name = (String) this.step.getAttributes().get("opensearch_ks_application_name"); - // logger.info("opensearch_ks_application_name: " + this.opensearch_ks_application_name); - // } - // if(this.step.getAttributes().get("opensearch_ks_doctype") != null){ - // this.opensearch_ks_doctype = (String) this.step.getAttributes().get("opensearch_ks_doctype"); - // logger.info("opensearch_ks_doctype: " + this.opensearch_ks_doctype); - // } - // if(this.step.getAttributes().get("opensearch_ks_doc_source") != null){ - // this.opensearch_ks_doc_source = (String) this.step.getAttributes().get("opensearch_ks_doc_source"); - // logger.info("opensearch_ks_doc_source: " + this.opensearch_ks_doc_source); - // } - // if(this.step.getAttributes().get("opensearch_ks_file_source") != null){ - // this.opensearch_ks_file_source = (String) this.step.getAttributes().get("opensearch_ks_file_source"); - // logger.info("opensearch_ks_file_source: " + this.opensearch_ks_file_source); - // } - // if(this.step.getAttributes().get("opensearch_ks_document_id") != null){ - // this.opensearch_ks_document_id = (String) this.step.getAttributes().get("opensearch_ks_document_id"); - // logger.info("opensearch_ks_document_id: " + this.opensearch_ks_document_id); - // } - // if(this.step.getAttributes().get("opensearch_ks_project_name") != null){ - // this.opensearch_ks_project_name = (String) this.step.getAttributes().get("opensearch_ks_project_name"); - // logger.info("opensearch_ks_project_name: " + this.opensearch_ks_project_name); - // } - // if(this.step.getAttributes().get("opensearch_ks_knowledge_path") != null){ - // this.opensearch_ks_knowledge_path = (String) this.step.getAttributes().get("opensearch_ks_knowledge_path"); - // logger.info("opensearch_ks_knowledge_path: " + this.opensearch_ks_knowledge_path); - // } - // if(this.step.getAttributes().get("opensearch_tags") != null){ - // this.opensearch_tags = (String) this.step.getAttributes().get("opensearch_tags"); - // logger.info("opensearch_tags: " + this.opensearch_tags); - // } + if(this.step.getAttributes().get("opensearch_ks_application_name") != null){ + this.opensearch_ks_application_name = (String) this.step.getAttributes().get("opensearch_ks_application_name"); + logger.info("opensearch_ks_application_name: " + this.opensearch_ks_application_name); + } + if(this.step.getAttributes().get("opensearch_ks_doctype") != null){ + this.opensearch_ks_doctype = (String) this.step.getAttributes().get("opensearch_ks_doctype"); + logger.info("opensearch_ks_doctype: " + this.opensearch_ks_doctype); + } + if(this.step.getAttributes().get("opensearch_ks_doc_source") != null){ + this.opensearch_ks_doc_source = (String) this.step.getAttributes().get("opensearch_ks_doc_source"); + logger.info("opensearch_ks_doc_source: " + this.opensearch_ks_doc_source); + } + if(this.step.getAttributes().get("opensearch_ks_file_source") != null){ + this.opensearch_ks_file_source = (String) this.step.getAttributes().get("opensearch_ks_file_source"); + logger.info("opensearch_ks_file_source: " + this.opensearch_ks_file_source); + } + if(this.step.getAttributes().get("opensearch_ks_document_id") != null){ + this.opensearch_ks_document_id = (String) this.step.getAttributes().get("opensearch_ks_document_id"); + logger.info("opensearch_ks_document_id: " + this.opensearch_ks_document_id); + } + if(this.step.getAttributes().get("opensearch_ks_project_name") != null){ + this.opensearch_ks_project_name = (String) this.step.getAttributes().get("opensearch_ks_project_name"); + logger.info("opensearch_ks_project_name: " + this.opensearch_ks_project_name); + } + if(this.step.getAttributes().get("opensearch_ks_knowledge_path") != null){ + this.opensearch_ks_knowledge_path = (String) this.step.getAttributes().get("opensearch_ks_knowledge_path"); + logger.info("opensearch_ks_knowledge_path: " + this.opensearch_ks_knowledge_path); + } + if(this.step.getAttributes().get("opensearch_tags") != null){ + this.opensearch_tags = (String) this.step.getAttributes().get("opensearch_tags"); + logger.info("opensearch_tags: " + this.opensearch_tags); + } // Parse variables from execution context AttributeParser attributeParser = new AttributeParser(this.scenarioExecution); this.opensearch_query = attributeParser.parse(this.opensearch_query); - // this.opensearch_project = attributeParser.parse(this.opensearch_project); + this.opensearch_project = attributeParser.parse(this.opensearch_project); - // if(this.opensearch_ks_application_name != null){ - // this.opensearch_ks_application_name = attributeParser.parse(this.opensearch_ks_application_name); - // } - // if(this.opensearch_ks_doctype != null){ - // this.opensearch_ks_doctype = attributeParser.parse(this.opensearch_ks_doctype); - // } - // if(this.opensearch_ks_doc_source != null){ - // this.opensearch_ks_doc_source = attributeParser.parse(this.opensearch_ks_doc_source); - // } - // if(this.opensearch_ks_file_source != null){ - // this.opensearch_ks_file_source = attributeParser.parse(this.opensearch_ks_file_source); - // } - // if(this.opensearch_ks_document_id != null){ - // this.opensearch_ks_document_id = attributeParser.parse(this.opensearch_ks_document_id); - // } - // if(this.opensearch_ks_project_name != null){ - // this.opensearch_ks_project_name = attributeParser.parse(this.opensearch_ks_project_name); - // } - // if(this.opensearch_ks_knowledge_path != null){ - // this.opensearch_ks_knowledge_path = attributeParser.parse(this.opensearch_ks_knowledge_path); - // } - // if(this.opensearch_tags != null){ - // this.opensearch_tags = attributeParser.parse(this.opensearch_tags); - // } + if(this.opensearch_ks_application_name != null){ + this.opensearch_ks_application_name = attributeParser.parse(this.opensearch_ks_application_name); + } + if(this.opensearch_ks_doctype != null){ + this.opensearch_ks_doctype = attributeParser.parse(this.opensearch_ks_doctype); + } + if(this.opensearch_ks_doc_source != null){ + this.opensearch_ks_doc_source = attributeParser.parse(this.opensearch_ks_doc_source); + } + if(this.opensearch_ks_file_source != null){ + this.opensearch_ks_file_source = attributeParser.parse(this.opensearch_ks_file_source); + } + if(this.opensearch_ks_document_id != null){ + this.opensearch_ks_document_id = attributeParser.parse(this.opensearch_ks_document_id); + } + if(this.opensearch_ks_project_name != null){ + this.opensearch_ks_project_name = attributeParser.parse(this.opensearch_ks_project_name); + } + if(this.opensearch_ks_knowledge_path != null){ + this.opensearch_ks_knowledge_path = attributeParser.parse(this.opensearch_ks_knowledge_path); + } + if(this.opensearch_tags != null){ + this.opensearch_tags = attributeParser.parse(this.opensearch_tags); + } } @Override @@ -225,46 +225,46 @@ public class OpenSearchQuerySolver extends StepSolver { JSONObject requestBody = new JSONObject(); // Required fields - // requestBody.put("project", this.opensearch_project); + requestBody.put("project", this.opensearch_project); requestBody.put("query", this.opensearch_query); requestBody.put("search_type", this.opensearch_search_type); - requestBody.put("k", this.opensearch_k); + requestBody.put("k", this.opensearch_topk); requestBody.put("max_context_chars", this.opensearch_max_context_chars); requestBody.put("vector_weight", this.opensearch_vector_weight); requestBody.put("entity_weight", this.opensearch_entity_weight); // Add optional Ks* filters - // if(this.opensearch_ks_application_name != null){ - // requestBody.put("KsApplicationName", this.opensearch_ks_application_name); - // } - // if(this.opensearch_ks_doctype != null){ - // requestBody.put("KsDoctype", this.opensearch_ks_doctype); - // } - // if(this.opensearch_ks_doc_source != null){ - // requestBody.put("KsDocSource", this.opensearch_ks_doc_source); - // } - // if(this.opensearch_ks_file_source != null){ - // requestBody.put("KsFileSource", this.opensearch_ks_file_source); - // } - // if(this.opensearch_ks_document_id != null){ - // requestBody.put("KsDocumentId", this.opensearch_ks_document_id); - // } - // if(this.opensearch_ks_project_name != null){ - // requestBody.put("KsProjectName", this.opensearch_ks_project_name); - // } - // if(this.opensearch_ks_knowledge_path != null){ - // requestBody.put("KsKnowledgePath", this.opensearch_ks_knowledge_path); - // } + if(this.opensearch_ks_application_name != null){ + requestBody.put("KsApplicationName", this.opensearch_ks_application_name); + } + if(this.opensearch_ks_doctype != null){ + requestBody.put("KsDoctype", this.opensearch_ks_doctype); + } + if(this.opensearch_ks_doc_source != null){ + requestBody.put("KsDocSource", this.opensearch_ks_doc_source); + } + if(this.opensearch_ks_file_source != null){ + requestBody.put("KsFileSource", this.opensearch_ks_file_source); + } + if(this.opensearch_ks_document_id != null){ + requestBody.put("KsDocumentId", this.opensearch_ks_document_id); + } + if(this.opensearch_ks_project_name != null){ + requestBody.put("KsProjectName", this.opensearch_ks_project_name); + } + if(this.opensearch_ks_knowledge_path != null){ + requestBody.put("KsKnowledgePath", this.opensearch_ks_knowledge_path); + } - // // Add tags filter if provided - // if(this.opensearch_tags != null && !this.opensearch_tags.isEmpty()){ - // try { - // JSONObject tagsObj = new JSONObject(this.opensearch_tags); - // requestBody.put("tags", tagsObj); - // } catch (Exception e) { - // logger.warn("Failed to parse opensearch_tags as JSON, skipping", e); - // } - // } + // Add tags filter if provided + if(this.opensearch_tags != null && !this.opensearch_tags.isEmpty()){ + try { + JSONObject tagsObj = new JSONObject(this.opensearch_tags); + requestBody.put("tags", tagsObj); + } catch (Exception e) { + logger.warn("Failed to parse opensearch_tags as JSON, skipping", e); + } + } logger.info("Calling OpenSearch endpoint: " + endpoint); logger.info("Request body: " + requestBody.toString(2));