Search in sources :

Example 11 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class VersionManagerImpl method setActivity.

/**
     * {@inheritDoc}
     */
public Node setActivity(Node activity) throws RepositoryException {
    Node oldActivity = getActivity();
    if (activity == null) {
        currentActivity = null;
    } else {
        NodeImpl actNode = (NodeImpl) activity;
        if (!actNode.isNodeType(NameConstants.NT_ACTIVITY)) {
            String msg = "Given node is not an activity: " + actNode.safeGetJCRPath();
            log.error(msg);
            throw new UnsupportedRepositoryOperationException(msg);
        }
        currentActivity = actNode.getNodeId();
    }
    return oldActivity;
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Node(javax.jcr.Node)

Example 12 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class QueryImpl method storeAsNode.

/**
     * {@inheritDoc}
     */
public Node storeAsNode(String absPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
    checkInitialized();
    try {
        Path p = sessionContext.getQPath(absPath).getNormalizedPath();
        if (!p.isAbsolute()) {
            throw new RepositoryException(absPath + " is not an absolute path");
        }
        String relPath = sessionContext.getJCRPath(p).substring(1);
        Node queryNode = sessionContext.getSessionImpl().getRootNode().addNode(relPath, sessionContext.getJCRName(NT_QUERY));
        // set properties
        queryNode.setProperty(sessionContext.getJCRName(JCR_LANGUAGE), language);
        queryNode.setProperty(sessionContext.getJCRName(JCR_STATEMENT), statement);
        node = queryNode;
        return node;
    } catch (NameException e) {
        throw new RepositoryException(e.getMessage(), e);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NameException(org.apache.jackrabbit.spi.commons.conversion.NameException) Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException)

Example 13 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class VersionHistoryImpl method getAllLinearVersions.

/**
     * @see VersionHistory#getAllLinearVersions()
     */
@SuppressWarnings("deprecation")
public VersionIterator getAllLinearVersions() throws RepositoryException {
    // get base version. this can certainly be optimized
    SessionImpl session = sessionContext.getSessionImpl();
    InternalVersionHistory vh = getInternalVersionHistory();
    Node vn = session.getNodeById(vh.getVersionableId());
    InternalVersion base = ((VersionImpl) vn.getBaseVersion()).getInternalVersion();
    return new VersionIteratorImpl(getSession(), vh.getRootVersion(), base);
}
Also used : Node(javax.jcr.Node) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 14 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class NodeCorruptionTest method testCopyMultiSingleValue.

public void testCopyMultiSingleValue() throws Exception {
    Node root = superuser.getRootNode();
    String nodeName = "testCopyMulti" + System.currentTimeMillis();
    if (root.hasNode(nodeName)) {
        root.getNode(nodeName).remove();
        superuser.save();
    }
    Node test = root.addNode(nodeName);
    test.setProperty("x", "Hi");
    superuser.save();
    String wsp = superuser.getWorkspace().getName();
    String workspace2 = getAlternativeWorkspaceName();
    if (workspace2 == null) {
        throw new NotExecutableException();
    }
    Session s2 = getHelper().getSuperuserSession(workspace2);
    s2.getWorkspace().clone(wsp, "/" + nodeName, "/" + nodeName, true);
    Node test2 = s2.getRootNode().getNode(nodeName);
    test2.setProperty("x", (Value) null);
    test2.setProperty("x", new String[] {});
    s2.save();
    test.update(workspace2);
    try {
        Value[] values = test.getProperty("x").getValues();
        assertEquals(0, values.length);
    } catch (RepositoryException e) {
        // if we get here, it's a bug, as it is a multi-valued property now
        // anyway, let's see what happens if we try to read it as a single valued property
        test.getProperty("x").getValue();
        // even if that works: it's still a bug
        throw e;
    }
}
Also used : NotExecutableException(org.apache.jackrabbit.test.NotExecutableException) Node(javax.jcr.Node) Value(javax.jcr.Value) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 15 with Node

use of javax.jcr.Node in project jackrabbit by apache.

the class VersionEventsTest method testXACheckin.

/**
     * Test if checkin of a node in an XA transaction creates two add node
     * events: one for the version and one for the frozen node.
     */
public void testXACheckin() throws Exception {
    // create versionable node
    Node n1 = testRootNode.addNode(nodeName1);
    n1.addMixin(mixVersionable);
    testRootNode.save();
    EventResult listener = new EventResult(log);
    addEventListener(listener, Event.NODE_ADDED);
    // use a transaction
    UserTransaction utx = new UserTransactionImpl(superuser);
    // start transaction
    utx.begin();
    Version v = n1.checkin();
    // commit transaction
    utx.commit();
    removeEventListener(listener);
    Event[] events = listener.getEvents(1000);
    Set paths = new HashSet();
    for (int i = 0; i < events.length; i++) {
        paths.add(events[i].getPath());
    }
    assertTrue("missing 'node added' event: " + v.getPath(), paths.contains(v.getPath()));
    String frozenPath = v.getPath() + "/" + jcrFrozenNode;
    assertTrue("missing 'node added' event: " + frozenPath, paths.contains(frozenPath));
}
Also used : UserTransaction(javax.transaction.UserTransaction) EventResult(org.apache.jackrabbit.test.api.observation.EventResult) HashSet(java.util.HashSet) Set(java.util.Set) Version(javax.jcr.version.Version) Node(javax.jcr.Node) UserTransactionImpl(org.apache.jackrabbit.core.UserTransactionImpl) Event(javax.jcr.observation.Event) HashSet(java.util.HashSet)

Aggregations

Node (javax.jcr.Node)2620 Session (javax.jcr.Session)645 Test (org.junit.Test)643 RepositoryException (javax.jcr.RepositoryException)317 Property (javax.jcr.Property)251 NodeIterator (javax.jcr.NodeIterator)214 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)182 Value (javax.jcr.Value)158 Version (javax.jcr.version.Version)155 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)151 Query (javax.jcr.query.Query)122 QueryResult (javax.jcr.query.QueryResult)108 Event (javax.jcr.observation.Event)103 VersionManager (javax.jcr.version.VersionManager)97 Resource (org.apache.sling.api.resource.Resource)96 ArrayList (java.util.ArrayList)93 AccessDeniedException (javax.jcr.AccessDeniedException)89 InvalidItemStateException (javax.jcr.InvalidItemStateException)82 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)82 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)81