use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.
the class UserAttributeSkinMappingTransformerConfigurationSource method getSkinName.
protected String getSkinName(HttpServletRequest request) {
final IUserInstance userInstance = this.userInstanceManager.getUserInstance(request);
final IPerson person = userInstance.getPerson();
final IPersonAttributes personAttrs = this.personAttributeDao.getPerson(person.getUserName());
if (personAttrs == null) {
logger.debug("No user attributes found for {} no skin override will be done", person.getUserName());
return null;
}
final Object attributeValue = personAttrs.getAttributeValue(this.skinAttributeName);
if (attributeValue == null) {
logger.debug("No user {} does not have attribute {} defined, no skin override will be done", person.getUserName(), this.skinAttributeName);
return null;
}
final String mappedSkinName = this.getMappedSkinName(attributeValue.toString());
if (mappedSkinName == null) {
logger.debug("No skin is mapped for attribute {}, no skin override will be done", attributeValue);
return null;
}
logger.debug("Overidding skin to {}", mappedSkinName);
return mappedSkinName;
}
use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.
the class UserAccountHelperTest method testMatchingDisplayAttributes.
@Test
public void testMatchingDisplayAttributes() {
final IPersonAttributes person = mock(IPersonAttributes.class);
final Map<String, List<Object>> attributes = new HashMap<String, List<Object>>();
attributes.put("username", Collections.<Object>singletonList("user1"));
attributes.put("user.login.id", Collections.<Object>singletonList("user1"));
when(person.getAttributes()).thenReturn(attributes);
final List<GroupedPersonAttribute> displayed = helper.groupPersonAttributes(person, request);
assertEquals(1, displayed.size());
assertEquals(2, displayed.get(0).getAttributeNames().size());
}
use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.
the class PersonDirectoryUserInfoService method getUserInfo.
/**
* Commons logic to get a subset of the user's attributes for the specified portlet window.
*
* @param remoteUser The user to get attributes for.
* @param httpServletRequest The current, underlying httpServletRequest
* @param portletWindow The window to filter attributes for
* @return A Map of user attributes for the user and windows
* @throws PortletContainerException
*/
protected Map<String, String> getUserInfo(String remoteUser, HttpServletRequest httpServletRequest, IPortletWindow portletWindow) throws PortletContainerException {
//Get the list of user attributes the portal knows about the user
final IPersonAttributes personAttributes = this.personAttributeDao.getPerson(remoteUser);
if (personAttributes == null) {
return Collections.emptyMap();
}
final List<? extends UserAttribute> expectedUserAttributes = this.getExpectedUserAttributes(httpServletRequest, portletWindow);
final Map<String, String> portletUserAttributes = this.generateUserInfo(personAttributes, expectedUserAttributes, httpServletRequest);
return portletUserAttributes;
}
use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.
the class DirectoryPortletController method search2.
@EventMapping(SearchConstants.SEARCH_REQUEST_QNAME_STRING)
public void search2(EventRequest request, EventResponse response) {
// get the search query object from the event
Event event = request.getEvent();
SearchRequest query = (SearchRequest) event.getValue();
// search the portal's directory service for people matching the request
final List<IPersonAttributes> people = searchDirectory(query.getSearchTerms(), request);
if (people.size() > 0) {
// transform the list of directory results into our generic search
// response object
final SearchResults results = new SearchResults();
results.setQueryId(query.getQueryId());
results.setWindowId(request.getWindowID());
for (IPersonAttributes person : people) {
final SearchResult result = new SearchResult();
result.setTitle((String) person.getAttributeValue("displayName"));
result.getType().add(directorySearchResultType);
PortletUrl url = new PortletUrl();
url.setType(PortletUrlType.RENDER);
url.setPortletMode("VIEW");
url.setWindowState("maximized");
PortletUrlParameter actionParam = new PortletUrlParameter();
actionParam.setName("action");
actionParam.getValue().add("findByUsername");
url.getParam().add(actionParam);
PortletUrlParameter usernameParam = new PortletUrlParameter();
usernameParam.setName("username");
usernameParam.getValue().add(person.getName());
url.getParam().add(usernameParam);
result.setPortletUrl(url);
results.getSearchResult().add(result);
}
// fire a search response event
response.setEvent(SearchConstants.SEARCH_RESULTS_QNAME, results);
}
}
use of org.jasig.services.persondir.IPersonAttributes in project uPortal by Jasig.
the class LocalAccountPersonAttributeDao method mapPersonAttributes.
/**
* This implementation uses the result attribute mapping to supplement, rather than replace, the
* attributes returned from the database.
*/
protected IPersonAttributes mapPersonAttributes(final ILocalAccountPerson person) {
final Map<String, List<Object>> mappedAttributes = new LinkedHashMap<String, List<Object>>();
mappedAttributes.putAll(person.getAttributes());
// map the user's username to the portal's username attribute in the
// attribute map
mappedAttributes.put(this.getUsernameAttributeProvider().getUsernameAttribute(), Collections.<Object>singletonList(person.getName()));
// to build one from the first and last name attributes
if (!mappedAttributes.containsKey(displayNameAttribute) || mappedAttributes.get(displayNameAttribute).size() == 0 || StringUtils.isBlank((String) mappedAttributes.get(displayNameAttribute).get(0))) {
final List<Object> firstNames = mappedAttributes.get("givenName");
final List<Object> lastNames = mappedAttributes.get("sn");
final StringBuilder displayName = new StringBuilder();
if (firstNames != null && firstNames.size() > 0) {
displayName.append(firstNames.get(0)).append(" ");
}
if (lastNames != null && lastNames.size() > 0) {
displayName.append(lastNames.get(0));
}
mappedAttributes.put(displayNameAttribute, Collections.<Object>singletonList(displayName.toString()));
}
for (final Map.Entry<String, Set<String>> resultAttrEntry : this.getResultAttributeMapping().entrySet()) {
final String dataKey = resultAttrEntry.getKey();
//Only map found data attributes
if (mappedAttributes.containsKey(dataKey)) {
Set<String> resultKeys = resultAttrEntry.getValue();
//If dataKey has no mapped resultKeys just use the dataKey
if (resultKeys == null) {
resultKeys = Collections.singleton(dataKey);
}
//Add the value to the mapped attributes for each mapped key
final List<Object> value = mappedAttributes.get(dataKey);
for (final String resultKey : resultKeys) {
if (resultKey == null) {
//TODO is this possible?
if (!mappedAttributes.containsKey(dataKey)) {
mappedAttributes.put(dataKey, value);
}
} else if (!mappedAttributes.containsKey(resultKey)) {
mappedAttributes.put(resultKey, value);
}
}
}
}
final IPersonAttributes newPerson;
final String name = person.getName();
if (name != null) {
newPerson = new NamedPersonImpl(name, mappedAttributes);
} else {
final String userNameAttribute = this.getConfiguredUserNameAttribute();
newPerson = new AttributeNamedPersonImpl(userNameAttribute, mappedAttributes);
}
return newPerson;
}
Aggregations