ClusterRequest.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.RequestElement;
  8. import no.nav.data.common.validator.Validator;
  9. import no.nav.data.team.shared.domain.DomainObjectStatus;

  10. import java.util.List;
  11. import java.util.UUID;

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

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

  20.     private String id;
  21.     private String name;
  22.     private String description;
  23.     private String slackChannel;
  24.     private List<String> tags;
  25.     private String productAreaId;
  26.     private List<ClusterMemberRequest> members;

  27.     private DomainObjectStatus status;

  28.     private Boolean update;

  29.     public UUID productAreaIdAsUUID() {
  30.         return productAreaId != null ? UUID.fromString(productAreaId) : null;
  31.     }

  32.     @Override
  33.     public void format() {
  34.         setName(trimToNull(name));
  35.         setDescription(trimToNull(description));
  36.         setSlackChannel(trimToNull(slackChannel));
  37.         setTags(formatList(tags));
  38.         setProductAreaId(trimToNull(productAreaId));
  39.     }

  40.     @Override
  41.     public void validateFieldValues(Validator<?> validator) {
  42.         validator.checkId(this);
  43.         validator.checkUUID(Fields.id, id);
  44.         validator.checkBlank(Fields.name, name);
  45.         validator.checkBlank(Fields.description, description);
  46.         validator.validateType(Fields.members, members);
  47.         validator.checkUUID(Fields.productAreaId, productAreaId);
  48.     }
  49. }