Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,33 @@ public class IndexUtils {
public static final Map<String, String> MAPPING_PLACEHOLDERS = Map
.of(USER_PLACEHOLDER, "index-mappings/placeholders/user.json", CONNECTOR_PLACEHOLDER, "index-mappings/placeholders/connector.json");

public static String getMappingFromFile(String path) throws IOException {
/**
* Loads a resource file from the classpath as a String.
* This is a utility method for loading JSON or text resources.
*
* @param path The path to the resource file relative to the classpath root
* @param resourceType A descriptive name for the resource type (e.g., "mapping", "schema") for error messages
* @return The resource content as a trimmed String
* @throws IOException if the resource cannot be found or loaded
* @throws IllegalArgumentException if the resource is empty
*/
public static String loadResourceFromFile(String path, String resourceType) throws IOException {
URL url = IndexUtils.class.getClassLoader().getResource(path);
if (url == null) {
throw new IOException("Resource not found: " + path);
throw new IOException(resourceType + " resource not found: " + path);
}

String mapping = Resources.toString(url, Charsets.UTF_8).trim();
if (mapping.isEmpty()) {
throw new IllegalArgumentException("Empty mapping found at: " + path);
String content = Resources.toString(url, Charsets.UTF_8).trim();
if (content.isEmpty()) {
throw new IllegalArgumentException("Empty " + resourceType + " found at: " + path);
}

return content;
}

public static String getMappingFromFile(String path) throws IOException {
String mapping = loadResourceFromFile(path, "Mapping");

mapping = replacePlaceholders(mapping);
validateMapping(mapping);

Expand Down
Loading
Loading