@Deprecated public static ContentStore createDataStore(final String type, String name) { if (contentStore == null) { contentStore = new ContentStore(type, name); } return contentStore; }
contentStore.startup(); updateDocTypesFromConfiguration(); contentStore.updateSchema(); contentStore.updateAndClearCacheIfNeeded(config.getClearCache(), config.getTemplateFolder()); contentStore.close(); contentStore.shutdown();
private void deleteAllDocumentTypes() { for (String docType : DocumentTypes.getDocumentTypes()) { try { this.deleteAllByDocType(docType); } catch (Exception e) { // maybe a non existing document type } } }
@Override public DocumentList get(ContentStore db, Map model, String key) { DocumentList dl = new DocumentList(); Map<?, ?> config = (Map<?, ?>) model.get("config"); String tagPath = config.get(TAG_PATH.replace(".", "_")).toString(); for (String tag : db.getAllTags()) { Map<String, Object> newTag = new HashMap<>(); String tagName = tag; newTag.put("name", tagName); String uri = tagPath + FileUtil.URI_SEPARATOR_CHAR + tag + config.get(OUTPUT_EXTENSION.replace(".", "_")).toString(); newTag.put("uri", uri); newTag.put("tagged_posts", db.getPublishedPostsByTag(tagName)); newTag.put("tagged_documents", db.getPublishedDocumentsByTag(tagName)); dl.push(newTag); } return dl; }
public void renderIndexPaging(String indexFile) throws Exception { long totalPosts = db.getPublishedCount("post"); int postsPerPage = config.getPostsPerPage(); db.setLimit(postsPerPage); for (int pageStart = 0, page = 1; pageStart < totalPosts; pageStart += postsPerPage, page++) { String fileName = indexFile; db.setStart(pageStart); model.put("currentPageNumber", page); String previous = pagingHelper.getPreviousFileName(page); render(renderConfig); db.resetPagination(); } catch (Exception e) { throw new Exception("Failed to render index. Cause: " + e.getMessage(), e);
@Test public void crawl() { Crawler crawler = new Crawler(db, config); crawler.crawl(); Assert.assertEquals(4, db.getDocumentCount("post")); Assert.assertEquals(3, db.getDocumentCount("page")); DocumentList results = db.getPublishedPosts(); assertThat(results.size()).isEqualTo(3); for (Map<String, Object> content : results) { assertThat(content) .containsKey(Crawler.Attributes.ROOTPATH) .containsValue("../../../"); } DocumentList allPosts = db.getAllContent("post"); assertThat(allPosts.size()).isEqualTo(4); for (Map<String, Object> content : allPosts) { if (content.get(Crawler.Attributes.TITLE).equals("Draft Post")) { assertThat(content).containsKey(Crawler.Attributes.DATE); } } // covers bug #213 DocumentList publishedPostsByTag = db.getPublishedPostsByTag("blog"); Assert.assertEquals(3, publishedPostsByTag.size()); }
db.setLimit(PER_PAGE); db.setStart(start); DocumentList posts = db.getPublishedPosts(true);
public DocumentList getAllContent(String docType) { return getAllContent(docType, false); }
final List<String> errors = new LinkedList<>(); for (String docType : DocumentTypes.getDocumentTypes()) { DocumentList documentList = db.getUnrenderedContent(docType); db.markContentAsRendered(docType);
@Test public void renderWithPrettyUrls() throws Exception { config.setUriWithoutExtension(true); config.setPrefixForUriWithoutExtension("/blog"); Crawler crawler = new Crawler(db, config); crawler.crawl(); Assert.assertEquals(4, db.getDocumentCount("post")); Assert.assertEquals(3, db.getDocumentCount("page")); DocumentList documents = db.getPublishedPosts(); for (Map<String, Object> model : documents) { String noExtensionUri = "blog/\\d{4}/" + FilenameUtils.getBaseName((String) model.get("file")) + "/"; Assert.assertThat(model.get("noExtensionUri"), RegexMatcher.matches(noExtensionUri)); Assert.assertThat(model.get("uri"), RegexMatcher.matches(noExtensionUri + "index\\.html")); assertThat(model).containsEntry("rootpath", "../../../"); } }
@Test public void shouldCrawlRenderAndCopyAssets() throws Exception { configuration.setTemplateFolder( folder.newFolder("template") ); configuration.setContentFolder( folder.newFolder("content") ); configuration.setAssetFolder( folder.newFolder("assets") ); contentStore = spy(new ContentStore("memory", "documents"+ System.currentTimeMillis())); Crawler crawler = mock(Crawler.class); Renderer renderer = mock(Renderer.class); Asset asset = mock(Asset.class); Utensils utensils = new Utensils(); utensils.setConfiguration(configuration); utensils.setContentStore(contentStore); utensils.setRenderer(renderer); utensils.setCrawler(crawler); utensils.setAsset(asset); Oven oven = new Oven(utensils); oven.bake(); verify(contentStore, times(1)).startup(); verify(renderer,atLeastOnce()).renderIndex(anyString()); verify(crawler,times(1)).crawl(); verify(asset,times(1)).copy(); } }
@Test public void shouldGetCountForPublishedDocuments() throws Exception { for (int i = 0; i < 5; i++) { FakeDocumentBuilder builder = new FakeDocumentBuilder(DOC_TYPE_POST); builder.withName("dummyfile" + i) .withStatus("published") .withRandomSha1() .build(); } FakeDocumentBuilder builder = new FakeDocumentBuilder(DOC_TYPE_POST); builder.withName("draftdummy") .withStatus("draft") .withRandomSha1() .build(); assertEquals(6, db.getDocumentCount(DOC_TYPE_POST)); assertEquals(5, db.getPublishedCount(DOC_TYPE_POST)); }
@Test public void shouldReturnZeroIfNothingHasRendered() throws Exception { when(db.getUnrenderedContent(anyString())).thenReturn(emptyDocumentList); int renderResponse = documentsRenderer.render(renderer, db, configuration); assertThat(renderResponse).isEqualTo(0); }
@Test public void testMergeDocument() { final String uri = "test/testMergeDocument"; ODocument doc = new ODocument(DOC_TYPE_POST); Map<String, String> values = new HashMap(); values.put(Crawler.Attributes.TYPE, DOC_TYPE_POST); values.put(DocumentAttributes.SOURCE_URI.toString(), uri); values.put("foo", "originalValue"); doc.fromMap(values); doc.save(); // 1st values.put("foo", "newValue"); db.mergeDocument(values); DocumentList docs = db.getDocumentByUri(DOC_TYPE_POST, uri); assertEquals(1, docs.size()); assertEquals("newValue", docs.get(0).get("foo")); // 2nd values.put("foo", "anotherValue"); db.mergeDocument(values); docs = db.getDocumentByUri(DOC_TYPE_POST, uri); assertEquals(1, docs.size()); assertEquals("anotherValue", docs.get(0).get("foo")); db.deleteContent(DOC_TYPE_POST, uri); docs = db.getDocumentByUri(DOC_TYPE_POST, uri); assertEquals(0, docs.size()); }
public void crawl() { crawl(config.getContentFolder()); LOGGER.info("Content detected:"); for (String docType : DocumentTypes.getDocumentTypes()) { long count = db.getDocumentCount(docType); if (count > 0) { LOGGER.info("Parsed {} files of type: {}", count, docType); } } }
@Override public DocumentList get(ContentStore db, Map model, String key) { String tag = null; if (model.get(Crawler.Attributes.TAG) != null) { tag = model.get(Crawler.Attributes.TAG).toString(); } // fetch the tag posts from db return db.getPublishedPostsByTag(tag); }
@Override public DocumentList get(ContentStore db, Map model, String key) { if (model.containsKey("numberOfPages")) { return db.getPublishedPosts(true); } else { return db.getPublishedPosts(); } }
if (status == DocumentStatus.UPDATED) { sb.append(" : modified "); db.deleteContent(docType, uri);