PaMember.java

  1. package no.nav.data.team.po.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.po.dto.PaMemberRequest;
  9. import no.nav.data.team.resource.NomClient;
  10. import no.nav.data.team.resource.dto.ResourceResponse;
  11. import no.nav.data.team.shared.domain.Member;
  12. import no.nav.data.team.team.domain.TeamRole;

  13. import java.util.List;

  14. import static no.nav.data.common.utils.StreamUtils.copyOf;

  15. @Data
  16. @Builder
  17. @NoArgsConstructor
  18. @AllArgsConstructor
  19. public class PaMember implements Member {

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

  24.     public static PaMember convert(PaMemberRequest request) {
  25.         return PaMember.builder()
  26.                 .navIdent(request.getNavIdent())
  27.                 .roles(request.getRoles())
  28.                 .description(request.getDescription())
  29.                 .build();
  30.     }

  31.     public MemberResponse convertToResponse() {
  32.         var builder = MemberResponse.builder()
  33.                 .navIdent(getNavIdent())
  34.                 .roles(copyOf(getRoles()))
  35.                 .description(getDescription());

  36.         NomClient.getInstance()
  37.                 .getByNavIdent(getNavIdent())
  38.                 .ifPresentOrElse(resource ->
  39.                                 builder.resource(resource.convertToResponse())
  40.                         , () -> builder.resource(ResourceResponse.builder().navIdent(getNavIdent()).stale(true).build()));
  41.         return builder.build();
  42.     }
  43. }