/** * Returns the default avatar, if configured. Otherwise returns null. * * @return the default Avatar, or null */ protected Avatar getDefaultAvatar() { Long defaultAvatarId = avatarManager.getDefaultAvatarId(Avatar.Type.USER); return defaultAvatarId != null ? avatarManager.getById(defaultAvatarId) : null; }
/** * Returns the anonymous avatar, if configured. Otherwise returns null. * * @return the anonymous avatar, or null */ protected Avatar getAnonymousAvatar() { Long anonAvatarId = avatarManager.getAnonymousAvatarId(); return anonAvatarId != null ? avatarManager.getById(anonAvatarId) : null; }
@Override public Avatar getAvatar(final ApplicationUser remoteUser, final long avatarId) { final Avatar currentAvatar = avatarManager.getById(avatarId); final boolean userCanViewAvatar = currentAvatar != null ? policy.userCanViewAvatar(remoteUser, currentAvatar) : false; return userCanViewAvatar ? currentAvatar : null; }
@Nonnull @Override public Avatar getDefaultAvatar() { final Long defaultAvatarId = avatarManager.getDefaultAvatarId(this.type); if (null == defaultAvatarId) { throw new NoSuchElementException("No default avatar id for " + this.type); } final Avatar avatar = avatarManager.getById(defaultAvatarId); if (null == avatar) { throw new NoSuchElementException("No default avatar for " + this.type); } return avatar; }
/** * In some cases getting an id of avatar might return null or throw an Exception. * This method handles this critical path and tries to obtain JIRA specific avatar. */ private Optional<Avatar> getJiraAvatar(final Avatar avatar) { try { final Long avatarId = avatar.getId(); if (avatarId == null) { return Optional.empty(); } else { return Optional.ofNullable(avatarManager.getById(avatarId)); } } catch (Exception e) { log.debug("Could not obtain JIRA avatar.", e); return Optional.empty(); } } }
@Nonnull public Avatar getAvatar() { final AvatarManager avatarManager = ComponentAccessor.getAvatarManager(); final Avatar projectAvatar = avatarManager.getById(getLongFromGV("avatar")); if (null == projectAvatar) { final Long defaultAvatarId = avatarManager.getDefaultAvatarId(Avatar.Type.PROJECT); final Avatar defaultAvatar = avatarManager.getById(defaultAvatarId); if (null == defaultAvatar) { throw new NoSuchElementException("There is no project default avatar - configuration failure!"); } return defaultAvatar; } else { return projectAvatar; } }
/** * Checks that the avatar id is for an existing suitable avatar. * * @param avatarId null or the id of an existing avatar * @param oldProject the project before the update, null if this is a create. * @param errorCollection the errorCollection * @param i18nHelper the I18nHelper */ private void validateAvatarId(final Long avatarId, final Project oldProject, final ErrorCollection errorCollection, final I18nHelper i18nHelper) { if (avatarId == null) { return; } final Avatar avatar = avatarManager.getById(avatarId); if (avatar == null) { errorCollection.addErrorMessage(i18nHelper.getText("admin.errors.avatar.does.not.exist", avatarId), Reason.VALIDATION_FAILED); } else if (!avatar.isSystemAvatar() && !oldProject.getId().toString().equals(avatar.getOwner())) { errorCollection.addErrorMessage(i18nHelper.getText("admin.errors.invalid.avatar")); } }
final Avatar avatar = avatarManager.getById(avatarId); if(avatar == null)
final Avatar avatar = getAvatarManager().getById(realAvatarId); if (avatar == null)
Avatar avatar = avatarManager.getById(id); if (avatar == null)
public void deleteProjectAvatar(final User user, final long avatarId) throws RemoteException { final Avatar avatar = avatarManager.getById(avatarId); // only when the avtatar is system, the owner is null, but we check either since we cannot proceed either way if (avatar == null || avatar.isSystemAvatar() || avatar.getOwner() == null) { throw new RemoteException("No such custom Avatar with id " + avatarId); } Project project = retrieveProjectForAdministration(user, Long.valueOf(avatar.getOwner())); final boolean deletingTheCurrentAvatar = project.getAvatar().getId() == avatarId; if (deletingTheCurrentAvatar) { // deleting the current one need to switch current avatar to default final Long defaultAvatarId = avatarManager.getDefaultAvatarId(Avatar.Type.PROJECT); final com.atlassian.jira.bc.project.ProjectService.UpdateProjectValidationResult updateProjectValidationResult = validateSetAvatar(user, project, defaultAvatarId); if (updateProjectValidationResult.isValid()) { projectService.updateProject(updateProjectValidationResult); avatarManager.delete(avatarId, true); } } else { avatarManager.delete(avatarId, true); } }