use of io.milton.ldap.LdapPropertyMapper.LdapMappedProp in project lobcder by skoulouzis.
the class SearchRunnable method sendPersons.
private void sendPersons(int currentMessageId, String baseContext, Set<LdapContact> persons, Set<String> returningAttributes) throws IOException, NotAuthorizedException, BadRequestException {
LogUtils.debug(log, "sendPersons", baseContext, "size:", persons.size());
boolean needObjectClasses = returningAttributes.contains("objectclass") || returningAttributes.isEmpty();
boolean returnAllAttributes = returningAttributes.isEmpty();
if (persons.isEmpty()) {
log.warn("No contacts to send! -------------------");
}
for (LdapContact person : persons) {
if (abandon) {
log.warn("Abandon flag is set, so exiting send!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
break;
}
Map<String, Object> response = new HashMap<String, Object>();
Set<LdapMappedProp> props = propertyMapper.mapProperties(returnAllAttributes, returningAttributes, person);
response.put("uid", person.getName());
for (LdapMappedProp prop : props) {
ValueAndType vt;
try {
vt = propertyMapper.getProperty(prop.mappedName, person);
} catch (NotAuthorizedException ex) {
vt = null;
}
if (vt == null) {
LogUtils.trace(log, "sendPersons: property not found: ldap property: ", prop.ldapName, " - dav prop: ", prop.mappedName, "resource: ", person.getClass());
} else {
if (vt.getValue() != null) {
response.put(prop.ldapName, vt.getValue());
}
}
}
// Process all attributes which have static mappings
for (Map.Entry<String, String> entry : Ldap.STATIC_ATTRIBUTE_MAP.entrySet()) {
String ldapAttribute = entry.getKey();
String value = entry.getValue();
if (value != null && (returnAllAttributes || returningAttributes.contains(ldapAttribute))) {
response.put(ldapAttribute, value);
}
}
if (needObjectClasses) {
response.put("objectClass", Ldap.PERSON_OBJECT_CLASSES);
}
// iCal: copy email to apple-generateduid, encode @
if (returnAllAttributes || returningAttributes.contains("apple-generateduid")) {
String mail = (String) response.get("mail");
if (mail != null) {
response.put("apple-generateduid", mail.replaceAll("@", "__AT__"));
} else {
// failover, should not happen
// failover, should not happen
response.put("apple-generateduid", response.get("uid"));
}
}
// iCal: replace current user alias with login name
if (user.getName().equals(response.get("uid"))) {
if (returningAttributes.contains("uidnumber")) {
response.put("uidnumber", user.getName());
}
}
LogUtils.debug(log, "LOG_LDAP_REQ_SEARCH_SEND_PERSON", currentMessageId, response.get("uid"), baseContext, response);
responseHandler.sendEntry(currentMessageId, "uid=" + response.get("uid") + baseContext, response);
}
}
Aggregations