Search in sources :

Example 11 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiDocumentArchiveTest method testUpdateLoad.

public void testUpdateLoad() throws XWikiException {
    XWikiDocument doc = new XWikiDocument(new DocumentReference("Test", "Test", "Test"));
    doc.setContent("content 1.1");
    XWikiDocumentArchive archive = new XWikiDocumentArchive(doc.getId());
    assertEquals(0, archive.getNodes().size());
    String author = "XWiki.some author";
    archive.updateArchive(doc, author, new Date(), "initial, 1.1", null, context);
    assertEquals(new Version(1, 1), archive.getLatestVersion());
    String archive11 = archive.getArchive(context);
    assertEquals(1, archive.getNodes().size());
    assertEquals(1, archive.getUpdatedNodeInfos().size());
    assertEquals(1, archive.getUpdatedNodeContents().size());
    XWikiDocumentArchive archive2 = new XWikiDocumentArchive(doc.getId());
    archive2.setArchive(archive11);
    assertEquals(new Version(1, 1), archive2.getLatestVersion());
    assertEquals(archive11, archive2.getArchive(context));
    assertEquals(1, archive2.getNodes().size());
    assertEquals(1, archive2.getUpdatedNodeInfos().size());
    assertEquals(1, archive2.getUpdatedNodeContents().size());
    doc.setContent("content\n1.2");
    archive.updateArchive(doc, author, new Date(), "1.2", new Version(1, 2), context);
    assertEquals(new Version(1, 2), archive.getLatestVersion());
    String archive12 = archive.getArchive(context);
    assertEquals(2, archive.getNodes().size());
    assertEquals(2, archive.getUpdatedNodeInfos().size());
    assertEquals(2, archive.getUpdatedNodeContents().size());
    XWikiDocumentArchive archive3 = new XWikiDocumentArchive(doc.getId());
    archive3.setArchive(archive12);
    assertEquals(new Version(1, 2), archive3.getLatestVersion());
    assertEquals(2, archive3.getNodes().size());
    assertEquals(2, archive3.getUpdatedNodeInfos().size());
    assertEquals(2, archive3.getUpdatedNodeContents().size());
    doc.setContent("major change\ncontent\n2.1");
    archive.updateArchive(doc, author, new Date(), "2.1", new Version(1, 1), context);
    assertEquals(new Version(2, 1), archive.getLatestVersion());
    assertEquals(3, archive.getNodes().size());
    assertEquals(3, archive.getUpdatedNodeInfos().size());
    assertEquals(3, archive.getUpdatedNodeContents().size());
    doc.setContent("major change\ncontent\n 3.3");
    archive.updateArchive(doc, author, new Date(), "2.1", new Version(3, 3), context);
    assertEquals(new Version(3, 3), archive.getLatestVersion());
}
Also used : Version(org.suigeneris.jrcs.rcs.Version) DocumentReference(org.xwiki.model.reference.DocumentReference) Date(java.util.Date)

Example 12 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiDocumentArchiveTest method testVerifyDiffAndFullRevisionAlgorithm.

public void testVerifyDiffAndFullRevisionAlgorithm() throws Exception {
    XWikiDocument doc = new XWikiDocument(new DocumentReference("Test", "Test", "Test"));
    XWikiDocumentArchive archive = new XWikiDocumentArchive(doc.getId());
    doc.setDocumentArchive(archive);
    String author = "XWiki.some author";
    // The first revision is always a full revision (not a diff)
    addRevisionToHistory(archive, doc, "content 1.1", author, "1.1");
    assertFalse(archive.getNode(new Version(1, 1)).isDiff());
    // When a new revision is added the new revision is always the full revision but the previous one is
    // modified to be a diff.
    addRevisionToHistory(archive, doc, "content 2.1", author, "2.1");
    assertTrue(archive.getNode(new Version(1, 1)).isDiff());
    assertFalse(archive.getNode(new Version(2, 1)).isDiff());
    addRevisionToHistory(archive, doc, "content 3.1", author, "3.1");
    assertTrue(archive.getNode(new Version(1, 1)).isDiff());
    assertTrue(archive.getNode(new Version(2, 1)).isDiff());
    assertFalse(archive.getNode(new Version(3, 1)).isDiff());
    addRevisionToHistory(archive, doc, "content 4.1", author, "4.1");
    assertTrue(archive.getNode(new Version(1, 1)).isDiff());
    assertTrue(archive.getNode(new Version(2, 1)).isDiff());
    assertTrue(archive.getNode(new Version(3, 1)).isDiff());
    assertFalse(archive.getNode(new Version(4, 1)).isDiff());
    // Every 5th revision we save the full content and not a diff
    addRevisionToHistory(archive, doc, "content 5.1", author, "5.1");
    assertTrue(archive.getNode(new Version(1, 1)).isDiff());
    assertTrue(archive.getNode(new Version(2, 1)).isDiff());
    assertTrue(archive.getNode(new Version(3, 1)).isDiff());
    assertTrue(archive.getNode(new Version(4, 1)).isDiff());
    assertFalse(archive.getNode(new Version(5, 1)).isDiff());
    // Verify that the 5th revision is kept as a full content revision when the 6th is added
    addRevisionToHistory(archive, doc, "content 6.1", author, "6.1");
    assertTrue(archive.getNode(new Version(1, 1)).isDiff());
    assertTrue(archive.getNode(new Version(2, 1)).isDiff());
    assertTrue(archive.getNode(new Version(3, 1)).isDiff());
    assertTrue(archive.getNode(new Version(4, 1)).isDiff());
    assertFalse(archive.getNode(new Version(5, 1)).isDiff());
    assertFalse(archive.getNode(new Version(6, 1)).isDiff());
}
Also used : Version(org.suigeneris.jrcs.rcs.Version) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 13 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class WatchListEvent method getPreviousVersion.

/**
 * @return The version of the document which has generated the event, before the actual event.
 */
public String getPreviousVersion() {
    if (previousVersion == null) {
        String currentVersion = "";
        previousVersion = "";
        try {
            if (!isComposite()) {
                currentVersion = getActivityEvent().getVersion();
            } else {
                List<String> allVersions = getVersions();
                if (allVersions.size() > 1) {
                    currentVersion = allVersions.get(allVersions.size() - 1);
                }
            }
            if (currentVersion.equals(INITIAL_DOCUMENT_VERSION)) {
                previousVersion = PREINITIAL_DOCUMENT_VERSION;
            }
            if (!StringUtils.isBlank(currentVersion) && StringUtils.isBlank(previousVersion)) {
                XWikiDocument doc = context.getWiki().getDocument(prefixedFullName, context);
                XWikiDocument docRev = context.getWiki().getDocument(doc, currentVersion, context);
                doc.loadArchive(context);
                Version version = doc.getDocumentArchive().getPrevVersion(docRev.getRCSVersion());
                if (version != null) {
                    previousVersion = version.toString();
                }
            }
        } catch (XWikiException e) {
            // Catch the exception to be sure we won't send emails containing stacktraces to users.
            e.printStackTrace();
        }
    }
    return previousVersion;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Version(org.suigeneris.jrcs.rcs.Version) XWikiException(com.xpn.xwiki.XWikiException)

Example 14 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiDocumentArchiveTest method testRemoveVersions.

public void testRemoveVersions() throws XWikiException {
    XWikiDocument doc = new XWikiDocument(new DocumentReference("Test", "Test", "Test"));
    XWikiDocumentArchive archive = new XWikiDocumentArchive(doc.getId());
    doc.setDocumentArchive(archive);
    String author = "XWiki.some author";
    addRevisionToHistory(archive, doc, "content 1.1", author, "initial 1.1");
    XWikiDocument doc11 = doc.clone();
    doc.setContent("content 2.1\nqwe @ ");
    archive.updateArchive(doc, author, new Date(), "2.1", new Version(2, 1), context);
    doc.setContent("content 2.2\nqweq@ ");
    archive.updateArchive(doc, author, new Date(), "2.2", new Version(2, 2), context);
    doc.setContent("content 2.3\nqweqe @@");
    archive.updateArchive(doc, author, new Date(), "2.3", new Version(2, 3), context);
    assertEquals(new Version(2, 3), archive.getLatestVersion());
    archive.removeVersions(new Version(2, 1), new Version(2, 2), context);
    assertEquals(2, archive.getNodes().size());
    assertEquals(2, archive.getDeletedNodeInfo().size());
    assertNull(archive.getNode(new Version(2, 1)));
    assertNull(archive.getNode(new Version(2, 2)));
    XWikiDocument actual = archive.loadDocument(new Version(1, 1), context);
    assertEquals(doc11.getContent(), actual.getContent());
    assertEquals(doc11.getDate(), actual.getDate());
    assertEquals(doc11.getAuthor(), actual.getAuthor());
    assertEquals(doc11.getComment(), actual.getComment());
}
Also used : Version(org.suigeneris.jrcs.rcs.Version) DocumentReference(org.xwiki.model.reference.DocumentReference) Date(java.util.Date)

Example 15 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiDocumentArchiveTest method testVerifyCreationDateWhenLoadingDocumentFromArchive.

/**
 * Verify issue "When loading a revision of a document the creation date is incorrectly set as the last
 * modification date".
 * @see <a href="https://jira.xwiki.org/browse/XWIKI-2029">XWIKI-2029</a>
 */
public void testVerifyCreationDateWhenLoadingDocumentFromArchive() throws Exception {
    XWikiDocument doc = new XWikiDocument(new DocumentReference("Test", "Test", "Test"));
    XWikiDocumentArchive archive = new XWikiDocumentArchive(doc.getId());
    doc.setDocumentArchive(archive);
    String author = "XWiki.some author";
    addRevisionToHistory(archive, doc, "content 1.1", author, "initial 1.1");
    Date creationDate = doc.getCreationDate();
    // Wait for 2 seconds and make a change. We'll then load the last revision and verify it has a correct
    // creation date.
    Thread.sleep(1000L);
    doc.setContent("content 2.1\nqwe @ ");
    archive.updateArchive(doc, author, new Date(), "2.1", new Version(2, 1), context);
    XWikiDocument latest = archive.loadDocument(new Version(2, 1), context);
    assertEquals(creationDate, latest.getCreationDate());
}
Also used : Version(org.suigeneris.jrcs.rcs.Version) DocumentReference(org.xwiki.model.reference.DocumentReference) Date(java.util.Date)

Aggregations

Version (org.suigeneris.jrcs.rcs.Version)24 XWikiException (com.xpn.xwiki.XWikiException)7 ToString (org.suigeneris.jrcs.util.ToString)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 ArrayList (java.util.ArrayList)5 DocumentReference (org.xwiki.model.reference.DocumentReference)5 XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)4 Date (java.util.Date)4 Archive (org.suigeneris.jrcs.rcs.Archive)4 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)3 XWikiDocumentArchive (com.xpn.xwiki.doc.XWikiDocumentArchive)3 XWikiRCSNodeContent (com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 Test (org.junit.Test)2 Document (com.xpn.xwiki.api.Document)1 XWikiAttachmentArchive (com.xpn.xwiki.doc.XWikiAttachmentArchive)1 XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)1 IOException (java.io.IOException)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1