Search in sources :

Example 76 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class CacheValidatorProviderTest method testCreateCacheByNodeType.

@Test
public void testCreateCacheByNodeType() throws RepositoryException {
    for (Authorizable a : authorizables) {
        try {
            NodeUtil node = new NodeUtil(getAuthorizableTree(a));
            NodeUtil cache = node.addChild("childNode", CacheConstants.NT_REP_CACHE);
            cache.setLong(CacheConstants.REP_EXPIRATION, 1);
            root.commit();
            fail("Creating node with nt rep:Cache below a user or group must fail.");
        } catch (CommitFailedException e) {
            assertTrue(e.isConstraintViolation());
            assertEquals(34, e.getCode());
        } finally {
            root.refresh();
        }
    }
}
Also used : Authorizable(org.apache.jackrabbit.api.security.user.Authorizable) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Example 77 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class CommitContextTest method attributeAddedByCommitHook.

@Test
public void attributeAddedByCommitHook() throws Exception {
    repository = new Oak(store).with(new OpenSecurityProvider()).with(observer).with(new CommitHook() {

        @Nonnull
        @Override
        public NodeState processCommit(NodeState before, NodeState after, CommitInfo info) throws CommitFailedException {
            CommitContext attrs = (CommitContext) info.getInfo().get(CommitContext.NAME);
            assertNotNull(attrs);
            attrs.set("foo", "bar");
            return after;
        }
    }).createContentRepository();
    session = newSession();
    Root root = session.getLatestRoot();
    Tree tree = root.getTree("/");
    tree.setProperty("a", 1);
    root.commit();
    assertNotNull(observer.info);
    CommitContext attrs = (CommitContext) observer.info.getInfo().get(CommitContext.NAME);
    assertNotNull(attrs.get("foo"));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Root(org.apache.jackrabbit.oak.api.Root) Nonnull(javax.annotation.Nonnull) Oak(org.apache.jackrabbit.oak.Oak) Tree(org.apache.jackrabbit.oak.api.Tree) OpenSecurityProvider(org.apache.jackrabbit.oak.spi.security.OpenSecurityProvider) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) Test(org.junit.Test) OakBaseTest(org.apache.jackrabbit.oak.OakBaseTest)

Example 78 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class SolrIndexEditorProvider method getIndexEditor.

@Override
public Editor getIndexEditor(@Nonnull String type, @Nonnull NodeBuilder definition, @Nonnull NodeState root, @Nonnull IndexUpdateCallback callback) throws CommitFailedException {
    SolrIndexEditor editor = null;
    if (SolrQueryIndex.TYPE.equals(type)) {
        try {
            // if index definition contains a persisted configuration, use that
            if (isPersistedConfiguration(definition)) {
                NodeState nodeState = definition.getNodeState();
                OakSolrConfiguration configuration = new OakSolrNodeStateConfiguration(nodeState);
                SolrServerConfigurationProvider configurationProvider = new NodeStateSolrServerConfigurationProvider(definition.getChildNode("server").getNodeState());
                SolrServer solrServer = new OakSolrServer(configurationProvider);
                editor = getEditor(configuration, solrServer, callback);
            } else {
                // otherwise use the default configuration providers (e.g. defined via code or OSGi)
                OakSolrConfiguration configuration = oakSolrConfigurationProvider.getConfiguration();
                editor = getEditor(configuration, solrServerProvider.getIndexingSolrServer(), callback);
            }
        } catch (Exception e) {
            log.warn("could not get Solr index editor from {}", definition.getNodeState(), e);
        }
    }
    return editor;
}
Also used : NodeStateSolrServerConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.NodeStateSolrServerConfigurationProvider) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) NodeStateSolrServerConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.NodeStateSolrServerConfigurationProvider) SolrServerConfigurationProvider(org.apache.jackrabbit.oak.plugins.index.solr.configuration.SolrServerConfigurationProvider) OakSolrServer(org.apache.jackrabbit.oak.plugins.index.solr.server.OakSolrServer) OakSolrConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration) OakSolrNodeStateConfiguration(org.apache.jackrabbit.oak.plugins.index.solr.configuration.nodestate.OakSolrNodeStateConfiguration) SolrServer(org.apache.solr.client.solrj.SolrServer) OakSolrServer(org.apache.jackrabbit.oak.plugins.index.solr.server.OakSolrServer) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 79 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class SolrIndexEditor method childNodeDeleted.

@Override
public Editor childNodeDeleted(String name, NodeState before) throws CommitFailedException {
    String path = partialEscape(PathUtils.concat(getPath(), name)).toString();
    try {
        String formattedQuery = String.format("%s:%s*", configuration.getPathField(), path);
        if (log.isDebugEnabled()) {
            log.debug("deleting by query {}", formattedQuery);
        }
        solrServer.deleteByQuery(formattedQuery);
        updateCallback.indexUpdate();
    } catch (SolrServerException e) {
        throw new CommitFailedException("Solr", 5, "Failed to remove documents from Solr", e);
    } catch (IOException e) {
        throw new CommitFailedException("Solr", 6, "Failed to send data to Solr", e);
    }
    // no need to recurse down the removed subtree
    return null;
}
Also used : SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException)

Example 80 with CommitFailedException

use of org.apache.jackrabbit.oak.api.CommitFailedException in project jackrabbit-oak by apache.

the class SystemUserImplTest method testCreateSystemUserWithOtherPath.

@Test
public void testCreateSystemUserWithOtherPath() throws Exception {
    String path = null;
    try {
        Tree t = root.getTree(UserConstants.DEFAULT_USER_PATH);
        NodeUtil systemUserTree = new NodeUtil(t).addChild("systemUser", UserConstants.NT_REP_SYSTEM_USER);
        systemUserTree.setString(UserConstants.REP_PRINCIPAL_NAME, "systemUser");
        systemUserTree.setString(UserConstants.REP_AUTHORIZABLE_ID, "systemUser");
        path = systemUserTree.getTree().getPath();
        root.commit();
        fail();
    } catch (CommitFailedException e) {
        // success
        assertTrue(e.isConstraintViolation());
    } finally {
        root.refresh();
        if (path != null) {
            Tree t = root.getTree(path);
            if (t.exists()) {
                t.remove();
                root.commit();
            }
        }
    }
}
Also used : Tree(org.apache.jackrabbit.oak.api.Tree) CommitFailedException(org.apache.jackrabbit.oak.api.CommitFailedException) NodeUtil(org.apache.jackrabbit.oak.util.NodeUtil) AbstractSecurityTest(org.apache.jackrabbit.oak.AbstractSecurityTest) Test(org.junit.Test)

Aggregations

CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)246 Test (org.junit.Test)166 Tree (org.apache.jackrabbit.oak.api.Tree)75 AbstractSecurityTest (org.apache.jackrabbit.oak.AbstractSecurityTest)66 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)60 NodeUtil (org.apache.jackrabbit.oak.util.NodeUtil)59 Root (org.apache.jackrabbit.oak.api.Root)48 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)42 RepositoryException (javax.jcr.RepositoryException)17 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)13 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)13 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)12 Nonnull (javax.annotation.Nonnull)10 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)10 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)10 TokenInfo (org.apache.jackrabbit.oak.spi.security.authentication.token.TokenInfo)10 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)9 ArrayList (java.util.ArrayList)8 ContentSession (org.apache.jackrabbit.oak.api.ContentSession)8 UserManager (org.apache.jackrabbit.api.security.user.UserManager)7