Search in sources :

Example 81 with Query

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);
    }
}
Also used : QueryFilter(org.xwiki.query.QueryFilter) Query(org.xwiki.query.Query) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWikiException(com.xpn.xwiki.XWikiException) QueryException(org.xwiki.query.QueryException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException)

Example 82 with Query

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);
}
Also used : Query(org.xwiki.query.Query) ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) Map(java.util.Map)

Example 83 with Query

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);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Query(org.xwiki.query.Query) XWikiContext(com.xpn.xwiki.XWikiContext) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) XWikiException(com.xpn.xwiki.XWikiException) ComponentLifecycleException(org.xwiki.component.manager.ComponentLifecycleException) InitializationException(org.xwiki.component.phase.InitializationException) TranslationBundleDoesNotExistsException(org.xwiki.localization.TranslationBundleDoesNotExistsException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ComponentRepositoryException(org.xwiki.component.manager.ComponentRepositoryException) CacheException(org.xwiki.cache.CacheException)

Example 84 with Query

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;
}
Also used : Query(org.xwiki.query.Query) Map(java.util.Map)

Example 85 with 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));
}
Also used : NotificationPreference(org.xwiki.notifications.preferences.NotificationPreference) NotificationPreferenceManager(org.xwiki.notifications.preferences.NotificationPreferenceManager) Query(org.xwiki.query.Query) EventStream(org.xwiki.eventstream.EventStream) NotificationFormat(org.xwiki.notifications.NotificationFormat) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ComponentList(org.xwiki.test.annotation.ComponentList) List(java.util.List) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) Date(java.util.Date) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Aggregations

Query (org.xwiki.query.Query)129 DocumentReference (org.xwiki.model.reference.DocumentReference)41 Test (org.junit.Test)39 QueryException (org.xwiki.query.QueryException)36 ArrayList (java.util.ArrayList)29 XWikiException (com.xpn.xwiki.XWikiException)18 QueryFilter (org.xwiki.query.QueryFilter)18 QueryManager (org.xwiki.query.QueryManager)18 XWikiContext (com.xpn.xwiki.XWikiContext)15 HashMap (java.util.HashMap)14 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)12 Map (java.util.Map)11 List (java.util.List)9 Before (org.junit.Before)9 SecureQuery (org.xwiki.query.SecureQuery)9 XWiki (com.xpn.xwiki.XWiki)8 BaseObject (com.xpn.xwiki.objects.BaseObject)8 SQLQuery (org.hibernate.SQLQuery)8 WikiReference (org.xwiki.model.reference.WikiReference)8 WrappingQuery (org.xwiki.query.WrappingQuery)8