use of org.xwiki.query.Query in project xwiki-platform by xwiki.
the class DefaultWikiDescriptorDocumentHelper method getAllXWikiServerClassDocumentNames.
@Override
public List<String> getAllXWikiServerClassDocumentNames() throws WikiManagerException {
WikiDescriptorManager wikiDescriptorManager = wikiDescriptorManagerProvider.get();
try {
Query query = this.queryManager.createQuery("from doc.object(XWiki.XWikiServerClass) as descriptor where doc.name like 'XWikiServer%' " + "and doc.fullName <> 'XWiki.XWikiServerClassTemplate'", Query.XWQL);
query.setWiki(wikiDescriptorManager.getMainWikiId());
query.addFilter(componentManager.<QueryFilter>getInstance(QueryFilter.class, "unique"));
return query.execute();
} catch (Exception e) {
throw new WikiManagerException("Failed to locate XWiki.XWikiServerClass documents", e);
}
}
use of org.xwiki.query.Query in project xwiki-platform by xwiki.
the class BridgeEventStream method searchEvents.
@Override
public List<Event> searchEvents(Query query) throws QueryException {
Query q = this.qm.createQuery("select event from ActivityEventImpl event " + query.getStatement(), query.getLanguage());
for (Map.Entry<String, Object> entry : query.getNamedParameters().entrySet()) {
q.bindValue(entry.getKey(), entry.getValue());
}
for (Map.Entry<Integer, Object> entry : query.getPositionalParameters().entrySet()) {
q.bindValue(entry.getKey(), entry.getValue());
}
q.setLimit(query.getLimit());
q.setOffset(query.getOffset());
List<ActivityEvent> events = q.execute();
return convertActivitiesToEvents(events);
}
use of org.xwiki.query.Query in project xwiki-platform by xwiki.
the class DocumentTranslationBundleFactory method loadTranslations.
private void loadTranslations(String wiki) {
XWikiContext xcontext = this.xcontextProvider.get();
WikiReference wikiReference = new WikiReference(wiki);
try {
Query query = this.queryManager.createQuery(String.format("select distinct doc.fullName from Document doc, doc.object(%s) as translation", TranslationDocumentModel.TRANSLATIONCLASS_REFERENCE_STRING), Query.XWQL);
query.setWiki(wiki);
List<String> documents = query.execute();
for (String documentName : documents) {
DocumentReference reference = currentResolver.resolve(documentName, wikiReference);
XWikiDocument document = xcontext.getWiki().getDocument(reference, xcontext);
try {
registerTranslationBundle(document);
} catch (Exception e) {
this.logger.error("Failed to register translation bundle from document [{}]", document.getDocumentReference(), e);
}
}
} catch (Exception e) {
this.logger.error("Failed to load existing translations", e);
}
}
use of org.xwiki.query.Query in project xwiki-platform by xwiki.
the class QueryGenerator method generateQuery.
/**
* Generate the query.
*
* @param user user interested in the notifications
* @param format only match notifications enabled for that format
* @param endDate do not return events happened after this date
* @param startDate do not return events happened before this date. Note that since 9.7RC1, this start date is
* completely optional, {@link NotificationPreference#getStartDate()} should be used for more granular control on
* notifications
* @param blackList list of ids of blacklisted events to not return (to not get already known events again)
* @return the query to execute
* @throws NotificationException if error happens
* @throws QueryException if error happens
*/
public Query generateQuery(DocumentReference user, NotificationFormat format, Date endDate, Date startDate, List<String> blackList) throws NotificationException, QueryException {
ExpressionNodeToHQLConverter.HQLQuery result = hqlConverter.parse(generateQueryExpression(user, format, endDate, startDate, blackList));
if (result.getQuery().isEmpty()) {
return null;
}
Query query = queryManager.createQuery(String.format("where %s", result.getQuery()), Query.HQL);
for (Map.Entry<String, Object> queryParameter : result.getQueryParameters().entrySet()) {
query.bindValue(queryParameter.getKey(), queryParameter.getValue());
}
return query;
}
use of org.xwiki.query.Query in project xwiki-platform by xwiki.
the class DefaultNotificationManagerTest method setUp.
@Before
public void setUp() throws Exception {
eventStream = mocker.getInstance(EventStream.class);
queryGenerator = mocker.getInstance(QueryGenerator.class);
documentAccessBridge = mocker.getInstance(DocumentAccessBridge.class);
documentReferenceResolver = mocker.getInstance(DocumentReferenceResolver.TYPE_STRING);
notificationPreferenceManager = mocker.getInstance(NotificationPreferenceManager.class);
authorizationManager = mocker.getInstance(AuthorizationManager.class);
startDate = new Date(10);
when(documentReferenceResolver.resolve("xwiki:XWiki.UserA")).thenReturn(userReference);
query = mock(Query.class);
when(queryGenerator.generateQuery(any(DocumentReference.class), any(NotificationFormat.class), nullable(Date.class), nullable(Date.class), nullable(List.class))).thenReturn(query);
NotificationPreference pref1 = mock(NotificationPreference.class);
when(pref1.getProperties()).thenReturn(Collections.singletonMap(NotificationPreferenceProperty.EVENT_TYPE, "create"));
when(pref1.isNotificationEnabled()).thenReturn(true);
when(notificationPreferenceManager.getAllPreferences(userReference)).thenReturn(Arrays.asList(pref1));
}
Aggregations