Search in sources :

Example 1 with MemberProfile

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;
}
Also used : MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate)

Example 2 with MemberProfile

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));
}
Also used : Role(com.objectcomputing.checkins.services.role.Role) Role(com.objectcomputing.checkins.services.role.Role) Controller(io.micronaut.http.annotation.Controller) Permission(com.objectcomputing.checkins.services.permissions.Permission) Secured(io.micronaut.security.annotation.Secured) PermissionServices(com.objectcomputing.checkins.services.permissions.PermissionServices) Authentication(io.micronaut.security.authentication.Authentication) Set(java.util.Set) MemberProfileUtils(com.objectcomputing.checkins.services.memberprofile.MemberProfileUtils) SecurityRule(io.micronaut.security.rules.SecurityRule) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Tag(io.swagger.v3.oas.annotations.tags.Tag) Nullable(io.micronaut.core.annotation.Nullable) PermissionRepository(com.objectcomputing.checkins.services.permissions.PermissionRepository) HttpResponse(io.micronaut.http.HttpResponse) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) RoleRepository(com.objectcomputing.checkins.services.role.RoleRepository) URI(java.net.URI) RoleServices(com.objectcomputing.checkins.services.role.RoleServices) Get(io.micronaut.http.annotation.Get) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) Permission(com.objectcomputing.checkins.services.permissions.Permission) Get(io.micronaut.http.annotation.Get)

Example 3 with MemberProfile

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;
}
Also used : Role(com.objectcomputing.checkins.services.role.Role) AlreadyExistsException(com.objectcomputing.checkins.exceptions.AlreadyExistsException) MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile)

Example 4 with MemberProfile

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;
}
Also used : MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate)

Example 5 with MemberProfile

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;
}
Also used : MemberProfile(com.objectcomputing.checkins.services.memberprofile.MemberProfile) LocalDate(java.time.LocalDate)

Aggregations

MemberProfile (com.objectcomputing.checkins.services.memberprofile.MemberProfile)623 Test (org.junit.jupiter.api.Test)557 HttpClientResponseException (io.micronaut.http.client.exceptions.HttpClientResponseException)245 JsonNode (com.fasterxml.jackson.databind.JsonNode)157 CheckIn (com.objectcomputing.checkins.services.checkins.CheckIn)141 Role (com.objectcomputing.checkins.services.role.Role)110 MemberProfileTestUtil.mkMemberProfile (com.objectcomputing.checkins.services.memberprofile.MemberProfileTestUtil.mkMemberProfile)73 Map (java.util.Map)62 Guild (com.objectcomputing.checkins.services.guild.Guild)36 Team (com.objectcomputing.checkins.services.team.Team)34 LocalDate (java.time.LocalDate)33 UUID (java.util.UUID)29 List (java.util.List)26 FeedbackTemplate (com.objectcomputing.checkins.services.feedback_template.FeedbackTemplate)25 Skill (com.objectcomputing.checkins.services.skills.Skill)20 PermissionException (com.objectcomputing.checkins.exceptions.PermissionException)18 Opportunities (com.objectcomputing.checkins.services.opportunities.Opportunities)18 BadArgException (com.objectcomputing.checkins.exceptions.BadArgException)15 MicronautTest (io.micronaut.test.annotation.MicronautTest)14 NotFoundException (com.objectcomputing.checkins.exceptions.NotFoundException)10