use of org.xwiki.rest.model.jaxb.PropertyValue in project xwiki-platform by xwiki.
the class AbstractUsersAndGroupsClassPropertyValuesProvider method getValueFromQueryResult.
@Override
protected PropertyValue getValueFromQueryResult(Object result, T propertyDefinition) {
PropertyValue value = super.getValueFromQueryResult(result, propertyDefinition);
if (value != null && value.getValue() instanceof DocumentReference) {
DocumentReference documentReference = (DocumentReference) value.getValue();
WikiReference wikiReference = propertyDefinition.getOwnerDocument().getDocumentReference().getWikiReference();
// Serialize the user/group reference relative to the wiki were the property is defined.
value.setValue(this.compactSerializer.serialize(documentReference, wikiReference));
value.getMetaData().put(META_DATA_LABEL, getLabel(documentReference, value.getMetaData().get(META_DATA_LABEL)));
value.getMetaData().put(META_DATA_ICON, getIcon(documentReference));
value.getMetaData().put("url", getURL(documentReference));
}
return value;
}
use of org.xwiki.rest.model.jaxb.PropertyValue in project xwiki-platform by xwiki.
the class DBListClassPropertyValuesProviderTest method getValuesMixedWithUsed.
@Test
public void getValuesMixedWithUsed() throws Exception {
ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
DocumentReference authorReference = this.dbListClass.getOwnerDocument().getAuthorReference();
PropertyValues values = new PropertyValues();
PropertyValue red = new PropertyValue();
red.setValue("red");
red.setMetaData(new HashMap<String, Object>());
red.getMetaData().put("label", "Red");
values.getPropertyValues().add(red);
when(this.authorExecutor.call(any(), eq(authorReference))).thenReturn(values);
Query query = mock(Query.class);
QueryParameter queryParameter = mock(QueryParameter.class);
when(this.usedValuesQueryBuilder.build(dbListClass)).thenReturn(query);
when(query.bindValue("text")).thenReturn(queryParameter);
when(queryParameter.anyChars()).thenReturn(queryParameter);
when(queryParameter.literal("bar")).thenReturn(queryParameter);
when(query.execute()).thenReturn(Arrays.asList(new Object[] { "blue", 21L }, new Object[] { "red", 17L }));
assertSame(values, this.mocker.getComponentUnderTest().getValues(propertyReference, 3, "bar"));
verify(query).setLimit(2);
verify(query).addFilter(this.mocker.getInstance(QueryFilter.class, "text"));
verify(queryParameter, times(2)).anyChars();
assertEquals(2, values.getPropertyValues().size());
assertEquals("red", values.getPropertyValues().get(0).getValue());
assertEquals(17L, values.getPropertyValues().get(0).getMetaData().get("count"));
assertEquals("blue", values.getPropertyValues().get(1).getValue());
assertEquals(21L, values.getPropertyValues().get(1).getMetaData().get("count"));
}
use of org.xwiki.rest.model.jaxb.PropertyValue in project xwiki-platform by xwiki.
the class DBListClassPropertyValuesProviderTest method getValuesMixedWithoutUsed.
@Test
public void getValuesMixedWithoutUsed() throws Exception {
ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference);
DocumentReference authorReference = this.dbListClass.getOwnerDocument().getAuthorReference();
PropertyValues values = new PropertyValues();
values.getPropertyValues().add(new PropertyValue());
when(this.authorExecutor.call(any(), eq(authorReference))).thenReturn(values);
assertSame(values, this.mocker.getComponentUnderTest().getValues(propertyReference, 1, "foo"));
assertEquals(1, values.getPropertyValues().size());
verify(this.usedValuesQueryBuilder, never()).build(any());
}
use of org.xwiki.rest.model.jaxb.PropertyValue in project xwiki-platform by xwiki.
the class AbstractUsersAndGroupsClassPropertyValuesProvider method getLocalAndGlobalAllowedValues.
protected PropertyValues getLocalAndGlobalAllowedValues(T propertyDefinition, int limit, String filter) throws Exception {
PropertyValues localUsers = getLocalAllowedValues(propertyDefinition, limit, filter);
PropertyValues globalUsers = getGlobalAllowedValues(propertyDefinition, limit, filter);
Iterator<PropertyValue> localUsersIterator = localUsers.getPropertyValues().iterator();
Iterator<PropertyValue> globalUsersIterator = globalUsers.getPropertyValues().iterator();
PropertyValues users = new PropertyValues();
int oldSize;
do {
oldSize = users.getPropertyValues().size();
if (localUsersIterator.hasNext() && (limit <= 0 || users.getPropertyValues().size() < limit)) {
users.getPropertyValues().add(localUsersIterator.next());
}
if (globalUsersIterator.hasNext() && (limit <= 0 || users.getPropertyValues().size() < limit)) {
users.getPropertyValues().add(globalUsersIterator.next());
}
} while (oldSize < users.getPropertyValues().size());
users.getPropertyValues().sort((alice, bob) -> {
String aliceName = alice.getMetaData().getOrDefault(META_DATA_LABEL, alice.getValue()).toString();
String bobName = bob.getMetaData().getOrDefault(META_DATA_LABEL, alice.getValue()).toString();
return aliceName.compareToIgnoreCase(bobName);
});
return users;
}
Aggregations