use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class SolrFieldStringEntityReferenceResolverTest method resolve.
@Test
public void resolve() throws Exception {
EntityReferenceProvider currentEntityReferenceProvider = this.mocker.getInstance(EntityReferenceProvider.class, "current");
when(currentEntityReferenceProvider.getDefaultReference(EntityType.WIKI)).thenReturn(new WikiReference("test"));
EntityReferenceResolver<String> resolver = mocker.getComponentUnderTest();
DocumentReference documentReference = new DocumentReference("test", Arrays.asList("My App", "Code", "Model"), "A Class");
assertEquals(new ClassPropertyReference("title", documentReference), new ClassPropertyReference(resolver.resolve("My App.Code.Model.A Class.title", EntityType.CLASS_PROPERTY)));
documentReference = new DocumentReference("test", Arrays.asList("My.App", "Co.de"), "A.Class");
assertEquals(new ClassPropertyReference("ti.tle", documentReference), new ClassPropertyReference(resolver.resolve("My..App.Co..de.A..Class.ti..tle", EntityType.CLASS_PROPERTY)));
assertEquals(new SpaceReference("0.9", new SpaceReference("a..z", new WikiReference("test"))), new SpaceReference(resolver.resolve("a....z.0..9", EntityType.SPACE)));
// Relative reference resolved based on the given parameters.
assertEquals(new ClassPropertyReference("title", new DocumentReference("foo", Arrays.asList("Code", "Model"), "A Class")), new ClassPropertyReference(resolver.resolve("Code.Model.A Class.title", EntityType.CLASS_PROPERTY, new SpaceReference("My App", new WikiReference("foo")))));
// Relative reference resolve based on the current entity.
when(currentEntityReferenceProvider.getDefaultReference(EntityType.SPACE)).thenReturn(new EntityReference("Code", EntityType.SPACE, new EntityReference("My App", EntityType.SPACE, null)));
assertEquals(new ClassPropertyReference("title", new DocumentReference("bar", Arrays.asList("My App", "Code"), "A Class")), new ClassPropertyReference(resolver.resolve("A Class.title", EntityType.CLASS_PROPERTY, new WikiReference("bar"))));
}
use of org.xwiki.model.reference.SpaceReference in project xwiki-platform by xwiki.
the class AbstractValidationTest method createGetMethod.
protected GetMethod createGetMethod() throws UnsupportedEncodingException {
GetMethod getMethod = null;
if (this.target instanceof DocumentReferenceTarget) {
DocumentReferenceTarget documentReferenceTarget = (DocumentReferenceTarget) this.target;
StringBuilder url = new StringBuilder();
url.append("http://127.0.0.1:8080/xwiki/bin/view/");
for (SpaceReference spaceReference : documentReferenceTarget.getDocumentReference().getSpaceReferences()) {
url.append(URLEncoder.encode(spaceReference.getName(), "UTF-8"));
url.append("/");
}
url.append(URLEncoder.encode(documentReferenceTarget.getDocumentReference().getName(), "UTF-8"));
getMethod = new GetMethod(url.toString());
} else if (this.target instanceof URLPathTarget) {
String urlPath = ((URLPathTarget) this.target).getUrlPath();
if (urlPath.startsWith("http://")) {
getMethod = new GetMethod(urlPath);
} else {
getMethod = new GetMethod("http://127.0.0.1:8080" + urlPath);
}
}
return getMethod;
}
use of org.xwiki.model.reference.SpaceReference in project celements-blog by celements.
the class ArticleLuceneQueryBuilder method getSubsRestrictions.
QueryRestrictionGroup getSubsRestrictions(ArticleLoadParameter param) throws XWikiException {
QueryRestrictionGroup ret = null;
QueryRestrictionGroup subsOrGrp = searchService.createRestrictionGroup(Type.OR);
for (DocumentReference docRef : param.getSubscribedToBlogs()) {
SpaceReference spaceRef = blogService.getBlogSpaceRef(docRef);
if (rightsAccess.hasAccessLevel(spaceRef, EAccessLevel.VIEW)) {
subsOrGrp.add(getSubsSpaceRestriction(param, spaceRef));
}
}
if (!subsOrGrp.isEmpty()) {
ret = searchService.createRestrictionGroup(Type.AND);
DocumentReference articleClassRef = getBlogClasses().getArticleClassRef(param.getBlogDocRef().getWikiReference().getName());
ret.add(searchService.createFieldRestriction(articleClassRef, BlogClasses.PROPERTY_ARTICLE_IS_SUBSCRIBABLE, "\"1\""));
ret.add(subsOrGrp);
}
LOGGER.trace("got subs restriction " + ret + "' for '" + param + "'");
return ret;
}
use of org.xwiki.model.reference.SpaceReference in project celements-blog by celements.
the class ArticleLuceneQueryBuilder method getBlogRestriction.
IQueryRestriction getBlogRestriction(ArticleLoadParameter param) throws XWikiException {
QueryRestrictionGroup restr = null;
SpaceReference blogSpaceRef = blogService.getBlogSpaceRef(param.getBlogDocRef());
if (param.isWithBlogArticles() && rightsAccess.hasAccessLevel(blogSpaceRef, EAccessLevel.VIEW)) {
IQueryRestriction dateRestr = getDateRestrictions(param.getDateModes(), param.getExecutionDate(), rightsAccess.hasAccessLevel(blogSpaceRef, EAccessLevel.EDIT));
if (dateRestr != null) {
restr = searchService.createRestrictionGroup(Type.AND);
restr.add(searchService.createSpaceRestriction(blogSpaceRef));
restr.add(dateRestr);
}
}
LOGGER.trace("got blog restriction " + restr + "' for '" + param + "'");
return restr;
}
use of org.xwiki.model.reference.SpaceReference in project celements-blog by celements.
the class BlogService method getBlogSpaceRef.
@Override
public SpaceReference getBlogSpaceRef(DocumentReference docRef) throws XWikiException {
SpaceReference spaceRef = null;
BaseObject confObj = getBlogConfigObject(docRef);
if (confObj != null) {
String spaceName = confObj.getStringValue(BlogClasses.PROPERTY_BLOG_CONFIG_BLOGSPACE);
if (StringUtils.isNotBlank(spaceName)) {
spaceRef = webUtils.resolveSpaceReference(spaceName, docRef.getWikiReference());
}
if (spaceRef == null) {
spaceRef = new SpaceReference(docRef.getName(), docRef.getWikiReference());
}
}
LOGGER.debug("getBlogSpaceRef: resolved for '" + docRef + "' space:" + spaceRef);
return spaceRef;
}
Aggregations