@Test public void getValue() throws Exception { ClassPropertyReference propertyReference = new ClassPropertyReference("category", this.classReference); when(this.authorExecutor.call(any(), any(), any())) .thenAnswer(answer -> ((Callable) answer.getArgument(0)).call()); PropertyValue red = new PropertyValue(); red.setValue("red"); red.setMetaData(new HashMap<>()); red.getMetaData().put("label", "Red"); Query query = mock(Query.class); QueryParameter queryParameter = mock(QueryParameter.class); when(this.allowedValuesQueryBuilder.build(dbListClass)).thenReturn(query); when(query.bindValue("text")).thenReturn(queryParameter); when(queryParameter.literal("red")).thenReturn(queryParameter); when(query.execute()).thenReturn(Collections.singletonList(new Object[] { "red", "Red" })); PropertyValue propertyValue = this.provider.getValue(propertyReference, "red"); assertEquals(red.getValue(), propertyValue.getValue()); assertEquals(red.getMetaData(), propertyValue.getMetaData()); verify(query).addFilter(this.componentManager.getInstance(QueryFilter.class, "text")); }
@Override public PropertyValue getValue(ClassPropertyReference propertyReference, Object rawValue) throws XWikiRestException { PropertyValue propertyValue = null; DBListClass dbListClass = getPropertyDefinition(propertyReference); if (rawValue != null) { try { propertyValue = this.authorExecutor .call(() -> getValue(this.allowedValuesQueryBuilder.build(dbListClass), rawValue.toString(), dbListClass), dbListClass.getOwnerDocument().getAuthorReference(), dbListClass.getDocumentReference()); } catch (Exception e) { throw new XWikiRestException(e); } } if (propertyValue == null) { propertyValue = super.getValue(propertyReference, rawValue); } return propertyValue; }
DBListClassPropertyValuesProvider extends AbstractListClassPropertyValuesProvider<DBListClass> { @Override public PropertyValue getValue(ClassPropertyReference propertyReference, Object rawValue) throws XWikiRestException { PropertyValue propertyValue = null; DBListClass dbListClass = getPropertyDefinition(propertyReference); if (rawValue != null) { try { propertyValue = this.authorExecutor .call(() -> getValue(this.allowedValuesQueryBuilder.build(dbListClass), rawValue.toString(), dbListClass), dbListClass.getOwnerDocument().getAuthorReference(), dbListClass.getDocumentReference()); } catch (Exception e) { throw new XWikiRestException(e); } } if (propertyValue == null) { propertyValue = super.getValue(propertyReference, rawValue); } return propertyValue; } }
DBListClassPropertyValuesProvider extends AbstractListClassPropertyValuesProvider<DBListClass> { @Override public PropertyValue getValue(ClassPropertyReference propertyReference, Object rawValue) throws XWikiRestException { PropertyValue propertyValue = null; DBListClass dbListClass = getPropertyDefinition(propertyReference); if (rawValue != null) { try { propertyValue = this.authorExecutor .call(() -> getValue(this.allowedValuesQueryBuilder.build(dbListClass), rawValue.toString(), dbListClass), dbListClass.getOwnerDocument().getAuthorReference(), dbListClass.getDocumentReference()); } catch (Exception e) { throw new XWikiRestException(e); } } if (propertyValue == null) { propertyValue = super.getValue(propertyReference, rawValue); } return propertyValue; }  }
DBListClassPropertyValuesProvider extends AbstractListClassPropertyValuesProvider<DBListClass> { @Override public PropertyValue getValue(ClassPropertyReference propertyReference, Object rawValue) throws XWikiRestException { PropertyValue propertyValue = null; DBListClass dbListClass = getPropertyDefinition(propertyReference); if (rawValue != null) { try { propertyValue = this.authorExecutor .call(() -> getValue(this.allowedValuesQueryBuilder.build(dbListClass), rawValue.toString(), dbListClass), dbListClass.getOwnerDocument().getAuthorReference(), dbListClass.getDocumentReference()); } catch (Exception e) { throw new XWikiRestException(e); } } if (propertyValue == null) { propertyValue = super.getValue(propertyReference, rawValue); } return propertyValue; }  @Override PropertyValue getValue(ClassPropertyReference propertyReference, Object rawValue); }
DBListClassPropertyValuesProvider extends AbstractListClassPropertyValuesProvider<DBListClass> { @Override public PropertyValue getValue(ClassPropertyReference propertyReference, Object rawValue) throws XWikiRestException { PropertyValue propertyValue = null; DBListClass dbListClass = getPropertyDefinition(propertyReference); if (rawValue != null) { try { propertyValue = this.authorExecutor .call(() -> getValue(this.allowedValuesQueryBuilder.build(dbListClass), rawValue.toString(), dbListClass), dbListClass.getOwnerDocument().getAuthorReference(), dbListClass.getDocumentReference()); } catch (Exception e) { throw new XWikiRestException(e); } } if (propertyValue == null) { propertyValue = super.getValue(propertyReference, rawValue); } return propertyValue; }  @Override PropertyValue getValue(ClassPropertyReference propertyReference, Object rawValue);  }