All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.co.mruoc.nac.entities.User Maven / Gradle / Ivy

There is a newer version: 0.1.42
Show newest version
package uk.co.mruoc.nac.entities;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;
import lombok.Builder;
import lombok.Data;

@Builder(toBuilder = true)
@Data
public class User {

  private final String username;
  private final String id;
  private final String firstName;
  private final String lastName;
  private final String email;
  private final boolean emailVerified;
  private final Collection groups;
  private final String status;

  public String getFullName() {
    Collection names = new ArrayList<>();
    if (Objects.nonNull(firstName)) {
      names.add(firstName);
    }
    if (Objects.nonNull(lastName)) {
      names.add(lastName);
    }
    return String.join(" ", names);
  }

  public User update(UpsertUserRequest request) {
    return toBuilder()
        .firstName(request.getFirstName())
        .lastName(request.getLastName())
        .email(request.getEmail())
        .emailVerified(request.isEmailVerified())
        .groups(request.getGroups())
        .build();
  }

  public boolean isMemberOfAtLeastOneGroup(Collection groupsToCheck) {
    return groupsToCheck.stream().anyMatch(groups::contains);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy