use of org.xwiki.rest.model.jaxb.PropertyValues 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.PropertyValues in project xwiki-platform by xwiki.
the class GroupsClassPropertyValuesProviderTest method getValuesLocal.
@Test
public void getValuesLocal() throws Exception {
when(this.wikiUserManager.getUserScope(this.classReference.getWikiReference().getName())).thenReturn(UserScope.LOCAL_ONLY);
DocumentReference devsReference = new DocumentReference("wiki", "Groups", "Devs");
XWikiDocument devsProfile = mock(XWikiDocument.class, "devs");
when(this.xcontext.getWiki().getDocument(devsReference, this.xcontext)).thenReturn(devsProfile);
when(devsProfile.getRenderedTitle(Syntax.PLAIN_1_0, this.xcontext)).thenReturn("Developers");
DocumentReference adminsReference = new DocumentReference("wiki", "Groups", "Admins");
XWikiDocument adminsProfile = mock(XWikiDocument.class, "admins");
XWikiAttachment notAnImageAttachment = mock(XWikiAttachment.class, "noAnImage");
XWikiAttachment imageAttachment = mock(XWikiAttachment.class, "image");
AttachmentReference imageAttachmentReference = new AttachmentReference("admins.png", adminsReference);
when(this.xcontext.getWiki().getDocument(adminsReference, this.xcontext)).thenReturn(adminsProfile);
when(adminsProfile.getRenderedTitle(Syntax.PLAIN_1_0, this.xcontext)).thenReturn("Administrators");
when(adminsProfile.getAttachmentList()).thenReturn(Arrays.asList(notAnImageAttachment, imageAttachment));
when(imageAttachment.isImage(this.xcontext)).thenReturn(true);
when(imageAttachment.getReference()).thenReturn(imageAttachmentReference);
when(this.xcontext.getWiki().getURL(imageAttachmentReference, "download", "width=30&height=30&keepAspectRatio=true", null, this.xcontext)).thenReturn("url/to/admins/image");
when(this.allowedValuesQuery.execute()).thenReturn(Arrays.asList(devsReference, adminsReference));
PropertyValues values = this.mocker.getComponentUnderTest().getValues(this.propertyReference, 5, "foo");
assertEquals(2, values.getPropertyValues().size());
assertEquals("Developers", values.getPropertyValues().get(0).getMetaData().get("label"));
assertEquals("url/to/noavatar.png", values.getPropertyValues().get(0).getMetaData().get("icon"));
assertEquals("Administrators", values.getPropertyValues().get(1).getMetaData().get("label"));
assertEquals("url/to/admins/image", values.getPropertyValues().get(1).getMetaData().get("icon"));
}
use of org.xwiki.rest.model.jaxb.PropertyValues in project xwiki-platform by xwiki.
the class UsersClassPropertyValuesProviderTest method getValuesLocalAndGlobal.
@Test
public void getValuesLocalAndGlobal() throws Exception {
when(this.wikiUserManager.getUserScope(this.classReference.getWikiReference().getName())).thenReturn(UserScope.LOCAL_AND_GLOBAL);
WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
when(wikiDescriptorManager.getMainWikiId()).thenReturn("chess");
DocumentReference aliceReference = new DocumentReference("wiki", "Users", "Alice");
when(this.xcontext.getWiki().getDocument(aliceReference, this.xcontext)).thenReturn(mock(XWikiDocument.class, "alice"));
DocumentReference bobReference = new DocumentReference("chess", "Users", "Bob");
when(this.xcontext.getWiki().getDocument(bobReference, this.xcontext)).thenReturn(mock(XWikiDocument.class, "bob"));
when(this.allowedValuesQuery.execute()).thenReturn(Collections.singletonList(bobReference), Collections.singletonList(aliceReference));
PropertyValues values = this.mocker.getComponentUnderTest().getValues(this.propertyReference, 5, "foo");
assertEquals(2, values.getPropertyValues().size());
assertEquals("Alice", values.getPropertyValues().get(0).getMetaData().get("label"));
assertEquals("Bob", values.getPropertyValues().get(1).getMetaData().get("label"));
verify(this.allowedValuesQuery).setWiki("chess");
verify(this.allowedValuesQuery, times(2)).execute();
}
use of org.xwiki.rest.model.jaxb.PropertyValues 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;
}
use of org.xwiki.rest.model.jaxb.PropertyValues in project xwiki-platform by xwiki.
the class ClassPropertyValuesResourceImpl method getClassPropertyValues.
@Override
public PropertyValues getClassPropertyValues(String wikiName, String className, String propertyName, Integer limit, List<String> filterParameters) throws XWikiRestException {
DocumentReference classReference = this.resolver.resolve(className, new WikiReference(wikiName));
ClassPropertyReference classPropertyReference = new ClassPropertyReference(propertyName, classReference);
if (!this.authorization.hasAccess(Right.VIEW, classPropertyReference)) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
if (!exists(classPropertyReference)) {
throw new WebApplicationException(Status.NOT_FOUND);
}
URI propertyURI = Utils.createURI(this.uriInfo.getBaseUri(), ClassPropertyResource.class, wikiName, className, propertyName);
Link propertyLink = this.objectFactory.createLink();
propertyLink.setHref(propertyURI.toString());
propertyLink.setRel(Relations.PROPERTY);
PropertyValues propertyValues = this.propertyValuesProvider.getValues(classPropertyReference, limit, filterParameters.toArray());
propertyValues.getLinks().add(propertyLink);
return propertyValues;
}
Aggregations