use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class CurrentEntityReferenceProvider method getDefaultReference.
@Override
public EntityReference getDefaultReference(EntityType type) {
EntityReference result = null;
XWikiContext xcontext = this.xcontextProvider.get();
if (xcontext != null) {
if (type == EntityType.WIKI) {
result = xcontext.getWikiReference();
} else if (type == EntityType.SPACE) {
XWikiDocument currentDoc = xcontext.getDoc();
if (currentDoc != null) {
SpaceReference spaceReference = currentDoc.getDocumentReference().getLastSpaceReference();
// Keep only the spaces part
result = spaceReference.removeParent(spaceReference.getWikiReference());
}
} else if (type == EntityType.DOCUMENT) {
XWikiDocument currentDoc = xcontext.getDoc();
if (currentDoc != null) {
DocumentReference documentReference = currentDoc.getDocumentReference();
// Keep only the document part
result = documentReference.removeParent(documentReference.getLastSpaceReference());
}
}
}
if (result == null) {
result = super.getDefaultReference(type);
}
return result;
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class XWikiMockitoTest method getSpacePreference.
@Test
public void getSpacePreference() throws Exception {
this.mocker.registerMockComponent(ConfigurationSource.class, "wiki");
ConfigurationSource spaceConfiguration = this.mocker.registerMockComponent(ConfigurationSource.class, "space");
when(this.xwikiCfgConfigurationSource.getProperty(any(), anyString())).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgument(1);
}
});
WikiReference wikiReference = new WikiReference("wiki");
SpaceReference space1Reference = new SpaceReference("space1", wikiReference);
SpaceReference space2Reference = new SpaceReference("space2", space1Reference);
// Without preferences and current doc
assertEquals("", this.xwiki.getSpacePreference("pref", this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
assertEquals("", this.xwiki.getSpacePreference("pref", space2Reference, this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("pref", space2Reference, "defaultvalue", this.context));
// Without preferences but with current doc
this.context.setDoc(new XWikiDocument(new DocumentReference("document", space2Reference)));
assertEquals("", this.xwiki.getSpacePreference("pref", this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
assertEquals("", this.xwiki.getSpacePreference("pref", space2Reference, this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("pref", space2Reference, "defaultvalue", this.context));
// With preferences
final Map<String, Map<String, String>> spacesPreferences = new HashMap<>();
Map<String, String> space1Preferences = new HashMap<>();
space1Preferences.put("pref", "prefvalue1");
space1Preferences.put("pref1", "pref1value1");
Map<String, String> space2Preferences = new HashMap<>();
space2Preferences.put("pref", "prefvalue2");
space2Preferences.put("pref2", "pref2value2");
spacesPreferences.put(space1Reference.getName(), space1Preferences);
spacesPreferences.put(space2Reference.getName(), space2Preferences);
when(spaceConfiguration.getProperty(any(), same(String.class))).then(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
if (context.getDoc() != null) {
Map<String, String> spacePreferences = spacesPreferences.get(context.getDoc().getDocumentReference().getParent().getName());
if (spacePreferences != null) {
return spacePreferences.get(invocation.getArgument(0));
}
}
return null;
}
});
this.context.setDoc(new XWikiDocument(new DocumentReference("document", space1Reference)));
assertEquals("prefvalue1", this.xwiki.getSpacePreference("pref", this.context));
assertEquals("prefvalue1", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
assertEquals("pref1value1", this.xwiki.getSpacePreference("pref1", this.context));
assertEquals("", this.xwiki.getSpacePreference("pref2", this.context));
this.context.setDoc(new XWikiDocument(new DocumentReference("document", space2Reference)));
assertEquals("prefvalue2", this.xwiki.getSpacePreference("pref", this.context));
assertEquals("prefvalue2", this.xwiki.getSpacePreference("pref", "defaultvalue", this.context));
assertEquals("pref1value1", this.xwiki.getSpacePreference("pref1", this.context));
assertEquals("pref2value2", this.xwiki.getSpacePreference("pref2", this.context));
assertEquals("", this.xwiki.getSpacePreference("nopref", space1Reference, this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("nopref", space1Reference, "defaultvalue", this.context));
assertEquals("prefvalue1", this.xwiki.getSpacePreference("pref", space1Reference, this.context));
assertEquals("prefvalue1", this.xwiki.getSpacePreference("pref", space1Reference, "defaultvalue", this.context));
assertEquals("pref1value1", this.xwiki.getSpacePreference("pref1", space1Reference, this.context));
assertEquals("", this.xwiki.getSpacePreference("pref2", space1Reference, this.context));
assertEquals("", this.xwiki.getSpacePreference("nopref", space2Reference, this.context));
assertEquals("defaultvalue", this.xwiki.getSpacePreference("nopref", space2Reference, "defaultvalue", this.context));
assertEquals("prefvalue2", this.xwiki.getSpacePreference("pref", space2Reference, this.context));
assertEquals("prefvalue2", this.xwiki.getSpacePreference("pref", space2Reference, "defaultvalue", this.context));
assertEquals("pref1value1", this.xwiki.getSpacePreference("pref1", space2Reference, this.context));
assertEquals("pref2value2", this.xwiki.getSpacePreference("pref2", space2Reference, this.context));
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class DatabaseDocumentIterator method next.
@Override
public Pair<DocumentReference, String> next() {
Object[] result = getResults().get(index++);
String localSpaceReference = (String) result[0];
String name = (String) result[1];
String locale = (String) result[2];
String version = (String) result[3];
SpaceReference spaceReference = new SpaceReference(this.explicitEntityReferenceResolver.resolve(localSpaceReference, EntityType.SPACE, new WikiReference(wiki)));
DocumentReference documentReference = new DocumentReference(name, spaceReference);
if (!StringUtils.isEmpty(locale)) {
documentReference = new DocumentReference(documentReference, LocaleUtils.toLocale(locale));
}
return new ImmutablePair<DocumentReference, String>(documentReference, version);
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class CurrentAttachmentReferenceResolverTest method resolveTest.
@Test
public void resolveTest() throws Exception {
// Mocks
EntityReference entityReference = new EntityReference("hello.txt", EntityType.ATTACHMENT);
AttachmentReference attachmentReference = new AttachmentReference("hello.txt", new DocumentReference("Document", new SpaceReference("Space", new WikiReference("wiki"))));
when(entityReferenceResolver.resolve(entityReference, EntityType.ATTACHMENT)).thenReturn(attachmentReference);
// Test
AttachmentReference result = mocker.getComponentUnderTest().resolve(entityReference);
// Verify
assertEquals(attachmentReference, result);
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class SolrIndexScriptServiceTest method openrationsOnMultipleReferencesOnTheSameWikiChecksRightsOnlyOnceForThatWiki.
@Test
public void openrationsOnMultipleReferencesOnTheSameWikiChecksRightsOnlyOnceForThatWiki() throws Exception {
// References from the same wiki
WikiReference wikiReference = new WikiReference("wiki");
SpaceReference spaceReference = new SpaceReference("space", wikiReference);
DocumentReference documentReference = new DocumentReference("wiki", "space", "name");
DocumentReference documentReference2 = new DocumentReference("wiki", "space", "name2");
// Call
this.service.index(Arrays.asList(wikiReference, spaceReference, documentReference, documentReference2));
// Assert and verify
// Actual rights check
verify(this.mockAuthorization).hasAccess(Right.ADMIN, this.userReference, wikiReference);
verify(this.mockAuthorization).hasAccess(Right.PROGRAM, this.contentAuthorReference, wikiReference);
}
Aggregations