Search in sources :

Example 26 with JcrCallback

use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.

the class JcrRepositoryFileDao method restoreFileAtVersion.

/**
 * {@inheritDoc}
 */
@Override
public void restoreFileAtVersion(final Serializable fileId, final Serializable versionId, final String versionMessage) {
    if (isKioskEnabled()) {
        throw new RuntimeException(// $NON-NLS-1$
        Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
    }
    Assert.notNull(fileId);
    Assert.notNull(versionId);
    jcrTemplate.execute(new JcrCallback() {

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            Node fileNode = session.getNodeByIdentifier(fileId.toString());
            session.getWorkspace().getVersionManager().restore(fileNode.getPath(), versionId.toString(), true);
            return null;
        }
    });
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Node(javax.jcr.Node) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) JcrCallback(org.springframework.extensions.jcr.JcrCallback) Session(javax.jcr.Session)

Example 27 with JcrCallback

use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.

the class JcrRepositoryFileDao method deleteFileAtVersion.

/**
 * {@inheritDoc}
 */
@Override
public void deleteFileAtVersion(final Serializable fileId, final Serializable versionId) {
    if (isKioskEnabled()) {
        // $NON-NLS-1$
        throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
    }
    Assert.notNull(fileId);
    Assert.notNull(versionId);
    jcrTemplate.execute(new JcrCallback() {

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            RepositoryFile fileToBeDeleted = getFileById(fileId);
            // Get repository file info and acl info of parent
            if (fileToBeDeleted != null) {
                RepositoryFileAcl toBeDeletedFileAcl = aclDao.getAcl(fileToBeDeleted.getId());
                // Invoke accessVoterManager to see if we have access to perform this operation
                if (!accessVoterManager.hasAccess(fileToBeDeleted, RepositoryFilePermission.DELETE, toBeDeletedFileAcl, PentahoSessionHolder.getSession())) {
                    return null;
                }
            }
            Node fileToDeleteNode = session.getNodeByIdentifier(fileId.toString());
            session.getWorkspace().getVersionManager().getVersionHistory(fileToDeleteNode.getPath()).removeVersion(versionId.toString());
            session.save();
            return null;
        }
    });
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Node(javax.jcr.Node) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryException(javax.jcr.RepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IOException(java.io.IOException) JcrCallback(org.springframework.extensions.jcr.JcrCallback) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Session(javax.jcr.Session)

Example 28 with JcrCallback

use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.

the class JcrRepositoryFileDao method getReferrers.

@Override
@SuppressWarnings("unchecked")
public List<RepositoryFile> getReferrers(final Serializable fileId) {
    if (fileId == null) {
        return new ArrayList<RepositoryFile>();
    }
    return (List<RepositoryFile>) jcrTemplate.execute(new JcrCallback() {

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            Node fileNode = session.getNodeByIdentifier(fileId.toString());
            // guard against using a file retrieved from a more lenient session inside a more strict session
            Assert.notNull(fileNode);
            Set<RepositoryFile> referrers = new HashSet<RepositoryFile>();
            PropertyIterator refIter = fileNode.getReferences();
            if (refIter.hasNext()) {
                while (refIter.hasNext()) {
                    // for each referrer property, march up the tree until we find the file node to which the property
                    // belongs
                    RepositoryFile referrer = getReferrerFile(session, pentahoJcrConstants, refIter.nextProperty());
                    if (referrer != null) {
                        referrers.add(referrer);
                    }
                }
            }
            session.save();
            return Arrays.asList(referrers.toArray());
        }
    });
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) JcrCallback(org.springframework.extensions.jcr.JcrCallback) Session(javax.jcr.Session) HashSet(java.util.HashSet)

Example 29 with JcrCallback

use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.

the class JcrRepositoryFileDao method canUnlockFile.

/**
 * {@inheritDoc}
 */
@Override
public boolean canUnlockFile(final Serializable fileId) {
    return (Boolean) jcrTemplate.execute(new JcrCallback() {

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            Node fileNode = session.getNodeByIdentifier(fileId.toString());
            Lock lock = session.getWorkspace().getLockManager().getLock(fileNode.getPath());
            return lockHelper.canUnlock(session, pentahoJcrConstants, lock);
        }
    });
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) Node(javax.jcr.Node) JcrCallback(org.springframework.extensions.jcr.JcrCallback) Session(javax.jcr.Session) Lock(javax.jcr.lock.Lock)

Example 30 with JcrCallback

use of org.springframework.extensions.jcr.JcrCallback in project pentaho-platform by pentaho.

the class JcrRepositoryFileDao method deleteLocalePropertiesForFile.

@Override
public void deleteLocalePropertiesForFile(final RepositoryFile repositoryFile, final String locale) {
    if (isKioskEnabled()) {
        // $NON-NLS-1$
        throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
    }
    Assert.notNull(repositoryFile);
    Assert.notNull(locale);
    jcrTemplate.execute(new JcrCallback() {

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            String versionMessage = Messages.getInstance().getString("JcrRepositoryFileDao.LOCALE_0002_DELETE_PROPERTIES", repositoryFile.getId());
            lockHelper.addLockTokenToSessionIfNecessary(session, pentahoJcrConstants, repositoryFile.getId());
            JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, repositoryFile.getId());
            JcrRepositoryFileUtils.deleteFileLocaleProperties(session, repositoryFile.getId(), locale);
            session.save();
            JcrRepositoryFileUtils.checkinNearestVersionableFileIfNecessary(session, pentahoJcrConstants, repositoryFile.getId(), versionMessage);
            lockHelper.removeLockTokenFromSessionIfNecessary(session, pentahoJcrConstants, repositoryFile.getId());
            return null;
        }
    });
}
Also used : UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) JcrCallback(org.springframework.extensions.jcr.JcrCallback) Session(javax.jcr.Session)

Aggregations

JcrCallback (org.springframework.extensions.jcr.JcrCallback)38 Session (javax.jcr.Session)37 Node (javax.jcr.Node)18 IOException (java.io.IOException)14 RepositoryException (javax.jcr.RepositoryException)14 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)12 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)11 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)11 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)8 Item (javax.jcr.Item)7 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)6 Serializable (java.io.Serializable)5 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)5 PentahoJcrConstants (org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants)4 TransactionStatus (org.springframework.transaction.TransactionStatus)4 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 AccessDeniedException (javax.jcr.AccessDeniedException)3 PathNotFoundException (javax.jcr.PathNotFoundException)3