GroovyPersonAttributeDao extends AbstractDefaultAttributePersonAttributeDao { @Override public IPersonAttributes getPerson(final String uid, final IPersonAttributeDaoFilter filter) { if (!this.isEnabled()) { return null; } logger.debug("Executing groovy script's getAttributesForUser method"); final Map<String, Object> personAttributesMap = groovyObject.getAttributesForUser(uid); if (personAttributesMap != null) { logger.debug("Creating person attributes with the username {} and attributes {}", uid, personAttributesMap); final Map<String, List<Object>> personAttributes = MultivaluedPersonAttributeUtils.toMultivaluedMap(personAttributesMap); if (this.caseInsensitiveUsername) { return new CaseInsensitiveNamedPersonImpl(uid, personAttributes); } return new NamedPersonImpl(uid, personAttributes); } logger.debug("Groovy script returned null for uid={}", uid); return null; } GroovyPersonAttributeDao(final IPersonAttributeScriptDao groovyObject); void setCaseInsensitiveUsername(final boolean caseInsensitiveUsername); @Override IPersonAttributes getPerson(final String uid, final IPersonAttributeDaoFilter filter); @Override Set<IPersonAttributes> getPeopleWithMultivaluedAttributes(final Map<String, List<Object>> attributes,
                                                                     final IPersonAttributeDaoFilter filter); void setPossibleUserAttributeNames(final Set<String> possibleUserAttributeNames); void setAvailableQueryAttributes(final Set<String> availableQueryAttributes); @Override Set<String> getAvailableQueryAttributes(final IPersonAttributeDaoFilter filter); @Override Set<String> getPossibleUserAttributeNames(final IPersonAttributeDaoFilter filter);  }
@Test public void testGetPerson() { final IPersonAttributes attrs = dao.getPerson("userid", IPersonAttributeDaoFilter.alwaysChoose()); assertFalse(attrs.getAttributes().isEmpty()); assertEquals(getAttributeAsSingleValue(attrs, "name"), "userid"); assertEquals(getAttributeAsList(attrs, "likes").size(), 2); }
@Test public void testGetPersonNullResult() { GroovyPersonAttributeDao nullResponseDao = new GroovyPersonAttributeDao(loadGroovyClass("SampleGroovyPersonAttributeDaoForTestingUpdates.groovy")); final IPersonAttributes attrs = nullResponseDao.getPerson("userid", IPersonAttributeDaoFilter.alwaysChoose()); assertNull(attrs); }