/**
  * Handle complete table selection event after having ensured that the navigation context stills
  * points to currentDocumentRef to protect against browsers' back button errors
  *
  * @throws ClientException if currentDocRef is not a valid document
  */
 public void checkCurrentDocAndProcessSelectPage(
     String contentViewName, String listName, Boolean selection, String currentDocRef)
     throws ClientException {
   DocumentRef currentDocumentRef = new IdRef(currentDocRef);
   if (!currentDocumentRef.equals(navigationContext.getCurrentDocument().getRef())) {
     navigationContext.navigateToRef(currentDocumentRef);
   }
   processSelectPage(contentViewName, listName, selection);
 }
  /**
   * Handle version row selection event after having ensured that the navigation context stills
   * points to currentDocumentRef to protect against browsers' back button errors.
   *
   * @param versionModelSelection the version model selection
   * @param requestedCurrentDocRef the requested current doc ref
   * @throws ClientException if currentDocRef is not a valid document
   * @since 5.6
   */
  public void checkCurrentDocAndProcessVersionSelectRow(
      PageSelection<VersionModel> versionModelSelection, String requestedCurrentDocRef)
      throws ClientException {

    DocumentRef requestedCurrentDocumentRef = new IdRef(requestedCurrentDocRef);
    DocumentRef currentDocumentRef = null;
    DocumentModel currentDocument = navigationContext.getCurrentDocument();
    if (currentDocument != null) {
      currentDocumentRef = currentDocument.getRef();
    }
    if (!requestedCurrentDocumentRef.equals(currentDocumentRef)) {
      navigationContext.navigateToRef(requestedCurrentDocumentRef);
    }
    processVersionSelectRow(versionModelSelection);
  }
 /**
  * Handle row selection event after having ensured that the navigation context stills points to
  * currentDocumentRef to protect against browsers' back button errors
  *
  * @throws ClientException if currentDocRef is not a valid document
  */
 public void checkCurrentDocAndProcessSelectRow(
     String docRef,
     String providerName,
     String listName,
     Boolean selection,
     String requestedCurrentDocRef)
     throws ClientException {
   DocumentRef requestedCurrentDocumentRef = new IdRef(requestedCurrentDocRef);
   DocumentRef currentDocumentRef = null;
   DocumentModel currentDocument = navigationContext.getCurrentDocument();
   if (currentDocument != null) {
     currentDocumentRef = currentDocument.getRef();
   }
   if (!requestedCurrentDocumentRef.equals(currentDocumentRef)) {
     navigationContext.navigateToRef(requestedCurrentDocumentRef);
   }
   processSelectRow(docRef, providerName, listName, selection);
 }
Пример #4
0
 public PublicationNode getParent() {
   if (parent == null) {
     DocumentRef docRef = folder.getParentRef();
     try {
       if (getCoreSession().hasPermission(docRef, SecurityConstants.READ)) {
         parent =
             new CoreFolderPublicationNode(
                 getCoreSession().getDocument(folder.getParentRef()),
                 treeConfigName,
                 sid,
                 factory);
       } else {
         parent =
             new VirtualCoreFolderPublicationNode(
                 getCoreSession().getSessionId(), docRef.toString(), treeConfigName, sid, factory);
       }
     } catch (ClientException e) {
       log.error("Error while retrieving parent: ", e);
     }
   }
   return parent;
 }
Пример #5
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"));
  }
Пример #6
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());
  }
Пример #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);
  }