applyOverridesIfPresent(person); // default -- won't normally need to do anything rslt = selectUsernameIfAbsent(rslt); rslt = selectDisplayNameIfAbsent(rslt);
/** * This method is for "filling" a specific individual. * * @param uid The username (identity) of a known individual * @return A completely "filled" person, including overrides, or <code>null</code> if the person * is unknown */ @Override public IPersonAttributes getPerson(String uid) { final IPersonAttributes rslt = delegatePersonAttributeDao.getPerson(uid); if (rslt == null) { // Nothing we can do with that return null; } return postProcessPerson(rslt, uid); }
@Override public IPersonAttributes getOriginalUserAttributes(String uid) { final IPersonAttributeDao delegatePersonAttributeDao = this.portalRootPersonAttributeDao.getDelegatePersonAttributeDao(); return delegatePersonAttributeDao.getPerson(uid); }
@Test public void applyOverridesIfPresentTest() { // Setup final Map<String, List<Object>> attributes = Collections.singletonMap( CUSTOMARY_FIRST_NAME_ATTRIBUTE, Collections.singletonList(FIRST_NAME)); final IPersonAttributes person = new NamedPersonImpl(USERNAME, attributes); // First without overrides portalRootPersonAttributeDao.setUserAttributeOverride( "somebody.else", Collections.singletonMap(CUSTOMARY_FIRST_NAME_ATTRIBUTE, "something")); final IPersonAttributes rsltWithout = portalRootPersonAttributeDao.applyOverridesIfPresent(person); Assert.assertEquals( FIRST_NAME, rsltWithout.getAttributeValue(CUSTOMARY_FIRST_NAME_ATTRIBUTE)); // Then with overrides final String overriddenFirstName = "Nebby"; portalRootPersonAttributeDao.setUserAttributeOverride( USERNAME, Collections.singletonMap(CUSTOMARY_FIRST_NAME_ATTRIBUTE, overriddenFirstName)); final IPersonAttributes rsltWith = portalRootPersonAttributeDao.applyOverridesIfPresent(person); Assert.assertEquals( overriddenFirstName, rsltWith.getAttributeValue(CUSTOMARY_FIRST_NAME_ATTRIBUTE)); }
@Test public void selectDisplayNameIfAbsent() { // Setup final Map<String, List<Object>> attributes = new HashMap<>(); attributes.put(CUSTOMARY_FIRST_NAME_ATTRIBUTE, Collections.singletonList(FIRST_NAME)); attributes.put(CUSTOMARY_LAST_NAME_ATTRIBUTE, Collections.singletonList(LAST_NAME)); final IPersonAttributes person = new NamedPersonImpl(USERNAME, attributes); // Test final IPersonAttributes rslt = portalRootPersonAttributeDao.selectDisplayNameIfAbsent(person); Assert.assertEquals( FIRST_NAME + " " + LAST_NAME, rslt.getAttributeValue(ILocalAccountPerson.ATTR_DISPLAY_NAME)); } }
@Test public void selectUsernameIfAbsentTest() { // Setup final Map<String, List<Object>> attributes = Collections.singletonMap( CUSTOMARY_FIRST_NAME_ATTRIBUTE, Collections.singletonList(FIRST_NAME)); final IPersonAttributes person = new NamedPersonImpl(USERNAME, attributes); // Test final IPersonAttributes rslt = portalRootPersonAttributeDao.selectUsernameIfAbsent(person); Assert.assertEquals( USERNAME, rslt.getAttributeValue(usernameAttributeProvider.getUsernameAttribute())); }
this.portalRootPersonAttributeDao.setUserAttributeOverride(uid, attributes);
@Override public void populateSwapRequest( ExternalContext externalContext, AttributeSwapRequest attributeSwapRequest) { final Principal currentUser = externalContext.getCurrentUser(); final String uid = currentUser.getName(); final IPersonAttributes person = this.portalRootPersonAttributeDao.getPerson(uid); final Map<String, Attribute> currentAttributes = attributeSwapRequest.getCurrentAttributes(); currentAttributes.clear(); final Set<String> swappableAttributes = this.getSwappableAttributes(externalContext); for (final String attribute : swappableAttributes) { final Object value = person.getAttributeValue(attribute); if (value != null) { currentAttributes.put(attribute, new Attribute(String.valueOf(value))); } } }
this.portalRootPersonAttributeDao.getPossibleUserAttributeNames(); if (possibleAttributes != null) { swappableAttributes = new TreeSet<String>(possibleAttributes);
@Override public void resetAttributes(ExternalContext externalContext) { final Principal currentUser = externalContext.getCurrentUser(); final String uid = currentUser.getName(); this.logger.warn("User '" + uid + "' reseting to default attributes"); // Remove the person directory override this.portalRootPersonAttributeDao.removeUserAttributeOverride(uid); // Remove the IPerson attribute override, bit of a hack as we really just remove all // overrides // then re-add all attributes from person directory final PortletRequest portletRequest = (PortletRequest) externalContext.getNativeRequest(); final HttpServletRequest portalRequest = this.portalRequestUtils.getPortletHttpRequest(portletRequest); final IPerson person = this.personManager.getPerson(portalRequest); final Set<String> overriddenAttributes = (Set<String>) person.getAttribute(OVERRIDDEN_ATTRIBUTES); if (overriddenAttributes != null) { person.setAttribute(OVERRIDDEN_ATTRIBUTES, null); for (final String attribute : overriddenAttributes) { person.setAttribute(attribute, null); } } final IPersonAttributes originalUserAttributes = this.getOriginalUserAttributes(uid); final Map<String, List<Object>> attributes = originalUserAttributes.getAttributes(); person.setAttributes(attributes); }
applyOverridesIfPresent(person); // default -- won't normally need to do anything rslt = selectUsernameIfAbsent(rslt); rslt = selectDisplayNameIfAbsent(rslt);
/** * This method is for "filling" a specific individual. * * @param uid The username (identity) of a known individual * @return A completely "filled" person, including overrides, or <code>null</code> if the person * is unknown */ @Override public IPersonAttributes getPerson(String uid) { final IPersonAttributes rslt = delegatePersonAttributeDao.getPerson(uid); if (rslt == null) { // Nothing we can do with that return null; } return postProcessPerson(rslt, uid); }
/** * This method is for matching a search query. Each matching item will subsequently be passed to * <code>getPerson(uid)</code> for "filling." */ @Override public Set<IPersonAttributes> getPeopleWithMultivaluedAttributes( Map<String, List<Object>> query) { final Set<IPersonAttributes> people = delegatePersonAttributeDao.getPeopleWithMultivaluedAttributes(query); if (people == null) { return null; } final Set<IPersonAttributes> modifiedPeople = new LinkedHashSet<>(); for (final IPersonAttributes person : people) { /* * WARNING: Not safe to pass uidInQuery in this scenario; results will be "filled" by * getPerson(uid) subsequently. */ final IPersonAttributes mergedPerson = postProcessPerson(person, null); modifiedPeople.add(mergedPerson); } return modifiedPeople; }
/** * This method is for matching a search query. Each matching item will subsequently be passed to * <code>getPerson(uid)</code> for "filling." */ @Override public Set<IPersonAttributes> getPeopleWithMultivaluedAttributes( Map<String, List<Object>> query) { final Set<IPersonAttributes> people = delegatePersonAttributeDao.getPeopleWithMultivaluedAttributes(query); if (people == null) { return null; } final Set<IPersonAttributes> modifiedPeople = new LinkedHashSet<>(); for (final IPersonAttributes person : people) { /* * WARNING: Not safe to pass uidInQuery in this scenario; results will be "filled" by * getPerson(uid) subsequently. */ final IPersonAttributes mergedPerson = postProcessPerson(person, null); modifiedPeople.add(mergedPerson); } return modifiedPeople; }