Merged PR 225: Update openSearch step

This commit is contained in:
2026-01-16 08:26:20 +00:00
3 changed files with 127 additions and 117 deletions

View File

@@ -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);

View File

@@ -345,8 +345,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);
@@ -637,20 +638,21 @@ public class ScenarioExecutionService {
List<ScenarioExecution> 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<String, String> userInput = (HashMap<String, String>) execution.getExecSharedMap().get("user_input");
if (userInput.containsKey("MultiFileUpload")) {
userInput.put("MultiFileUpload", null);
userInput.put("MultiFileUpload", "uploaded");
}
}
}

View File

@@ -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));