コード例 #1
0
  @Test
  public void testGetDocumentWithVersion() throws Exception {
    String name2 = "file#248";
    DocumentModel childFile = new DocumentModelImpl("/", name2, "File");
    childFile = session.createDocument(childFile);
    session.save();
    DocumentRef v1Ref = session.checkIn(childFile.getRef(), null, null);
    session.checkOut(childFile.getRef());

    childFile.setProperty("file", "filename", "second name");
    childFile.setProperty("dc", "title", "f1");
    childFile.setProperty("dc", "description", "desc 1");
    session.saveDocument(childFile);
    session.save();
    maybeSleepToNextSecond();
    DocumentRef v2Ref = session.checkIn(childFile.getRef(), null, null);

    DocumentModel newDoc = session.getDocument(childFile.getRef());
    assertNotNull(newDoc);
    assertNotNull(newDoc.getRef());
    assertEquals("second name", newDoc.getProperty("file", "filename"));

    // restore, no snapshot as already pristine
    waitForFulltextIndexing();
    maybeSleepToNextSecond();
    DocumentModel restoredDoc = session.restoreToVersion(childFile.getRef(), v1Ref);

    assertNotNull(restoredDoc);
    assertNotNull(restoredDoc.getRef());
    assertNull(restoredDoc.getProperty("file", "filename"));

    DocumentModel last = session.getLastDocumentVersion(childFile.getRef());
    assertNotNull(last);
    assertNotNull(last.getRef());
    assertEquals(v2Ref.reference(), last.getId());
    assertEquals("second name", last.getProperty("file", "filename"));
  }
コード例 #2
0
  @Test
  public void testGetLastVersion() {
    DocumentModel doc = session.createDocumentModel("/", "doc", "File");
    doc = session.createDocument(doc);
    session.save();
    DocumentRef v1ref = session.checkIn(doc.getRef(), VersioningOption.MAJOR, null);
    session.checkOut(doc.getRef());
    DocumentRef v2ref = session.checkIn(doc.getRef(), VersioningOption.MINOR, null);

    // last version on the doc
    DocumentModel last = session.getLastDocumentVersion(doc.getRef());
    assertEquals(v2ref.reference(), last.getId());
    DocumentRef lastRef = session.getLastDocumentVersionRef(doc.getRef());
    assertEquals(v2ref.reference(), lastRef.reference());

    // last version on any version
    last = session.getLastDocumentVersion(v2ref);
    assertEquals(v2ref.reference(), last.getId());
    lastRef = session.getLastDocumentVersionRef(v2ref);
    assertEquals(v2ref.reference(), lastRef.reference());
  }
コード例 #3
0
  @Test
  public void testStandardVersioning() throws Exception {
    DocumentModel folder = session.createDocumentModel("/", "folder", "Folder");
    folder = session.createDocument(folder);
    DocumentModel doc = session.createDocumentModel("/", "testfile1", "File");
    doc = session.createDocument(doc);
    doc.setPropertyValue("dc:title", "A");
    doc = session.saveDocument(doc);
    DocumentRef docRef = doc.getRef();
    assertTrue(doc.isCheckedOut());
    assertVersion("0.0", doc);
    assertVersionLabel("0.0", doc);
    assertLatestVersion(null, doc);

    // save with no option, use default
    doc.setPropertyValue("dc:title", "B");
    doc = session.saveDocument(doc);
    assertTrue(doc.isCheckedOut());
    assertVersion("0.0", doc);
    assertVersionLabel("0.0", doc);
    assertLatestVersion(null, doc);

    // change and save with new minor
    doc.setPropertyValue("dc:title", "C");
    doc.putContextData(VersioningService.VERSIONING_OPTION, VersioningOption.MINOR);
    maybeSleepToNextSecond();
    doc = session.saveDocument(doc);
    assertFalse(doc.isCheckedOut());
    assertVersion("0.1", doc);
    assertVersionLabel("0.1", doc);
    assertLatestVersion("0.1", doc);
    DocumentModel v01 = session.getLastDocumentVersion(docRef);
    assertEquals(v01.getId(), session.getBaseVersion(docRef).reference());

    // checkout
    doc.checkOut();
    assertTrue(doc.isCheckedOut());
    assertVersion("0.1", doc);
    assertVersionLabel("0.1+", doc);
    assertLatestVersion("0.1", doc);

    // change and save with new major
    doc.setPropertyValue("dc:title", "D");
    doc.putContextData(VersioningService.VERSIONING_OPTION, VersioningOption.MAJOR);
    maybeSleepToNextSecond();
    doc = session.saveDocument(doc);
    assertFalse(doc.isCheckedOut());
    assertVersion("1.0", doc);
    assertVersionLabel("1.0", doc);
    assertLatestVersion("1.0", doc);
    DocumentModel v10 = session.getLastDocumentVersion(docRef);
    assertEquals(v10.getId(), session.getBaseVersion(docRef).reference());

    // direct save for autocheckout
    doc.setPropertyValue("dc:title", "E");
    doc = session.saveDocument(doc);
    assertTrue(doc.isCheckedOut());
    assertVersion("1.0", doc);
    assertVersionLabel("1.0+", doc);
    assertLatestVersion("1.0", doc);

    // checkin
    maybeSleepToNextSecond();
    DocumentRef v11ref = doc.checkIn(VersioningOption.MINOR, "foo");
    assertFalse(doc.isCheckedOut());
    assertVersion("1.1", doc);
    assertVersionLabel("1.1", doc);
    assertLatestVersion("1.1", doc);
    assertEquals(v11ref.reference(), session.getBaseVersion(docRef).reference());

    // wait before doing a restore
    session.save();
    waitForAsyncCompletion();

    // restore 0.1
    doc = session.restoreToVersion(docRef, v01.getRef());
    assertFalse(doc.isCheckedOut());
    assertVersion("0.1", doc);
    assertVersionLabel("0.1", doc);
    assertLatestVersion("1.1", doc);
    assertEquals(v01.getId(), session.getBaseVersion(docRef).reference());

    // checkout restored version
    doc.checkOut();
    assertTrue(doc.isCheckedOut());
    assertVersion("1.1", doc);
    assertVersionLabel("1.1+", doc);
    assertLatestVersion("1.1", doc);

    // publish (checks in first)
    maybeSleepToNextSecond();
    DocumentModel proxy = session.publishDocument(doc, folder);
    assertFalse(doc.isCheckedOut());
    assertVersion("1.2", doc);
    assertVersionLabel("1.2", doc);
    assertLatestVersion("1.2", doc);
    assertVersion("1.2", proxy);

    // republish, no new version
    proxy = session.publishDocument(doc, folder);
    assertFalse(doc.isCheckedOut());
    assertVersion("1.2", doc);
    assertVersionLabel("1.2", doc);
    assertLatestVersion("1.2", doc);
    assertVersion("1.2", proxy);

    // do a change (autocheckout), and republish
    doc.setPropertyValue("dc:title", "F");
    session.saveDocument(doc);
    maybeSleepToNextSecond();
    proxy = session.publishDocument(doc, folder);
    assertFalse(doc.isCheckedOut());
    assertVersion("1.3", doc);
    assertVersionLabel("1.3", doc);
    assertLatestVersion("1.3", doc);
  }