TeamRequest.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.RequestElement;
  8. import no.nav.data.common.validator.Validator;
  9. import no.nav.data.team.contact.domain.ContactAddress;
  10. import no.nav.data.team.team.domain.OfficeHours;
  11. import no.nav.data.team.shared.domain.DomainObjectStatus;
  12. import no.nav.data.team.team.domain.TeamOwnershipType;
  13. import no.nav.data.team.team.domain.TeamType;

  14. import java.time.LocalDateTime;
  15. import java.util.List;
  16. import java.util.UUID;

  17. import static no.nav.data.common.utils.StringUtils.formatList;
  18. import static org.apache.commons.lang3.StringUtils.trimToNull;

  19. @Data
  20. @Builder
  21. @NoArgsConstructor
  22. @AllArgsConstructor
  23. @FieldNameConstants
  24. public class TeamRequest implements RequestElement {

  25.     private String id;
  26.     private String name;
  27.     private String description;
  28.     private String slackChannel;
  29.     private String contactPersonIdent;
  30.     private List<ContactAddress> contactAddresses;
  31.     private String productAreaId;
  32.     private String teamOwnerIdent;
  33.     private List<String> clusterIds;
  34.     private TeamType teamType;
  35.     private TeamOwnershipType teamOwnershipType;
  36.     private LocalDateTime qaTime;
  37.     private List<String> naisTeams;
  38.     private List<TeamMemberRequest> members;
  39.     private List<String> tags;
  40.     private OfficeHours officeHours;
  41.     private DomainObjectStatus status;


  42.     private Boolean update;

  43.     @Override
  44.     public void format() {
  45.         setName(trimToNull(name));
  46.         setDescription(trimToNull(description));
  47.         setSlackChannel(trimToNull(slackChannel));
  48.         setContactPersonIdent(trimToNull(contactPersonIdent));
  49.         setProductAreaId(trimToNull(productAreaId));
  50.         setClusterIds(formatList(clusterIds));
  51.         setNaisTeams(formatList(naisTeams));
  52.         setTags(formatList(tags));
  53.         if (teamType == null) {
  54.             setTeamType(TeamType.UNKNOWN);
  55.         }
  56.         if (teamOwnershipType == null) {
  57.             setTeamOwnershipType(TeamOwnershipType.UNKNOWN);
  58.         }
  59.     }

  60.     @Override
  61.     public void validateFieldValues(Validator<?> validator) {
  62.         validator.checkId(this);
  63.         validator.checkUUID(Fields.id, id);
  64.         validator.checkUUID(Fields.productAreaId, productAreaId);
  65.         clusterIds.forEach(id -> validator.checkUUID(Fields.clusterIds, id));
  66.         validator.checkBlank(Fields.name, name);
  67.         validator.checkBlank(Fields.description, description);
  68.         validator.validateType(Fields.members, members);
  69.         validator.validateType(Fields.contactAddresses, contactAddresses);
  70.     }

  71.     public UUID productAreaIdAsUUID() {
  72.         return productAreaId != null ? UUID.fromString(productAreaId) : null;
  73.     }
  74. }