GenericNotificationTask.java

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

  2. import com.fasterxml.jackson.annotation.JsonSubTypes;
  3. import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
  4. import com.fasterxml.jackson.annotation.JsonTypeInfo;
  5. import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
  6. import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
  7. import lombok.AllArgsConstructor;
  8. import lombok.Builder;
  9. import lombok.Data;
  10. import lombok.NoArgsConstructor;
  11. import lombok.ToString;
  12. import no.nav.data.common.storage.domain.ChangeStamp;
  13. import no.nav.data.common.storage.domain.DomainObject;
  14. import no.nav.data.common.storage.domain.TypeRegistration;
  15. import no.nav.data.common.utils.StreamUtils;
  16. import no.nav.data.team.cluster.domain.Cluster;
  17. import no.nav.data.team.po.domain.ProductArea;
  18. import no.nav.data.team.team.domain.Team;

  19. import java.util.List;
  20. import java.util.UUID;

  21. @Data
  22. @NoArgsConstructor
  23. @ToString(exclude = {"changeStamp"})
  24. public class GenericNotificationTask implements DomainObject {

  25.     private UUID id;
  26.     private ChangeStamp changeStamp;

  27.     private TaskType taskType;
  28.     private TaskObject taskObject;

  29.     public GenericNotificationTask(TaskObject taskObject) {
  30.         setTaskObject(taskObject);
  31.     }

  32.     public void setTaskObject(TaskObject taskObject) {
  33.         this.taskObject = taskObject;
  34.         this.taskType = TaskType.valueOf(taskObject.getClass().getSimpleName());
  35.     }

  36.     public enum TaskType {
  37.         InactiveMembers
  38.     }

  39.     @Data
  40.     @Builder
  41.     @AllArgsConstructor
  42.     @NoArgsConstructor
  43.     public static final class InactiveMembers implements TaskObject {

  44.         private UUID teamId;
  45.         private UUID clusterId;
  46.         private UUID productAreaId;
  47.         private List<String> identsInactive;

  48.         public static InactiveMembers team(UUID id, List<String> identsInactive) {
  49.             return InactiveMembers.builder().teamId(id).identsInactive(identsInactive).build();
  50.         }

  51.         public static InactiveMembers cluster(UUID id, List<String> identsInactive) {
  52.             return InactiveMembers.builder().clusterId(id).identsInactive(identsInactive).build();
  53.         }

  54.         public static InactiveMembers productArea(UUID id, List<String> identsInactive) {
  55.             return InactiveMembers.builder().productAreaId(id).identsInactive(identsInactive).build();
  56.         }

  57.         public String getType() {
  58.             return teamId != null ? TypeRegistration.typeOf(Team.class)
  59.                     : productAreaId != null ? TypeRegistration.typeOf(ProductArea.class) : TypeRegistration.typeOf(Cluster.class);
  60.         }

  61.         public UUID getId() {
  62.             return StreamUtils.first(teamId, productAreaId, clusterId);
  63.         }
  64.     }

  65.     @JsonTypeInfo(use = Id.NAME, include = As.EXTERNAL_PROPERTY, property = "taskType")
  66.     @JsonSubTypes({
  67.             @Type(value = InactiveMembers.class, name = "InactiveMembers")
  68.     })
  69.     public interface TaskObject {

  70.     }
  71. }