Skip to content

Commit c2b616d

Browse files
marko-kriskovicivicac
authored andcommitted
SA
1 parent 6f825cd commit c2b616d

4 files changed

Lines changed: 44 additions & 20 deletions

File tree

server/libs/automation/automation-knowledge-base/automation-knowledge-base-graphql/src/test/java/com/bytechef/automation/knowledgebase/web/graphql/KnowledgeBaseDocumentGraphQlControllerIntTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ void testGetKnowledgeBaseDocumentChunks() {
9595
KnowledgeBaseDocument mockDocument = createMockDocument(documentId, "Test Document");
9696

9797
List<KnowledgeBaseDocumentChunk> mockChunks = List.of(
98-
createMockChunk(1L, "Chunk 1"),
99-
createMockChunk(2L, "Chunk 2"));
98+
createMockChunk(1L),
99+
createMockChunk(2L));
100100

101101
when(knowledgeBaseDocumentService.getKnowledgeBaseDocument(documentId)).thenReturn(mockDocument);
102102
when(knowledgeBaseDocumentChunkFacade.getKnowledgeBaseDocumentChunksByDocumentId(documentId))
@@ -222,7 +222,7 @@ private KnowledgeBaseDocument createMockDocument(Long id, String name) {
222222
return document;
223223
}
224224

225-
private KnowledgeBaseDocumentChunk createMockChunk(Long id, String content) {
225+
private KnowledgeBaseDocumentChunk createMockChunk(Long id) {
226226
KnowledgeBaseDocumentChunk chunk = new KnowledgeBaseDocumentChunk();
227227

228228
chunk.setId(id);

server/libs/automation/automation-knowledge-base/automation-knowledge-base-service/src/main/java/com/bytechef/automation/knowledgebase/config/KnowledgeBaseVectorStoreMetadataUpdater.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
import static com.bytechef.automation.knowledgebase.constant.KnowledgeBaseConstants.METADATA_TAG_NAMES;
2020

21+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2122
import java.util.LinkedHashMap;
2223
import java.util.List;
2324
import java.util.Map;
25+
import java.util.regex.Pattern;
2426
import org.slf4j.Logger;
2527
import org.slf4j.LoggerFactory;
2628
import org.springframework.jdbc.core.JdbcTemplate;
@@ -32,17 +34,24 @@
3234
*
3335
* @author Marko Kriskovic
3436
*/
35-
public class KnowledgeBaseVectorStoreMetadataUpdater {
37+
public final class KnowledgeBaseVectorStoreMetadataUpdater {
3638

3739
private static final Logger logger = LoggerFactory.getLogger(KnowledgeBaseVectorStoreMetadataUpdater.class);
40+
private static final Pattern SAFE_TABLE_NAME_PATTERN = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_.]*$");
3841

3942
private final JdbcTemplate pgVectorJdbcTemplate;
4043
private final ObjectMapper objectMapper;
4144
private final String fullTableName;
4245

46+
@SuppressFBWarnings("EI2")
4347
public KnowledgeBaseVectorStoreMetadataUpdater(
4448
JdbcTemplate pgVectorJdbcTemplate, ObjectMapper objectMapper, String fullTableName) {
4549

50+
if (!SAFE_TABLE_NAME_PATTERN.matcher(fullTableName)
51+
.matches()) {
52+
throw new IllegalArgumentException("Invalid table name: " + fullTableName);
53+
}
54+
4655
this.pgVectorJdbcTemplate = pgVectorJdbcTemplate;
4756
this.objectMapper = objectMapper;
4857
this.fullTableName = fullTableName;
@@ -56,6 +65,7 @@ public KnowledgeBaseVectorStoreMetadataUpdater(
5665
* @param vectorStoreId the vector store document ID
5766
* @param tagNames the new tag names to set; an empty list removes all tag fields
5867
*/
68+
@SuppressFBWarnings("SQL_INJECTION_SPRING_JDBC")
5969
public void updateTagNames(String vectorStoreId, List<String> tagNames) {
6070
List<String> rows = pgVectorJdbcTemplate.queryForList(
6171
"SELECT metadata::text FROM " + fullTableName + " WHERE id = ?::uuid",

server/libs/automation/automation-knowledge-base/automation-knowledge-base-service/src/test/java/com/bytechef/automation/knowledgebase/config/KnowledgeBaseIntTestConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ FileStorageServiceRegistry fileStorageServiceRegistry(FileStorageService fileSto
9393
return registry;
9494
}
9595

96+
@Bean
97+
KnowledgeBaseVectorStoreMetadataUpdater knowledgeBaseVectorStoreMetadataUpdater() {
98+
return mock(KnowledgeBaseVectorStoreMetadataUpdater.class);
99+
}
100+
96101
@Bean
97102
MessageBroker messageBroker() {
98103
return mock(MessageBroker.class);

server/libs/modules/components/ai/vectorstore/knowledgebase/src/test/resources/definition/knowledgeBase_v1.json

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,30 +115,33 @@
115115
"hidden": null,
116116
"items": [ {
117117
"advancedOption": null,
118-
"controlType": "INTEGER",
118+
"controlType": "TEXT",
119119
"defaultValue": null,
120120
"description": null,
121121
"displayCondition": null,
122122
"exampleValue": null,
123123
"expressionEnabled": null,
124124
"hidden": null,
125125
"label": null,
126-
"maxValue": null,
126+
"languageId": null,
127+
"maxLength": null,
127128
"metadata": { },
128-
"minValue": null,
129+
"minLength": null,
129130
"name": null,
130131
"options": null,
131132
"optionsDataSource": null,
133+
"optionsLoadedDynamically": null,
132134
"placeholder": null,
135+
"regex": null,
133136
"required": null,
134-
"type": "INTEGER"
137+
"type": "STRING"
135138
} ],
136139
"label": "Tags",
137140
"maxItems": null,
138141
"metadata": { },
139142
"minItems": null,
140143
"multipleValues": null,
141-
"name": "tagIds",
144+
"name": "tagNames",
142145
"options": null,
143146
"optionsDataSource": {
144147
"options": { },
@@ -250,30 +253,33 @@
250253
"hidden": null,
251254
"items": [ {
252255
"advancedOption": null,
253-
"controlType": "INTEGER",
256+
"controlType": "TEXT",
254257
"defaultValue": null,
255258
"description": null,
256259
"displayCondition": null,
257260
"exampleValue": null,
258261
"expressionEnabled": null,
259262
"hidden": null,
260263
"label": null,
261-
"maxValue": null,
264+
"languageId": null,
265+
"maxLength": null,
262266
"metadata": { },
263-
"minValue": null,
267+
"minLength": null,
264268
"name": null,
265269
"options": null,
266270
"optionsDataSource": null,
271+
"optionsLoadedDynamically": null,
267272
"placeholder": null,
273+
"regex": null,
268274
"required": null,
269-
"type": "INTEGER"
275+
"type": "STRING"
270276
} ],
271277
"label": "Tags",
272278
"maxItems": null,
273279
"metadata": { },
274280
"minItems": null,
275281
"multipleValues": null,
276-
"name": "tagIds",
282+
"name": "tagNames",
277283
"options": null,
278284
"optionsDataSource": {
279285
"options": { },
@@ -395,30 +401,33 @@
395401
"hidden": null,
396402
"items": [ {
397403
"advancedOption": null,
398-
"controlType": "INTEGER",
404+
"controlType": "TEXT",
399405
"defaultValue": null,
400406
"description": null,
401407
"displayCondition": null,
402408
"exampleValue": null,
403409
"expressionEnabled": null,
404410
"hidden": null,
405411
"label": null,
406-
"maxValue": null,
412+
"languageId": null,
413+
"maxLength": null,
407414
"metadata": { },
408-
"minValue": null,
415+
"minLength": null,
409416
"name": null,
410417
"options": null,
411418
"optionsDataSource": null,
419+
"optionsLoadedDynamically": null,
412420
"placeholder": null,
421+
"regex": null,
413422
"required": null,
414-
"type": "INTEGER"
423+
"type": "STRING"
415424
} ],
416425
"label": "Tags",
417426
"maxItems": null,
418427
"metadata": { },
419428
"minItems": null,
420429
"multipleValues": null,
421-
"name": "tagIds",
430+
"name": "tagNames",
422431
"options": null,
423432
"optionsDataSource": {
424433
"options": { },
@@ -455,4 +464,4 @@
455464
"triggers": null,
456465
"unifiedApi": null,
457466
"version": 1
458-
}
467+
}

0 commit comments

Comments
 (0)