Java 与参数具有相同对象的对象构造函数

Java 与参数具有相同对象的对象构造函数,java,spring,fusionauth,Java,Spring,Fusionauth,我目前正在用FusionAuth用Java开发一个应用程序,我正在使用该工具的Java客户端,我想创建一个用户,所以我使用createUser()方法,它需要UID和UserRequest对象,这一个,需要一个user对象,下一个构造函数是: 用户请求类 public class UserRequest { public boolean sendSetPasswordEmail; public boolean skipVerification; public User u

我目前正在用FusionAuth用Java开发一个应用程序,我正在使用该工具的Java客户端,我想创建一个用户,所以我使用createUser()方法,它需要UID和UserRequest对象,这一个,需要一个user对象,下一个构造函数是:

用户请求类

public class UserRequest {
    public boolean sendSetPasswordEmail;
    public boolean skipVerification;
    public User user;

    @JacksonConstructor
    public UserRequest() {
    }

    public UserRequest(User user) {
        this.sendSetPasswordEmail = false;
        this.skipVerification = true;
        this.user = user;
    }

    public UserRequest(boolean sendSetPasswordEmail, boolean skipVerification, User user) {
        this.sendSetPasswordEmail = sendSetPasswordEmail;
        this.skipVerification = skipVerification;
        this.user = user;
    }
}
用户类

public class User extends SecureIdentity implements Buildable<User>, _InternalJSONColumn, Tenantable {
    @InternalJSONColumn
    @JsonMerge(OptBoolean.FALSE)
    public final List<Locale> preferredLanguages = new ArrayList();
    @JsonMerge(OptBoolean.FALSE)
    private final List<GroupMember> memberships = new ArrayList();
    @JsonMerge(OptBoolean.FALSE)
    private final List<UserRegistration> registrations = new ArrayList();
    public boolean active;
    public LocalDate birthDate;
    public UUID cleanSpeakId;
    @JsonMerge(OptBoolean.FALSE)
    public Map<String, Object> data = new LinkedHashMap();
    public String email;
    public ZonedDateTime expiry;
    public String firstName;
    public String fullName;
    public URI imageUrl;
    public ZonedDateTime insertInstant;
    public ZonedDateTime lastLoginInstant;
    public String lastName;
    public String middleName;
    public String mobilePhone;
    public String parentEmail;
    public UUID tenantId;
    public ZoneId timezone;
    public TwoFactorDelivery twoFactorDelivery;
    public boolean twoFactorEnabled;
    public String twoFactorSecret;
    public String username;
    public ContentStatus usernameStatus;

    public User() {
    }

    public User(User user) {
        this.active = user.active;
        this.birthDate = user.birthDate;
        this.cleanSpeakId = user.cleanSpeakId;
        this.email = user.email;
        this.encryptionScheme = user.encryptionScheme;
        this.expiry = user.expiry;
        this.factor = user.factor;
        this.firstName = user.firstName;
        this.fullName = user.fullName;
        this.id = user.id;
        this.imageUrl = user.imageUrl;
        this.insertInstant = user.insertInstant;
        this.lastLoginInstant = user.lastLoginInstant;
        this.lastName = user.lastName;
        this.memberships.addAll((Collection)user.memberships.stream().map(GroupMember::new).collect(Collectors.toList()));
        this.middleName = user.middleName;
        this.mobilePhone = user.mobilePhone;
        this.parentEmail = user.parentEmail;
        this.password = user.password;
        this.passwordChangeRequired = user.passwordChangeRequired;
        this.passwordLastUpdateInstant = user.passwordLastUpdateInstant;
        this.preferredLanguages.addAll(user.preferredLanguages);
        this.registrations.addAll((Collection)user.registrations.stream().map(UserRegistration::new).collect(Collectors.toList()));
        this.salt = user.salt;
        this.tenantId = user.tenantId;
        this.timezone = user.timezone;
        this.twoFactorDelivery = user.twoFactorDelivery;
        this.twoFactorEnabled = user.twoFactorEnabled;
        this.twoFactorSecret = user.twoFactorSecret;
        this.username = user.username;
        this.usernameStatus = user.usernameStatus;
        this.verified = user.verified;
        if (user.data != null) {
            this.data.putAll(user.data);
        }

    }

    public void addMemberships(GroupMember member) {
        this.memberships.removeIf((m) -> {
            return m.groupId.equals(member.groupId);
        });
        this.memberships.add(member);
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (!(o instanceof User)) {
            return false;
        } else {
            User user = (User)o;
            this.sort();
            user.sort();
            return super.equals(o) && Objects.equals(this.active, user.active) && Objects.equals(this.birthDate, user.birthDate) && Objects.equals(this.cleanSpeakId, user.cleanSpeakId) && Objects.equals(this.data, user.data) && Objects.equals(this.email, user.email) && Objects.equals(this.expiry, user.expiry) && Objects.equals(this.firstName, user.firstName) && Objects.equals(this.fullName, user.fullName) && Objects.equals(this.imageUrl, user.imageUrl) && Objects.equals(this.insertInstant, user.insertInstant) && Objects.equals(this.lastLoginInstant, user.lastLoginInstant) && Objects.equals(this.lastName, user.lastName) && Objects.equals(this.memberships, user.memberships) && Objects.equals(this.middleName, user.middleName) && Objects.equals(this.mobilePhone, user.mobilePhone) && Objects.equals(this.registrations, user.registrations) && Objects.equals(this.parentEmail, user.parentEmail) && Objects.equals(this.tenantId, user.tenantId) && Objects.equals(this.timezone, user.timezone) && Objects.equals(this.twoFactorDelivery, user.twoFactorDelivery) && Objects.equals(this.twoFactorEnabled, user.twoFactorEnabled) && Objects.equals(this.twoFactorSecret, user.twoFactorSecret) && Objects.equals(this.username, user.username) && Objects.equals(this.usernameStatus, user.usernameStatus);
        }
    }

    @JsonIgnore
    public int getAge() {
        return this.birthDate == null ? -1 : (int)this.birthDate.until(LocalDate.now(), ChronoUnit.YEARS);
    }

    @JsonIgnore
    public String getLogin() {
        return this.email == null ? this.username : this.email;
    }

    public List<GroupMember> getMemberships() {
        return this.memberships;
    }

    @JsonIgnore
    public String getName() {
        if (this.fullName != null) {
            return this.fullName;
        } else {
            return this.firstName != null ? this.firstName + (this.lastName != null ? " " + this.lastName : "") : null;
        }
    }

    public UserRegistration getRegistrationForApplication(UUID id) {
        return (UserRegistration)this.getRegistrations().stream().filter((reg) -> {
            return reg.applicationId.equals(id);
        }).findFirst().orElse((Object)null);
    }

    public List<UserRegistration> getRegistrations() {
        return this.registrations;
    }

    public Set<String> getRoleNamesForApplication(UUID id) {
        UserRegistration registration = this.getRegistrationForApplication(id);
        return registration != null ? registration.roles : null;
    }

    public UUID getTenantId() {
        return this.tenantId;
    }

    public boolean hasUserData() {
        if (!this.data.isEmpty()) {
            return true;
        } else {
            Iterator var1 = this.registrations.iterator();

            UserRegistration userRegistration;
            do {
                if (!var1.hasNext()) {
                    return false;
                }

                userRegistration = (UserRegistration)var1.next();
            } while(!userRegistration.hasRegistrationData());

            return true;
        }
    }

    public int hashCode() {
        return Objects.hash(new Object[]{super.hashCode(), this.active, this.birthDate, this.cleanSpeakId, this.data, this.email, this.expiry, this.firstName, this.fullName, this.imageUrl, this.insertInstant, this.lastLoginInstant, this.lastName, this.memberships, this.middleName, this.mobilePhone, this.registrations, this.parentEmail, this.tenantId, this.timezone, this.twoFactorDelivery, this.twoFactorEnabled, this.twoFactorSecret, this.username, this.usernameStatus});
    }

    public String lookupEmail() {
        if (this.email != null) {
            return this.email;
        } else {
            return this.data.containsKey("email") ? this.data.get("email").toString() : null;
        }
    }

    public Locale lookupPreferredLanguage(UUID applicationId) {
        Iterator var2 = this.registrations.iterator();

        UserRegistration registration;
        do {
            if (!var2.hasNext()) {
                if (this.preferredLanguages.size() > 0) {
                    return (Locale)this.preferredLanguages.get(0);
                }

                return null;
            }

            registration = (UserRegistration)var2.next();
        } while(!registration.applicationId.equals(applicationId) || registration.preferredLanguages.size() <= 0);

        return (Locale)registration.preferredLanguages.get(0);
    }

    public void normalize() {
        Normalizer.removeEmpty(this.data);
        this.email = Normalizer.toLowerCase(Normalizer.trim(this.email));
        this.encryptionScheme = Normalizer.trim(this.encryptionScheme);
        this.firstName = Normalizer.trim(this.firstName);
        this.fullName = Normalizer.trim(this.fullName);
        this.lastName = Normalizer.trim(this.lastName);
        this.middleName = Normalizer.trim(this.middleName);
        this.mobilePhone = Normalizer.trim(this.mobilePhone);
        this.parentEmail = Normalizer.toLowerCase(Normalizer.trim(this.parentEmail));
        this.preferredLanguages.removeIf(Objects::isNull);
        this.username = Normalizer.trim(this.username);
        if (this.username != null && this.username.length() == 0) {
            this.username = null;
        }

        this.getRegistrations().forEach(UserRegistration::normalize);
    }

    public void removeMembershipById(UUID groupId) {
        this.memberships.removeIf((m) -> {
            return m.groupId.equals(groupId);
        });
    }

    public User secure() {
        this.encryptionScheme = null;
        this.factor = null;
        this.password = null;
        this.salt = null;
        this.twoFactorSecret = null;
        return this;
    }

    public User sort() {
        this.registrations.sort(Comparator.comparing((ur) -> {
            return ur.applicationId;
        }));
        return this;
    }

    public String toString() {
        return ToString.toString(this);
    }
}
公共类用户扩展SecureIdentity实现可构建、内部JsonColumn、可租户{
@内柱
@JsonMerge(OptBoolean.FALSE)
public final List preferredLanguages=new ArrayList();
@JsonMerge(OptBoolean.FALSE)
私有最终列表成员身份=新ArrayList();
@JsonMerge(OptBoolean.FALSE)
私有最终列表注册=新ArrayList();
公共布尔活动;
公共本地日期出生日期;
公共UUID已清除;
@JsonMerge(OptBoolean.FALSE)
公共地图数据=新建LinkedHashMap();
公共字符串电子邮件;
公共区域日期到期;
公共字符串名;
公共字符串全名;
公共URI图像URL;
公共分区时间插入器;
公共区域DateTime lastLoginInstant;
公共字符串lastName;
公共字符串名称;
公共电话;
公共电子邮件;
公共UUID租户;
公共时区;
公共双工厂交货双工厂交货;
公共布尔双因子出血;
公共字符串双因素Cret;
公共字符串用户名;
公共内容状态usernameStatus;
公共用户(){
}
公共用户(用户){
this.active=user.active;
this.birthDate=user.birthDate;
this.cleanSpeakId=user.cleanSpeakId;
this.email=user.email;
this.encryptionScheme=user.encryptionScheme;
this.expiry=user.expiry;
this.factor=user.factor;
this.firstName=user.firstName;
this.fullName=user.fullName;
this.id=user.id;
this.imageUrl=user.imageUrl;
this.insertInstant=user.insertInstant;
this.lastLoginInstant=user.lastLoginInstant;
this.lastName=user.lastName;
this.memberships.addAll((Collection)user.memberships.stream().map(GroupMember::new).collect(Collectors.toList());
this.middleName=user.middleName;
this.mobilePhone=user.mobilePhone;
this.parentEmail=user.parentEmail;
this.password=user.password;
this.passwordChangeRequired=user.passwordChangeRequired;
this.passwordLastUpdateInstant=user.passwordLastUpdateInstant;
this.preferredLanguages.addAll(user.preferredLanguages);
this.registrations.addAll((Collection)user.registrations.stream().map(UserRegistration::new).collect(Collectors.toList());
this.salt=user.salt;
this.tenantId=user.tenantId;
this.timezone=user.timezone;
this.twoFactorDelivery=user.twoFactorDelivery;
this.twofacturenabled=user.twofacturenabled;
this.twoFactorCret=user.twoFactorCret;
this.username=user.username;
this.usernameStatus=user.usernameStatus;
this.verified=user.verified;
if(user.data!=null){
this.data.putAll(user.data);
}
}
公共无效添加成员身份(组成员){
此.memberships.removeIf((m)->{
返回m.groupId.equals(member.groupId);
});
此.memberships.add(成员);
}
公共布尔等于(对象o){
if(this==o){
返回true;
}else if(!(用户的实例)){
返回false;
}否则{
用户=(用户)o;
this.sort();
user.sort();
返回super.equals(o)和&Objects.equals(this.active,user.active)和&Objects.equals(this.birthDate,user.birthDate)和&Objects.equals(this.cleanSpeakId,user.cleanSpeakId)和&Objects.equals(this.email,user.email)和&Objects.equals(this.expiry,user.expiration)和&Objects.equals(this.firstName,user.firstName)&&Objects.equals(this.fullName,user.fullName)&&Objects.equals(this.imageUrl,user.imageUrl)&&Objects.equals(this.insertInstant,user.insertInstant)&&Objects.equals(this.lastLoginInstant,user.lastLoginInstant)&&Objects.equals(this.memberships,user.memberships)&&Objects.equals.equals(this.middleName,user.middleName)和&Objects.equals(this.mobilePhone,user.mobilePhone)和&Objects.equals(this.registrations,user.registrations)和&Objects.equals(this.parentEmail,user.parentEmail)和&Objects.equals(this.tenantId,user.tenantId)和&Objects.equals(this.timezone,user.timezone)和&Objects.equals(this.twoFactorDelivery,user.twoFactorDelivery)和&Objects.equals(this.twoFactorEnabled,user.twoFactorEnabled)和&Objects.equals(this.twoFactorSecret,user.twoFactorSecret)和&Objects.equals(this.username,user.usernameStatus);
}
}
@杰索尼奥雷
公共整数getAge(){
返回this.birthDate==null?-1:(int)this.birthDate.until(LocalDate.now(),ChronoUnit.YEARS);
}
@杰索尼奥雷
公共字符串getLogin(){
返回this.email==null?this.username:this.email;
}
公共列表getMemberships(){
返回此项。会员资格;
}
@杰索尼奥雷
公共字符串getName(){
if(this.fullName!=null){
返回this.fullName;
}否则{
返回this.firstName!=null?this.firstName+(this.lastName!=null?“+this.lastName:”):null;
}
}
公共用户注册getRegistrationForApplication(UUID id){
返回(UserRegistration)this.getRegistrations().stream().filter((reg)->{
返回reg.applicationId.equals(id);
}).findFirst().orElse((对象)null);
}
公共列表getRegistrations(){
返回此文件。注册;