Skip to content

Commit

Permalink
Add logging when looking up users.
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierdagenais committed Oct 16, 2013
1 parent afd7ffb commit 509c497
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/main/java/hudson/plugins/tfs/model/TfsUserLookup.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hudson.plugins.tfs.model;

import java.io.IOException;
import java.util.logging.Logger;

import com.microsoft.tfs.core.clients.webservices.IIdentityManagementService;
import com.microsoft.tfs.core.clients.webservices.IdentitySearchFactor;
Expand All @@ -13,6 +14,8 @@

public class TfsUserLookup implements UserLookup {

private static final Logger LOGGER = Logger.getLogger(TfsUserLookup.class.getName());

private final IIdentityManagementService ims;

public TfsUserLookup(IIdentityManagementService ims) {
Expand All @@ -23,9 +26,10 @@ public TfsUserLookup(IIdentityManagementService ims) {
* @param accountName Windows NT account name: domain\alias.
*/
public User find(String accountName) {
LOGGER.fine("Looking up Jenkins user for TFS account '%s'.");
final User jenkinsUser = User.get(accountName);
Mailer.UserProperty mailerProperty = jenkinsUser.getProperty(Mailer.UserProperty.class);
if (mailerProperty == null || mailerProperty.getAddress() == null) {
if (mailerProperty == null || mailerProperty.getAddress() == null || mailerProperty.getAddress().length() == 0) {
final TeamFoundationIdentity tfsUser = ims.readIdentity(
IdentitySearchFactor.ACCOUNT_NAME,
accountName,
Expand All @@ -36,15 +40,20 @@ public User find(String accountName) {
final String displayName = tfsUser.getDisplayName();
jenkinsUser.setFullName(displayName);
final String emailAddress = (String) tfsUser.getProperty("Mail");
// TODO: What should we do if an e-mail address is not configured? Send to a default account??
if (emailAddress != null) {
mailerProperty = new Mailer.UserProperty(emailAddress);
try {
jenkinsUser.addProperty(mailerProperty);
} catch (IOException e) {
// ignore
LOGGER.warning(String.format("Unable to save Jenkins account for TFS user '%s'.", accountName));
}
}
else {
LOGGER.info(String.format("TFS user '%s' did not have an e-mail address configured.", accountName));
}
}
else {
LOGGER.warning(String.format("Unable to find TFS user '%s'.", accountName));
}
}
return jenkinsUser;
Expand Down

0 comments on commit 509c497

Please sign in to comment.