use of com.objectcomputing.checkins.services.memberprofile.MemberProfile in project check-ins by objectcomputing.
the class BirthDayServicesImpl method profileToBirthDateResponseDto.
private List<BirthDayResponseDTO> profileToBirthDateResponseDto(List<MemberProfile> memberProfiles) {
List<BirthDayResponseDTO> birthDays = new ArrayList<>();
LocalDate currentDate = LocalDate.now();
for (MemberProfile member : memberProfiles) {
if (member.getTerminationDate() == null || member.getTerminationDate().isAfter(currentDate)) {
BirthDayResponseDTO birthDayResponseDTO = new BirthDayResponseDTO();
birthDayResponseDTO.setUserId(member.getId());
birthDayResponseDTO.setName(member.getFirstName() + "" + member.getLastName());
birthDayResponseDTO.setBirthDay(member.getBirthDate().getMonthValue() + "/" + member.getBirthDate().getDayOfMonth());
birthDays.add(birthDayResponseDTO);
}
}
return birthDays;
}
use of com.objectcomputing.checkins.services.memberprofile.MemberProfile in project check-ins by objectcomputing.
the class CurrentUserController method currentUser.
/**
* Get user details from Google authentication
*
* @param authentication {@link Authentication} or null
* @return {@link HttpResponse<CurrentUserDTO>}
*/
@Get
public HttpResponse<CurrentUserDTO> currentUser(@Nullable Authentication authentication) {
if (authentication == null) {
return HttpResponse.unauthorized();
}
String workEmail = authentication.getAttributes().get("email").toString();
String imageUrl = authentication.getAttributes().get("picture") != null ? authentication.getAttributes().get("picture").toString() : "";
String name = authentication.getAttributes().get("name").toString().trim();
String firstName = name.substring(0, name.indexOf(' '));
String lastName = name.substring(name.indexOf(' ') + 1).trim();
MemberProfile user = currentUserServices.findOrSaveUser(firstName, lastName, workEmail);
List<Permission> permissions = permissionServices.findUserPermissions(user.getId());
Set<Role> roles = roleServices.findUserRoles(user.getId());
List<String> rolesAsString = roles.stream().map(o -> o.getRole()).collect(Collectors.toList());
return HttpResponse.ok().headers(headers -> headers.location(location(user.getId()))).body(fromEntity(user, imageUrl, permissions, rolesAsString));
}
use of com.objectcomputing.checkins.services.memberprofile.MemberProfile in project check-ins by objectcomputing.
the class CurrentUserServicesImpl method saveNewUser.
private MemberProfile saveNewUser(String firstName, String lastName, String workEmail) {
MemberProfile emailProfile = memberProfileRepo.findByWorkEmail(workEmail).orElse(null);
if (emailProfile != null) {
throw new AlreadyExistsException(String.format("Email %s already exists in database", workEmail));
}
MemberProfile createdMember = memberProfileRepo.save(new MemberProfile(firstName, null, lastName, null, "", null, "", workEmail, "", null, "", null, null, null, null, null));
Optional<Role> role = roleServices.findByRole("MEMBER");
if (role.isPresent()) {
memberRoleServices.saveByIds(createdMember.getId(), role.get().getId());
} else {
Role memberRole = roleServices.save(new Role(RoleType.MEMBER.name(), "role description"));
memberRoleServices.saveByIds(createdMember.getId(), memberRole.getId());
}
return createdMember;
}
use of com.objectcomputing.checkins.services.memberprofile.MemberProfile in project check-ins by objectcomputing.
the class AnniversaryReportServicesImpl method profileToAnniversaryResponseDto.
private List<AnniversaryReportResponseDTO> profileToAnniversaryResponseDto(List<MemberProfile> memberProfiles) {
List<AnniversaryReportResponseDTO> anniversaries = new ArrayList<>();
LocalDate currentDate = LocalDate.now();
for (MemberProfile member : memberProfiles) {
if (member.getTerminationDate() == null || member.getTerminationDate().isAfter(currentDate)) {
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.CEILING);
double yearsOfService = (currentDate.toEpochDay() - member.getStartDate().toEpochDay()) / 365.25;
AnniversaryReportResponseDTO anniversary = new AnniversaryReportResponseDTO();
anniversary.setUserId(member.getId());
anniversary.setName(member.getFirstName() + " " + member.getLastName());
anniversary.setYearsOfService(Double.parseDouble(df.format(yearsOfService)));
if (member.getStartDate() != null) {
anniversary.setAnniversary(member.getStartDate().getMonthValue() + "/" + member.getStartDate().getDayOfMonth());
}
anniversaries.add(anniversary);
}
}
return anniversaries;
}
use of com.objectcomputing.checkins.services.memberprofile.MemberProfile in project check-ins by objectcomputing.
the class RetentionReportServicesImpl method getTerminationsForMonth.
public int getTerminationsForMonth(LocalDate dateToStudy, List<MemberProfile> memberProfiles) {
int numberOfTerms = 0;
LocalDate beginningDate = dateToStudy.minusMonths(1);
for (MemberProfile mp : memberProfiles) {
if (mp.getExcluded() == null || !mp.getExcluded()) {
if (mp.getTerminationDate() != null && mp.getTerminationDate().isAfter(beginningDate) && (mp.getTerminationDate().isBefore(dateToStudy) || mp.getTerminationDate().isEqual(dateToStudy))) {
numberOfTerms += 1;
}
}
}
return numberOfTerms;
}
Aggregations