Search in sources :

Example 51 with WikiReference

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

the class WikiUIExtensionParametersTest method getParametersFromDifferentRequests.

@Test
public void getParametersFromDifferentRequests() throws Exception {
    when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("wiki1"));
    when(velocityEngine.evaluate(any(VelocityContext.class), any(StringWriter.class), eq("id:key"), eq("value"))).thenReturn(true);
    WikiUIExtensionParameters parameters = new WikiUIExtensionParameters("id", "key=value", componentManager);
    ExecutionContext ec1 = mock(ExecutionContext.class, "ec1");
    ExecutionContext ec2 = mock(ExecutionContext.class, "ec2");
    when(execution.getContext()).thenReturn(ec1).thenReturn(ec2);
    // It should fail silently
    Assert.assertEquals("", parameters.get().get("key"));
    Assert.assertEquals("", parameters.get().get("key"));
    // Verify the velocity evaluation has been done for both wikis.
    verify(velocityEngine, times(2)).evaluate(any(VelocityContext.class), any(StringWriter.class), eq("id:key"), eq("value"));
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) StringWriter(java.io.StringWriter) WikiUIExtensionParameters(org.xwiki.uiextension.internal.WikiUIExtensionParameters) VelocityContext(org.apache.velocity.VelocityContext) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 52 with WikiReference

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

the class WikiUIExtensionParametersTest method getParametersWithAnEmptyParametersProperty.

@Test
public void getParametersWithAnEmptyParametersProperty() throws Exception {
    when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("xwiki"));
    WikiUIExtensionParameters parameters = new WikiUIExtensionParameters("id", "", componentManager);
    Assert.assertEquals(MapUtils.EMPTY_MAP, parameters.get());
}
Also used : WikiUIExtensionParameters(org.xwiki.uiextension.internal.WikiUIExtensionParameters) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 53 with WikiReference

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

the class WikiUIExtensionParametersTest method getParametersFromTheSameRequestButForDifferentWikis.

@Test
public void getParametersFromTheSameRequestButForDifferentWikis() throws Exception {
    when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("wiki1")).thenReturn(new WikiReference("wiki2"));
    when(velocityEngine.evaluate(any(VelocityContext.class), any(StringWriter.class), eq("id:key"), eq("value"))).thenReturn(true);
    WikiUIExtensionParameters parameters = new WikiUIExtensionParameters("id", "key=value", componentManager);
    // It should fail silently
    Assert.assertEquals("", parameters.get().get("key"));
    Assert.assertEquals("", parameters.get().get("key"));
    // Verify the velocity evaluation has been done for both wikis.
    verify(velocityEngine, times(2)).evaluate(any(VelocityContext.class), any(StringWriter.class), eq("id:key"), eq("value"));
}
Also used : StringWriter(java.io.StringWriter) WikiUIExtensionParameters(org.xwiki.uiextension.internal.WikiUIExtensionParameters) VelocityContext(org.apache.velocity.VelocityContext) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 54 with WikiReference

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

the class WikiEntityResourceReferenceResolver method extractWikiReference.

@Override
protected WikiReference extractWikiReference(ExtendedURL extendedURL) {
    WikiReference wikiReference = this.wikiExtractor.extract(extendedURL);
    // Remove the first path segment since it contains the wiki name and we need the first segment to be the
    // action name
    extendedURL.getSegments().remove(0);
    return wikiReference;
}
Also used : WikiReference(org.xwiki.model.reference.WikiReference)

Example 55 with WikiReference

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

the class EventConverter method convertActivityToEvent.

/**
 * Convert an old {@link ActivityEvent} to the new {@link Event}.
 *
 * @param e the activity event to transform
 * @return the equivalent event
 */
public Event convertActivityToEvent(ActivityEvent e) {
    Event result = this.eventFactory.createRawEvent();
    result.setApplication(e.getApplication());
    result.setBody(e.getBody());
    result.setDate(e.getDate());
    result.setDocument(new DocumentReference(this.resolver.resolve(e.getPage(), EntityType.DOCUMENT, new WikiReference(e.getWiki()))));
    result.setId(e.getEventId());
    result.setDocumentTitle(e.getParam1());
    if (StringUtils.isNotEmpty(e.getParam2())) {
        if (StringUtils.endsWith(e.getType(), "Attachment")) {
            result.setRelatedEntity(this.explicitResolver.resolve(e.getParam2(), EntityType.ATTACHMENT, result.getDocument()));
        } else if (StringUtils.endsWith(e.getType(), "Comment") || StringUtils.endsWith(e.getType(), "Annotation")) {
            result.setRelatedEntity(this.explicitResolver.resolve(e.getParam2(), EntityType.OBJECT, result.getDocument()));
        }
    }
    result.setImportance(Event.Importance.MEDIUM);
    if (e.getPriority() > 0) {
        int priority = e.getPriority() / 10 - 1;
        if (priority >= 0 && priority < Event.Importance.values().length) {
            result.setImportance(Event.Importance.values()[priority]);
        }
    }
    result.setGroupId(e.getRequestId());
    result.setStream(e.getStream());
    result.setTitle(e.getTitle());
    result.setType(e.getType());
    if (StringUtils.isNotBlank(e.getUrl())) {
        try {
            result.setUrl(new URL(e.getUrl()));
        } catch (MalformedURLException ex) {
        // Should not happen
        }
    }
    result.setUser(new DocumentReference(this.resolver.resolve(e.getUser(), EntityType.DOCUMENT)));
    result.setDocumentVersion(e.getVersion());
    result.setParameters(e.getParameters());
    result.setTarget(e.getTarget());
    return result;
}
Also used : MalformedURLException(java.net.MalformedURLException) ActivityEvent(com.xpn.xwiki.plugin.activitystream.api.ActivityEvent) Event(org.xwiki.eventstream.Event) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) URL(java.net.URL)

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