use of hudson.model.Cause.UserIdCause in project promoted-builds-plugin by jenkinsci.
the class Promotion method getUserId.
/**
* Gets ID of the {@link User}, who triggered the promotion.
* The method tries various sources like {@link UserIdCause} or {@link ManualCondition.Badge}.
* @return ID of the user who triggered the promotion.
* If the search fails, returns ID of {@link User#getUnknown()}.
* @since 2.22
*/
@Nonnull
public String getUserId() {
// Deprecated, but we still want to support it in order to maintain the compatiibility
// We try to convert the cause to the user ID by using a search by the full name, not reliable
final UserCause userCause = getCause(UserCause.class);
final String nameFromUserCause = userCause != null ? userCause.getUserName() : null;
final User user = nameFromUserCause != null ? User.get(nameFromUserCause, false, null) : null;
if (user != null) {
return user.getId();
}
// Modern UserIdCause
final UserIdCause userIdCause = getCause(UserIdCause.class);
final String idFromUserIdCause = userIdCause != null ? userIdCause.getUserId() : null;
if (idFromUserIdCause != null) {
return idFromUserIdCause;
}
//fallback to badge lookup for compatibility
for (PromotionBadge badget : getStatus().getBadges()) {
if (badget instanceof ManualCondition.Badge) {
final String idFromBadge = ((ManualCondition.Badge) badget).getUserId();
if (!idFromBadge.equals(ManualCondition.MISSING_USER_ID_DISPLAY_STRING)) {
return idFromBadge;
}
}
}
return User.getUnknown().getId();
}
use of hudson.model.Cause.UserIdCause in project promoted-builds-plugin by jenkinsci.
the class Promotion method getUserName.
/**
* Get a user name of the person, who triggered the promotion.
* The method tries various sources like {@link UserIdCause} or {@link ManualCondition.Badge}.
* @return user's name who triggered the promotion, or 'anonymous' if the search fails
*/
@Nonnull
public String getUserName() {
// Deprecated, but we still want to support it in order to maintain the compatiibility
final UserCause userCause = getCause(UserCause.class);
final String nameFromUserCause = userCause != null ? userCause.getUserName() : null;
if (nameFromUserCause != null) {
return nameFromUserCause;
}
// Modern UserIdCause
final UserIdCause userIdCause = getCause(UserIdCause.class);
final String nameFromUserIdCause = userIdCause != null ? userIdCause.getUserName() : null;
if (nameFromUserIdCause != null) {
return nameFromUserIdCause;
}
//fallback to badge lookup for compatibility
for (PromotionBadge badget : getStatus().getBadges()) {
if (badget instanceof ManualCondition.Badge) {
final String nameFromBadge = ((ManualCondition.Badge) badget).getUserName();
if (!nameFromBadge.equals(ManualCondition.MISSING_USER_ID_DISPLAY_STRING)) {
return nameFromBadge;
}
}
}
return Jenkins.ANONYMOUS.getName();
}
Aggregations