예제 #1
0
  @Override
  public Node getNodeVersion(final String label) {
    try {
      final Session session = getSession();

      final Node n = getFrozenNode(label);

      if (n != null) {
        return n;
      }

      if (isVersioned()) {
        final VersionHistory hist =
            session.getWorkspace().getVersionManager().getVersionHistory(getPath());

        if (hist.hasVersionLabel(label)) {
          LOGGER.debug("Found version for {} by label {}.", this, label);
          return hist.getVersionByLabel(label).getFrozenNode();
        }
      }

      LOGGER.warn("Unknown version {} with label or uuid {}!", this, label);
      return null;
    } catch (final RepositoryException e) {
      throw new RepositoryRuntimeException(e);
    }
  }
예제 #2
0
  @Override
  public void deleteFile(long companyId, long repositoryId, String fileName, String versionLabel)
      throws PortalException, SystemException {

    Session session = null;

    try {
      session = JCRFactoryUtil.createSession();

      Workspace workspace = session.getWorkspace();

      VersionManager versionManager = workspace.getVersionManager();

      Node rootNode = getRootNode(session, companyId);

      Node repositoryNode = getFolderNode(rootNode, repositoryId);

      Node fileNode = repositoryNode.getNode(fileName);

      Node contentNode = fileNode.getNode(JCRConstants.JCR_CONTENT);

      VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath());

      if (!versionHistory.hasVersionLabel(versionLabel)) {
        throw new NoSuchFileException(
            "{fileName=" + fileName + ", versionLabel=" + versionLabel + "}");
      }

      Version version = versionHistory.getVersionByLabel(versionLabel);

      versionManager.restore(version.getPredecessors()[0], true);

      versionHistory.removeVersion(version.getName());

      session.save();
    } catch (PathNotFoundException pnfe) {
      throw new NoSuchFileException(
          "{fileName=" + fileName + ", versionLabel=" + versionLabel + "}");
    } catch (RepositoryException re) {
      throw new SystemException(re);
    } finally {
      JCRFactoryUtil.closeSession(session);
    }
  }
예제 #3
0
  protected Node getFileContentNode(
      Session session, long companyId, long repositoryId, String fileName, String versionLabel)
      throws PortalException, SystemException {

    Node contentNode = null;

    try {
      Workspace workspace = session.getWorkspace();

      VersionManager versionManager = workspace.getVersionManager();

      Node rootNode = getRootNode(session, companyId);

      Node repositoryNode = getFolderNode(rootNode, repositoryId);

      Node fileNode = repositoryNode.getNode(fileName);

      contentNode = fileNode.getNode(JCRConstants.JCR_CONTENT);

      if (Validator.isNotNull(versionLabel)) {
        VersionHistory versionHistory = versionManager.getVersionHistory(contentNode.getPath());

        if (!versionHistory.hasVersionLabel(versionLabel)) {
          throw new NoSuchFileException(
              "{fileName=" + fileName + ", versionLabel=" + versionLabel + "}");
        }

        Version version = versionHistory.getVersionByLabel(versionLabel);

        contentNode = version.getNode(JCRConstants.JCR_FROZEN_NODE);
      }
    } catch (PathNotFoundException pnfe) {
      throw new NoSuchFileException(
          "{fileName=" + fileName + ", versionLabel=" + versionLabel + "}");
    } catch (RepositoryException re) {
      throw new SystemException(re);
    }

    return contentNode;
  }