Search in sources :

Example 66 with SpaceReference

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"))));
}
Also used : EntityReferenceProvider(org.xwiki.model.reference.EntityReferenceProvider) SpaceReference(org.xwiki.model.reference.SpaceReference) EntityReference(org.xwiki.model.reference.EntityReference) WikiReference(org.xwiki.model.reference.WikiReference) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 67 with SpaceReference

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;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) GetMethod(org.apache.commons.httpclient.methods.GetMethod)

Example 68 with SpaceReference

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;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) DocumentReference(org.xwiki.model.reference.DocumentReference) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup)

Example 69 with SpaceReference

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;
}
Also used : IQueryRestriction(com.celements.search.lucene.query.IQueryRestriction) SpaceReference(org.xwiki.model.reference.SpaceReference) QueryRestrictionGroup(com.celements.search.lucene.query.QueryRestrictionGroup)

Example 70 with SpaceReference

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;
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Aggregations

SpaceReference (org.xwiki.model.reference.SpaceReference)142 DocumentReference (org.xwiki.model.reference.DocumentReference)96 Test (org.junit.Test)83 WikiReference (org.xwiki.model.reference.WikiReference)58 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)21 ArrayList (java.util.ArrayList)11 ResourceReference (org.xwiki.rendering.listener.reference.ResourceReference)11 XWikiException (com.xpn.xwiki.XWikiException)9 QueryRestrictionGroup (com.celements.search.lucene.query.QueryRestrictionGroup)8 Expectations (org.jmock.Expectations)8 XWikiContext (com.xpn.xwiki.XWikiContext)7 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)7 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)7 ComponentManager (org.xwiki.component.manager.ComponentManager)7 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)7 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)7 EntityReferenceResolver (org.xwiki.model.reference.EntityReferenceResolver)7 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)7 DocumentResourceReference (org.xwiki.rendering.listener.reference.DocumentResourceReference)7