Search in sources :

Example 1 with ObjectReference

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

the class ObjectsOfTypeTreeNode method getXObjectReferences.

private List<ObjectReference> getXObjectReferences(DocumentReference documentReference, DocumentReference classReference) throws Exception {
    XWikiContext xcontext = this.xcontextProvider.get();
    XWikiDocument document = xcontext.getWiki().getDocument(documentReference, xcontext);
    List<ObjectReference> objectReferences = new ArrayList<ObjectReference>();
    List<BaseObject> objects = document.getXObjects(classReference);
    if (objects != null) {
        for (BaseObject object : objects) {
            // Yes, the list of objects can contain null values..
            if (object != null) {
                objectReferences.add(object.getReference());
            }
        }
    }
    return objectReferences;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ObjectReference(org.xwiki.model.reference.ObjectReference) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 2 with ObjectReference

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

the class DefaultMessageStream method postMessageToGroup.

@Override
public void postMessageToGroup(String message, DocumentReference group) throws IllegalAccessError {
    if (!this.bridge.exists(group)) {
        throw new IllegalArgumentException("Target group does not exist");
    }
    Event e = createMessageEvent(message, "groupMessage");
    e.setRelatedEntity(new ObjectReference("XWiki.XWikiGroups", group));
    e.setStream(this.serializer.serialize(group));
    e.setImportance(Importance.MAJOR);
    this.stream.addEvent(e);
}
Also used : ObjectReference(org.xwiki.model.reference.ObjectReference) Event(org.xwiki.eventstream.Event)

Example 3 with ObjectReference

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

the class MessageStreamTest method testPostGroupMessage.

@Test
public void testPostGroupMessage() throws Exception {
    Event postedMessage = setupForGroupMessage();
    this.stream.postMessageToGroup("Hello Friends!", this.targetGroup);
    Assert.assertEquals("Hello Friends!", postedMessage.getBody());
    Assert.assertEquals(Importance.MAJOR, postedMessage.getImportance());
    Assert.assertEquals("groupMessage", postedMessage.getType());
    Assert.assertEquals("wiki:XWiki.MyFriends", postedMessage.getStream());
    Assert.assertEquals(new ObjectReference("XWiki.XWikiGroups", this.targetGroup), postedMessage.getRelatedEntity());
}
Also used : ObjectReference(org.xwiki.model.reference.ObjectReference) Event(org.xwiki.eventstream.Event) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) Test(org.junit.Test)

Example 4 with ObjectReference

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

the class XWikiTest method testGetDocumentWithEntityReference.

public void testGetDocumentWithEntityReference() throws Exception {
    Mock mockStore = registerMockComponent(XWikiStoreInterface.class);
    this.xwiki.setStore((XWikiStoreInterface) mockStore.proxy());
    mockStore.expects(atLeastOnce()).method("loadXWikiDoc").with(NOT_NULL, same(getContext())).will(new CustomStub("Implements XWikiStoreInterface.loadXWikiDoc") {

        @Override
        public Object invoke(Invocation invocation) throws Throwable {
            return invocation.parameterValues.get(0);
        }
    });
    DocumentReference documentReference = new DocumentReference("wiki", "Main", "WebHome");
    WikiDescriptor mockWikiDescriptor = new WikiDescriptor("wiki", "wiki");
    mockWikiDescriptor.setMainPageReference(documentReference);
    this.mockWikiDescriptorManager.stubs().method("getById").with(same("wiki")).will(returnValue(mockWikiDescriptor));
    assertEquals(documentReference, this.xwiki.getDocument(new WikiReference("wiki"), getContext()).getDocumentReference());
    assertEquals(documentReference, this.xwiki.getDocument(new ObjectReference("object", documentReference), getContext()).getDocumentReference());
}
Also used : Invocation(org.jmock.core.Invocation) CustomStub(org.jmock.core.stub.CustomStub) ObjectReference(org.xwiki.model.reference.ObjectReference) BaseObject(com.xpn.xwiki.objects.BaseObject) WikiReference(org.xwiki.model.reference.WikiReference) Mock(org.jmock.Mock) DocumentReference(org.xwiki.model.reference.DocumentReference) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor)

Example 5 with ObjectReference

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

the class TestUtils method disableSyntaxHighlighting.

/**
 * Disable Syntax Highlighting.
 *
 * @since 9.7RC1
 */
public void disableSyntaxHighlighting() throws Exception {
    ObjectPropertyReference enabledPropertyReference = new ObjectPropertyReference("enabled", new ObjectReference("SyntaxHighlighting.ConfigurationClass[0]", new DocumentReference(getCurrentWiki(), "SyntaxHighlighting", "Configuration")));
    Property property = new Property();
    property.setValue("0");
    TestUtils.assertStatusCodes(rest().executePut(ObjectPropertyResource.class, property, rest().toElements(enabledPropertyReference)), true, STATUS_ACCEPTED);
}
Also used : ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) ObjectReference(org.xwiki.model.reference.ObjectReference) Property(org.xwiki.rest.model.jaxb.Property) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) ObjectPropertyResource(org.xwiki.rest.resources.objects.ObjectPropertyResource)

Aggregations

ObjectReference (org.xwiki.model.reference.ObjectReference)18 Test (org.junit.Test)8 DocumentReference (org.xwiki.model.reference.DocumentReference)8 BaseObject (com.xpn.xwiki.objects.BaseObject)6 BaseObjectReference (com.xpn.xwiki.objects.BaseObjectReference)5 ObjectPropertyReference (org.xwiki.model.reference.ObjectPropertyReference)5 Event (org.xwiki.eventstream.Event)4 ArrayList (java.util.ArrayList)2 DefaultEvent (org.xwiki.eventstream.internal.DefaultEvent)2 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)2 WikiReference (org.xwiki.model.reference.WikiReference)2 Property (org.xwiki.rest.model.jaxb.Property)2 ObjectPropertyResource (org.xwiki.rest.resources.objects.ObjectPropertyResource)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 HashSet (java.util.HashSet)1 Mock (org.jmock.Mock)1 Invocation (org.jmock.core.Invocation)1 CustomStub (org.jmock.core.stub.CustomStub)1 EntityUnifiedDiff (org.xwiki.extension.xar.job.diff.EntityUnifiedDiff)1