ProductArea.java

  1. package no.nav.data.team.po.domain;

  2. import lombok.AllArgsConstructor;
  3. import lombok.Builder;
  4. import lombok.Data;
  5. import lombok.NoArgsConstructor;
  6. import no.nav.data.common.storage.domain.ChangeStamp;
  7. import no.nav.data.common.storage.domain.DomainObject;
  8. import no.nav.data.common.utils.StreamUtils;
  9. import no.nav.data.team.po.dto.ProductAreaRequest;
  10. import no.nav.data.team.po.dto.ProductAreaResponse;
  11. import no.nav.data.team.shared.domain.HistorizedDomainObject;
  12. import no.nav.data.team.shared.domain.Membered;
  13. import no.nav.data.team.shared.dto.Links;
  14. import no.nav.data.team.shared.domain.DomainObjectStatus;

  15. import java.time.LocalDateTime;
  16. import java.util.Comparator;
  17. import java.util.List;
  18. import java.util.UUID;

  19. import static no.nav.data.common.utils.StreamUtils.copyOf;

  20. @Data
  21. @Builder
  22. @NoArgsConstructor
  23. @AllArgsConstructor
  24. public class ProductArea implements DomainObject, Membered, HistorizedDomainObject {

  25.     private UUID id;
  26.     private String name;
  27.     private AreaType areaType;
  28.     private String description;
  29.     private String slackChannel;
  30.     private List<String> tags;
  31.     private List<PaMember> members;
  32.     private PaOwnerGroup productAreaOwnerGroup;

  33.     private DomainObjectStatus status;

  34.     private ChangeStamp changeStamp;
  35.     private boolean updateSent;
  36.     private LocalDateTime lastNudge;

  37.     public List<PaMember> getMembers() {
  38.         return members == null ? List.of() : members;
  39.     }

  40.     public ProductArea convert(ProductAreaRequest request) {
  41.         name = request.getName();
  42.         areaType = request.getAreaType();
  43.         description = request.getDescription();
  44.         slackChannel = request.getSlackChannel();
  45.         tags = copyOf(request.getTags());
  46.         // If an update does not contain member array don't update
  47.         if (!request.isUpdate() || request.getMembers() != null) {
  48.             members = StreamUtils.convert(request.getMembers(), PaMember::convert);
  49.         }
  50.         members.sort(Comparator.comparing(PaMember::getNavIdent));
  51.         productAreaOwnerGroup = PaOwnerGroup.convertFromRequest(request.getOwnerGroup());
  52.         status = request.getStatus();

  53.         updateSent = false;
  54.         return this;
  55.     }

  56.     public ProductAreaResponse convertToResponse(String defaultProductAreaId) {
  57.         return ProductAreaResponse.builder()
  58.                 .id(id)
  59.                 .name(name)
  60.                 .areaType(areaType)
  61.                 .description(description)
  62.                 .slackChannel(slackChannel)
  63.                 .tags(copyOf(tags))
  64.                 .members(StreamUtils.convert(members, PaMember::convertToResponse))
  65.                 .changeStamp(convertChangeStampResponse())
  66.                 .links(Links.getFor(this))
  67.                 .paOwnerGroup(this.productAreaOwnerGroup != null ? this.productAreaOwnerGroup.convertToResponse() : null)
  68.                 .status(status)
  69.                 .isDefaultArea(this.id.toString().equals(defaultProductAreaId))
  70.                 .build();
  71.     }
  72. }