ClusterMemberRequest.java

  1. package no.nav.data.team.cluster.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.util.List;

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

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

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

  23.     @Override
  24.     public void format() {
  25.         setNavIdent(upperCase(navIdent));
  26.         setRoles(nullToEmptyList(roles));
  27.         setDescription(trimToNull(description));
  28.     }

  29.     @Override
  30.     public void validateFieldValues(Validator<?> validator) {
  31.         validator.checkPatternRequired(Fields.navIdent, navIdent, Validator.NAV_IDENT_PATTERN);
  32.         validator.checkBlank(Fields.roles, roles.isEmpty() ? null : roles.get(0).name());
  33.     }
  34. }