Team.java

  1. package no.nav.data.team.team.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.contact.domain.ContactAddress;
  10. import no.nav.data.team.location.LocationRepository;
  11. import no.nav.data.team.location.dto.LocationSimplePathResponse;
  12. import no.nav.data.team.shared.domain.DomainObjectStatus;
  13. import no.nav.data.team.shared.domain.HistorizedDomainObject;
  14. import no.nav.data.team.shared.domain.Membered;
  15. import no.nav.data.team.shared.dto.Links;
  16. import no.nav.data.team.team.dto.OfficeHoursResponse;
  17. import no.nav.data.team.team.dto.TeamRequest;
  18. import no.nav.data.team.team.dto.TeamResponse;

  19. import java.time.LocalDateTime;
  20. import java.util.ArrayList;
  21. import java.util.Comparator;
  22. import java.util.List;
  23. import java.util.UUID;

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

  25. @Data
  26. @Builder
  27. @NoArgsConstructor
  28. @AllArgsConstructor
  29. public class Team implements DomainObject, Membered, HistorizedDomainObject {

  30.     private UUID id;
  31.     private String name;
  32.     private String description;
  33.     private String slackChannel;
  34.     private String contactPersonIdent;
  35.     @Builder.Default
  36.     private List<ContactAddress> contactAddresses = new ArrayList<>();
  37.     private UUID productAreaId;
  38.     private String teamOwnerIdent;
  39.     private TeamType teamType;
  40.     private TeamOwnershipType teamOwnershipType;
  41.     private LocalDateTime qaTime;
  42.     @Builder.Default
  43.     private List<UUID> clusterIds = new ArrayList<>();
  44.     @Builder.Default
  45.     private List<String> naisTeams = new ArrayList<>();
  46.     @Builder.Default
  47.     private List<TeamMember> members = new ArrayList<>();
  48.     @Builder.Default
  49.     private List<String> tags = new ArrayList<>();
  50.     private OfficeHours officeHours;

  51.     private DomainObjectStatus status;

  52.     private ChangeStamp changeStamp;
  53.     private boolean updateSent;
  54.     private LocalDateTime lastNudge;

  55.     public Team convert(TeamRequest request){
  56.         name = request.getName();
  57.         description = request.getDescription();
  58.         slackChannel = request.getSlackChannel();
  59.         contactPersonIdent = request.getContactPersonIdent();
  60.         contactAddresses = copyOf(request.getContactAddresses());
  61.         productAreaId = request.productAreaIdAsUUID();
  62.         teamOwnerIdent = request.getTeamOwnerIdent();
  63.         clusterIds = StreamUtils.convert(request.getClusterIds(), UUID::fromString);
  64.         teamType = request.getTeamType();
  65.         teamOwnershipType = request.getTeamOwnershipType();
  66.         qaTime = request.getQaTime();
  67.         naisTeams = copyOf(request.getNaisTeams());
  68.         tags = copyOf(request.getTags());
  69.         officeHours = request.getOfficeHours();
  70.         status = request.getStatus();
  71.         // If an update does not contain member array don't update
  72.         if (!request.isUpdate() || request.getMembers() != null) {
  73.             members = StreamUtils.convert(request.getMembers(), TeamMember::convert);
  74.         }
  75.         members.sort(Comparator.comparing(TeamMember::getNavIdent));
  76.         updateSent = false;
  77.         return this;
  78.     }

  79.     public TeamResponse convertToResponse() {
  80.         return TeamResponse.builder()
  81.                 .id(id)
  82.                 .name(name)
  83.                 .description(description)
  84.                 .slackChannel(slackChannel)
  85.                 .contactPersonIdent(contactPersonIdent)
  86.                 .contactAddresses(copyOf(contactAddresses))
  87.                 .productAreaId(productAreaId)
  88.                 .teamOwnerIdent(teamOwnerIdent)
  89.                 .clusterIds(copyOf(clusterIds))
  90.                 .teamType(teamType)
  91.                 .teamOwnershipType(teamOwnershipType)
  92.                 .qaTime(qaTime)
  93.                 .naisTeams(copyOf(naisTeams))
  94.                 .tags(copyOf(tags))
  95.                 .members(StreamUtils.convert(members, TeamMember::convertToResponse))
  96.                 .changeStamp(convertChangeStampResponse())
  97.                 .links(Links.getFor(this))
  98.                 .officeHours(officeHours != null ? OfficeHoursResponse.builder()
  99.                         .location(LocationSimplePathResponse.convert(LocationRepository.getLocationFor(officeHours.getLocationCode())))
  100.                         .days(officeHours.getDays())
  101.                         .information(officeHours.getInformation())
  102.                         .build() : null)
  103.                 .status(status)
  104.                 .build();
  105.     }

  106. }