Search in sources :

Example 41 with UnsupportedRepositoryOperationException

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

the class VersionManagerImplMerge method finishMerge.

/**
     * Perform {@link Node#cancelMerge(Version)} or {@link Node#doneMerge(Version)}
     * depending on the value of <code>cancel</code>.
     * @param state state to finish
     * @param version version
     * @param cancel flag inidicates if this is a cancel operation
     * @throws RepositoryException if an error occurs
     */
protected void finishMerge(NodeStateEx state, Version version, boolean cancel) throws RepositoryException {
    // check versionable
    if (!checkVersionable(state)) {
        throw new UnsupportedRepositoryOperationException("Node not full versionable: " + safeGetJCRPath(state));
    }
    // check if version is in mergeFailed list
    Set<NodeId> failed = getMergeFailed(state);
    NodeId versionId = ((VersionImpl) version).getNodeId();
    if (!failed.remove(versionId)) {
        String msg = "Unable to finish merge. Specified version is not in" + " jcr:mergeFailed property: " + safeGetJCRPath(state);
        log.error(msg);
        throw new VersionException(msg);
    }
    WriteOperation ops = startWriteOperation();
    try {
        // remove version from mergeFailed list
        setMergeFailed(state, failed);
        if (!cancel) {
            // add version to jcr:predecessors list
            InternalValue[] vals = state.getPropertyValues(NameConstants.JCR_PREDECESSORS);
            InternalValue[] v = new InternalValue[vals.length + 1];
            for (int i = 0; i < vals.length; i++) {
                v[i] = InternalValue.create(vals[i].getNodeId());
            }
            v[vals.length] = InternalValue.create(versionId);
            state.setPropertyValues(NameConstants.JCR_PREDECESSORS, PropertyType.REFERENCE, v, true);
        }
        state.store();
        ops.save();
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    } finally {
        ops.close();
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) VersionException(javax.jcr.version.VersionException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 42 with UnsupportedRepositoryOperationException

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

the class OperandEvaluator method getValues.

/**
     * Evaluates the given operand in the context of the given row.
     *
     * @param operand operand to be evaluated
     * @param row query result row
     * @return values of the operand at the given row
     * @throws RepositoryException if the operand can't be evaluated
     */
public Value[] getValues(Operand operand, Row row) throws RepositoryException {
    if (operand instanceof StaticOperand) {
        StaticOperand so = (StaticOperand) operand;
        return new Value[] { getValue(so) };
    } else if (operand instanceof FullTextSearchScore) {
        FullTextSearchScore ftss = (FullTextSearchScore) operand;
        double score = row.getScore(ftss.getSelectorName());
        return new Value[] { factory.createValue(score) };
    } else if (operand instanceof NodeName) {
        NodeName nn = (NodeName) operand;
        String name = row.getNode(nn.getSelectorName()).getName();
        // root node
        if ("".equals(name)) {
            return new Value[] { factory.createValue(name, PropertyType.STRING) };
        }
        return new Value[] { factory.createValue(name, PropertyType.NAME) };
    } else if (operand instanceof Length) {
        return getLengthValues((Length) operand, row);
    } else if (operand instanceof LowerCase) {
        return getLowerCaseValues((LowerCase) operand, row);
    } else if (operand instanceof UpperCase) {
        return getUpperCaseValues((UpperCase) operand, row);
    } else if (operand instanceof NodeLocalName) {
        return getNodeLocalNameValues((NodeLocalName) operand, row);
    } else if (operand instanceof PropertyValue) {
        return getPropertyValues((PropertyValue) operand, row);
    } else {
        throw new UnsupportedRepositoryOperationException("Unknown operand type: " + operand);
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) UpperCase(javax.jcr.query.qom.UpperCase) StaticOperand(javax.jcr.query.qom.StaticOperand) NodeName(javax.jcr.query.qom.NodeName) Length(javax.jcr.query.qom.Length) Value(javax.jcr.Value) PropertyValue(javax.jcr.query.qom.PropertyValue) BindVariableValue(javax.jcr.query.qom.BindVariableValue) LowerCase(javax.jcr.query.qom.LowerCase) PropertyValue(javax.jcr.query.qom.PropertyValue) FullTextSearchScore(javax.jcr.query.qom.FullTextSearchScore) NodeLocalName(javax.jcr.query.qom.NodeLocalName)

Example 43 with UnsupportedRepositoryOperationException

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

the class EventJournalResourceImpl method spool.

@Override
public void spool(OutputContext outputContext) throws IOException {
    Calendar cal = Calendar.getInstance(Locale.ENGLISH);
    try {
        outputContext.setContentType("application/atom+xml; charset=UTF-8");
        outputContext.setProperty("Vary", "If-None-Match");
        // TODO: Content-Encoding: gzip
        // find out where to start
        long prevts = -1;
        String inm = request.getHeader("If-None-Match");
        if (inm != null) {
            // TODO: proper parsing when comma-delimited
            inm = inm.trim();
            if (inm.startsWith("\"") && inm.endsWith("\"")) {
                String tmp = inm.substring(1, inm.length() - 1);
                try {
                    prevts = Long.parseLong(tmp, 16);
                    journal.skipTo(prevts);
                } catch (NumberFormatException ex) {
                // broken etag
                }
            }
        }
        boolean hasPersistEvents = false;
        if (outputContext.hasStream()) {
            long lastts = -1;
            long now = System.currentTimeMillis();
            boolean done = false;
            // collect events
            List<Event> events = new ArrayList<Event>(MAXEV);
            while (!done && journal.hasNext()) {
                Event e = journal.nextEvent();
                hasPersistEvents |= e.getType() == Event.PERSIST;
                if (e.getDate() != lastts) {
                    // consider stopping
                    if (events.size() > MAXEV) {
                        done = true;
                    }
                    if (e.getDate() > now + MAXWAIT) {
                        done = true;
                    }
                }
                if (!done && (prevts == -1 || e.getDate() >= prevts)) {
                    events.add(e);
                }
                lastts = e.getDate();
            }
            if (lastts >= 0) {
                // construct ETag from newest event
                outputContext.setETag("\"" + Long.toHexString(lastts) + "\"");
            }
            OutputStream os = outputContext.getOutputStream();
            StreamResult streamResult = new StreamResult(os);
            SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance();
            TransformerHandler th = tf.newTransformerHandler();
            Transformer s = th.getTransformer();
            s.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            s.setOutputProperty(OutputKeys.INDENT, "yes");
            s.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
            th.setResult(streamResult);
            th.startDocument();
            th.startElement(ATOMNS, FEED, FEED, NOATTRS);
            writeAtomElement(th, TITLE, "EventJournal for " + getLocator().getWorkspaceName());
            th.startElement(ATOMNS, AUTHOR, AUTHOR, NOATTRS);
            writeAtomElement(th, NAME, "Jackrabbit Event Journal Feed Generator");
            th.endElement(ATOMNS, AUTHOR, AUTHOR);
            String id = getFullUri(request);
            writeAtomElement(th, ID, id);
            AttributesImpl linkattrs = new AttributesImpl();
            linkattrs.addAttribute(null, "self", "self", "CDATA", id);
            writeAtomElement(th, LINK, linkattrs, null);
            cal.setTimeInMillis(lastts >= 0 ? lastts : now);
            String upd = ISO8601.format(cal);
            writeAtomElement(th, UPDATED, upd);
            String lastDateString = "";
            long lastTimeStamp = 0;
            long index = 0;
            AttributesImpl contentatt = new AttributesImpl();
            contentatt.addAttribute(null, "type", "type", "CDATA", EVENTMEDIATYPE);
            while (!events.isEmpty()) {
                List<Event> bundle = null;
                String path = null;
                String op;
                if (hasPersistEvents) {
                    bundle = new ArrayList<Event>();
                    Event e = null;
                    op = "operations";
                    do {
                        e = events.remove(0);
                        bundle.add(e);
                        // compute common path
                        if (path == null) {
                            path = e.getPath();
                        } else {
                            if (e.getPath() != null && e.getPath().length() < path.length()) {
                                path = e.getPath();
                            }
                        }
                    } while (e.getType() != Event.PERSIST && !events.isEmpty());
                } else {
                    // no persist events
                    Event e = events.remove(0);
                    bundle = Collections.singletonList(e);
                    path = e.getPath();
                    op = EventUtil.getEventName(e.getType());
                }
                Event firstEvent = bundle.get(0);
                String entryupd = lastDateString;
                if (lastTimeStamp != firstEvent.getDate()) {
                    cal.setTimeInMillis(firstEvent.getDate());
                    entryupd = ISO8601.format(cal);
                    index = 0;
                } else {
                    index += 1;
                }
                th.startElement(ATOMNS, ENTRY, ENTRY, NOATTRS);
                String entrytitle = op + (path != null ? (": " + path) : "");
                writeAtomElement(th, TITLE, entrytitle);
                String entryid = id + "?type=journal&ts=" + Long.toHexString(firstEvent.getDate()) + "-" + index;
                writeAtomElement(th, ID, entryid);
                String author = firstEvent.getUserID() == null || firstEvent.getUserID().length() == 0 ? null : firstEvent.getUserID();
                if (author != null) {
                    th.startElement(ATOMNS, AUTHOR, AUTHOR, NOATTRS);
                    writeAtomElement(th, NAME, author);
                    th.endElement(ATOMNS, AUTHOR, AUTHOR);
                }
                writeAtomElement(th, UPDATED, entryupd);
                th.startElement(ATOMNS, CONTENT, CONTENT, contentatt);
                for (Event e : bundle) {
                    // serialize the event
                    th.startElement(EVNS, E_EVENT, E_EVENT, NOATTRS);
                    // DAV:href
                    if (e.getPath() != null) {
                        boolean isCollection = (e.getType() == Event.NODE_ADDED || e.getType() == Event.NODE_REMOVED);
                        String href = locator.getFactory().createResourceLocator(locator.getPrefix(), locator.getWorkspacePath(), e.getPath(), false).getHref(isCollection);
                        th.startElement(DavConstants.NAMESPACE.getURI(), DavConstants.XML_HREF, DavConstants.XML_HREF, NOATTRS);
                        th.characters(href.toCharArray(), 0, href.length());
                        th.endElement(DavConstants.NAMESPACE.getURI(), DavConstants.XML_HREF, DavConstants.XML_HREF);
                    }
                    // event type
                    String evname = EventUtil.getEventName(e.getType());
                    th.startElement(EVNS, E_EVENTTYPE, E_EVENTTYPE, NOATTRS);
                    th.startElement(EVNS, evname, evname, NOATTRS);
                    th.endElement(EVNS, evname, evname);
                    th.endElement(EVNS, E_EVENTTYPE, E_EVENTTYPE);
                    // date
                    writeObsElement(th, E_EVENTDATE, Long.toString(e.getDate()));
                    // user data
                    if (e.getUserData() != null && e.getUserData().length() > 0) {
                        writeObsElement(th, E_EVENTUSERDATA, firstEvent.getUserData());
                    }
                    // try to compute nodetype information
                    if (e instanceof AdditionalEventInfo) {
                        try {
                            Name pnt = ((AdditionalEventInfo) e).getPrimaryNodeTypeName();
                            if (pnt != null) {
                                writeObsElement(th, E_EVENTPRIMARNODETYPE, pnt.toString());
                            }
                            Set<Name> mixins = ((AdditionalEventInfo) e).getMixinTypeNames();
                            if (mixins != null) {
                                for (Name mixin : mixins) {
                                    writeObsElement(th, E_EVENTMIXINNODETYPE, mixin.toString());
                                }
                            }
                        } catch (UnsupportedRepositoryOperationException ex) {
                        // optional
                        }
                    }
                    // identifier
                    if (e.getIdentifier() != null) {
                        writeObsElement(th, E_EVENTIDENTIFIER, e.getIdentifier());
                    }
                    // info
                    if (!e.getInfo().isEmpty()) {
                        th.startElement(EVNS, E_EVENTINFO, E_EVENTINFO, NOATTRS);
                        Map<?, ?> m = e.getInfo();
                        for (Map.Entry<?, ?> entry : m.entrySet()) {
                            String key = entry.getKey().toString();
                            Object value = entry.getValue();
                            String t = value != null ? value.toString() : null;
                            writeElement(th, null, key, NOATTRS, t);
                        }
                        th.endElement(EVNS, E_EVENTINFO, E_EVENTINFO);
                    }
                    th.endElement(EVNS, E_EVENT, E_EVENT);
                    lastTimeStamp = e.getDate();
                    lastDateString = entryupd;
                }
                th.endElement(ATOMNS, CONTENT, CONTENT);
                th.endElement(ATOMNS, ENTRY, ENTRY);
            }
            th.endElement(ATOMNS, FEED, FEED);
            th.endDocument();
            os.flush();
        }
    } catch (Exception ex) {
        throw new IOException("error generating feed: " + ex.getMessage());
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) TransformerHandler(javax.xml.transform.sax.TransformerHandler) Transformer(javax.xml.transform.Transformer) OutputStream(java.io.OutputStream) AdditionalEventInfo(org.apache.jackrabbit.spi.commons.AdditionalEventInfo) ArrayList(java.util.ArrayList) Name(org.apache.jackrabbit.spi.Name) AttributesImpl(org.xml.sax.helpers.AttributesImpl) StreamResult(javax.xml.transform.stream.StreamResult) Calendar(java.util.Calendar) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) DavException(org.apache.jackrabbit.webdav.DavException) SAXException(org.xml.sax.SAXException) Event(javax.jcr.observation.Event) Map(java.util.Map)

Example 44 with UnsupportedRepositoryOperationException

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

the class NodeOrderableChildNodesTest method testOrderBeforeUnsupportedRepositoryOperationException.

/**
     * Tries to reorder on a node using {@link Node#orderBefore(String, String)}
     * that does not support child reordering.
     * <p>
     * This should throw and
     * {@link UnsupportedRepositoryOperationException}. Prequisites: <ul>
     * <li>javax.jcr.tck.NodeOrderableChildNodesTest.testOrderBeforeUnsupportedRepositoryOperationException.nodetype2:
     * A valid node type that does not support child node ordering.</li>
     * <li>javax.jcr.tck.NodeOrderableChildNodesTest.testOrderBeforeUnsupportedRepositoryOperationException.nodetype3:
     * A valid node type that can be added as a child. </ul>
     */
public void testOrderBeforeUnsupportedRepositoryOperationException() throws RepositoryException, NotExecutableException {
    // create testNode
    parentNode = testRootNode.addNode(nodeName1, getProperty("nodetype2"));
    // add child node
    Node firstNode = parentNode.addNode(nodeName2, getProperty("nodetype3"));
    // add a second child node
    Node secondNode = parentNode.addNode(nodeName3, getProperty("nodetype3"));
    // save the new nodes
    superuser.save();
    // ok lets try to reorder
    try {
        parentNode.orderBefore(secondNode.getName(), firstNode.getName());
        fail("Trying to reorder child nodes using Node.orderBefore() on node that " + "does not support ordering should throw UnsupportedRepositoryException!");
    } catch (UnsupportedRepositoryOperationException e) {
    // ok
    }
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) Node(javax.jcr.Node)

Example 45 with UnsupportedRepositoryOperationException

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

the class BatchedItemOperations method clone.

/**
     * Implementation of {@link #clone(Path, Path)} that has already determined
     * the affected <code>NodeState</code>s.
     *
     * @param srcState source state
     * @param destParentState destination parent state
     * @param destName destination name
     * @return the node id of the destination's parent
     *
     * @throws ConstraintViolationException if the operation would violate a
     * node-type or other implementation-specific constraint.
     * @throws VersionException if the parent node of <code>destAbsPath</code> is
     * versionable and checked-in, or is non-versionable but its nearest versionable ancestor is
     * checked-in. This exception will also be thrown if <code>removeExisting</code> is <code>true</code>,
     * and a UUID conflict occurs that would require the moving and/or altering of a node that is checked-in.
     * @throws AccessDeniedException if the current session does not have
     * sufficient access rights to complete the operation.
     * @throws PathNotFoundException if the node at <code>srcAbsPath</code> in
     * <code>srcWorkspace</code> or the parent of <code>destAbsPath</code> in this workspace does not exist.
     * @throws ItemExistsException if a property already exists at
     * <code>destAbsPath</code> or a node already exist there, and same name
     * siblings are not allowed or if <code>removeExisting</code> is false and a
     * UUID conflict occurs.
     * @throws LockException if a lock prevents the clone.
     * @throws RepositoryException if the last element of <code>destAbsPath</code>
     * has an index or if another error occurs.
     * @see #clone(Path, Path)
     */
public NodeId clone(NodeState srcState, NodeState destParentState, Name destName) throws ConstraintViolationException, AccessDeniedException, VersionException, PathNotFoundException, ItemExistsException, LockException, RepositoryException, IllegalStateException {
    // 2. check access rights, lock status, node type constraints, etc.
    checkAddNode(destParentState, destName, srcState.getNodeTypeName(), CHECK_ACCESS | CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_CONSTRAINTS | CHECK_HOLD | CHECK_RETENTION);
    // 3. verify that source has mixin mix:shareable
    if (!isShareable(srcState)) {
        String msg = "Cloning inside a workspace is only allowed for shareable" + " nodes. Node with type " + srcState.getNodeTypeName() + " is not shareable.";
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    // 4. detect share cycle
    NodeId srcId = srcState.getNodeId();
    NodeId destParentId = destParentState.getNodeId();
    if (destParentId.equals(srcId) || hierMgr.isAncestor(srcId, destParentId)) {
        String msg = "Cloning Node with id " + srcId + " to parent with id " + destParentId + " would create a share cycle.";
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    // 5. do clone operation (modify and store affected states)
    if (!srcState.addShare(destParentState.getNodeId())) {
        String msg = "Adding a shareable node with id (" + destParentState.getNodeId() + ") twice to the same parent is not supported.";
        log.debug(msg);
        throw new UnsupportedRepositoryOperationException(msg);
    }
    destParentState.addChildNodeEntry(destName, srcState.getNodeId());
    // store states
    stateMgr.store(srcState);
    stateMgr.store(destParentState);
    return destParentState.getNodeId();
}
Also used : UnsupportedRepositoryOperationException(javax.jcr.UnsupportedRepositoryOperationException) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException)

Aggregations

UnsupportedRepositoryOperationException (javax.jcr.UnsupportedRepositoryOperationException)57 RepositoryException (javax.jcr.RepositoryException)17 Node (javax.jcr.Node)14 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)12 NodeId (org.apache.jackrabbit.core.id.NodeId)8 ArrayList (java.util.ArrayList)7 Workspace (javax.jcr.Workspace)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 Session (javax.jcr.Session)4 VersionManager (javax.jcr.version.VersionManager)4 NodeState (org.apache.jackrabbit.core.state.NodeState)4 Name (org.apache.jackrabbit.spi.Name)4 Path (org.apache.jackrabbit.spi.Path)4 IOException (java.io.IOException)3 ItemExistsException (javax.jcr.ItemExistsException)3 ItemNotFoundException (javax.jcr.ItemNotFoundException)3 NodeType (javax.jcr.nodetype.NodeType)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AccessDeniedException (javax.jcr.AccessDeniedException)2