コード例 #1
0
  @Test
  public void testCopyCheckedIn() {
    DocumentModel doc = session.createDocumentModel("/", "file", "File");
    doc = session.createDocument(doc);
    doc.checkIn(VersioningOption.MAJOR, "comment");
    session.save();
    assertFalse(doc.isCheckedOut());
    assertEquals("1.0", doc.getVersionLabel());

    // copy
    DocumentModel copy =
        session.copy(doc.getRef(), session.getRootDocument().getRef(), "fileCopied");

    assertTrue(copy.isCheckedOut());
    assertEquals("0.0", copy.getVersionLabel());
  }
コード例 #2
0
  @Test
  public void testAutoCheckOut() throws Exception {
    DocumentModel doc = new DocumentModelImpl("/", "file", "File");
    doc.setPropertyValue("dc:title", "t0");
    doc = session.createDocument(doc);
    assertTrue(doc.isCheckedOut());
    session.checkIn(doc.getRef(), null, null);
    doc.refresh();
    assertFalse(doc.isCheckedOut());

    // auto-checkout
    doc.setPropertyValue("dc:title", "t1");
    doc = session.saveDocument(doc);
    assertTrue(doc.isCheckedOut());

    session.checkIn(doc.getRef(), null, null);
    doc.refresh();
    assertFalse(doc.isCheckedOut());

    // disable auto-checkout
    doc.setPropertyValue("dc:title", "t2");
    doc.putContextData(VersioningService.DISABLE_AUTO_CHECKOUT, Boolean.TRUE);
    doc = session.saveDocument(doc);
    assertFalse(doc.isCheckedOut());
    assertEquals("t2", doc.getPropertyValue("dc:title"));

    // can still be checked out normally afterwards
    doc.checkOut();
    assertTrue(doc.isCheckedOut());
    assertEquals("t2", doc.getPropertyValue("dc:title"));
  }
コード例 #3
0
  @Test
  public void testCheckInCheckOut() throws Exception {
    DocumentModel doc = new DocumentModelImpl("/", "file#789", "File");
    assertTrue(doc.isCheckedOut());
    doc = session.createDocument(doc);
    assertTrue(session.isCheckedOut(doc.getRef()));
    assertTrue(doc.isCheckedOut());
    session.save();
    assertTrue(session.isCheckedOut(doc.getRef()));
    assertTrue(doc.isCheckedOut());

    DocumentRef verRef = session.checkIn(doc.getRef(), null, null);
    DocumentModel ver = session.getDocument(verRef);
    assertTrue(ver.isVersion());
    doc.refresh();
    assertFalse(session.isCheckedOut(doc.getRef()));
    assertFalse(doc.isCheckedOut());

    session.checkOut(doc.getRef());
    assertTrue(session.isCheckedOut(doc.getRef()));

    // using DocumentModel API
    DocumentRef verRef2 = doc.checkIn(null, null);
    DocumentModel ver2 = session.getDocument(verRef2);
    assertTrue(ver2.isVersion());
    assertFalse(doc.isCheckedOut());
    doc.checkOut();
    assertTrue(doc.isCheckedOut());
  }
コード例 #4
0
  @Test
  public void testLiveProxyUpdate() throws Exception {
    DocumentModel section = session.createDocumentModel("/", "section", "Folder");
    section = session.createDocument(section);
    DocumentModel doc = session.createDocumentModel("/", "file", "File");
    doc = session.createDocument(doc);
    session.save();

    // create a live proxy
    DocumentModel proxy = session.createProxy(doc.getRef(), section.getRef());

    // --- change the doc, see changes on the proxy immediately without save ---

    // update
    doc.setPropertyValue("dc:title", "foo");
    doc = session.saveDocument(doc);
    assertEquals("foo", doc.getPropertyValue("dc:title"));
    // visible immediately on the proxy
    proxy.refresh();
    assertEquals("foo", proxy.getPropertyValue("dc:title"));

    // lifecycle change
    doc.followTransition("approve");
    assertEquals("approved", doc.getCurrentLifeCycleState());
    // visible immediately on the proxy
    proxy.refresh();
    assertEquals("approved", proxy.getCurrentLifeCycleState());

    // check in for version change
    doc.checkIn(VersioningOption.MINOR, null);
    assertFalse(doc.isCheckedOut());
    assertEquals("0.1", doc.getVersionLabel());
    // visible immediately on the proxy
    proxy.refresh();
    assertFalse(proxy.isCheckedOut());
    assertEquals("0.1", proxy.getVersionLabel());

    // check out
    doc.checkOut();
    assertTrue(doc.isCheckedOut());
    assertEquals("0.1+", doc.getVersionLabel());
    // visible immediately on the proxy
    proxy.refresh();
    assertTrue(proxy.isCheckedOut());
    assertEquals("0.1+", proxy.getVersionLabel());

    // --- change the proxy, see changes on the doc immediately without save ---

    // update
    proxy.setPropertyValue("dc:title", "bar");
    proxy = session.saveDocument(proxy);
    assertEquals("bar", proxy.getPropertyValue("dc:title"));
    // visible immediately on the doc, no save() needed
    doc.refresh();
    assertEquals("bar", doc.getPropertyValue("dc:title"));

    // lifecycle change
    proxy.followTransition("backToProject");
    assertEquals("project", proxy.getCurrentLifeCycleState());
    // visible immediately on the doc
    doc.refresh();
    assertEquals("project", doc.getCurrentLifeCycleState());

    // check in for version change
    proxy.checkIn(VersioningOption.MINOR, null);
    assertFalse(proxy.isCheckedOut());
    assertEquals("0.2", proxy.getVersionLabel());
    // visible immediately on the doc
    doc.refresh();
    assertFalse(doc.isCheckedOut());
    assertEquals("0.2", doc.getVersionLabel());

    // check out
    proxy.checkOut();
    assertTrue(proxy.isCheckedOut());
    assertEquals("0.2+", proxy.getVersionLabel());
    // visible immediately on the doc
    doc.refresh();
    assertTrue(doc.isCheckedOut());
    assertEquals("0.2+", doc.getVersionLabel());
  }
コード例 #5
0
  @Test
  public void testVersioningOnLiveProxy() throws Exception {
    DocumentModel folder = session.createDocumentModel("/", "folder", "Folder");
    folder = session.createDocument(folder);
    DocumentModel section = session.createDocumentModel("/", "section", "Folder");
    section = session.createDocument(section);
    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);

    // create a live proxy
    DocumentModel proxy = session.createProxy(doc.getRef(), section.getRef());
    assertTrue(proxy.isCheckedOut());
    assertVersion("0.0", proxy);
    assertVersionLabel("0.0", proxy);
    assertLatestVersion(null, proxy);

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

    // change live proxy and save with minor increment
    proxy.setPropertyValue("dc:title", "C");
    proxy.putContextData(VersioningService.VERSIONING_OPTION, VersioningOption.MINOR);
    proxy = session.saveDocument(proxy);
    assertFalse(proxy.isCheckedOut());
    assertVersion("0.1", proxy);
    assertVersionLabel("0.1", proxy);
    assertLatestVersion("0.1", proxy);

    // check the source document is also changed
    doc = session.getDocument(docRef);
    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());

    // change with no increment, the proxy is checked out
    proxy.setPropertyValue("dc:title", "D");
    proxy = session.saveDocument(proxy);
    assertTrue(proxy.isCheckedOut());
    assertVersion("0.1", proxy);
    assertVersionLabel("0.1+", proxy);

    // check source doc
    doc = session.getDocument(docRef);
    assertEquals("D", doc.getPropertyValue("dc:title"));
    assertTrue(doc.isCheckedOut());
    assertVersion("0.1", doc);
    assertVersionLabel("0.1+", doc);
  }
コード例 #6
0
  @SuppressWarnings("deprecation")
  @Test
  @LocalDeploy("org.nuxeo.ecm.core.test.tests:test-versioningservice-contrib.xml")
  public void testOldNuxeoVersioning() throws Exception {
    ((VersioningComponent) service).service = new CompatVersioningService();

    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");
    maybeSleepToNextSecond();
    doc = session.saveDocument(doc);
    DocumentRef docRef = doc.getRef();
    assertTrue(doc.isCheckedOut());
    assertVersion("1.0", doc);
    assertLatestVersion(null, doc);

    // snapshot A=1.0 and save B
    doc.setPropertyValue("dc:title", "B");
    doc.putContextData(VersioningService.VERSIONING_OPTION, VersioningOption.MINOR);
    maybeSleepToNextSecond();
    doc = session.saveDocument(doc);
    assertTrue(doc.isCheckedOut());
    assertVersion("1.1", doc);
    assertLatestVersion("1.0", doc);

    // another snapshot for B=1.1, using major inc
    doc.putContextData(VersioningService.VERSIONING_OPTION, VersioningOption.MAJOR);
    maybeSleepToNextSecond();
    doc = session.saveDocument(doc);
    assertTrue(doc.isCheckedOut());
    assertVersion("2.0", doc);
    assertLatestVersion("1.1", doc);
    DocumentModel v11 = session.getLastDocumentVersion(docRef);
    assertVersion("1.1", v11);

    // another snapshot but no increment doesn't change anything, doc is
    // clean
    doc.putContextData(
        ScopeType.REQUEST, VersioningDocument.CREATE_SNAPSHOT_ON_SAVE_KEY, Boolean.TRUE);
    doc = session.saveDocument(doc);
    assertTrue(doc.isCheckedOut());
    assertVersion("2.0", doc);
    assertLatestVersion("1.1", doc);

    // now dirty doc and snapshot+inc
    doc.setPropertyValue("dc:title", "C");
    maybeSleepToNextSecond();
    doc = session.saveDocument(doc);
    doc.putContextData(VersioningService.VERSIONING_OPTION, VersioningOption.MINOR);
    maybeSleepToNextSecond();
    doc = session.saveDocument(doc);
    assertTrue(doc.isCheckedOut());
    assertVersion("2.1", doc);
    assertLatestVersion("2.0", doc);

    // another save+inc, no snapshot
    doc.setPropertyValue("dc:title", "D");
    doc.putContextData(VersioningService.VERSIONING_OPTION, VersioningOption.MAJOR);
    maybeSleepToNextSecond();
    doc = session.saveDocument(doc);
    assertTrue(doc.isCheckedOut());
    assertVersion("3.0", doc);
    assertLatestVersion("2.1", doc);

    // checkin/checkout (old style)
    maybeSleepToNextSecond();
    session.checkIn(docRef, null);
    session.checkOut(docRef);
    doc = session.getDocument(docRef);
    assertTrue(doc.isCheckedOut());
    assertVersion("3.1", doc);
    assertLatestVersion("3.0", doc);

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

    // restore 1.1 -> 3.2 (snapshots 3.1)
    maybeSleepToNextSecond();
    doc = session.restoreToVersion(docRef, v11.getRef());
    assertFalse(doc.isCheckedOut());
    assertVersion("1.1", doc);
    assertVersionLabel("1.1", doc);
    assertLatestVersion("3.1", doc);

    // checkout restored version
    doc.checkOut();
    assertTrue(doc.isCheckedOut());
    assertVersion("3.2", doc);
    assertVersionLabel("3.2", doc);
    assertLatestVersion("3.1", doc);
  }
コード例 #7
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);
  }
コード例 #8
0
  @Test
  public void testCmisProperties() throws Exception {

    /*
     * checked out doc (live; private working copy)
     */

    DocumentModel doc = new DocumentModelImpl("/", "myfile", "File");
    doc = session.createDocument(doc);

    assertTrue(doc.isCheckedOut()); // nuxeo prop, false only on live
    assertFalse(doc.isVersion());
    assertFalse(doc.isProxy());
    assertFalse(doc.hasFacet(FacetNames.IMMUTABLE));
    assertFalse(doc.isImmutable());
    String versionSeriesId = doc.getVersionSeriesId();
    assertNotNull(versionSeriesId);
    // assertNotSame(versionSeriesId, doc.getId());
    assertEquals("0.0", doc.getVersionLabel());
    assertNull(doc.getCheckinComment());
    assertFalse(doc.isMajorVersion());
    assertFalse(doc.isLatestVersion());
    assertFalse(doc.isLatestMajorVersion());
    assertTrue(doc.isVersionSeriesCheckedOut());
    assertEquals(doc.getId(), session.getWorkingCopy(doc.getRef()).getId());

    /*
     * proxy to checked out doc (live proxy)
     */

    DocumentModel proxy = session.createProxy(doc.getRef(), session.getRootDocument().getRef());

    assertTrue(proxy.isCheckedOut()); // nuxeo prop, false only on live
    assertFalse(proxy.isVersion());
    assertTrue(proxy.isProxy());
    assertFalse(proxy.hasFacet(FacetNames.IMMUTABLE));
    assertFalse(proxy.isImmutable());
    assertEquals(versionSeriesId, proxy.getVersionSeriesId());
    assertEquals("0.0", proxy.getVersionLabel());
    assertNull(proxy.getCheckinComment());
    assertFalse(proxy.isMajorVersion());
    assertFalse(proxy.isLatestVersion());
    assertFalse(proxy.isLatestMajorVersion());
    assertTrue(proxy.isVersionSeriesCheckedOut());
    assertTrue(doc.isVersionSeriesCheckedOut());
    assertEquals(doc.getId(), session.getWorkingCopy(proxy.getRef()).getId());

    /*
     * checked in doc
     */

    DocumentRef verRef = doc.checkIn(VersioningOption.MINOR, "comment");
    session.save();
    DocumentModel ver = session.getDocument(verRef);
    proxy.refresh();

    assertFalse(doc.isCheckedOut());
    assertFalse(doc.isVersion());
    assertFalse(doc.isProxy());
    // assertTrue(doc.hasFacet(FacetNames.IMMUTABLE)); // debatable
    // assertTrue(doc.isImmutable()); // debatable
    assertEquals(versionSeriesId, doc.getVersionSeriesId());
    assertEquals("0.1", doc.getVersionLabel());
    assertNull(doc.getCheckinComment());
    assertFalse(doc.isMajorVersion());
    assertFalse(doc.isLatestVersion());
    assertFalse(doc.isLatestMajorVersion());
    assertFalse(doc.isVersionSeriesCheckedOut());
    assertFalse(proxy.isVersionSeriesCheckedOut());
    assertEquals(doc.getId(), session.getWorkingCopy(proxy.getRef()).getId());

    // TODO proxy to checked in doc

    /*
     * version
     */

    // assertFalse(ver.isCheckedOut()); // TODO
    assertTrue(ver.isVersion());
    assertFalse(ver.isProxy());
    assertTrue(ver.hasFacet(FacetNames.IMMUTABLE));
    assertTrue(ver.isImmutable());
    assertEquals(versionSeriesId, ver.getVersionSeriesId());
    assertEquals("0.1", ver.getVersionLabel());
    assertEquals("comment", ver.getCheckinComment());
    assertFalse(ver.isMajorVersion());
    assertTrue(ver.isLatestVersion());
    assertFalse(ver.isLatestMajorVersion());
    assertFalse(ver.isVersionSeriesCheckedOut());
    assertEquals(doc.getId(), session.getWorkingCopy(ver.getRef()).getId());

    /*
     * proxy to version
     */

    proxy = session.createProxy(ver.getRef(), session.getRootDocument().getRef());

    assertFalse(proxy.isCheckedOut());
    assertFalse(proxy.isVersion());
    assertTrue(proxy.isProxy());
    assertTrue(proxy.hasFacet(FacetNames.IMMUTABLE));
    assertTrue(proxy.isImmutable());
    assertEquals(versionSeriesId, proxy.getVersionSeriesId());
    assertEquals("0.1", proxy.getVersionLabel());
    assertEquals("comment", proxy.getCheckinComment());
    assertFalse(proxy.isMajorVersion());
    assertTrue(proxy.isLatestVersion());
    assertFalse(proxy.isLatestMajorVersion());
    assertFalse(proxy.isVersionSeriesCheckedOut());
    assertFalse(doc.isVersionSeriesCheckedOut());
    assertFalse(ver.isVersionSeriesCheckedOut());
    assertEquals(doc.getId(), session.getWorkingCopy(proxy.getRef()).getId());

    /*
     * re-checked out doc
     */

    doc.checkOut();
    ver.refresh();
    proxy.refresh();

    assertTrue(doc.isCheckedOut());
    assertFalse(doc.isVersion());
    assertFalse(doc.isProxy());
    assertFalse(doc.hasFacet(FacetNames.IMMUTABLE));
    assertFalse(doc.isImmutable());
    assertEquals(versionSeriesId, doc.getVersionSeriesId());
    assertEquals("0.1+", doc.getVersionLabel());
    assertNull(doc.getCheckinComment());
    assertFalse(doc.isMajorVersion());
    assertFalse(doc.isLatestVersion());
    assertFalse(doc.isLatestMajorVersion());
    assertTrue(doc.isVersionSeriesCheckedOut());
    assertTrue(ver.isVersionSeriesCheckedOut());
    assertTrue(proxy.isVersionSeriesCheckedOut());
    assertEquals(doc.getId(), session.getWorkingCopy(doc.getRef()).getId());

    /*
     * major checkin
     */

    DocumentRef majRef = doc.checkIn(VersioningOption.MAJOR, "yo");
    DocumentModel maj = session.getDocument(majRef);
    ver.refresh();
    proxy.refresh();

    assertTrue(maj.isMajorVersion());
    assertTrue(maj.isLatestVersion());
    assertTrue(maj.isLatestMajorVersion());
    assertFalse(maj.isVersionSeriesCheckedOut());
    assertEquals(doc.getId(), session.getWorkingCopy(maj.getRef()).getId());
    // previous ver
    assertFalse(ver.isMajorVersion());
    assertFalse(ver.isLatestVersion());
    assertFalse(ver.isLatestMajorVersion());
    assertFalse(ver.isVersionSeriesCheckedOut());
    assertFalse(doc.isVersionSeriesCheckedOut());
    assertFalse(proxy.isVersionSeriesCheckedOut());
    assertEquals(doc.getId(), session.getWorkingCopy(ver.getRef()).getId());
  }