protected DocumentModel subPublish(
      CoreSession session, DocumentModel parentProxy, Snapshot tree, boolean skipParent)
      throws ClientException {

    DocumentModel newFolderishProxy = null;
    if (skipParent) {
      newFolderishProxy = parentProxy;
    } else {
      DocumentModel version = tree.getDocument();
      newFolderishProxy = session.createProxy(version.getRef(), parentProxy.getRef());
    }

    for (Snapshot snap : tree.getChildrenSnapshots()) {
      subPublish(session, newFolderishProxy, snap, false);
    }

    return newFolderishProxy;
  }
Ejemplo n.º 2
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());
  }
Ejemplo n.º 3
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);
  }
  @Test
  public void documentManagementInTestCasesExample() throws ClientException {
    SchemaManager typeService = Framework.getLocalService(SchemaManager.class);

    DocumentType[] types = typeService.getDocumentTypes();
    for (DocumentType type : types) {
      System.out.println(type.getName());
    }

    DocumentModel mydoc = session.createDocumentModel("File");
    // DocumentModel mydoc = session.createDocumentModel("/", "toto",
    // "File");

    mydoc.setPathInfo("/", "toto");
    mydoc.setPropertyValue("dc:title", "Toto");
    mydoc = session.createDocument(mydoc);
    session.save();

    DocumentModelList docs = session.query("SELECT * FROM Document WHERE dc:title = 'Toto'");
    assertEquals(1, docs.size());
    mydoc = docs.get(0);
    assertEquals("toto", mydoc.getName());
    assertEquals("project", mydoc.getCurrentLifeCycleState());

    for (String state : mydoc.getAllowedStateTransitions()) {
      System.out.println("Transition : " + state);
    }

    // session.followTransition(mydoc.getRef(), "approve");
    mydoc.followTransition("approve");

    mydoc.setPropertyValue("dc:description", "My Description");
    mydoc = session.saveDocument(mydoc);
    session.save();

    assertEquals("approved", mydoc.getCurrentLifeCycleState());
    assertEquals("0.0", mydoc.getVersionLabel());
    assertEquals(0, session.getVersions(mydoc.getRef()).size());

    session.checkIn(mydoc.getRef(), VersioningOption.MINOR, "");
    mydoc = session.getDocument(mydoc.getRef());
    assertEquals("0.1", mydoc.getVersionLabel());
    assertEquals(1, session.getVersions(mydoc.getRef()).size());

    DocumentModel folder = session.createDocumentModel("/", "folder", "Folder");
    folder.setPropertyValue("dc:title", "Folder");
    folder = session.createDocument(folder);
    session.save();

    assertEquals(0, session.getChildren(folder.getRef()).size());
    session.publishDocument(mydoc, folder);
    assertEquals(1, session.getChildren(folder.getRef()).size());

    DocumentModel folder2 = session.createDocumentModel("/", "folder2", "Folder");
    folder2.setPropertyValue("dc:title", "Folder2");
    folder2 = session.createDocument(folder2);
    session.save();

    DocumentModel proxy = session.createProxy(mydoc.getRef(), folder2.getRef());

    assertEquals("Toto", proxy.getPropertyValue("dc:title"));
    mydoc.setPropertyValue("dc:title", "Tutu");
    session.saveDocument(mydoc);
    session.save();

    proxy = session.getDocument(proxy.getRef());
    assertEquals("Tutu", proxy.getPropertyValue("dc:title"));

    proxy.setPropertyValue("dc:title", "Tata");
    session.saveDocument(proxy);
    session.save();

    mydoc = session.getDocument(mydoc.getRef());
    assertEquals("Tata", mydoc.getPropertyValue("dc:title"));
  }
Ejemplo n.º 5
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());
  }