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