TeamMember.java

  1. package no.nav.data.team.team.domain;

  2. import lombok.AllArgsConstructor;
  3. import lombok.Builder;
  4. import lombok.Data;
  5. import lombok.NoArgsConstructor;
  6. import lombok.Singular;
  7. import no.nav.data.team.member.dto.MemberResponse;
  8. import no.nav.data.team.resource.NomClient;
  9. import no.nav.data.team.resource.dto.ResourceResponse;
  10. import no.nav.data.team.shared.domain.Member;
  11. import no.nav.data.team.team.dto.TeamMemberRequest;

  12. import java.time.LocalDate;
  13. import java.util.List;

  14. @Data
  15. @Builder
  16. @NoArgsConstructor
  17. @AllArgsConstructor
  18. public class TeamMember implements Member {

  19.     private String navIdent;
  20.     @Singular
  21.     private List<TeamRole> roles;
  22.     private String description;

  23.     private int teamPercent;
  24.     private LocalDate startDate;
  25.     private LocalDate endDate;

  26.     public static TeamMember convert(TeamMemberRequest request) {
  27.         return TeamMember.builder()
  28.                 .navIdent(request.getNavIdent())
  29.                 .roles(request.getRoles())
  30.                 .description(request.getDescription())
  31.                 .teamPercent(request.getTeamPercent())
  32.                 .startDate(request.getStartDate())
  33.                 .endDate(request.getEndDate())
  34.                 .build();
  35.     }

  36.     public MemberResponse convertToResponse() {
  37.         var builder = MemberResponse.builder()
  38.                 .navIdent(getNavIdent())
  39.                 .roles(getRoles())
  40.                 .description(getDescription())
  41.                 .teamPercent(getTeamPercent())
  42.                 .startDate(getStartDate())
  43.                 .endDate(getEndDate());

  44.         NomClient.getInstance()
  45.                 .getByNavIdent(getNavIdent())
  46.                 .ifPresentOrElse(resource ->
  47.                                 builder.resource(resource.convertToResponse())
  48.                         , () -> builder.resource(ResourceResponse.builder().navIdent(getNavIdent()).stale(true).build()));
  49.         return builder.build();
  50.     }
  51. }