Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
public interface MemberProfileServices {
MemberProfile getById(UUID id);

MemberProfile findByWorkEmail(@NotNull String workEmail);

Set<MemberProfile> findByValues(String firstName, String lastName, String title,
UUID pdlId, String workEmail, UUID supervisorId, Boolean terminated);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.objectcomputing.checkins.services.role.RoleServices;
import com.objectcomputing.checkins.services.team.member.TeamMemberServices;
import io.micronaut.cache.annotation.CacheConfig;
import io.micronaut.cache.annotation.CacheInvalidate;
import io.micronaut.cache.annotation.Cacheable;
import io.micronaut.core.annotation.Nullable;
import jakarta.inject.Named;
Expand Down Expand Up @@ -55,6 +56,7 @@ public MemberProfileServicesImpl(MemberProfileRepository memberProfileRepository
}

@Override
@Cacheable
public MemberProfile getById(@NotNull UUID id) {
Optional<MemberProfile> optional = memberProfileRepository.findById(id);
if (optional.isEmpty()) {
Expand All @@ -67,6 +69,14 @@ public MemberProfile getById(@NotNull UUID id) {
return memberProfile;
}

@Cacheable
@Override
public MemberProfile findByWorkEmail(@NotNull String workEmail) {
return memberProfileRepository.findByWorkEmail(workEmail).orElseThrow(() ->
new NotFoundException("Member not found")
);
}

@Override
public Set<MemberProfile> findByValues(@Nullable String firstName,
@Nullable String lastName,
Expand All @@ -86,6 +96,7 @@ public Set<MemberProfile> findByValues(@Nullable String firstName,
}

@Override
@CacheInvalidate(cacheNames = {"member-cache"})
public MemberProfile saveProfile(MemberProfile memberProfile) {
MemberProfile emailProfile = memberProfileRepository.findByWorkEmail(memberProfile.getWorkEmail()).orElse(null);

Expand Down Expand Up @@ -152,6 +163,7 @@ public void emailAssignment(MemberProfile member, boolean isPDL) {
}

@Override
@CacheInvalidate(cacheNames = {"member-cache"})
public boolean deleteProfile(@NotNull UUID id) {
if (!currentUserServices.isAdmin()) {
throw new PermissionException("Requires admin privileges");
Expand Down Expand Up @@ -183,6 +195,7 @@ public boolean deleteProfile(@NotNull UUID id) {
}

@Override
@Cacheable(parameters = {"firstName", "lastName"})
public MemberProfile findByName(@NotNull String firstName, @NotNull String lastName) {
List<MemberProfile> searchResult = memberProfileRepository.search(firstName, null, lastName,
null, null, null, null, null, null);
Expand Down Expand Up @@ -222,6 +235,7 @@ public List<MemberProfile> getSubordinatesForId(UUID id) {
}

@Override
@CacheInvalidate(cacheNames = {"member-cache"})
public MemberProfile updateProfile(MemberProfile memberProfile) {
return memberProfileRepository.update(memberProfile);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.objectcomputing.checkins.services.reports;

import com.objectcomputing.checkins.services.memberprofile.MemberProfileRepository;
import com.objectcomputing.checkins.exceptions.BadArgException;

import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;

Expand All @@ -18,7 +18,7 @@

abstract class CSVProcessor {

public void load(MemberProfileRepository memberProfileRepository,
public void load(MemberProfileServices memberProfileServices,
ByteBuffer dataSource) throws IOException,
BadArgException {
ByteArrayInputStream stream = new ByteArrayInputStream(dataSource.array());
Expand All @@ -30,10 +30,10 @@ public void load(MemberProfileRepository memberProfileRepository,
.setNullString("")
.build()
.parse(input);
loadImpl(memberProfileRepository, csvParser);
loadImpl(memberProfileServices, csvParser);
}

protected abstract void loadImpl(MemberProfileRepository memberProfileRepository, CSVParser csvParser) throws BadArgException;
protected abstract void loadImpl(MemberProfileServices memberProfileServices, CSVParser csvParser) throws BadArgException;

protected LocalDate parseDate(String date) {
List<String> formatStrings = List.of("yyyy", "M/d/yyyy");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.objectcomputing.checkins.services.reports;

import com.objectcomputing.checkins.exceptions.NotFoundException;
import com.objectcomputing.checkins.services.memberprofile.MemberProfile;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileRepository;
import com.objectcomputing.checkins.exceptions.BadArgException;

import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices;
import io.micronaut.core.annotation.Introspected;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
Expand All @@ -12,10 +13,7 @@
import org.slf4j.LoggerFactory;

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

public class CompensationHistory extends CSVProcessor {

Expand All @@ -32,41 +30,39 @@ public record Compensation(
private final List<Compensation> history = new ArrayList<>();

@Override
protected void loadImpl(MemberProfileRepository memberProfileRepository,
protected void loadImpl(MemberProfileServices memberProfileServices,
CSVParser csvParser) throws BadArgException {
history.clear();
for (CSVRecord csvRecord : csvParser) {
try {
String emailAddress = csvRecord.get("emailAddress");
Optional<MemberProfile> memberProfile =
memberProfileRepository.findByWorkEmail(emailAddress);
if (memberProfile.isPresent()) {
String startDate = csvRecord.get("startDate");
LocalDate date = parseDate(startDate);
if (date == null) {
LOG.error("Unable to parse date: {}", startDate);
} else {
String value = csvRecord.get("compensation");
Compensation comp = new Compensation(
memberProfile.get().getId(),
date,
value == null ? null : value.replaceAll("[^\\d\\.,]", ""),
csvRecord.get("totalComp")
);
history.add(comp);
history.clear();
for (CSVRecord csvRecord : csvParser) {
String emailAddress = null;
try {
emailAddress = csvRecord.get("emailAddress");
MemberProfile memberProfile = memberProfileServices.findByWorkEmail(emailAddress);
String startDate = csvRecord.get("startDate");
LocalDate date = parseDate(startDate);
if (date == null) {
LOG.error("Unable to parse date: {}", startDate);
} else {
String value = csvRecord.get("compensation");
Compensation comp = new Compensation(
memberProfile.getId(),
date,
value == null ? null : value.replaceAll("[^\\d\\.,]", ""),
csvRecord.get("totalComp")
);
history.add(comp);
}
} catch (NotFoundException nfe) {
LOG.error("Unable to find a profile for {}", emailAddress);
} catch (IllegalArgumentException ex) {
throw new BadArgException("Unable to parse the compensation history");
}
} else {
LOG.error("Unable to find a profile for {}", emailAddress);
}
} catch(IllegalArgumentException ex) {
throw new BadArgException("Unable to parse the compensation history");
}
}
}

public List<Compensation> getHistory(UUID memberId) {
return history.stream()
.filter(entry -> entry.memberId().equals(memberId))
.toList();
return history.stream()
.filter(entry -> entry.memberId().equals(memberId))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,66 @@

import com.objectcomputing.checkins.exceptions.NotFoundException;
import com.objectcomputing.checkins.services.memberprofile.MemberProfile;
import com.objectcomputing.checkins.services.memberprofile.MemberProfileRepository;
import com.objectcomputing.checkins.exceptions.BadArgException;

import com.objectcomputing.checkins.services.memberprofile.MemberProfileServices;
import io.micronaut.core.annotation.Introspected;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.Optional;
import java.util.*;

public class CurrentInformation extends CSVProcessor {

@Introspected
public record Information(
UUID memberId,
float salary,
String range,
String nationalRange,
String biography,
String commitments
) {
}
@Introspected
public record Information(
UUID memberId,
float salary,
String range,
String nationalRange,
String biography,
String commitments
) {
}

private static final Logger LOG = LoggerFactory.getLogger(CurrentInformation.class);
private final List<Information> information = new ArrayList<>();
private static final Logger LOG = LoggerFactory.getLogger(CurrentInformation.class);
private final List<Information> information = new ArrayList<>();

@Override
protected void loadImpl(MemberProfileRepository memberProfileRepository,
CSVParser csvParser) throws BadArgException {
information.clear();
for (CSVRecord csvRecord : csvParser) {
try {
String emailAddress = csvRecord.get("emailAddress");
Optional<MemberProfile> memberProfile =
memberProfileRepository.findByWorkEmail(emailAddress);
if (memberProfile.isPresent()) {
Information comp = new Information(
memberProfile.get().getId(),
Float.parseFloat(csvRecord.get("salary")
.replaceAll("[^\\d\\.,]", "")),
csvRecord.get("range"),
csvRecord.get("nationalRange"),
csvRecord.get("biography"),
csvRecord.get("commitments")
);
information.add(comp);
} else {
LOG.error("Unable to find a profile for {}", emailAddress);
@Override
protected void loadImpl(MemberProfileServices memberProfileServices,
CSVParser csvParser) throws BadArgException {
information.clear();
for (CSVRecord csvRecord : csvParser) {
String emailAddress = null;
try {
emailAddress = csvRecord.get("emailAddress");
MemberProfile memberProfile = memberProfileServices.findByWorkEmail(emailAddress);
Information comp = new Information(
memberProfile.getId(),
Float.parseFloat(csvRecord.get("salary")
.replaceAll("[^\\d\\.,]", "")),
csvRecord.get("range"),
csvRecord.get("nationalRange"),
csvRecord.get("biography"),
csvRecord.get("commitments")
);
information.add(comp);
} catch (NotFoundException nfe) {
LOG.error("Unable to find a profile for {}", emailAddress);
} catch (IllegalArgumentException ex) {
throw new BadArgException("Unable to parse the current information");
}
}
} catch(IllegalArgumentException ex) {
throw new BadArgException("Unable to parse the current information");
}
}
}

public Information getInformation(UUID memberId) {
// There should only be one entry per member.
return information.stream()
.filter(entry -> entry.memberId().equals(memberId))
.findFirst()
.orElseThrow(() -> new NotFoundException("Current Information not found for member: " + memberId));
}
public Information getInformation(UUID memberId) {
// There should only be one entry per member.
return information.stream()
.filter(entry -> entry.memberId().equals(memberId))
.findFirst()
.orElseThrow(() -> new NotFoundException("Current Information not found for member: " + memberId));
}
}
Loading