Skip to content

Commit 8d8d7a9

Browse files
committed
Fixes arangodb structure
1 parent c6331f8 commit 8d8d7a9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

arangodb-driver/src/main/java/org/jnosql/diana/arangodb/document/ArangoDBUtil.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@
3232
import java.util.Map;
3333
import java.util.Objects;
3434
import java.util.Optional;
35+
import java.util.function.Function;
3536
import java.util.logging.Level;
3637
import java.util.logging.Logger;
3738
import java.util.stream.Collectors;
39+
import java.util.stream.StreamSupport;
3840

3941
import static java.util.Collections.singletonMap;
4042
import static java.util.stream.Collectors.toList;
43+
import static java.util.stream.Collectors.toMap;
4144
import static java.util.stream.StreamSupport.stream;
4245

4346
/**
@@ -49,6 +52,9 @@ public final class ArangoDBUtil {
4952
public static final String ID = "_id";
5053
public static final String REV = "_rev";
5154

55+
private static final Function<Object, String> KEY_DOCUMENT = d -> cast(d).getName();
56+
private static final Function<Object, Object> VALUE_DOCUMENT = d -> cast(d).get();
57+
5258
private static final ValueWriter WRITER = ValueWriterDecorator.getInstance();
5359

5460

@@ -140,7 +146,20 @@ private static Object convert(Value value) {
140146
Document document = Document.class.cast(val);
141147
return singletonMap(document.getName(), convert(document.getValue()));
142148
}
149+
if(isSudDocument(val)) {
150+
return StreamSupport.stream(Iterable.class.cast(val).spliterator(), false)
151+
.collect(toMap(KEY_DOCUMENT, VALUE_DOCUMENT));
152+
}
143153
return val;
144154
}
145155

156+
private static boolean isSudDocument(Object value) {
157+
return value instanceof Iterable && StreamSupport.stream(Iterable.class.cast(value).spliterator(), false).
158+
allMatch(d -> org.jnosql.diana.api.document.Document.class.isInstance(d));
159+
}
160+
161+
private static org.jnosql.diana.api.document.Document cast(Object document) {
162+
return org.jnosql.diana.api.document.Document.class.cast(document);
163+
}
164+
146165
}

0 commit comments

Comments
 (0)