ProductAreaRequest.java

  1. package no.nav.data.team.po.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.po.domain.AreaType;
  10. import no.nav.data.team.shared.domain.DomainObjectStatus;

  11. import java.util.List;

  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 ProductAreaRequest implements RequestElement {

  20.     public static final String paOwnerGroupError = "paOwnerGroupError";

  21.     private String id;
  22.     private String name;
  23.     private AreaType areaType;
  24.     private String description;
  25.     private String slackChannel;
  26.     private List<String> tags;
  27.     private List<PaMemberRequest> members;
  28.     private PaOwnerGroupRequest ownerGroup;

  29.     private DomainObjectStatus status;

  30.     private Boolean update;

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

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

  47.     private void validateProductAreaOwners(Validator<?> validator) {
  48.         if (this.ownerGroup != null) {
  49.             if (this.areaType == AreaType.PRODUCT_AREA) {
  50.                 validator.validateType(Fields.ownerGroup, ownerGroup);
  51.             } else {
  52.                 validator.addError(Fields.ownerGroup, paOwnerGroupError, "Areas of type " + this.areaType + " cannot contain an owner group");
  53.             }
  54.         }
  55.     }

  56. }