From 06e4c0d47c36c2b38237dfede79d43d973bc783e Mon Sep 17 00:00:00 2001 From: Jonathan Bullock Date: Sun, 20 Mar 2022 16:52:37 +0000 Subject: [PATCH 1/2] Fixes #747 Force the OrientDB type rather than let OrientDB decide. --- .../src/main/java/org/jbake/app/ContentStore.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) 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 7dc71e88..352e97ae 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.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 boolean isActive() { } 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 { From 3fdfd65f2f8f980eb430c72d92090299395879aa Mon Sep 17 00:00:00 2001 From: Jonathan Bullock Date: Sun, 3 Apr 2022 23:55:58 +0100 Subject: [PATCH 2/2] Regression test for fix. --- .../test/java/org/jbake/app/CrawlerTest.java | 24 ++++++++++++++----- .../test/resources/fixture/data/authors.yaml | 23 ++++++++++++++++++ 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 jbake-core/src/test/resources/fixture/data/authors.yaml 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 73d9cfc1..de0aa14b 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.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 void crawlDataFiles() { DocumentTypes.addDocumentType(config.getDataFileDocType()); db.updateSchema(); crawler.crawlDataFiles(); - Assert.assertEquals(1, db.getDocumentCount("data")); - - DataFileUtil util = new DataFileUtil(db, "data"); - Map 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 videos = dataFileUtil.get("videos.yaml"); + Assert.assertFalse(videos.isEmpty()); + Assert.assertNotNull(videos.get("data")); + + // regression test for issue 747 + Map 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> authors = (LinkedHashMap>) 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 00000000..eb3f2bd0 --- /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"