@Override protected void compute(CoreSession session, List<String> ids, Map<String, Serializable> properties) { Collection<DocumentRef> refs = ids.stream().map(IdRef::new).collect(Collectors.toList()); for (DocumentRef ref : refs) { for (Entry<String, Serializable> entry : properties.entrySet()) { try { session.setDocumentSystemProp(ref, entry.getKey(), entry.getValue()); } catch (NuxeoException e) { // TODO send to error stream log.warn("Cannot set system property: " + entry.getKey() + " on: " + ref.toString(), e); } } } try { session.save(); } catch (PropertyException e) { // TODO send to error stream log.warn("Cannot save session", e); } } }
protected void extractAndUpdate() { // update all docs if (updateSimpleText) { extractAndUpdateSimpleText(); } if (updateBinaryText) { extractAndUpdateBinaryText(); } // reset job id for (DocumentRef docRef : docsToUpdate) { session.setDocumentSystemProp(docRef, SYSPROP_FULLTEXT_JOBID, null); } }
protected void extractAndUpdateSimpleText() { if (fulltextConfiguration.fulltextSearchDisabled) { // if fulltext search is disabled, we don't extract simple text at all return; } for (String indexName : fulltextConfiguration.indexNames) { if (!fulltextConfiguration.indexesAllSimple.contains(indexName) && fulltextConfiguration.propPathsByIndexSimple.get(indexName) == null) { // nothing to do: index not configured for simple text continue; } Set<String> includedPaths = fulltextConfiguration.indexesAllSimple.contains(indexName) ? null : fulltextConfiguration.propPathsByIndexSimple.get(indexName); Set<String> excludedPaths = fulltextConfiguration.propPathsExcludedByIndexSimple.get(indexName); // get string properties List<String> strings = new StringsExtractor().findStrings(document, includedPaths, excludedPaths); // transform to text (remove HTML and entities) // we do this here rather than in the indexing backend (Elasticsearch) because it's more efficient here // add space at beginning and end for simulated phrase search using LIKE "% foo bar %" String text = strings.stream().map(this::stringToText).collect(Collectors.joining(" ", " ", " ")); // limit size text = limitStringSize(text, fulltextConfiguration.fulltextFieldSizeLimit); String property = getFulltextPropertyName(SYSPROP_FULLTEXT_SIMPLE, indexName); for (DocumentRef docRef : docsToUpdate) { session.setDocumentSystemProp(docRef, property, text); } } }
public void setSystemProperty(CoreSession session, List<String> ids, Boolean value) { List<DocumentRef> updatedRefs = new ArrayList<>(ids.size()); String query = String.format(SYSPROP_QUERY_TEMPLATE, value ? "0" : "1", String.join("', '", ids)); try (IterableQueryResult res = session.queryAndFetch(query, NXQL.NXQL)) { for (Map<String, Serializable> map : res) { DocumentRef ref = new IdRef((String) map.get(NXQL.ECM_UUID)); try { session.setDocumentSystemProp(ref, "isTrashed", value); updatedRefs.add(ref); } catch (NuxeoException e) { // TODO send to error stream log.warn("Cannot set system property: isTrashed on: " + ref.toString(), e); } } } try { session.save(); if (!updatedRefs.isEmpty()) { fireEvent(session, value ? DOCUMENT_TRASHED : DOCUMENT_UNTRASHED, updatedRefs); } } catch (PropertyException e) { // TODO send to error stream log.warn("Cannot save session", e); } }
protected void extractAndUpdateBinaryText() { // we extract binary text even if fulltext search is disabled, // because it is still used to inject into external indexers like Elasticsearch BlobsExtractor blobsExtractor = new BlobsExtractor(); Map<Blob, String> blobsText = new IdentityHashMap<>(); for (String indexName : fulltextConfiguration.indexNames) { if (!fulltextConfiguration.indexesAllBinary.contains(indexName) && fulltextConfiguration.propPathsByIndexBinary.get(indexName) == null) { // nothing to do: index not configured for blob continue; } // get original text from all blobs blobsExtractor.setExtractorProperties(fulltextConfiguration.propPathsByIndexBinary.get(indexName), fulltextConfiguration.propPathsExcludedByIndexBinary.get(indexName), fulltextConfiguration.indexesAllBinary.contains(indexName)); List<String> strings = new ArrayList<>(); for (Blob blob : blobsExtractor.getBlobs(document)) { String string = blobsText.computeIfAbsent(blob, this::blobToText); strings.add(string); } // add space at beginning and end for simulated phrase search using LIKE "% foo bar %" String text = " " + String.join(" ", strings) + " "; text = limitStringSize(text, fulltextConfiguration.fulltextFieldSizeLimit); String property = getFulltextPropertyName(SYSPROP_FULLTEXT_BINARY, indexName); for (DocumentRef docRef : docsToUpdate) { session.setDocumentSystemProp(docRef, property, text); } } }
protected Set<DocumentRef> doUntrashDocument(DocumentModel doc, boolean processChildren) { CoreSession session = doc.getCoreSession(); DocumentRef docRef = doc.getRef(); DocumentModel docForEvent = doc; // move only non placeless document // currently we don't trash placeless document DocumentRef parentRef = doc.getParentRef(); if (!Boolean.TRUE.equals(doc.getContextData(DISABLE_TRASH_RENAMING)) && parentRef != null) { String newName = unmangleName(doc); if (!newName.equals(doc.getName())) { session.move(docRef, parentRef, newName); docForEvent = session.getDocument(docRef); docForEvent.copyContextData(doc); } } session.setDocumentSystemProp(docRef, SYSPROP_IS_TRASHED, Boolean.FALSE); notifyEvent(session, DOCUMENT_UNTRASHED, docForEvent); if (processChildren && session.hasChildren(doc.getRef())) { trashDescendants(doc, Boolean.FALSE); } Set<DocumentRef> docRefs = new HashSet<>(); docRefs.add(docRef); // now untrash the parent if needed if (parentRef != null && session.isTrashed(parentRef)) { DocumentModel parent = session.getDocument(parentRef); Set<DocumentRef> ancestorDocRefs = doUntrashDocument(parent, false); docRefs.addAll(ancestorDocRefs); } return docRefs; }
docForEvent.copyContextData(doc); session.setDocumentSystemProp(docRef, SYSPROP_IS_TRASHED, Boolean.TRUE); notifyEvent(session, DOCUMENT_TRASHED, docForEvent); if (session.hasChildren(doc.getRef())) {