Skip to content

Commit

Permalink
Merge pull request #2599 from objectcomputing/chore-sonar/use-logging…
Browse files Browse the repository at this point in the history
…-formatters

[chore] More low-hanging Sonar fruit
  • Loading branch information
mkimberlin authored Sep 20, 2024
2 parents 9a81338 + 870bc7f commit b15f93c
Show file tree
Hide file tree
Showing 32 changed files with 72 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.MutableHttpResponse;
import io.micronaut.http.annotation.*;
import io.micronaut.http.annotation.Consumes;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Post;
import io.micronaut.http.annotation.Produces;
import io.micronaut.http.cookie.Cookie;
import io.micronaut.http.cookie.SameSite;
import io.micronaut.http.netty.cookies.NettyCookie;
Expand All @@ -25,12 +29,16 @@
import io.micronaut.security.event.LoginSuccessfulEvent;
import io.micronaut.security.handlers.LoginHandler;
import io.micronaut.security.rules.SecurityRule;
import io.micronaut.security.utils.SecurityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@Requires(env = {Environments.LOCAL, Environment.DEVELOPMENT})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.objectcomputing.checkins.Environments;
import com.objectcomputing.checkins.services.memberprofile.MemberProfile;
import com.objectcomputing.checkins.services.memberprofile.currentuser.CurrentUserServices;
import com.objectcomputing.checkins.security.ImpersonationController;
import io.micronaut.http.MutableHttpResponse;
import io.micronaut.http.netty.cookies.NettyCookie;
import io.micronaut.context.annotation.Requires;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package com.objectcomputing.checkins.services.agenda_item;

import com.objectcomputing.checkins.exceptions.NotFoundException;
import com.objectcomputing.checkins.services.checkins.CheckIn;
import com.objectcomputing.checkins.services.permissions.Permission;
import com.objectcomputing.checkins.services.permissions.RequiredPermission;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.annotation.*;
import io.micronaut.http.annotation.Body;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Delete;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Post;
import io.micronaut.http.annotation.Put;
import io.micronaut.http.annotation.Status;
import io.micronaut.http.uri.UriBuilder;
import io.micronaut.scheduling.TaskExecutors;
import io.micronaut.scheduling.annotation.ExecuteOn;
Expand All @@ -16,7 +23,6 @@
import jakarta.validation.Valid;

import java.net.URI;
import java.util.List;
import java.util.Set;
import java.util.UUID;

Expand Down Expand Up @@ -52,7 +58,7 @@ HttpResponse<AgendaItem> createAgendaItem(@Body @Valid AgendaItemCreateDTO agend
* Update a agenda item
*
* @param agendaItem, {@link AgendaItem}
* @return {@link HttpResponse< AgendaItem >}
* @return {@link HttpResponse<AgendaItem>}
*/
@Put("/")
@RequiredPermission(Permission.CAN_UPDATE_CHECKINS)
Expand All @@ -72,7 +78,7 @@ HttpResponse<?> updateAgendaItem(@Body @Valid AgendaItem agendaItem) {
*
* @param checkinid {@link UUID} of checkin
* @param createdbyid {@link UUID} of member
* @return {@link List <CheckIn > list of checkins
* @return a Set of {@link CheckIn}
*/
@Get("/{?checkinid,createdbyid}")
@RequiredPermission(Permission.CAN_VIEW_CHECKINS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.objectcomputing.checkins.services.memberprofile.MemberProfileRepository;
import com.objectcomputing.checkins.services.memberprofile.currentuser.CurrentUserServices;
import com.objectcomputing.checkins.services.permissions.Permission;
import com.objectcomputing.checkins.services.role.RoleServices;
import com.objectcomputing.checkins.services.role.role_permissions.RolePermissionServices;
import com.objectcomputing.checkins.util.Util;
import jakarta.inject.Singleton;
Expand All @@ -32,17 +31,15 @@ public class CheckInServicesImpl implements CheckInServices {
private final CheckInRepository checkinRepo;
private final MemberProfileRepository memberRepo;
private final CurrentUserServices currentUserServices;
private final RoleServices roleServices;
private final RolePermissionServices rolePermissionServices;

public CheckInServicesImpl(CheckInRepository checkinRepo,
MemberProfileRepository memberRepo,
CurrentUserServices currentUserServices,
RoleServices roleServices, RolePermissionServices rolePermissionServices) {
RolePermissionServices rolePermissionServices) {
this.checkinRepo = checkinRepo;
this.memberRepo = memberRepo;
this.currentUserServices = currentUserServices;
this.roleServices = roleServices;
this.rolePermissionServices = rolePermissionServices;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public List<Email> sendAndSaveEmail(String subject, String content, boolean html
Email savedEmail = emailRepository.save(email);
sentEmails.add(savedEmail);
} else {
LOG.warn(String.format("Prevented sending email to terminated member: %s", recipientEmail));
LOG.warn("Prevented sending email to terminated member: {}", recipientEmail);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.objectcomputing.checkins.exceptions.BadArgException;
import com.objectcomputing.checkins.services.memberprofile.MemberProfile;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileRepository;
import com.objectcomputing.checkins.services.memberprofile.currentuser.CurrentUserServices;
import com.objectcomputing.checkins.services.memberprofile.memberphoto.MemberPhotoServiceImpl;
import io.micronaut.http.multipart.CompletedFileUpload;
Expand All @@ -24,16 +23,11 @@ public class EmployeeHoursServicesImpl implements EmployeeHoursServices{

private static final Logger LOG = LoggerFactory.getLogger(MemberPhotoServiceImpl.class);

private final MemberProfileRepository memberRepo;
private final CurrentUserServices currentUserServices;
private final EmployeeHoursRepository employeehourRepo;



public EmployeeHoursServicesImpl(MemberProfileRepository memberRepo,
CurrentUserServices currentUserServices,
public EmployeeHoursServicesImpl(CurrentUserServices currentUserServices,
EmployeeHoursRepository employeehourRepo) {
this.memberRepo = memberRepo;
this.currentUserServices = currentUserServices;
this.employeehourRepo = employeehourRepo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public List<FeedbackAnswer> findByValues(@Nullable UUID questionId, @Nullable UU
final UUID requestCreatorId = feedbackRequest.getCreatorId();
final UUID requesteeId = feedbackRequest.getRequesteeId();
final UUID recipientId = feedbackRequest.getRecipientId();
boolean isRequesteesSupervisor = requesteeId != null ? memberProfileServices.getSupervisorsForId(requesteeId).stream().filter(profile -> currentUserId.equals(profile.getId())).findAny().isPresent() : false;
boolean isRequesteesSupervisor = requesteeId != null ? memberProfileServices.getSupervisorsForId(requesteeId).stream().anyMatch(profile -> currentUserId.equals(profile.getId())) : false;
MemberProfile requestee = memberProfileServices.getById(requesteeId);
final UUID requesteePDL = requestee.getPdlId();
if (currentUserServices.isAdmin() || currentUserId.equals(requesteePDL) || isRequesteesSupervisor || requestCreatorId.equals(currentUserId) || recipientId.equals(currentUserId)) {
Expand Down Expand Up @@ -151,7 +151,7 @@ public boolean getIsPermitted(FeedbackRequest feedbackRequest) {
MemberProfile requestee = memberProfileServices.getById(requesteeId);
final UUID currentUserId = currentUserServices.getCurrentUser().getId();
final UUID recipientId = feedbackRequest.getRecipientId();
boolean isRequesteesSupervisor = requesteeId != null ? memberProfileServices.getSupervisorsForId(requesteeId).stream().filter(profile -> currentUserId.equals(profile.getId())).findAny().isPresent() : false;
boolean isRequesteesSupervisor = requesteeId != null ? memberProfileServices.getSupervisorsForId(requesteeId).stream().anyMatch(profile -> currentUserId.equals(profile.getId())) : false;
final UUID requesteePDL = requestee.getPdlId();

return isAdmin || currentUserId.equals(requesteePDL) || isRequesteesSupervisor || requestCreatorId.equals(currentUserId) || recipientId.equals(currentUserId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public boolean getIsPermitted(FeedbackRequest feedbackRequest) {
MemberProfile requestee = memberProfileServices.getById(requesteeId);
final UUID currentUserId = currentUserServices.getCurrentUser().getId();
final UUID recipientId = feedbackRequest.getRecipientId();
boolean isRequesteesSupervisor = requesteeId != null ? memberProfileServices.getSupervisorsForId(requesteeId).stream().filter(profile -> currentUserId.equals(profile.getId())).findAny().isPresent() : false;
boolean isRequesteesSupervisor = requesteeId != null ? memberProfileServices.getSupervisorsForId(requesteeId).stream().anyMatch(profile -> currentUserId.equals(profile.getId())) : false;
final UUID requesteePDL = requestee.getPdlId();

return isAdmin || currentUserId.equals(requesteePDL) || isRequesteesSupervisor || requestCreatorId.equals(currentUserId) || recipientId.equals(currentUserId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.time.LocalDate;
Expand All @@ -36,8 +34,6 @@
@Tag(name = "feedback request")
public class FeedbackRequestController {

private static final Logger LOG = LoggerFactory.getLogger(FeedbackRequestController.class);

private final FeedbackRequestServices feedbackReqServices;

public FeedbackRequestController(FeedbackRequestServices feedbackReqServices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import static com.objectcomputing.checkins.services.validate.PermissionsValidation.NOT_AUTHORIZED_MSG;

Expand Down Expand Up @@ -264,7 +263,7 @@ public List<FeedbackRequest> findByValues(UUID creatorId, UUID requesteeId, UUID
if (currentUserId.equals(request.getRecipientId())) visible = true;
}
return visible;
}).collect(Collectors.toList());
}).toList();

return feedbackReqList;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.objectcomputing.checkins.services.guild;

import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.HttpResponse;
Expand Down Expand Up @@ -32,11 +31,9 @@
public class GuildController {

private final GuildServices guildService;
private final MemberProfileServices profileServices;

public GuildController(GuildServices guildService, MemberProfileServices profileServices) {
public GuildController(GuildServices guildService) {
this.guildService = guildService;
this.profileServices = profileServices;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public GuildResponseDTO update(GuildUpdateDTO guildDTO) {

//delete any removed members from guild
existingGuildMembers.forEach(existingMember -> {
if(!guildDTO.getGuildMembers().stream().filter(updatedTeamMember -> updatedTeamMember.getMemberId().equals(existingMember.getMemberId())).findFirst().isPresent()) {
if(guildDTO.getGuildMembers().stream().noneMatch(updatedTeamMember -> updatedTeamMember.getMemberId().equals(existingMember.getMemberId()))) {
guildMemberServices.delete(existingMember.getId(), false);
removedMembers.add(memberProfileServices.getById(existingMember.getMemberId()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.objectcomputing.checkins.services.permissions.Permission;
import com.objectcomputing.checkins.services.permissions.RequiredPermission;
import com.objectcomputing.checkins.services.role.RoleType;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.annotation.Body;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.objectcomputing.checkins.services.kudos;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.objectcomputing.checkins.services.memberprofile.MemberProfile;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.core.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private void sendNotification(Kudos kudos, NotificationType notificationType) {
// Send email to receivers of kudos that they have new kudos...
MemberProfile sender = memberProfileRetrievalServices.getById(kudos.getSenderId()).orElse(null);
if (sender == null) {
LOG.error(String.format("Unable to locate member %s.", kudos.getSenderId().toString()));
LOG.error("Unable to locate member {}", kudos.getSenderId());
} else {
String fromEmail = sender.getWorkEmail();
String fromName = sender.getFirstName() + " " + sender.getLastName();
Expand All @@ -336,7 +336,7 @@ private void sendNotification(Kudos kudos, NotificationType notificationType) {
for (KudosRecipient kudosRecipient : recipients) {
MemberProfile member = memberProfileRetrievalServices.getById(kudosRecipient.getMemberId()).orElse(null);
if (member == null) {
LOG.error(String.format("Unable to locate member %s.", kudosRecipient.getMemberId().toString()));
LOG.error("Unable to locate member {}", kudosRecipient.getMemberId());
} else {
recipientAddresses.add(member.getWorkEmail());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.objectcomputing.checkins.services.kudos.kudos_recipient;

import com.objectcomputing.checkins.configuration.CheckInsConfiguration;
import com.objectcomputing.checkins.notifications.email.EmailSender;
import com.objectcomputing.checkins.notifications.email.MailJetFactory;
import com.objectcomputing.checkins.exceptions.BadArgException;
Expand All @@ -17,7 +16,6 @@
import org.slf4j.LoggerFactory;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

Expand All @@ -32,20 +30,17 @@ public class KudosRecipientServicesImpl implements KudosRecipientServices {
private final KudosRepository kudosRepository;
private final MemberProfileRetrievalServices memberProfileRetrievalServices;
private final EmailSender emailSender;
private final CheckInsConfiguration checkInsConfiguration;

public KudosRecipientServicesImpl(KudosRecipientRepository kudosRecipientRepository,
CurrentUserServices currentUserServices,
KudosRepository kudosRepository,
MemberProfileRetrievalServices memberProfileRetrievalServices,
@Named(MailJetFactory.HTML_FORMAT) EmailSender emailSender,
CheckInsConfiguration checkInsConfiguration) {
@Named(MailJetFactory.HTML_FORMAT) EmailSender emailSender) {
this.kudosRecipientRepository = kudosRecipientRepository;
this.currentUserServices = currentUserServices;
this.kudosRepository = kudosRepository;
this.memberProfileRetrievalServices = memberProfileRetrievalServices;
this.emailSender = emailSender;
this.checkInsConfiguration = checkInsConfiguration;
}

@Override
Expand Down Expand Up @@ -87,7 +82,7 @@ private void sendNotification(Kudos kudos, MemberProfile member) {
// This is a private kudos, so notify the receiver directly.
MemberProfile sender = memberProfileRetrievalServices.getById(kudos.getSenderId()).orElse(null);
if (sender == null) {
LOG.error(String.format("Unable to locate member %s.", kudos.getSenderId().toString()));
LOG.error("Unable to locate member {}", kudos.getSenderId());
} else {
String fromEmail = sender.getWorkEmail();
String fromName = sender.getFirstName() + " " + sender.getLastName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import com.objectcomputing.checkins.exceptions.BadArgException;
import com.objectcomputing.checkins.services.member_skill.MemberSkill;
import com.objectcomputing.checkins.services.member_skill.MemberSkillRepository;
import com.objectcomputing.checkins.services.memberprofile.MemberProfile;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileRepository;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileUtils;
import com.objectcomputing.checkins.services.skills.SkillRepository;
import jakarta.inject.Singleton;
import jakarta.validation.constraints.NotNull;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.UUID;

@Singleton
public class SkillsReportServicesImpl implements SkillsReportServices {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.util.List;
Expand All @@ -33,7 +31,6 @@
@Tag(name = "member profiles")
public class MemberProfileController {

private static final Logger LOG = LoggerFactory.getLogger(MemberProfileController.class);
private final MemberProfileServices memberProfileServices;

public MemberProfileController(MemberProfileServices memberProfileServices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public MemberProfile saveProfile(MemberProfile memberProfile) {
Optional<MemberProfile> existingProfileOpt = memberProfileRepository.findById(memberProfile.getId());
MemberProfile updatedMemberProfile = memberProfileRepository.update(memberProfile);
if (existingProfileOpt.isEmpty()) {
LOG.error(String.format("MemberProfile with id %s not found", memberProfile.getId()));
LOG.error("MemberProfile with id {} not found", memberProfile.getId());
} else {
MemberProfile existingProfile = existingProfileOpt.get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.objectcomputing.checkins.services.memberprofile.currentuser.CurrentUserServices;
import io.micronaut.core.annotation.Nullable;
import jakarta.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.RoundingMode;
import java.text.DecimalFormat;
Expand All @@ -18,7 +16,7 @@

@Singleton
public class AnniversaryReportServicesImpl implements AnniversaryServices {
private static final Logger LOG = LoggerFactory.getLogger(AnniversaryReportServicesImpl.class);

private final MemberProfileServices memberProfileServices;
private final CurrentUserServices currentUserServices;

Expand Down
Loading

0 comments on commit b15f93c

Please sign in to comment.