Repository: jbake-org/jbake (java)

Issue:
data.get('file.yaml') will return `class com.orientechnologies.orient.core.db.record.OTrackedMap`
for example, given this file:
https://github.com/apache/shiro-site/blob/6b06cb888e04febf8216d82c1043fb27eea45044/data/authors.yaml

## actual behaviour

When importing using
`<#assign authors = data.get('authors.yaml').authors />`

The returned type will be `com.orientechnologies.orient.core.db.record.OTrackedMap`

## expected behaviour

A hash is returned without methods like `getClass()`. Just the author names as keys and the data as values.

## version

```xml
          <dependency>
            <groupId>org.jbake</groupId>
            <artifactId>jbake-core</artifactId>
            <version>2.7.0-rc.4</version>
          </dependency>
```


Pull request description:
Resolves #747 - OTrackedMap returned for contents of data file
Fixes #747 - Force the OrientDB type rather than let OrientDB decide.

Patch:
diff --git a/jbake-core/src/main/java/org/jbake/app/ContentStore.java b/jbake-core/src/main/java/org/jbake/app/ContentStore.java
index 7dc71e8..352e97a 100644
--- a/jbake-core/src/main/java/org/jbake/app/ContentStore.java
+++ b/jbake-core/src/main/java/org/jbake/app/ContentStore.java
@@ -32,10 +32,8 @@ import com.orientechnologies.orient.core.db.OrientDBConfig;
 import com.orientechnologies.orient.core.metadata.schema.OClass;
 import com.orientechnologies.orient.core.metadata.schema.OSchema;
 import com.orientechnologies.orient.core.metadata.schema.OType;
-import com.orientechnologies.orient.core.record.impl.ODocument;
+import com.orientechnologies.orient.core.record.OElement;
 import com.orientechnologies.orient.core.sql.executor.OResultSet;
-import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
-import org.jbake.launcher.SystemExit;
 import org.jbake.model.DocumentModel;
 import org.jbake.model.DocumentTypes;
 import org.jbake.model.ModelAttributes;
@@ -408,9 +406,9 @@ public class ContentStore {
     }
 
     public void addDocument(DocumentModel document) {
-        ODocument doc = new ODocument(Schema.DOCUMENTS);
-        doc.fromMap(document);
-        doc.save();
+        OElement element = db.newElement(Schema.DOCUMENTS);
+        document.forEach((k, v) -> element.setProperty(k, v, OType.ANY));
+        element.save();
     }
 
     protected abstract class Schema {


Test patch:
diff --git a/jbake-core/src/test/java/org/jbake/app/CrawlerTest.java b/jbake-core/src/test/java/org/jbake/app/CrawlerTest.java
index 73d9cfc..de0aa14 100644
--- a/jbake-core/src/test/java/org/jbake/app/CrawlerTest.java
+++ b/jbake-core/src/test/java/org/jbake/app/CrawlerTest.java
@@ -1,5 +1,6 @@
 package org.jbake.app;
 
+import com.orientechnologies.orient.core.db.record.OTrackedMap;
 import org.apache.commons.io.FilenameUtils;
 import org.hamcrest.BaseMatcher;
 import org.hamcrest.Description;
@@ -12,6 +13,8 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -59,12 +62,21 @@ public class CrawlerTest extends ContentStoreIntegrationTest {
         DocumentTypes.addDocumentType(config.getDataFileDocType());
         db.updateSchema();
         crawler.crawlDataFiles();
-        Assert.assertEquals(1, db.getDocumentCount("data"));
-
-        DataFileUtil util = new DataFileUtil(db, "data");
-        Map<String, Object> data = util.get("videos.yaml");
-        Assert.assertFalse(data.isEmpty());
-        Assert.assertNotNull(data.get("data"));
+        Assert.assertEquals(2, db.getDocumentCount("data"));
+
+        DataFileUtil dataFileUtil = new DataFileUtil(db, "data");
+        Map<String, Object> videos = dataFileUtil.get("videos.yaml");
+        Assert.assertFalse(videos.isEmpty());
+        Assert.assertNotNull(videos.get("data"));
+
+        // regression test for issue 747
+        Map<String, Object> authorsFileContents = dataFileUtil.get("authors.yaml");
+        Assert.assertFalse(authorsFileContents.isEmpty());
+        Object authorsList = authorsFileContents.get("authors");
+        assertThat(authorsList).isNotInstanceOf(OTrackedMap.class);
+        assertThat(authorsList).isInstanceOf(LinkedHashMap.class);
+        LinkedHashMap<String, Map<String, Object>> authors = (LinkedHashMap<String, Map<String, Object>>) authorsList;
+        assertThat(authors.get("Joe Bloggs").get("last_name")).isEqualTo("Bloggs");
     }
 
     @Test
diff --git a/jbake-core/src/test/resources/fixture/data/authors.yaml b/jbake-core/src/test/resources/fixture/data/authors.yaml
new file mode 100644
index 0000000..eb3f2bd
--- /dev/null
+++ b/jbake-core/src/test/resources/fixture/data/authors.yaml
@@ -0,0 +1,23 @@
+authors:
+
+    John Smith:
+        first_name: John
+        last_name: Smith
+        twitter: "@jsmith"
+        facebook: "https://www.facebook.com/jsmith"
+
+    Jane Smith:
+        first_name: Jane
+        last_name: Smith
+        twitter: "@janesmith"
+
+    Joe Bloggs:
+        first_name: Joe
+        last_name: Bloggs
+        twitter: "@jblogs"
+
+    Tom Harry:
+        first_name: Tom
+        last_name: Harry
+        twitter: "@tharry"
+        facebook: "https://www.facebook.com/tharry"