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