Search in sources :

Example 1 with JcrCallback

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

the class PurRepositoryTestingUtils method setAclManagementCallback.

/**
 * Create a {@linkplain JcrCallback} for setting up ACL management in test repository
 *
 * @return acl management callback
 */
static JcrCallback setAclManagementCallback() {
    return new JcrCallback() {

        @Override
        public Object doInJcr(Session session) throws IOException, RepositoryException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            Workspace workspace = session.getWorkspace();
            PrivilegeManager privilegeManager = ((JackrabbitWorkspace) workspace).getPrivilegeManager();
            try {
                privilegeManager.getPrivilege(pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE());
            } catch (AccessControlException ace) {
                privilegeManager.registerPrivilege(pentahoJcrConstants.getPHO_ACLMANAGEMENT_PRIVILEGE(), false, new String[0]);
            }
            session.save();
            return null;
        }
    };
}
Also used : PentahoJcrConstants(org.pentaho.platform.repository2.unified.jcr.PentahoJcrConstants) PrivilegeManager(org.apache.jackrabbit.api.security.authorization.PrivilegeManager) AccessControlException(javax.jcr.security.AccessControlException) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) JcrCallback(org.springframework.extensions.jcr.JcrCallback) Session(javax.jcr.Session) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) JackrabbitWorkspace(org.apache.jackrabbit.api.JackrabbitWorkspace) Workspace(javax.jcr.Workspace)

Example 2 with JcrCallback

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

the class SimpleJcrTestUtils method isLocked.

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

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

Example 3 with JcrCallback

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

the class SimpleJcrTestUtils method addNode.

public static String addNode(final JcrTemplate jcrTemplate, final String parentAbsPath, final String name, final String primaryNodeTypeName) {
    return (String) jcrTemplate.execute(new JcrCallback() {

        public String doInJcr(final Session session) throws RepositoryException {
            PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
            Node newNode;
            try {
                Item item = session.getItem(parentAbsPath);
                Assert.isTrue(item.isNode());
                Node parentNode = (Node) item;
                newNode = parentNode.addNode(name, primaryNodeTypeName);
                newNode.addMixin(pentahoJcrConstants.getMIX_REFERENCEABLE());
            } catch (PathNotFoundException e) {
                return null;
            }
            session.save();
            return newNode.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 4 with JcrCallback

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

the class SimpleJcrTestUtils method getVersionCount.

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

        public Object doInJcr(final Session session) throws RepositoryException {
            Node fileNode = (Node) session.getItem(absPath);
            VersionHistory versionHistory = fileNode.getVersionHistory();
            VersionIterator versionIterator = versionHistory.getAllVersions();
            int versionCount = 0;
            while (versionIterator.hasNext()) {
                versionIterator.nextVersion();
                versionCount++;
            }
            return versionCount;
        }
    });
}
Also used : Node(javax.jcr.Node) VersionIterator(javax.jcr.version.VersionIterator) JcrCallback(org.springframework.extensions.jcr.JcrCallback) VersionHistory(javax.jcr.version.VersionHistory) Session(javax.jcr.Session)

Example 5 with JcrCallback

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

the class SimpleJcrTestUtils method getString.

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

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