Search in sources :

Example 36 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class DefaultNotificationFilterManager method fetchAllFilters.

/**
 * Fetches every filter available to the user, without taking care of whether the filter is disabled by the user
 * or not.
 *
 * @param user the user to use
 * @return a set of filters
 * @throws NotificationException if an error occurs
 */
private Set<NotificationFilter> fetchAllFilters(DocumentReference user) throws NotificationException {
    // If the user is from the main wiki, get filters from all wikis
    if (user.getWikiReference().getName().equals(wikiDescriptorManager.getMainWikiId())) {
        String currentWikiId = wikiDescriptorManager.getCurrentWikiId();
        Map<String, NotificationFilter> filters = new HashMap<>();
        try {
            for (String wikiId : wikiDescriptorManager.getAllIds()) {
                modelContext.setCurrentEntityReference(new WikiReference(wikiId));
                filters.putAll(componentManager.getInstanceMap(NotificationFilter.class));
            }
        } catch (Exception e) {
            throw new NotificationException(ERROR_MESSAGE, e);
        } finally {
            modelContext.setCurrentEntityReference(new WikiReference(currentWikiId));
        }
        return new HashSet<>(filters.values());
    } else {
        // If the user is local, get filters from the current wiki only (we assume it's the wiki of the user).
        try {
            return new HashSet<>(componentManager.getInstanceList(NotificationFilter.class));
        } catch (Exception e) {
            throw new NotificationException(ERROR_MESSAGE, e);
        }
    }
}
Also used : HashMap(java.util.HashMap) NotificationException(org.xwiki.notifications.NotificationException) WikiReference(org.xwiki.model.reference.WikiReference) NotificationFilter(org.xwiki.notifications.filters.NotificationFilter) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NotificationException(org.xwiki.notifications.NotificationException) HashSet(java.util.HashSet)

Example 37 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class ModelScriptServiceTest method resolveSpaceWithHintAndParameters.

@Test
public void resolveSpaceWithHintAndParameters() throws Exception {
    when(this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, "custom")).thenReturn(this.stringEntityReferenceResolver);
    SpaceReference reference = new SpaceReference("Foo", new WikiReference("bar"));
    Object[] parameters = new Object[] { new DocumentReference("wiki", "Space", "Page"), "extra" };
    when(this.stringEntityReferenceResolver.resolve("reference", EntityType.SPACE, parameters)).thenReturn(reference);
    Assert.assertEquals(reference, this.service.resolveSpace("reference", "custom", parameters[0], parameters[1]));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 38 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class ModelScriptServiceTest method resolveSpace.

@Test
public void resolveSpace() throws Exception {
    when(this.componentManager.getInstance(EntityReferenceResolver.TYPE_STRING, "current")).thenReturn(this.stringEntityReferenceResolver);
    SpaceReference reference = new SpaceReference("Space", new WikiReference("wiki"));
    when(this.stringEntityReferenceResolver.resolve("x", EntityType.SPACE, new Object[] {})).thenReturn(reference);
    Assert.assertEquals(reference, this.service.resolveSpace("x"));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 39 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class XWiki method getPreferencesDocumentReference.

/**
 * Return the document reference to the wiki preferences.
 *
 * @param context see {@link XWikiContext}
 * @since 4.3M2
 */
private DocumentReference getPreferencesDocumentReference(XWikiContext context) {
    String database = context.getWikiId();
    EntityReference spaceReference;
    if (database != null) {
        spaceReference = new EntityReference(SYSTEM_SPACE, EntityType.SPACE, new WikiReference(database));
    } else {
        spaceReference = getCurrentMixedEntityReferenceResolver().resolve(SYSTEM_SPACE, EntityType.SPACE);
    }
    return new DocumentReference("XWikiPreferences", new SpaceReference(spaceReference));
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference) RegexEntityReference(org.xwiki.model.reference.RegexEntityReference) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference)

Example 40 with WikiReference

use of org.xwiki.model.reference.WikiReference in project xwiki-platform by xwiki.

the class XWikiHibernateStore method searchDocumentReferencesInternal.

/**
 * @since 2.2M1
 */
private List<DocumentReference> searchDocumentReferencesInternal(String sql, int nb, int start, List<?> parameterValues, XWikiContext inputxcontext) throws XWikiException {
    XWikiContext context = getExecutionXContext(inputxcontext, true);
    try {
        List<DocumentReference> documentReferences = new ArrayList<DocumentReference>();
        // Construct a reference, using the current wiki as the wiki reference name. This is because the wiki
        // name is not stored in the database for document references.
        WikiReference wikiReference = new WikiReference(context.getWikiId());
        for (Object result : this.searchGenericInternal(sql, nb, start, parameterValues, context)) {
            // The select always contains several elements in case of order by so we have to support both Object[]
            // and
            // String
            String referenceString;
            if (result instanceof String) {
                referenceString = (String) result;
            } else {
                referenceString = (String) ((Object[]) result)[0];
            }
            DocumentReference reference = this.defaultDocumentReferenceResolver.resolve(referenceString, wikiReference);
            documentReferences.add(reference);
        }
        return documentReferences;
    } finally {
        restoreExecutionXContext();
    }
}
Also used : ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

WikiReference (org.xwiki.model.reference.WikiReference)220 DocumentReference (org.xwiki.model.reference.DocumentReference)127 Test (org.junit.Test)106 SpaceReference (org.xwiki.model.reference.SpaceReference)58 XWikiContext (com.xpn.xwiki.XWikiContext)33 XWikiException (com.xpn.xwiki.XWikiException)24 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 ArrayList (java.util.ArrayList)19 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)18 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)15 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)11 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)10 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)10 XWiki (com.xpn.xwiki.XWiki)9 BaseObject (com.xpn.xwiki.objects.BaseObject)9 ComponentManager (org.xwiki.component.manager.ComponentManager)9 Expectations (org.jmock.Expectations)8 Before (org.junit.Before)8 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)8