public static DocumentList wrap(Iterator<ODocument> docs) { DocumentList list = new DocumentList(); while (docs.hasNext()) { ODocument next = docs.next(); list.add(DBUtil.documentToModel(next)); } return list; }
while (index < documentList.size()) { try { Map<String, Object> document = documentList.get(index); document.put("nextContent", null); document.put("previousContent", null); if (index < documentList.size() - 1) { Map<String, Object> tempNext = documentList.get(index + 1); document.put("previousContent", getContentForNav(tempNext));
public DocumentList getPublishedDocumentsByTag(String tag) { final DocumentList documents = new DocumentList(); for (final String docType : DocumentTypes.getDocumentTypes()) { String statement = String.format(STATEMENT_GET_PUBLISHED_POST_BY_TYPE_AND_TAG, docType); DocumentList documentsByTag = query(statement, tag); documents.addAll(documentsByTag); } return documents; }
private DocumentStatus findDocumentStatus(String docType, String uri, String sha1) { DocumentList match = db.getDocumentStatus(docType, uri); if (!match.isEmpty()) { Map entries = match.get(0); String oldHash = (String) entries.get(String.valueOf(DocumentAttributes.SHA1)); if (!(oldHash.equals(sha1)) || Boolean.FALSE.equals(entries.get(String.valueOf(DocumentAttributes.RENDERED)))) { return DocumentStatus.UPDATED; } else { return DocumentStatus.IDENTICAL; } } else { return DocumentStatus.NEW; } }
@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; }
import com.google.gdata.data.docs.DocumentListEntry; import com.google.gdata.data.docs.DocumentListFeed; public class Example { static public void main(String[] args) throws Exception { DocumentList docList = new DocumentList("document"); docList.login("********@gmail.com", "********"); DocumentListFeed feed = docList.getDocsListFeed("all"); for (final DocumentListEntry entry : feed.getEntries()) { System.out.println(entry.getTitle().getPlainText()); } } }
@Override public DocumentList get(ContentStore db, Map model, String key) { // document types are pluralized in model, so unpluralize try { String type = DocumentTypeUtils.unpluralize(key); return db.getAllContent(type); } catch (UnsupportedOperationException e) { return new DocumentList(); } }
public long getPublishedCount(String docType) { String statement = String.format(STATEMENT_GET_PUBLISHED_COUNT, docType); return (Long) query(statement).get(0).get("count"); }
@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()); }
private DocumentList query(String sql) { activateOnCurrentThread(); List<ODocument> results = db.query(new OSQLSynchQuery<ODocument>(sql)); return DocumentList.wrap(results.iterator()); }
private boolean updateTemplateSignatureIfChanged(File templateFolder) { boolean templateSignatureChanged = false; DocumentList docs = this.getSignaturesForTemplates(); String currentTemplatesSignature; try { currentTemplatesSignature = FileUtil.sha1(templateFolder); } catch (Exception e) { currentTemplatesSignature = ""; } if (!docs.isEmpty()) { String sha1 = (String) docs.get(0).get(String.valueOf(DocumentAttributes.SHA1)); if (!sha1.equals(currentTemplatesSignature)) { this.updateSignatures(currentTemplatesSignature); templateSignatureChanged = true; } } else { // first computation of templates signature this.insertTemplatesSignature(currentTemplatesSignature); templateSignatureChanged = true; } return templateSignatureChanged; }
@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; }
@Before public void setUp() { MockitoAnnotations.initMocks(this); documentsRenderer = new DocumentsRenderer(); db = mock(ContentStore.class); renderer = mock(Renderer.class); configuration = mock(JBakeConfiguration.class); emptyDocumentList = new DocumentList(); }
public long getPublishedCount(String docType) { String statement = String.format(STATEMENT_GET_PUBLISHED_COUNT, docType); return (Long) query(statement).get(0).get("count"); }
private DocumentList query(String sql, Object... args) { activateOnCurrentThread(); List<ODocument> results = db.command(new OSQLSynchQuery<ODocument>(sql)).execute(args); return DocumentList.wrap(results.iterator()); }
@Test public void shouldReturnCountOfProcessedDocuments() throws Exception { // given: DocumentTypes.addDocumentType("customType"); DocumentList documentList = new DocumentList(); documentList.add(emptyDocument()); documentList.add(emptyDocument()); // return empty DocumentList independent from DocumentType when(db.getUnrenderedContent(anyString())).thenReturn(emptyDocumentList); // return given DocumentList for DocumentType 'custom type' when(db.getUnrenderedContent("customType")).thenReturn(documentList); // when: int renderResponse = documentsRenderer.render(renderer, db, configuration); // then: assertThat(renderResponse).isEqualTo(2); }
@Override public DocumentList get(ContentStore db, Map model, String key) { DocumentList publishedContent = new DocumentList(); String[] documentTypes = DocumentTypes.getDocumentTypes(); for (String docType : documentTypes) { DocumentList query = db.getPublishedContent(docType); publishedContent.addAll(query); } return publishedContent; }
private DocumentStatus findDocumentStatus(String docType, String uri, String sha1) { DocumentList match = db.getDocumentStatus(docType, uri); if (!match.isEmpty()) { Map entries = match.get(0); String oldHash = (String) entries.get(String.valueOf(DocumentAttributes.SHA1)); if (!(oldHash.equals(sha1)) || Boolean.FALSE.equals(entries.get(String.valueOf(DocumentAttributes.RENDERED)))) { return DocumentStatus.UPDATED; } else { return DocumentStatus.IDENTICAL; } } else { return DocumentStatus.NEW; } }
@Override public DocumentList get(ContentStore db, Map model, String key) { // document types are pluralized in model, so unpluralize try { String type = DocumentTypeUtils.unpluralize(key); return db.getAllContent(type); } catch (UnsupportedOperationException e) { return new DocumentList(); } }