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);
}
}
}
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]));
}
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"));
}
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));
}
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();
}
}
Aggregations