Skip to content

Commit

Permalink
Update NitriteDocument.java
Browse files Browse the repository at this point in the history
  • Loading branch information
anidotnet committed Sep 28, 2024
1 parent 5169f0f commit 8b10462
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ private void deepRemove(String[] splits) {
throw new ValidationException("Invalid key provided");
}
String key = splits[0];
if (isNullOrEmpty(key)) {
throw new ValidationException("Invalid key provided");
}

if (splits.length == 1) {
// if last key, simply remove the current document
remove(key);
Expand Down Expand Up @@ -417,8 +421,13 @@ private Object getByEmbeddedKey(String embeddedKey) {
return null;
}

String key = path[0];
if (isNullOrEmpty(key)) {
throw new ValidationException("Invalid key provided");
}

// get current level value and scan to next level using remaining keys
return recursiveGet(get(path[0]), Arrays.copyOfRange(path, 1, path.length));
return recursiveGet(get(key), Arrays.copyOfRange(path, 1, path.length));
}

@SuppressWarnings("unchecked")
Expand All @@ -433,7 +442,12 @@ private Object recursiveGet(Object object, String[] remainingPath) {

if (object instanceof Document) {
// if the current level value is document, scan to the next level with remaining keys
return recursiveGet(((Document) object).get(remainingPath[0]),
String key = remainingPath[0];
if (isNullOrEmpty(key)) {
throw new ValidationException("Invalid key provided");
}

return recursiveGet(((Document) object).get(key),
Arrays.copyOfRange(remainingPath, 1, remainingPath.length));
}

Expand All @@ -442,6 +456,9 @@ private Object recursiveGet(Object object, String[] remainingPath) {

// get the first key
String accessor = remainingPath[0];
if (isNullOrEmpty(accessor)) {
throw new ValidationException("Invalid key provided");
}

// convert current value to object array
Object[] array = convertToObjectArray(object);
Expand Down

0 comments on commit 8b10462

Please sign in to comment.