Search in sources :

Example 1 with StaticListClass

use of com.xpn.xwiki.objects.classes.StaticListClass in project xwiki-platform by xwiki.

the class XWikiDocument method getTagsPossibleValues.

public List<String> getTagsPossibleValues(XWikiContext context) {
    List<String> list;
    try {
        BaseClass tagsClass = context.getWiki().getTagClass(context);
        String possibleValues = ((StaticListClass) tagsClass.getField(XWikiConstant.TAG_CLASS_PROP_TAGS)).getValues();
        return ListClass.getListFromString(possibleValues);
    } catch (XWikiException e) {
        LOGGER.error("Failed to get tag class", e);
        list = Collections.emptyList();
    }
    return list;
}
Also used : StaticListClass(com.xpn.xwiki.objects.classes.StaticListClass) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) ToString(org.suigeneris.jrcs.util.ToString) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with StaticListClass

use of com.xpn.xwiki.objects.classes.StaticListClass in project xwiki-platform by xwiki.

the class XWikiDocument method setTags.

/**
 * add tags to the document.
 */
public void setTags(String tagsStr, XWikiContext context) throws XWikiException {
    BaseClass tagsClass = context.getWiki().getTagClass(context);
    StaticListClass tagProp = (StaticListClass) tagsClass.getField(XWikiConstant.TAG_CLASS_PROP_TAGS);
    BaseObject tags = getObject(XWikiConstant.TAG_CLASS, true, context);
    tags.safeput(XWikiConstant.TAG_CLASS_PROP_TAGS, tagProp.fromString(tagsStr));
    setMetaDataDirty(true);
}
Also used : StaticListClass(com.xpn.xwiki.objects.classes.StaticListClass) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 3 with StaticListClass

use of com.xpn.xwiki.objects.classes.StaticListClass in project xwiki-platform by xwiki.

the class ListMetaClass method addPresentationMetaProperties.

/**
 * Adds the meta properties that control how the XClass property is displayed in edit and view mode.
 */
private void addPresentationMetaProperties() {
    StaticListClass displayTypeClass = new StaticListClass(this);
    displayTypeClass.setName("displayType");
    displayTypeClass.setPrettyName("Display Type");
    displayTypeClass.setValues("input|select|radio|checkbox");
    safeput(displayTypeClass.getName(), displayTypeClass);
    BooleanClass multiSelectClass = newCheckBox(false);
    multiSelectClass.setName("multiSelect");
    multiSelectClass.setPrettyName("Multiple Select");
    safeput(multiSelectClass.getName(), multiSelectClass);
    BooleanClass pickerClass = newCheckBox(true);
    pickerClass.setName("picker");
    pickerClass.setPrettyName("Use Suggest");
    safeput(pickerClass.getName(), pickerClass);
    NumberClass sizeClass = new NumberClass(this);
    sizeClass.setName("size");
    sizeClass.setPrettyName("Size");
    sizeClass.setSize(5);
    sizeClass.setNumberType("integer");
    safeput(sizeClass.getName(), sizeClass);
    addValueSeparatorMetaProperties();
    StaticListClass sortClass = new StaticListClass(this);
    sortClass.setName("sort");
    sortClass.setPrettyName("Sort");
    sortClass.setValues("none|id|value");
    safeput(sortClass.getName(), sortClass);
}
Also used : StaticListClass(com.xpn.xwiki.objects.classes.StaticListClass) BooleanClass(com.xpn.xwiki.objects.classes.BooleanClass) NumberClass(com.xpn.xwiki.objects.classes.NumberClass)

Example 4 with StaticListClass

use of com.xpn.xwiki.objects.classes.StaticListClass in project xwiki-platform by xwiki.

the class DocumentSolrMetadataExtractorTest method setStaticListPropertyValue.

/**
 * @see "XWIKI-9417: Search does not return any results for Static List values"
 */
@Test
public void setStaticListPropertyValue() throws Exception {
    BaseObject xobject = mock(BaseObject.class);
    @SuppressWarnings("unchecked") BaseProperty<EntityReference> listProperty = mock(BaseProperty.class);
    when(listProperty.getName()).thenReturn("color");
    when(listProperty.getValue()).thenReturn(Arrays.asList("red", "green"));
    when(listProperty.getObject()).thenReturn(xobject);
    DocumentReference classReference = new DocumentReference("wiki", "Space", "MyClass");
    when(this.document.getXObjects()).thenReturn(Collections.singletonMap(classReference, Arrays.asList(xobject)));
    BaseClass xclass = mock(BaseClass.class);
    when(xobject.getXClass(this.xcontext)).thenReturn(xclass);
    when(xobject.getFieldList()).thenReturn(Arrays.<Object>asList(listProperty));
    when(xobject.getRelativeXClassReference()).thenReturn(classReference.removeParent(classReference.getWikiReference()));
    StaticListClass staticListClass = mock(StaticListClass.class);
    when(xclass.get("color")).thenReturn(staticListClass);
    when(staticListClass.getMap(xcontext)).thenReturn(Collections.singletonMap("red", new ListItem("red", "Dark Red")));
    SolrInputDocument solrDocument = this.mocker.getComponentUnderTest().getSolrDocument(this.documentReference);
    // Make sure both the raw value (which is saved in the database) and the display value (specified in the XClass)
    // are indexed. The raw values are indexed as strings in order to be able to perform exact matches.
    assertEquals(Arrays.asList("red", "green"), solrDocument.getFieldValues("property.Space.MyClass.color_string"));
    assertEquals(Collections.singletonList("Dark Red"), solrDocument.getFieldValues(FieldUtils.getFieldName("property.Space.MyClass.color", Locale.US)));
    // Check the sort field. Only the last value we set is used for sorting because we cannot sort on fields that
    // have multiple values.
    assertEquals(Collections.singletonList("green"), solrDocument.getFieldValues("property.Space.MyClass.color_sortString"));
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) StaticListClass(com.xpn.xwiki.objects.classes.StaticListClass) EntityReference(org.xwiki.model.reference.EntityReference) BaseClass(com.xpn.xwiki.objects.classes.BaseClass) ListItem(com.xpn.xwiki.objects.classes.ListItem) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Aggregations

StaticListClass (com.xpn.xwiki.objects.classes.StaticListClass)4 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)3 BaseObject (com.xpn.xwiki.objects.BaseObject)2 XWikiException (com.xpn.xwiki.XWikiException)1 BooleanClass (com.xpn.xwiki.objects.classes.BooleanClass)1 ListItem (com.xpn.xwiki.objects.classes.ListItem)1 NumberClass (com.xpn.xwiki.objects.classes.NumberClass)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 Test (org.junit.Test)1 ToString (org.suigeneris.jrcs.util.ToString)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 EntityReference (org.xwiki.model.reference.EntityReference)1