Search in sources :

Example 46 with PropertyState

use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.

the class SearchIndex method mergeAggregatedNodeIndexes.

/**
     * Merges the fulltext indexed fields of the aggregated node states into
     * <code>doc</code>.
     *
     * @param state the node state on which <code>doc</code> was created.
     * @param doc the lucene document with index fields from <code>state</code>.
     * @param ifv the current index format version.
     */
protected void mergeAggregatedNodeIndexes(NodeState state, Document doc, IndexFormatVersion ifv) {
    if (indexingConfig != null) {
        AggregateRule[] aggregateRules = indexingConfig.getAggregateRules();
        if (aggregateRules == null) {
            return;
        }
        try {
            ItemStateManager ism = getContext().getItemStateManager();
            for (AggregateRule aggregateRule : aggregateRules) {
                boolean ruleMatched = false;
                // node includes
                NodeState[] aggregates = aggregateRule.getAggregatedNodeStates(state);
                if (aggregates != null) {
                    ruleMatched = true;
                    for (NodeState aggregate : aggregates) {
                        Document aDoc = createDocument(aggregate, getNamespaceMappings(), ifv);
                        // transfer fields to doc if there are any
                        Fieldable[] fulltextFields = aDoc.getFieldables(FieldNames.FULLTEXT);
                        if (fulltextFields != null) {
                            for (Fieldable fulltextField : fulltextFields) {
                                doc.add(fulltextField);
                            }
                            doc.add(new Field(FieldNames.AGGREGATED_NODE_UUID, false, aggregate.getNodeId().toString(), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
                        }
                    }
                    // make sure that fulltext fields are aligned properly
                    // first all stored fields, then remaining
                    Fieldable[] fulltextFields = doc.getFieldables(FieldNames.FULLTEXT);
                    doc.removeFields(FieldNames.FULLTEXT);
                    Arrays.sort(fulltextFields, FIELDS_COMPARATOR_STORED);
                    for (Fieldable f : fulltextFields) {
                        doc.add(f);
                    }
                }
                // property includes
                PropertyState[] propStates = aggregateRule.getAggregatedPropertyStates(state);
                if (propStates != null) {
                    ruleMatched = true;
                    for (PropertyState propState : propStates) {
                        String namePrefix = FieldNames.createNamedValue(getNamespaceMappings().translateName(propState.getName()), "");
                        NodeState parent = (NodeState) ism.getItemState(propState.getParentId());
                        Document aDoc = createDocument(parent, getNamespaceMappings(), ifv);
                        try {
                            // find the right fields to transfer
                            Fieldable[] fields = aDoc.getFieldables(FieldNames.PROPERTIES);
                            for (Fieldable field : fields) {
                                // assume properties fields use SingleTokenStream
                                TokenStream tokenStream = field.tokenStreamValue();
                                TermAttribute termAttribute = tokenStream.addAttribute(TermAttribute.class);
                                PayloadAttribute payloadAttribute = tokenStream.addAttribute(PayloadAttribute.class);
                                tokenStream.incrementToken();
                                tokenStream.end();
                                tokenStream.close();
                                String value = new String(termAttribute.termBuffer(), 0, termAttribute.termLength());
                                if (value.startsWith(namePrefix)) {
                                    // extract value
                                    String rawValue = value.substring(namePrefix.length());
                                    // create new named value
                                    Path p = getRelativePath(state, propState);
                                    String path = getNamespaceMappings().translatePath(p);
                                    value = FieldNames.createNamedValue(path, rawValue);
                                    termAttribute.setTermBuffer(value);
                                    PropertyMetaData pdm = PropertyMetaData.fromByteArray(payloadAttribute.getPayload().getData());
                                    doc.add(new Field(field.name(), new SingletonTokenStream(value, pdm.getPropertyType())));
                                    doc.add(new Field(FieldNames.AGGREGATED_NODE_UUID, false, parent.getNodeId().toString(), Field.Store.NO, Field.Index.NOT_ANALYZED_NO_NORMS, Field.TermVector.NO));
                                    if (pdm.getPropertyType() == PropertyType.STRING) {
                                        // add to fulltext index
                                        Field ft = new Field(FieldNames.FULLTEXT, false, rawValue, Field.Store.YES, Field.Index.ANALYZED_NO_NORMS, Field.TermVector.NO);
                                        doc.add(ft);
                                    }
                                }
                            }
                        } finally {
                            Util.disposeDocument(aDoc);
                        }
                    }
                }
                // only use first aggregate definition that matches
                if (ruleMatched) {
                    break;
                }
            }
        } catch (NoSuchItemStateException e) {
            // do not fail if aggregate cannot be created
            log.info("Exception while building indexing aggregate for {}. Node is not available {}.", state.getNodeId(), e.getMessage());
        } catch (Exception e) {
            // do not fail if aggregate cannot be created
            log.warn("Exception while building indexing aggregate for " + state.getNodeId(), e);
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) TokenStream(org.apache.lucene.analysis.TokenStream) PayloadAttribute(org.apache.lucene.analysis.tokenattributes.PayloadAttribute) NodeState(org.apache.jackrabbit.core.state.NodeState) Document(org.apache.lucene.document.Document) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) SAXException(org.xml.sax.SAXException) JournalException(org.apache.jackrabbit.core.journal.JournalException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) RepositoryException(javax.jcr.RepositoryException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) InvalidQueryException(javax.jcr.query.InvalidQueryException) PropertyState(org.apache.jackrabbit.core.state.PropertyState) SortField(org.apache.lucene.search.SortField) Field(org.apache.lucene.document.Field) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) Fieldable(org.apache.lucene.document.Fieldable) ItemStateManager(org.apache.jackrabbit.core.state.ItemStateManager) TermAttribute(org.apache.lucene.analysis.tokenattributes.TermAttribute)

Example 47 with PropertyState

use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.

the class NodeImpl method isCheckedOut.

//------------------------------< versioning support: public Node methods >
/**
     * {@inheritDoc}
     */
public boolean isCheckedOut() throws RepositoryException {
    // check state of this instance
    sanityCheck();
    // otherwise it would had been impossible to add it in the first place
    if (isNew()) {
        return true;
    }
    // this would have a negative impact on performance though...
    try {
        NodeState state = getNodeState();
        while (!state.hasPropertyName(JCR_ISCHECKEDOUT)) {
            ItemId parentId = state.getParentId();
            if (parentId == null) {
                // root reached or out of hierarchy
                return true;
            }
            state = (NodeState) sessionContext.getItemStateManager().getItemState(parentId);
        }
        PropertyId id = new PropertyId(state.getNodeId(), JCR_ISCHECKEDOUT);
        PropertyState ps = (PropertyState) sessionContext.getItemStateManager().getItemState(id);
        InternalValue[] values = ps.getValues();
        if (values == null || values.length != 1) {
            // in which case it's probably not mix:versionable
            return true;
        }
        return values[0].getBoolean();
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) RepositoryException(javax.jcr.RepositoryException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) ItemId(org.apache.jackrabbit.core.id.ItemId) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 48 with PropertyState

use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.

the class XMLPersistenceManager method load.

/**
     * {@inheritDoc}
     */
public synchronized PropertyState load(PropertyId id) throws NoSuchItemStateException, ItemStateException {
    if (!initialized) {
        throw new IllegalStateException("not initialized");
    }
    Exception e = null;
    String propFilePath = buildPropFilePath(id);
    try {
        if (!itemStateFS.isFile(propFilePath)) {
            throw new NoSuchItemStateException(id.toString());
        }
        InputStream in = itemStateFS.getInputStream(propFilePath);
        try {
            DOMWalker walker = new DOMWalker(in);
            PropertyState state = createNew(id);
            readState(walker, state);
            return state;
        } finally {
            in.close();
        }
    } catch (IOException ioe) {
        e = ioe;
    // fall through
    } catch (FileSystemException fse) {
        e = fse;
    // fall through
    }
    String msg = "failed to read property state: " + id.toString();
    log.debug(msg);
    throw new ItemStateException(msg, e);
}
Also used : DOMWalker(org.apache.jackrabbit.core.util.DOMWalker) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InputStream(java.io.InputStream) IOException(java.io.IOException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) IOException(java.io.IOException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) FileSystemException(org.apache.jackrabbit.core.fs.FileSystemException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PropertyState(org.apache.jackrabbit.core.state.PropertyState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 49 with PropertyState

use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.

the class InternalVersionHistoryImpl method init.

/**
     * Initializes the history and loads all internal caches
     *
     * @throws RepositoryException if an error occurs
     */
private synchronized void init() throws RepositoryException {
    nameCache.clear();
    versionCache.clear();
    labelCache.clear();
    // get id
    historyId = node.getNodeId();
    // get versionable id
    versionableId = NodeId.valueOf(node.getPropertyValue(NameConstants.JCR_VERSIONABLEUUID).toString());
    // get label node
    labelNode = node.getNode(NameConstants.JCR_VERSIONLABELS, 1);
    // init label cache
    try {
        PropertyState[] labels = labelNode.getProperties();
        for (PropertyState pState : labels) {
            if (pState.getType() == PropertyType.REFERENCE) {
                Name labelName = pState.getName();
                NodeId id = pState.getValues()[0].getNodeId();
                if (node.getState().hasChildNodeEntry(id)) {
                    labelCache.put(labelName, node.getState().getChildNodeEntry(id).getName());
                } else {
                    log.warn("Error while resolving label reference. Version missing: " + id);
                }
            }
        }
    } catch (ItemStateException e) {
        throw new RepositoryException(e);
    }
    // get root version
    rootVersion = createVersionInstance(NameConstants.JCR_ROOTVERSION);
    // get version entries
    for (ChildNodeEntry child : node.getState().getChildNodeEntries()) {
        if (child.getName().equals(NameConstants.JCR_VERSIONLABELS)) {
            continue;
        }
        nameCache.put(child.getName(), child.getId());
    }
}
Also used : ChildNodeEntry(org.apache.jackrabbit.core.state.ChildNodeEntry) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) PropertyState(org.apache.jackrabbit.core.state.PropertyState) Name(org.apache.jackrabbit.spi.Name) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 50 with PropertyState

use of org.apache.jackrabbit.core.state.PropertyState in project jackrabbit by apache.

the class UpdateEventFactory method createUpdateOperation.

/**
     * Create an update operation.
     *
     * @return update operation
     */
public UpdateEvent createUpdateOperation() {
    NodeState n1 = createNodeState();
    NodeState n2 = createNodeState();
    NodeState n3 = createNodeState();
    PropertyState p1 = createPropertyState(n1.getNodeId(), "{}a");
    PropertyState p2 = createPropertyState(n2.getNodeId(), "{}b");
    ChangeLog changes = new ChangeLog();
    changes.added(n1);
    changes.added(p1);
    changes.deleted(p2);
    changes.modified(n2);
    changes.deleted(n3);
    List events = new ArrayList();
    events.add(createEventState(n1, Event.NODE_ADDED, "{}n1", session));
    events.add(createEventState(p1, n1, Event.PROPERTY_ADDED, session));
    events.add(createEventState(p2, n2, Event.PROPERTY_REMOVED, session));
    events.add(createEventState(n3, Event.NODE_REMOVED, "{}n3", session));
    return new UpdateEvent(changes, events, System.currentTimeMillis(), "user-data");
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ChangeLog(org.apache.jackrabbit.core.state.ChangeLog) PropertyState(org.apache.jackrabbit.core.state.PropertyState) UpdateEvent(org.apache.jackrabbit.core.cluster.SimpleEventListener.UpdateEvent)

Aggregations

PropertyState (org.apache.jackrabbit.core.state.PropertyState)53 PropertyId (org.apache.jackrabbit.core.id.PropertyId)25 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)25 NodeState (org.apache.jackrabbit.core.state.NodeState)25 RepositoryException (javax.jcr.RepositoryException)22 Name (org.apache.jackrabbit.spi.Name)22 InternalValue (org.apache.jackrabbit.core.value.InternalValue)19 NodeId (org.apache.jackrabbit.core.id.NodeId)14 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)14 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)13 InvalidItemStateException (javax.jcr.InvalidItemStateException)9 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)5 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)5 ItemExistsException (javax.jcr.ItemExistsException)4 Value (javax.jcr.Value)4 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)4 PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)4