use of com.xpn.xwiki.api.Document in project celements-blog by celements.
the class NewsletterAttachmentServiceTest method testClearAttachmentList.
@Test
public void testClearAttachmentList() throws Exception {
DocumentReference docRef = new DocumentReference(getContext().getDatabase(), "Test", "Img");
XWikiDocument doc = createMockAndAddToDefault(XWikiDocument.class);
XWikiAttachment att = new XWikiAttachment();
expect(attService.getAttachmentNameEqual(same(doc), eq("file.pdf"))).andReturn(att).anyTimes();
expect(attService.getApiAttachment(same(att))).andReturn(new Attachment(new Document(doc, getContext()), att, getContext()));
expect(xwiki.getDocument(eq(docRef), same(getContext()))).andReturn(doc).once();
replayDefault();
service.addAttachment("Test.Img;file.pdf");
service.clearAttachmentList();
verifyDefault();
List<Attachment> atts = service.getAttachmentList(false);
assertTrue("clearAttachmentList must clear the list.", (atts == null) || atts.isEmpty());
List<Attachment> atts2 = service.getAttachmentList(true);
assertTrue("clearAttachmentList must clear both list.", (atts2 == null) || atts2.isEmpty());
}
use of com.xpn.xwiki.api.Document in project celements-blog by celements.
the class ArticleEngineHQL method filterRightsAndSubscription.
// checkRights = false braucht programmingrights auf blogdoc
private void filterRightsAndSubscription(List<Article> articles, String blogArticleSpace, String language, boolean withUnsubscribed, boolean withUndecided, boolean withSubscribed, boolean subscribableOnly, boolean checkRights) throws XWikiException {
List<Article> deleteArticles = new ArrayList<>();
XWikiDocument spaceBlogDoc = blogService.getBlogPageByBlogSpace(blogArticleSpace);
if (spaceBlogDoc == null) {
LOGGER.debug("Missing Blog Configuration! (Blog space: '" + blogArticleSpace + "')");
deleteArticles.addAll(articles);
} else {
Document origBlogDoc = spaceBlogDoc.newDocument(getContext());
for (Iterator<Article> artIter = articles.iterator(); artIter.hasNext(); ) {
Article article = artIter.next();
try {
XWikiDocument articleDoc = getContext().getWiki().getDocument(article.getDocumentReference(), getContext());
DocumentReference blogDocRef = blogService.getBlogDocRefByBlogSpace(articleDoc.getDocumentReference().getLastSpaceReference().getName());
LOGGER.debug("articleDoc='" + articleDoc + "', " + blogDocRef);
Document blogDoc = getContext().getWiki().getDocument(blogDocRef, getContext()).newDocument(getContext());
boolean hasRight = false;
boolean hasEditOnBlog = false;
if (checkRights || !blogDoc.hasProgrammingRights()) {
LOGGER.info("'" + article.getDocName() + "' - Checking rights. Reason: " + "checkRights='" + checkRights + "' || !programming='" + !blogDoc.hasProgrammingRights() + "'");
Date publishdate = article.getPublishDate(language);
if ((publishdate != null) && (publishdate.after(new Date()))) {
if (blogDoc.hasAccessLevel("edit")) {
hasRight = true;
}
} else if (blogDoc.hasAccessLevel("view")) {
hasRight = true;
}
LOGGER.debug("'" + articleDoc.getSpace() + "' != '" + blogArticleSpace + "' && origBlogDoc.hasAccessLevel('edit') => '" + origBlogDoc.hasAccessLevel("edit") + "'");
if (!articleDoc.getSpace().equals(blogArticleSpace) && origBlogDoc.hasAccessLevel("edit")) {
hasEditOnBlog = true;
}
} else {
LOGGER.info("'" + article.getDocName() + "' - Saved with programming rights " + "and not checking for rights.");
hasRight = true;
hasEditOnBlog = true;
}
LOGGER.info("'" + article.getDocName() + "' - hasRight: '" + hasRight + "' " + "hasEditOnBlog: '" + hasEditOnBlog + "'");
if (hasRight) {
if (!articleDoc.getSpace().equals(blogArticleSpace)) {
Boolean isSubscribed = article.isSubscribed(spaceBlogDoc.getDocumentReference());
if (isSubscribed == null) {
if (!withUndecided || !hasEditOnBlog) {
LOGGER.info("'" + article.getDocName() + "' - Removed reason: from " + "subscribed blog && isUndecided && (!withUndecided='" + !withUndecided + "' || !hasEditOnBlog='" + !hasEditOnBlog + "')");
deleteArticles.add(article);
}
} else {
if (!isSubscribed && (!withUnsubscribed || !hasEditOnBlog)) {
LOGGER.info("'" + article.getDocName() + "' - Removed reason: from " + "subscribed blog && isDecided && ((!isSubscribed='" + !isSubscribed + "' && !withUnsubscribed='" + !withUnsubscribed + "') || " + "!hasEditOnBlog='" + !hasEditOnBlog + "')");
deleteArticles.add(article);
} else if (isSubscribed && !withSubscribed) {
LOGGER.info("'" + article.getDocName() + "' - Removed reason: from " + "subscribed blog && isDecided && (isSubscribed='" + isSubscribed + "' && !withSubscribed='" + !withSubscribed + "')");
deleteArticles.add(article);
}
}
} else if (subscribableOnly) {
LOGGER.info("'" + article.getDocName() + "' - Removed reason: from own " + "blog, but subscribableOnly='" + subscribableOnly + "'");
deleteArticles.add(article);
}
} else {
LOGGER.info("'" + article.getDocName() + "' - Removed reason: has no rights");
deleteArticles.add(article);
}
} catch (XWikiException exp) {
LOGGER.error("filterRightsAndSubscription: Failed to check rights on: " + article.getDocumentReference(), exp);
}
}
}
for (Iterator<Article> delIter = deleteArticles.iterator(); delIter.hasNext(); ) {
articles.remove(delIter.next());
}
}
Aggregations