protected void copyTags(CoreSession session, String srcDocId, String dstDocId, boolean removeExistingTags) { CoreInstance.doPrivileged(session, s -> { doCopyTags(s, srcDocId, dstDocId, removeExistingTags); }); }
protected String probeRepository(String repositoryName) { return TransactionHelper.runInTransaction(() -> CoreInstance.doPrivileged(repositoryName, this::probeSession)); }
@Override public Set<String> getTags(CoreSession session, String docId) { return CoreInstance.doPrivileged(session, (CoreSession s) -> doGetTags(s, docId)); }
protected void migrateRepository(String repositoryName) { TransactionHelper.runInTransaction(() -> CoreInstance.doPrivileged(repositoryName, this::migrateSession)); }
@Override public List<DocumentModel> getSubscribedDocuments(String prefixedPrincipalName, String repositoryName) { String nxql = "SELECT * FROM Document WHERE ecm:mixinType = '" + SubscriptionAdapter.NOTIFIABLE_FACET + "' " + "AND ecm:isVersion = 0 " + "AND notif:notifications/*/subscribers/* = " + NXQL.escapeString(prefixedPrincipalName); return CoreInstance.doPrivileged(repositoryName, (CoreSession s) -> s.query(nxql).stream().map(NotificationService::detachDocumentModel).collect( toList())); }
@Override @SuppressWarnings("unchecked") public List<Annotation> getAnnotations(CoreSession session, String documentId, String xpath) { return CoreInstance.doPrivileged(session, s -> { PageProviderService ppService = Framework.getService(PageProviderService.class); Map<String, Serializable> props = Collections.singletonMap( CoreQueryAndFetchPageProvider.CORE_SESSION_PROPERTY, (Serializable) s); List<DocumentModel> annotationList = // ((PageProvider<DocumentModel>) ppService.getPageProvider(GET_ANNOTATIONS_FOR_DOC_PAGEPROVIDER_NAME, null, null, null, props, documentId, xpath)).getCurrentPage(); return annotationList.stream().map(AnnotationImpl::new).collect(Collectors.toList()); }); }
@Override public List<String> getTagDocumentIds(CoreSession session, String label) { String cleanLabel = cleanLabel(label, true, false); return CoreInstance.doPrivileged(session, (CoreSession s) -> doGetTagDocumentIds(s, cleanLabel)); }
@Override public Annotation getAnnotation(CoreSession session, String annotationId) { return CoreInstance.doPrivileged(session, s -> { DocumentModel annotationModel = getAnnotationModel(s, annotationId); if (annotationModel == null) { return null; } return new AnnotationImpl(annotationModel); }); }
@Override public void deleteAnnotation(CoreSession session, String annotationId) throws IllegalArgumentException { CoreInstance.doPrivileged(session, s -> { DocumentModel annotationModel = getAnnotationModel(s, annotationId); if (annotationModel == null) { throw new IllegalArgumentException("The annotation " + annotationId + " does not exist."); } s.removeDocument(annotationModel.getRef()); }); }
@Override public Set<String> getSuggestions(CoreSession session, String label) { label = cleanLabel(label, true, true); if (!isTagSanitizationEnabled()) { // Escape character for LIKE statement label = label.replace("\\", "\\\\"); } if (!label.contains("%")) { label += "%"; } // effectively final for lambda String l = label; return CoreInstance.doPrivileged(session, (CoreSession s) -> doGetTagSuggestions(s, l)); }
public List<DocumentModel> getComments(DocumentModel parent) { CoreSession session = docModel.getCoreSession(); List<Comment> comments = commentManager.getComments(session, parent.getId()); return CoreInstance.doPrivileged(session, s -> { return comments.stream().map(comment -> { DocumentModel commentModel = s.getDocument(new IdRef(comment.getId())); commentModel.detach(true); return commentModel; }).collect(Collectors.toList()); }); }
@Override public void updateAnnotation(CoreSession session, Annotation annotation) { CoreInstance.doPrivileged(session, s -> { DocumentModel annotationModel = getAnnotationModel(s, annotation.getId()); if (annotationModel == null) { if (log.isWarnEnabled()) { log.warn("The annotation " + annotation.getId() + " on document blob " + annotation.getXpath() + " does not exist. Update operation is ignored."); } return; } setAnnotationProperties(annotationModel, annotation); s.saveDocument(annotationModel); }); }
protected DocumentRef getAncestorRef(CoreSession session, DocumentModel documentModel) { return CoreInstance.doPrivileged(session, s -> { if (!documentModel.hasSchema(COMMENT_SCHEMA)) { return documentModel.getRef(); } DocumentModel ancestorComment = getThreadForComment(s, documentModel); return new IdRef((String) ancestorComment.getPropertyValue(COMMENT_PARENT_ID)); }); }
@Override public void removeSubscriptions(String username, List<String> notifications, DocumentModel doc) { CoreInstance.doPrivileged(doc.getRepositoryName(), (CoreSession session) -> { SubscriptionAdapter sa = doc.getAdapter(SubscriptionAdapter.class); for (String notification : notifications) { sa.removeUserNotificationSubscription(username, notification); } disableEvents(doc); session.saveDocument(doc); restoreEvents(doc); }); }
@Override public void tag(CoreSession session, String docId, String label) throws DocumentSecurityException { String cleanLabel = cleanLabel(label, true, false); String username = cleanUsername(session.getPrincipal().getName()); CoreInstance.doPrivileged(session, s -> { doTag(s, docId, cleanLabel, username); }); fireUpdateEvent(session, docId); }
@Override public void addSubscription(String username, String notification, DocumentModel doc, Boolean sendConfirmationEmail, NuxeoPrincipal principal, String notificationName) { CoreInstance.doPrivileged(doc.getRepositoryName(), (CoreSession session) -> { doc.getAdapter(SubscriptionAdapter.class).addSubscription(username, notification); disableEvents(doc); session.saveDocument(doc); restoreEvents(doc); }); // send event for email if necessary if (sendConfirmationEmail) { raiseConfirmationEvent(principal, doc, username, notificationName); } }
@Override @SuppressWarnings("unchecked") public List<DocumentModel> getComments(CoreSession session, DocumentModel docModel) throws CommentSecurityException { DocumentRef docRef = getAncestorRef(session, docModel); if (session.exists(docRef) && !session.hasPermission(docRef, SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " does not have access to the comments of document " + docModel.getId()); } PageProviderService ppService = Framework.getService(PageProviderService.class); return CoreInstance.doPrivileged(session, s -> { Map<String, Serializable> props = Collections.singletonMap(CORE_SESSION_PROPERTY, (Serializable) s); PageProvider<DocumentModel> pageProvider = (PageProvider<DocumentModel>) ppService.getPageProvider( GET_COMMENTS_FOR_DOC_PAGEPROVIDER_NAME, singletonList(new SortInfo(COMMENT_CREATION_DATE, true)), null, null, props, docModel.getId()); return pageProvider.getCurrentPage(); }); }
@Override public void addSubscriptions(String username, DocumentModel doc, Boolean sendConfirmationEmail, NuxeoPrincipal principal) { CoreInstance.doPrivileged(doc.getRepositoryName(), (CoreSession session) -> { doc.getAdapter(SubscriptionAdapter.class).addSubscriptionsToAll(username); disableEvents(doc); session.saveDocument(doc); restoreEvents(doc); }); // send event for email if necessary if (sendConfirmationEmail) { raiseConfirmationEvent(principal, doc, username, "All Notifications"); } }
protected PathRef getExistingUserWorkspaceRoot(CoreSession session, String username) { String uwrPath = computePathUserWorkspaceRoot(session, username); if (uwrPath == null) { return null; } PathRef rootref = new PathRef(uwrPath); if (session.exists(rootref)) { return rootref; } String path = CoreInstance.doPrivileged(session, s -> { DocumentModel uwsRootModel = doCreateUserWorkspacesRoot(session, rootref); DocumentModel docModel = s.getOrCreateDocument(uwsRootModel, doc -> initCreateUserWorkspacesRoot(s, doc)); return docModel.getPathAsString(); }); return new PathRef(path); }
@Override public DocumentModel createLocatedComment(DocumentModel docModel, DocumentModel comment, String path) { CoreSession session = docModel.getCoreSession(); DocumentRef docRef = getAncestorRef(session, docModel); if (!session.hasPermission(docRef, SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " can not create comments on document " + docModel.getId()); } return CoreInstance.doPrivileged(session, s -> { DocumentModel commentModel = s.createDocumentModel(path, COMMENT_NAME, comment.getType()); commentModel.copyContent(comment); commentModel.setPropertyValue(COMMENT_ANCESTOR_IDS, (Serializable) computeAncestorIds(s, docModel.getId())); commentModel = s.createDocument(commentModel); notifyEvent(s, CommentEvents.COMMENT_ADDED, docModel, commentModel); return commentModel; }); }