com.onegini.sdk.model.ProfileImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of idp-sdk Show documentation
Show all versions of idp-sdk Show documentation
Java SDK to connect to the Onegini platform
/*
* Copyright 2013-2020 Onegini b.v.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.onegini.sdk.model;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
import org.joda.time.LocalDate;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.joda.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.joda.ser.LocalDateSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Default implementation of {@link Profile}. Annotated for Jackson JSON (de)serialization
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(NON_EMPTY)
@JsonAutoDetect(getterVisibility = NONE, setterVisibility = NONE, creatorVisibility = NONE, fieldVisibility = NONE,
isGetterVisibility = NONE)
public class ProfileImpl implements Profile {
private static final long serialVersionUID = 4958124503294167774L;
@JsonProperty("gender")
private Gender gender;
@JsonProperty("name")
@JsonDeserialize(as = NameImpl.class)
private Name name;
@JsonProperty("email_addresses")
@JsonDeserialize(as = HashSet.class, contentAs = EmailAddressImpl.class)
private Collection emailAddresses = new HashSet<>();
@JsonProperty("phone_numbers")
@JsonDeserialize(as = HashSet.class, contentAs = PhoneNumberImpl.class)
private Collection phoneNumbers = new HashSet<>();
@JsonProperty(value = "addresses")
@JsonDeserialize(as = HashSet.class, contentAs = AddressImpl.class)
private Collection addresses = new HashSet<>();
@JsonProperty(value = "date_of_birth")
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
private LocalDate dateOfBirth;
@JsonProperty(value = "preferred_locale")
private Locale preferredLocale;
@JsonProperty(value = "reference_id")
private String referenceId;
@JsonProperty("migration_code")
private String migrationCode;
@JsonProperty(value = "custom_attributes")
@JsonDeserialize(as = HashSet.class, contentAs = CustomAttributeImpl.class)
private Collection customAttributes = new HashSet<>();
@Override
public Collection getEmailAddresses() {
return emailAddresses == null ? new HashSet<>() : emailAddresses;
}
@Override
public Collection getPhoneNumbers() {
return phoneNumbers == null ? new HashSet<>() : phoneNumbers;
}
@Override
public Collection getAddresses() {
return addresses == null ? new HashSet<>() : addresses;
}
@Override
public Collection getCustomAttributes() {
return customAttributes == null ? new HashSet<>() : customAttributes;
}
@Override
public boolean containsAlternativeAddress() {
if (getAddresses().isEmpty()) {
return false;
}
for (final Address address : getAddresses()) {
if (address.isAlternative()) {
return true;
}
}
return false;
}
}