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();
}
}
}
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"));
}
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;
}
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;
}
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();
}
}
}
}
Aggregations