Search in sources :

Example 6 with ObjectPropertyReference

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

the class ObjectPropertySolrMetadataExtractor method setFieldsInternal.

@Override
public boolean setFieldsInternal(LengthSolrInputDocument solrDocument, EntityReference entityReference) throws Exception {
    ObjectPropertyReference objectPropertyReference = new ObjectPropertyReference(entityReference);
    BaseObjectReference objectReference = new BaseObjectReference(objectPropertyReference.getParent());
    DocumentReference classReference = objectReference.getXClassReference();
    DocumentReference documentReference = new DocumentReference(objectReference.getParent());
    XWikiDocument originalDocument = getDocument(documentReference);
    BaseProperty<ObjectPropertyReference> objectProperty = originalDocument.getXObjectProperty(objectPropertyReference);
    if (objectProperty == null) {
        return false;
    }
    // Object
    solrDocument.setField(FieldUtils.CLASS, localSerializer.serialize(classReference));
    solrDocument.setField(FieldUtils.NUMBER, objectReference.getObjectNumber());
    // Property
    solrDocument.setField(FieldUtils.PROPERTY_NAME, objectPropertyReference.getName());
    setLocaleAndContentFields(documentReference, solrDocument, objectProperty);
    return true;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) BaseObjectReference(com.xpn.xwiki.objects.BaseObjectReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 7 with ObjectPropertyReference

use of org.xwiki.model.reference.ObjectPropertyReference 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)

Example 8 with ObjectPropertyReference

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

the class SSXListenerTest method onEvent.

@Test
public void onEvent() throws Exception {
    // Mocks
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
    XWikiDocument doc = mock(XWikiDocument.class);
    BaseObject obj1 = mock(BaseObject.class);
    BaseObject obj2 = mock(BaseObject.class);
    List<BaseObject> objList = new ArrayList<>();
    DocumentReference ssxDocRef = new DocumentReference("wiki", "XWiki", "StyleSheetExtension");
    when(doc.getXObjects(eq(ssxDocRef))).thenReturn(objList);
    objList.add(obj1);
    objList.add(null);
    objList.add(obj2);
    when(obj1.getStringValue("contentType")).thenReturn("CSS");
    when(obj2.getStringValue("contentType")).thenReturn("LESS");
    when(obj2.getNumber()).thenReturn(2);
    DocumentReference documentReference = new DocumentReference("wiki", "Space", "Doc");
    when(doc.getDocumentReference()).thenReturn(documentReference);
    // Because BaseObjectReference uses components from the Utils class, we need to set up the component manager
    ComponentManager rootComponentManager = mock(ComponentManager.class);
    Utils.setComponentManager(rootComponentManager);
    ComponentManager contextComponentManager = mock(ComponentManager.class);
    when(rootComponentManager.getInstance(ComponentManager.class, "context")).thenReturn(contextComponentManager);
    // Mock to serialize the object
    EntityReferenceSerializer entityReferenceSerializer = mock(EntityReferenceSerializer.class);
    when(contextComponentManager.getInstance(EntityReferenceSerializer.TYPE_STRING, "compactwiki")).thenReturn(entityReferenceSerializer);
    when(entityReferenceSerializer.serialize(any(EntityReference.class), any(EntityReference.class))).thenReturn("objName");
    ObjectPropertyReference objPropertyReference = new ObjectPropertyReference("code", new BaseObjectReference(ssxDocRef, 2, documentReference));
    LESSObjectPropertyResourceReference lessObjectPropertyResourceReference = new LESSObjectPropertyResourceReference(objPropertyReference, null, null);
    when(lessResourceReferenceFactory.createReferenceForXObjectProperty(eq(objPropertyReference))).thenReturn(lessObjectPropertyResourceReference);
    // Test
    mocker.getComponentUnderTest().onEvent(new DocumentUpdatedEvent(), doc, new Object());
    // Verify
    verify(lessResourcesCache, atLeastOnce()).clearFromLESSResource(lessObjectPropertyResourceReference);
    verify(colorThemeCache, atLeastOnce()).clearFromLESSResource(lessObjectPropertyResourceReference);
}
Also used : ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) LESSObjectPropertyResourceReference(org.xwiki.lesscss.internal.resources.LESSObjectPropertyResourceReference) ArrayList(java.util.ArrayList) DocumentUpdatedEvent(org.xwiki.bridge.event.DocumentUpdatedEvent) BaseObject(com.xpn.xwiki.objects.BaseObject) EntityReferenceSerializer(org.xwiki.model.reference.EntityReferenceSerializer) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) BaseObjectReference(com.xpn.xwiki.objects.BaseObjectReference) ComponentManager(org.xwiki.component.manager.ComponentManager) EntityReference(org.xwiki.model.reference.EntityReference) BaseObject(com.xpn.xwiki.objects.BaseObject) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 9 with ObjectPropertyReference

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

the class LESSObjectPropertyResourceReferenceTest method serialize.

@Test
public void serialize() throws Exception {
    ObjectPropertyReference objectPropertyReference = new ObjectPropertyReference("property", new ObjectReference("class", new DocumentReference("wiki", "Space", "Document")));
    LESSObjectPropertyResourceReference lessObjectPropertyResourceReference = new LESSObjectPropertyResourceReference(objectPropertyReference, entityReferenceSerializer, bridge);
    // Mock
    when(entityReferenceSerializer.serialize(eq(objectPropertyReference))).thenReturn("objPropertyRef");
    // Test
    assertEquals("LessXObjectProperty[objPropertyRef]", lessObjectPropertyResourceReference.serialize());
}
Also used : ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) ObjectReference(org.xwiki.model.reference.ObjectReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 10 with ObjectPropertyReference

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

the class SolrEntityReferenceResolverTest method resolve.

@Test
public void resolve() throws Exception {
    WikiReference wikiReference = new WikiReference("chess");
    assertReference(wikiReference);
    assertReference(new SpaceReference("Success", new SpaceReference("To", new SpaceReference("Path", wikiReference))));
    DocumentReference documentReference = new DocumentReference("chess", Arrays.asList("Path", "To", "Success"), "WebHome", Locale.FRENCH);
    assertReference(documentReference);
    assertReference(new AttachmentReference("image.png", documentReference));
    ObjectReference objectReference = new ObjectReference("App.Code.PlayerClass[13]", documentReference);
    assertReference(objectReference);
    assertReference(new ObjectPropertyReference("age", objectReference));
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) ObjectPropertyReference(org.xwiki.model.reference.ObjectPropertyReference) ObjectReference(org.xwiki.model.reference.ObjectReference) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

ObjectPropertyReference (org.xwiki.model.reference.ObjectPropertyReference)16 DocumentReference (org.xwiki.model.reference.DocumentReference)10 BaseObject (com.xpn.xwiki.objects.BaseObject)9 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)6 Test (org.junit.Test)5 ObjectReference (org.xwiki.model.reference.ObjectReference)5 BaseObjectReference (com.xpn.xwiki.objects.BaseObjectReference)4 ArrayList (java.util.ArrayList)3 EntityReference (org.xwiki.model.reference.EntityReference)3 XWiki (com.xpn.xwiki.XWiki)2 XWikiContext (com.xpn.xwiki.XWikiContext)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 BaseProperty (com.xpn.xwiki.objects.BaseProperty)2 LESSResourceReference (org.xwiki.lesscss.resources.LESSResourceReference)2 AttachmentReference (org.xwiki.model.reference.AttachmentReference)2 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)2 Property (org.xwiki.rest.model.jaxb.Property)2 ObjectPropertyResource (org.xwiki.rest.resources.objects.ObjectPropertyResource)2 IntegerProperty (com.xpn.xwiki.objects.IntegerProperty)1 StringProperty (com.xpn.xwiki.objects.StringProperty)1