Skip to content

Commit

Permalink
Merge pull request jbake-org#757 from jonbullock/fix/747-orientdb-otr…
Browse files Browse the repository at this point in the history
…ackedmap

Resolves jbake-org#747 - OTrackedMap returned for contents of data file
  • Loading branch information
jonbullock authored May 30, 2022
2 parents 4d5cd56 + 3fdfd65 commit 2e5a20b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
10 changes: 4 additions & 6 deletions jbake-core/src/main/java/org/jbake/app/ContentStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 18 additions & 6 deletions jbake-core/src/test/java/org/jbake/app/CrawlerTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<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
Expand Down
23 changes: 23 additions & 0 deletions jbake-core/src/test/resources/fixture/data/authors.yaml
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 2e5a20b

Please sign in to comment.