List of usage examples for org.apache.commons.collections.collection TransformedCollection decorate
public static Collection decorate(Collection coll, Transformer transformer)
From source file:org.apache.jackrabbit.core.query.lucene.SearchIndex.java
/** * This implementation forwards the call to * {@link MultiIndex#update(Collection, Collection)} and * transforms the two iterators to the required types. * * @param remove uuids of nodes to remove. * @param add NodeStates to add. Calls to <code>next()</code> on this * iterator may return <code>null</code>, to indicate that a * node could not be indexed successfully. * @throws RepositoryException if an error occurs while indexing a node. * @throws IOException if an error occurs while updating the index. *//*from www. j av a 2 s .c o m*/ public void updateNodes(NodeIdIterator remove, NodeStateIterator add) throws RepositoryException, IOException { checkOpen(); final Map aggregateRoots = new HashMap(); final HashSet removedUUIDs = new HashSet(); final Set addedUUIDs = new HashSet(); index.update(IteratorUtils.toList(new TransformIterator(remove, new Transformer() { public Object transform(Object input) { UUID uuid = ((NodeId) input).getUUID(); removedUUIDs.add(uuid); return uuid; } })), IteratorUtils.toList(new TransformIterator(add, new Transformer() { public Object transform(Object input) { NodeState state = (NodeState) input; if (state == null) { return null; } UUID uuid = state.getNodeId().getUUID(); addedUUIDs.add(uuid); removedUUIDs.remove(uuid); Document doc = null; try { doc = createDocument(state, getNamespaceMappings(), index.getIndexFormatVersion()); retrieveAggregateRoot(state, aggregateRoots); } catch (RepositoryException e) { log.warn("Exception while creating document for node: " + state.getNodeId() + ": " + e.toString()); } return doc; } }))); // remove any aggregateRoot nodes that are new // and therefore already up-to-date aggregateRoots.keySet().removeAll(addedUUIDs); // based on removed UUIDs get affected aggregate root nodes retrieveAggregateRoot(removedUUIDs, aggregateRoots); // update aggregates if there are any affected if (aggregateRoots.size() > 0) { Collection modified = TransformedCollection.decorate(new ArrayList(), new Transformer() { public Object transform(Object input) { NodeState state = (NodeState) input; try { return createDocument(state, getNamespaceMappings(), index.getIndexFormatVersion()); } catch (RepositoryException e) { log.warn("Exception while creating document for node: " + state.getNodeId() + ": " + e.toString()); } return null; } }); modified.addAll(aggregateRoots.values()); index.update(aggregateRoots.keySet(), modified); } }
From source file:org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex.java
/** * {@inheritDoc}// ww w . j a v a 2s.c om */ public ChangesHolder getChanges(Iterator<String> remove, Iterator<NodeData> add) { final Map<String, NodeData> aggregateRoots = new HashMap<String, NodeData>(); final Set<String> removedNodeIds = new HashSet<String>(); final Set<String> addedNodeIds = new HashSet<String>(); Collection<String> docIdsToRemove = IteratorUtils.toList(new TransformIterator(remove, new Transformer() { public Object transform(Object input) { String uuid = ((String) input); removedNodeIds.add(uuid); return uuid; } })); Collection<Document> docsToAdd = IteratorUtils.toList(new TransformIterator(add, new Transformer() { public Object transform(Object input) { NodeData state = (NodeData) input; if (state == null) { return null; } String uuid = state.getIdentifier(); addedNodeIds.add(uuid); removedNodeIds.remove(uuid); Document doc = null; try { doc = createDocument(state, getNamespaceMappings(), index.getIndexFormatVersion()); retrieveAggregateRoot(state, aggregateRoots); } catch (RepositoryException e) { log.warn("Exception while creating document for node: " + state.getIdentifier() + ": " + e.toString(), e); } return doc; } })); // remove any aggregateRoot nodes that are new // and therefore already up-to-date aggregateRoots.keySet().removeAll(addedNodeIds); // based on removed UUIDs get affected aggregate root nodes retrieveAggregateRoot(removedNodeIds, aggregateRoots); // update aggregates if there are any affected if (aggregateRoots.size() > 0) { Collection modified = TransformedCollection.decorate(new ArrayList(), new Transformer() { public Object transform(Object input) { NodeData state = (NodeData) input; try { return createDocument(state, getNamespaceMappings(), index.getIndexFormatVersion()); } catch (RepositoryException e) { log.warn("Exception while creating document for node: " + state.getIdentifier() + ": " + e.toString()); } return null; } }); modified.addAll(aggregateRoots.values()); docIdsToRemove.addAll(aggregateRoots.keySet()); docsToAdd.addAll(modified); } if (docIdsToRemove.isEmpty() && docsToAdd.isEmpty()) { return null; } return new ChangesHolder(docIdsToRemove, docsToAdd); }
From source file:org.nuxeo.runtime.management.RuntimeServiceMBeanAdapter.java
@Override @SuppressWarnings("unchecked") public Set<String> getResolvedComponents() { Collection<RegistrationInfo> registrations = doGetRuntime().getComponentManager().getRegistrations(); Set<String> returnedNames = new HashSet<String>(registrations.size()); if (registrations.size() > 0) { TransformedCollection.decorate(returnedNames, RegistrationTransformer.INSTANCE).addAll(registrations); }//from ww w . ja v a 2 s. com return returnedNames; }