use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class DefaultInstanceModel method getDocumentReferences.
@Override
public List<DocumentReference> getDocumentReferences(SpaceReference spaceReference) throws FilterException {
List<String> documentNames;
try {
Query query = this.queryManager.createQuery("select distinct doc.name from Document doc where doc.space = :space order by doc.name asc", Query.XWQL);
query.bindValue("space", localSerializer.serialize(spaceReference));
query.setWiki(spaceReference.getWikiReference().getName());
documentNames = query.execute();
} catch (QueryException e) {
throw new FilterException(String.format("Failed to get the list of documents in space [%s]", spaceReference), e);
}
List<DocumentReference> documentReferences = new ArrayList<>(documentNames.size());
for (String documentName : documentNames) {
documentReferences.add(new DocumentReference(documentName, spaceReference));
}
return documentReferences;
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class HqlQueryExecutorTest method executeWhenStoreException.
@Test
public void executeWhenStoreException() throws Exception {
XWikiException exception = mock(XWikiException.class);
when(exception.getMessage()).thenReturn("nestedmessage");
when(this.store.executeRead(any(XWikiContext.class), any(XWikiHibernateBaseStore.HibernateCallback.class))).thenThrow(exception);
try {
execute("statement", null);
fail("Should have thrown an exception here");
} catch (QueryException expected) {
assertEquals("Exception while executing query. Query statement = [statement]", expected.getMessage());
// Verify nested exception!
assertEquals("nestedmessage", expected.getCause().getMessage());
}
}
use of org.xwiki.query.QueryException in project celements-blog by celements.
the class NewsletterReceivers method addNewsletterReceiver.
void addNewsletterReceiver(XWikiDocument blogDoc) throws XWikiException {
String blogFN = getWebUtilsService().serializeRef(blogDoc.getDocumentReference(), true);
String xwql = "from doc.object(Celements.NewsletterReceiverClass) as nr " + "where nr.isactive = '1' and nr.subscribed = :subscribed";
// String hql = "select nr.email,doc.date from Celements.NewsletterReceiverClass as nr, "
// + " XWikiDocument as doc "
// + "where doc.fullName = "
// + " nr.isactive='1' "
// + "and subscribed='" + blogDoc.getFullName() + "'";
// List<String> nlRegAddresses = context.getWiki().search(hql, context);
DocumentReference receverClassRef = getBlogClasses().getNewsletterReceiverClassRef(getContext().getDatabase());
try {
List<String> nlRegReceiverList = Utils.getComponent(QueryManager.class).createQuery(xwql, Query.XWQL).bindValue("subscribed", blogFN).execute();
if (nlRegReceiverList != null) {
LOGGER.info("Found " + nlRegReceiverList.size() + " Celements.NewsletterReceiverClass" + " object-subscriptions for blog " + blogFN);
String blogSpace = blogDoc.getXObject(getBlogClasses().getBlogConfigClassRef(getContext().getDatabase())).getStringValue("blogspace");
for (String nlRegReceiverFN : nlRegReceiverList) {
DocumentReference nlRegReceiverDocRef = getWebUtilsService().resolveDocumentReference(nlRegReceiverFN);
XWikiDocument receiverDoc = getContext().getWiki().getDocument(nlRegReceiverDocRef, getContext());
List<BaseObject> recieverObjs = receiverDoc.getXObjects(receverClassRef);
for (BaseObject receiverObj : recieverObjs) {
String subscribedBlogs = receiverObj.getStringValue("subscribed");
if ((subscribedBlogs != null) && (("," + subscribedBlogs + ",").indexOf("," + blogFN + ",") >= 0)) {
String address = receiverObj.getStringValue("email");
address = address.toLowerCase();
if (!allAddresses.contains(address)) {
String language = receiverObj.getStringValue("language");
String firstname = "";
String name = "";
BaseObject contactObj = receiverDoc.getXObject(new DocumentReference(getContext().getWiki().getDatabase(), "Celements", "ContactClass"));
if (contactObj != null) {
firstname = contactObj.getStringValue("firstname");
name = contactObj.getStringValue("lastname");
}
if (getWebUtilsService().getAllowedLanguages(blogSpace).contains(language)) {
addrLangs.add(new String[] { "XWiki.XWikiGuest", address, language, firstname, name });
} else {
addresses.add(address);
}
allAddresses.add(address);
emailAddressDateList.add(new EmailAddressDate(address, receiverDoc.getDate(), language));
LOGGER.info("reveiver added: " + address);
}
}
}
}
}
} catch (QueryException exp) {
LOGGER.error("Failed to execute newsletter receiver xwql [" + xwql + "].", exp);
}
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class DefaultMessageStream method getRecentDirectMessages.
@Override
public List<Event> getRecentDirectMessages(int limit, int offset) {
List<Event> result = new ArrayList<Event>();
try {
Query q = this.qm.createQuery("where event.application = 'MessageStream' and event.type = 'directMessage'" + " and event.stream = :targetUser order by event.date desc", Query.XWQL);
q.bindValue("targetUser", this.serializer.serialize(this.bridge.getCurrentUserReference()));
q.setLimit(limit > 0 ? limit : 30).setOffset(offset >= 0 ? offset : 0);
result = this.stream.searchEvents(q);
} catch (QueryException ex) {
LOG.warn("Failed to search direct messages: {}", ex.getMessage());
}
return result;
}
use of org.xwiki.query.QueryException in project xwiki-platform by xwiki.
the class DefaultMessageStream method getRecentMessagesForGroup.
@Override
public List<Event> getRecentMessagesForGroup(DocumentReference group, int limit, int offset) {
List<Event> result = new ArrayList<Event>();
try {
Query q = this.qm.createQuery("where event.application = 'MessageStream' and event.type = 'groupMessage'" + " and event.stream = :group order by event.date desc", Query.XWQL);
q.bindValue("group", this.serializer.serialize(group));
q.setLimit(limit > 0 ? limit : 30).setOffset(offset >= 0 ? offset : 0);
result = this.stream.searchEvents(q);
} catch (QueryException ex) {
LOG.warn("Failed to search group messages: {}", ex.getMessage());
}
return result;
}
Aggregations