TeamMemberRequest.java

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

  2. import lombok.AllArgsConstructor;
  3. import lombok.Builder;
  4. import lombok.Data;
  5. import lombok.NoArgsConstructor;
  6. import lombok.experimental.FieldNameConstants;
  7. import no.nav.data.common.validator.Validated;
  8. import no.nav.data.common.validator.Validator;
  9. import no.nav.data.team.team.domain.TeamRole;

  10. import java.time.LocalDate;
  11. import java.util.List;

  12. import static no.nav.data.common.utils.StreamUtils.nullToEmptyList;
  13. import static org.apache.commons.lang3.StringUtils.trimToNull;
  14. import static org.apache.commons.lang3.StringUtils.upperCase;

  15. @Data
  16. @Builder
  17. @FieldNameConstants
  18. @NoArgsConstructor
  19. @AllArgsConstructor
  20. public class TeamMemberRequest implements Validated {

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

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

  27.     @Override
  28.     public void format() {
  29.         setNavIdent(upperCase(navIdent));
  30.         setRoles(nullToEmptyList(roles));
  31.         setDescription(trimToNull(description));
  32.         if (teamPercent < 0) {
  33.             setTeamPercent(0);
  34.         }
  35.         if (teamPercent > 100) {
  36.             setTeamPercent(100);
  37.         }
  38.     }

  39.     @Override
  40.     public void validateFieldValues(Validator<?> validator) {
  41.         validator.checkPatternRequired(Fields.navIdent, navIdent, Validator.NAV_IDENT_PATTERN);
  42.         validator.checkBlank(Fields.roles, roles.isEmpty() ? null : roles.get(0).name());
  43.     }
  44. }