/** * Legacy code: Explicitly detach the document to send the document as an event context parameter. * * @see org.nuxeo.ecm.core.event.EventContext * @since 7.10 */ private void writeObject(ObjectOutputStream stream) throws IOException { detach(ref != null && hasSession() && getSession().exists(ref)); stream.defaultWriteObject(); }
@Override public boolean hasNext() { if (next != null) { return true; } // this could be optimized to retrieve batches of documents instead of // one at a time; this would need to call SQLSession.getDocumentsById // through a new CoreSession API (or improve getDocuments) for (;;) { if (!it.hasNext()) { return false; } String id = it.next(); IdRef idRef = new IdRef(id); if (!session.exists(idRef)) { continue; } DocumentModel doc; doc = session.getDocument(idRef); if (accept(doc)) { next = doc; return true; } // continue } }
if (!session.exists(ref)) { return this;
@Override public Set<String> doGetTags(CoreSession session, String docId) { DocumentRef docRef = new IdRef(docId); if (!session.exists(docRef)) { return Collections.emptySet(); } DocumentModel docModel = session.getDocument(docRef); List<Map<String, Serializable>> tags = getTags(docModel); return tags.stream().map(t -> (String) t.get(LABEL_PROPERTY)).collect(Collectors.toSet()); }
public boolean getDocumentExistsAndIsVisibleWithPath(String path) { if (StringUtils.isEmpty(path)) { return false; } PathRef ref = new PathRef(path); return documentManager.exists(ref) && documentManager.hasPermission(ref, SecurityConstants.READ); }
public boolean getDocumentExistsAndIsVisibleWithId(String id) { if (StringUtils.isEmpty(id)) { return false; } IdRef ref = new IdRef(id); return documentManager.exists(ref) && documentManager.hasPermission(ref, SecurityConstants.READ); }
public DocumentModel getDocument(String docId) { // test if user has READ right DocumentRef ref = new IdRef(docId); if (documentManager.exists(ref)) { return documentManager.getDocument(ref); } return null; }
protected Collection<String> computeAncestorIds(CoreSession session, String parentId) { Collection<String> ancestorIds = new HashSet<>(); ancestorIds.add(parentId); DocumentRef parentRef = new IdRef(parentId); while (session.exists(parentRef) && session.getDocument(parentRef).hasSchema(COMMENT_SCHEMA)) { parentId = (String) session.getDocument(parentRef).getPropertyValue(COMMENT_PARENT_ID); ancestorIds.add(parentId); parentRef = new IdRef(parentId); } return ancestorIds; }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel input) { DocumentRef docRef = new PathRef(path); if (!session.exists(docRef)) { throw new NuxeoException(String.format("Destination \"%s\" specified into operation not found", path)); } DocumentModel proxy = session.createProxy(input.getRef(), docRef); return proxy; }
private boolean exists(DocumentRef ref) { if (getSession().exists(ref)) { DocumentModel model = getSession().getDocument(ref); return !isTrashDocument(model); } return false; }
@Override public boolean validate(Object value, Object context) { MutableBoolean validated = new MutableBoolean(); resolve(value, context, (session, docRef) -> { if (session.exists(docRef)) { validated.setTrue(); } }); return validated.isTrue(); }
@Override public Comment getComment(CoreSession session, String commentId) throws CommentNotFoundException, CommentSecurityException { DocumentRef commentRef = new IdRef(commentId); if (!session.exists(commentRef)) { throw new CommentNotFoundException("The document " + commentId + " does not exist."); } DocumentModel commentModel = session.getDocument(commentRef); return Comments.newComment(commentModel); }
protected String findFarthestContainerPath(String documentPath) { Path containerPath = new Path(documentPath); String result; do { result = containerPath.toString(); containerPath = containerPath.removeLastSegments(1); } while (!containerPath.isRoot() && documentManager.exists(new PathRef(containerPath.toString()))); return result; }
protected DocumentModel getDocumentationRoot(CoreSession session) { DocumentRef rootRef = new PathRef(Root_PATH + Root_NAME); if (session.exists(rootRef)) { return session.getDocument(rootRef); } UnrestrictedRootCreator creator = new UnrestrictedRootCreator(session); creator.runUnrestricted(); // flush caches session.save(); return session.getDocument(creator.getRootRef()); }
@OperationMethod public DocumentModelList run(DocumentModelList docs) { trashService.trashDocuments(docs); // return docs with updated deleted markers DocumentModelList result = new DocumentModelListImpl(); for (DocumentModel doc : docs) { if (session.exists(doc.getRef())) { result.add(session.getDocument(doc.getRef())); } } return result; }
protected void fireUpdateEvent(CoreSession session, String docId) { DocumentRef documentRef = new IdRef(docId); if (session.exists(documentRef)) { DocumentModel documentModel = session.getDocument(documentRef); DocumentEventContext ctx = new DocumentEventContext(session, session.getPrincipal(), documentModel); Event event = ctx.newEvent(DocumentEventTypes.DOCUMENT_TAG_UPDATED); Framework.getService(EventService.class).fireEvent(event); } }
@Override public void deleteComment(CoreSession session, String commentId) throws CommentNotFoundException, CommentSecurityException { DocumentRef commentRef = new IdRef(commentId); if (!session.exists(commentRef)) { throw new CommentNotFoundException("The comment " + commentId + " does not exist."); } DocumentModel comment = session.getDocument(commentRef); DocumentModel commentedDoc = session.getDocument( new IdRef((String) comment.getPropertyValue(COMMENT_PARENT_ID))); deleteComment(commentedDoc, comment); }
public DocumentModel getDistributionRoot(CoreSession session) { DocumentRef rootRef = new PathRef(Root_PATH + Root_NAME); if (session.exists(rootRef)) { return session.getDocument(rootRef); } UnrestrictedRootCreator creator = new UnrestrictedRootCreator(session, Root_PATH, Root_NAME, true); creator.runUnrestricted(); // flush caches session.save(); return session.getDocument(creator.getRootRef()); }
protected DocumentModel getParentDocument(CoreSession session, DocumentModel doc) { DocumentModel parent; if (session.exists(doc.getRef())) { parent = session.getParentDocument(doc.getRef()); } else { Path parentPath = doc.getPath().removeLastSegments(1); parent = session.getDocument(new PathRef(parentPath.toString())); } return parent; }
protected boolean cleanTrashPath(DocumentModel parent, String name) { Path checkedPath = new Path(parent.getPathAsString()).append(name); if (getSession().exists(new PathRef(checkedPath.toString()))) { DocumentModel model = getSession().getDocument(new PathRef(checkedPath.toString())); if (model != null && model.isTrashed()) { name = name + "." + System.currentTimeMillis(); getSession().move(model.getRef(), parent.getRef(), name); return true; } } return false; }