Search in sources :

Example 31 with JcrCallback

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

the class JcrRepositoryFileDao method unlockFile.

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

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            lockHelper.unlockFile(session, pentahoJcrConstants, fileId);
            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)

Example 32 with JcrCallback

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

the class JcrRepositoryFileDao method setLocalePropertiesForFile.

@Override
public void setLocalePropertiesForFile(final RepositoryFile repositoryFile, final String locale, final Properties properties) {
    if (isKioskEnabled()) {
        // $NON-NLS-1$
        throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
    }
    Assert.notNull(repositoryFile);
    Assert.notNull(locale);
    Assert.notNull(properties);
    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_0001_UPDATE_PROPERTIES", repositoryFile.getId());
            lockHelper.addLockTokenToSessionIfNecessary(session, pentahoJcrConstants, repositoryFile.getId());
            JcrRepositoryFileUtils.checkoutNearestVersionableFileIfNecessary(session, pentahoJcrConstants, repositoryFile.getId());
            JcrRepositoryFileUtils.updateFileLocaleProperties(session, repositoryFile.getId(), locale, properties);
            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)

Example 33 with JcrCallback

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

the class JcrRepositoryFileDao method lockFile.

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

        @Override
        public Object doInJcr(final Session session) throws RepositoryException, IOException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            lockHelper.lockFile(session, pentahoJcrConstants, fileId, message);
            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)

Example 34 with JcrCallback

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

the class SimpleJcrTestUtils method getNodeId.

public static String getNodeId(final JcrTemplate jcrTemplate, final String absPath) {
    return (String) jcrTemplate.execute(new JcrCallback() {

        public Object doInJcr(final Session session) throws RepositoryException {
            Item item;
            try {
                item = session.getItem(absPath);
            } catch (PathNotFoundException e) {
                return null;
            }
            Assert.isTrue(item.isNode());
            return ((Node) item).getUUID();
        }
    });
}
Also used : Item(javax.jcr.Item) Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException) JcrCallback(org.springframework.extensions.jcr.JcrCallback) Session(javax.jcr.Session)

Example 35 with JcrCallback

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

the class SimpleJcrTestUtils method getDate.

public static Date getDate(final JcrTemplate jcrTemplate, final String absPath) {
    return (Date) jcrTemplate.execute(new JcrCallback() {

        public Object doInJcr(final Session session) throws RepositoryException {
            Item item = session.getItem(absPath);
            Assert.isTrue(!item.isNode());
            return ((Property) item).getDate().getTime();
        }
    });
}
Also used : Item(javax.jcr.Item) JcrCallback(org.springframework.extensions.jcr.JcrCallback) Date(java.util.Date) 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