Skip to content

Commit

Permalink
Merge pull request #2538 from objectcomputing/bugfix-sonar-next-round
Browse files Browse the repository at this point in the history
Bugfix sonar next round
  • Loading branch information
mkimberlin authored Jul 30, 2024
2 parents 9c2ae3d + 15791fb commit eb29edd
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ public FeedbackRequest update(FeedbackRequestUpdateDTO feedbackRequestUpdateDTO)
boolean submitDateUpdateAttempted = !Objects.equals(originalFeedback.getSubmitDate(), feedbackRequest.getSubmitDate());

// If a status update is made to anything other than submitted by the requestee, throw an error.
if (!feedbackRequest.getStatus().equals("submitted") && !Objects.equals(originalFeedback.getStatus(), feedbackRequest.getStatus())) {
if (currentUserServices.getCurrentUser().getId().equals(originalFeedback.getRequesteeId())) {
throw new PermissionException(NOT_AUTHORIZED_MSG);
}
if (!"submitted".equals(feedbackRequest.getStatus())
&& !Objects.equals(originalFeedback.getStatus(), feedbackRequest.getStatus())
&& currentUserServices.getCurrentUser().getId().equals(originalFeedback.getRequesteeId())) {
throw new PermissionException(NOT_AUTHORIZED_MSG);
}

if (reassignAttempted) {
Expand Down Expand Up @@ -270,7 +270,8 @@ public List<FeedbackRequest> findByValues(UUID creatorId, UUID requesteeId, UUID
}

private boolean isSupervisor(UUID requesteeId, UUID currentUserId) {
return requesteeId != null ? memberProfileServices.getSupervisorsForId(requesteeId).stream().filter(profile -> currentUserId.equals(profile.getId())).findAny().isPresent() : false;
return requesteeId != null
&& memberProfileServices.getSupervisorsForId(requesteeId).stream().anyMatch(profile -> currentUserId.equals(profile.getId()));
}

private boolean createIsPermitted(UUID requesteeId) {
Expand Down Expand Up @@ -313,12 +314,8 @@ private boolean isCurrentUserAdminOrOwner(FeedbackRequest feedbackRequest) {
private boolean updateSubmitDateIsPermitted(FeedbackRequest feedbackRequest) {
boolean isAdmin = currentUserServices.isAdmin();
UUID currentUserId = currentUserServices.getCurrentUser().getId();
if (isAdmin) {
if (isAdmin || (currentUserId.equals(feedbackRequest.getCreatorId()) && feedbackRequest.getSubmitDate() != null)) {
return true;
} else if (currentUserId.equals(feedbackRequest.getCreatorId())) {
if (feedbackRequest.getSubmitDate() != null) {
return true;
}
}

return currentUserId.equals(feedbackRequest.getRecipientId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import io.micronaut.core.annotation.Nullable;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.UUID;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Introspected
public class SkillLevelDTO {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,66 +32,65 @@ public SkillsReportServicesImpl(MemberSkillRepository memberSkillRepo,


public @NotNull SkillsReportResponseDTO report(@NotNull SkillsReportRequestDTO request) {
SkillsReportResponseDTO response = null;
if (request != null) {
final List<SkillLevelDTO> skills = request.getSkills();
final Set<UUID> members = request.getMembers();
final Boolean inclusive = request.isInclusive();

for (SkillLevelDTO skill : skills) {
if (!skillRepo.existsById(skill.getId())) {
throw new BadArgException(String.format("Invalid skill ID %s", skill.getId()));
}
}
final List<SkillLevelDTO> skills = request.getSkills();
final Set<UUID> members = request.getMembers();
final boolean inclusive = Boolean.TRUE.equals(request.isInclusive());

if (members != null) {
for (UUID member : members) {
if (!memberProfileRepo.existsById(member)) {
throw new BadArgException(String.format("Invalid member profile ID %s", member));
}
}
}
validateSkills(skills);
validateMembers(members);

response = new SkillsReportResponseDTO();
SkillsReportResponseDTO response = new SkillsReportResponseDTO();

final List<TeamMemberSkillDTO> potentialMembers = getPotentialQualifyingMembers(skills);
if (members == null || members.isEmpty()) {
if (inclusive == null || !inclusive) {
response.setTeamMembers(potentialMembers);
} else {
final List<TeamMemberSkillDTO> qualifiedMembers = getMembersSatisfyingAllSkills(potentialMembers, skills);
response.setTeamMembers(qualifiedMembers);
}
final List<TeamMemberSkillDTO> potentialMembers = getPotentialQualifyingMembers(skills);
if (members == null || members.isEmpty()) {
if (inclusive) {
response.setTeamMembers(getMembersSatisfyingAllSkills(potentialMembers, skills));
} else {
response.setTeamMembers(potentialMembers);
}
} else {
final List<TeamMemberSkillDTO> membersInList = removeMembersNotRequested(potentialMembers, members);
if (inclusive) {
response.setTeamMembers(getMembersSatisfyingAllSkills(membersInList, skills));
} else {
final List<TeamMemberSkillDTO> membersInList = removeMembersNotRequested(potentialMembers, members);
if (inclusive == null || !inclusive) {
response.setTeamMembers(membersInList);
} else {
final List<TeamMemberSkillDTO> qualifiedMembers = getMembersSatisfyingAllSkills(membersInList, skills);
response.setTeamMembers(qualifiedMembers);
response.setTeamMembers(membersInList);
}
}
return response;
}

private void validateMembers(Set<UUID> members) {
if (members != null) {
for (UUID member : members) {
if (!memberProfileRepo.existsById(member)) {
throw new BadArgException(String.format("Invalid member profile ID %s", member));
}
}
}
}

return response;
private void validateSkills(List<SkillLevelDTO> skills) {
for (SkillLevelDTO skill : skills) {
if (!skillRepo.existsById(skill.getId())) {
throw new BadArgException(String.format("Invalid skill ID %s", skill.getId()));
}
}
}

private List<TeamMemberSkillDTO> getPotentialQualifyingMembers(List<SkillLevelDTO> skills) {
// Get all member_skill entries that satisfy a requested skill
final List<MemberSkill> entries = new ArrayList<>();
List<MemberSkill> entries = new ArrayList<>();

for (SkillLevelDTO skill : skills) {
if (skill.getId() == null) {
throw new BadArgException("Invalid requested skill ID");
}

final List<MemberSkill> temp = memberSkillRepo.findBySkillid(skill.getId());
if (skill.getLevel() != null && temp.size() > 0) {
if (skill.getLevel() != null && !temp.isEmpty()) {
for (MemberSkill memSkill : temp) {
if (memSkill.getSkilllevel() != null) {
if (isSkillLevelSatisfied(memSkill.getSkilllevel(), skill.getLevel())) {
entries.add(memSkill);
}
if (memSkill.getSkilllevel() != null && isSkillLevelSatisfied(memSkill.getSkilllevel(), skill.getLevel())) {
entries.add(memSkill);
}
}
} else {
Expand All @@ -101,33 +100,29 @@ private List<TeamMemberSkillDTO> getPotentialQualifyingMembers(List<SkillLevelDT
}

// Collect all entries belong to each team member
final HashMap<UUID, TeamMemberSkillDTO> map = collectEntries(entries);

return new ArrayList<>(map.values());
}

private HashMap<UUID, TeamMemberSkillDTO> collectEntries(List<MemberSkill> entries) {
final HashMap<UUID, TeamMemberSkillDTO> map = new HashMap<>();

for (MemberSkill ms : entries) {
final UUID memberId = ms.getMemberid();
final SkillLevelDTO skill = new SkillLevelDTO();
skill.setId(ms.getSkillid());
skill.setLevel(SkillLevel.convertFromString(ms.getSkilllevel()));

if (map.containsKey(memberId)) {
final TeamMemberSkillDTO dto = map.get(memberId);
dto.getSkills().add(skill);
} else {
final TeamMemberSkillDTO dto = new TeamMemberSkillDTO();
dto.setId(memberId);

final MemberProfile memProfile = memberProfileServices.getById(memberId);
final String memberName = MemberProfileUtils.getFullName(memProfile);
dto.setName(memberName);

final List<SkillLevelDTO> memberSkills = new ArrayList<>();
memberSkills.add(skill);
dto.setSkills(memberSkills);
final SkillLevelDTO skill = new SkillLevelDTO(ms.getSkillid(), SkillLevel.convertFromString(ms.getSkilllevel()));

map.put(memberId, dto);
}
var dto = map.computeIfAbsent(memberId, mId ->
new TeamMemberSkillDTO(
mId,
MemberProfileUtils.getFullName(memberProfileServices.getById(mId)),
new ArrayList<>()
)
);
dto.getSkills().add(skill);
}

return new ArrayList<>(map.values());
return map;
}

private List<TeamMemberSkillDTO> getMembersSatisfyingAllSkills(List<TeamMemberSkillDTO> potentialMembers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import io.micronaut.core.annotation.Nullable;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;
Expand All @@ -13,7 +15,10 @@
@Getter
@Setter
@Introspected
@AllArgsConstructor
@NoArgsConstructor
public class TeamMemberSkillDTO {

@NotNull
@Schema(description = "UUID of the team member profile")
private UUID id;
Expand All @@ -25,6 +30,5 @@ public class TeamMemberSkillDTO {
@NotNull
@Schema(description = "Skills of the team member")
private List<SkillLevelDTO> skills;

}

Loading

0 comments on commit eb29edd

Please sign in to comment.