/**
   * Processes the version selection row.
   *
   * @param versionModelSelection the version model selection
   * @throws ClientException the client exception
   */
  protected final void processVersionSelectRow(PageSelection<VersionModel> versionModelSelection)
      throws ClientException {

    DocumentModel currentDocument = navigationContext.getCurrentDocument();
    if (currentDocument == null) {
      throw new ClientException(
          "Cannot process version select row since current document is null.");
    }

    DocumentModel version =
        documentManager.getDocumentWithVersion(
            currentDocument.getRef(), versionModelSelection.getData());
    if (version == null) {
      throw new ClientException(
          "Cannot process version select row since selected version document is null.");
    }

    if (Boolean.TRUE.equals(versionModelSelection.isSelected())) {
      documentsListsManager.addToWorkingList(
          DocumentsListsManager.CURRENT_VERSION_SELECTION, version);
    } else {
      documentsListsManager.removeFromWorkingList(
          DocumentsListsManager.CURRENT_VERSION_SELECTION, version);
    }
  }
Exemplo n.º 2
0
  @Test
  public void testPublishingAfterVersionDelete() {
    DocumentModel folder = session.createDocumentModel("/", "folder", "Folder");
    folder = session.createDocument(folder);
    DocumentModel doc = session.createDocumentModel("/", "file", "File");
    doc = session.createDocument(doc);
    checkVersions(doc);

    VersionModel lastVersion = session.getLastVersion(doc.getRef());
    assertNull(lastVersion);
    DocumentModel lastVersionDocument = session.getLastDocumentVersion(doc.getRef());
    assertNull(lastVersionDocument);

    // publish
    DocumentModel proxy = session.publishDocument(doc, folder);
    checkVersions(doc, "0.1");
    lastVersion = session.getLastVersion(doc.getRef());
    assertNotNull(lastVersion);
    assertEquals("0.1", lastVersion.getLabel());
    lastVersionDocument = session.getLastDocumentVersion(doc.getRef());
    assertNotNull(lastVersionDocument);
    assertEquals("file", lastVersionDocument.getName());

    // unpublish
    session.removeDocument(proxy.getRef());
    // delete the version
    List<VersionModel> versions = session.getVersionsForDocument(doc.getRef());
    assertEquals(1, versions.size());
    DocumentModel docVersion = session.getDocumentWithVersion(doc.getRef(), versions.get(0));
    session.removeDocument(docVersion.getRef());

    checkVersions(doc);
    lastVersion = session.getLastVersion(doc.getRef());
    assertNull(lastVersion);
    lastVersionDocument = session.getLastDocumentVersion(doc.getRef());
    assertNull(lastVersionDocument);

    // republish
    DocumentModel newProxy = session.publishDocument(doc, folder);
    checkVersions(doc, "0.2");
    lastVersion = session.getLastVersion(doc.getRef());
    assertNotNull(lastVersion);
    assertEquals("0.2", lastVersion.getLabel());
    lastVersionDocument = session.getLastDocumentVersion(doc.getRef());
    assertNotNull(lastVersionDocument);
    assertEquals("file", lastVersionDocument.getName());
  }