org.osiam.resources.scim.User Maven / Gradle / Ivy
Show all versions of scim-schema Show documentation
/*
* Copyright (C) 2013 tarent AG
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.osiam.resources.scim;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.base.Objects;
/**
* Java class for User complex type.
*
* The following schema fragment specifies the expected content contained within this class.
*/
@JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY)
public class User extends CoreResource {
private String userName;
private Name name;
private String displayName;
private String nickName;
private String profileUrl;
private String title;
private String userType;
private String preferredLanguage;
private String locale;
private String timezone;
private Boolean active;
private String password = "";
private List emails = new ArrayList<>();
private List phoneNumbers = new ArrayList<>();
private List ims = new ArrayList<>();
private List photos = new ArrayList<>();
private List addresses = new ArrayList<>();
private List groups = new ArrayList<>();
private List entitlements = new ArrayList<>();
private List roles = new ArrayList<>();
private List x509Certificates = new ArrayList<>();
private Map extensions = new HashMap<>();
public User() {
}
private User(Builder builder) {
super(builder);
this.userName = builder.userName;
this.name = builder.name;
this.displayName = builder.displayName;
this.nickName = builder.nickName;
this.profileUrl = builder.profileUrl;
this.title = builder.title;
this.userType = builder.userType;
this.preferredLanguage = builder.preferredLanguage;
this.locale = builder.locale;
this.timezone = builder.timezone;
this.active = builder.active;
this.password = builder.password;
this.emails = builder.emails;
this.phoneNumbers = builder.phoneNumbers;
this.ims = builder.ims;
this.photos = builder.photos;
this.addresses = builder.addresses;
this.groups = builder.groups;
this.entitlements = builder.entitlements;
this.roles = builder.roles;
this.x509Certificates = builder.x509Certificates;
this.extensions = builder.extensions;
}
/**
* Gets the value of the userName property.
*
* @return possible object is
* {@link String }
*/
public String getUserName() {
return userName;
}
/**
* Gets the value of the name property.
*
* @return possible object is
* {@link Name }
*/
public Name getName() {
return name;
}
/**
* Gets the value of the displayName property.
*
* @return possible object is
* {@link String }
*/
public String getDisplayName() {
return displayName;
}
/**
* Gets the value of the nickName property.
*
* @return possible object is
* {@link String }
*/
public String getNickName() {
return nickName;
}
/**
* Gets the value of the profileUrl property.
*
* @return possible object is
* {@link String }
*/
public String getProfileUrl() {
return profileUrl;
}
/**
* Gets the value of the title property.
*
* @return possible object is
* {@link String }
*/
public String getTitle() {
return title;
}
/**
* Gets the value of the userType property.
*
* @return possible object is
* {@link String }
*/
public String getUserType() {
return userType;
}
/**
* Gets the value of the preferredLanguage property.
*
* @return possible object is
* {@link String }
*/
public String getPreferredLanguage() {
return preferredLanguage;
}
/**
* Gets the value of the locale property.
*
* @return possible object is
* {@link String }
*/
public String getLocale() {
return locale;
}
/**
* Gets the value of the timezone property.
*
* @return possible object is
* {@link String }
*/
public String getTimezone() {
return timezone;
}
/**
* Gets the value of the active property.
*
* @return possible object is
* {@link Boolean }
*/
public Boolean isActive() {
return active;
}
/**
* Gets the value of the password property.
*
* @return possible object is
* {@link String }
*/
public String getPassword() {
return password;
}
public List getEmails() {
return emails;
}
public List getPhoneNumbers() {
return phoneNumbers;
}
public List getIms() {
return ims;
}
public List getPhotos() {
return photos;
}
public List getAddresses() {
return addresses;
}
public List getGroups() {
return groups;
}
public List getEntitlements() {
return entitlements;
}
public List getRoles() {
return roles;
}
public List getX509Certificates() {
return x509Certificates;
}
/**
* Provides an unmodifiable view of the extensions as a map
*
* @return an unmodifiable view of the extensions
*/
@JsonAnyGetter
public Map getAllExtensions() {
return Collections.unmodifiableMap(extensions);
}
/**
* Provides the extension with the given URN
*
* @param urn The URN of the extension
* @return The extension for the given URN
* @throws IllegalArgumentException If urn is null or empty
* @throws NoSuchElementException If extension with given urn is not available
*/
public Extension getExtension(String urn) {
if (urn == null || urn.isEmpty()) {
throw new IllegalArgumentException("urn must be neither null nor empty");
}
if (!extensions.containsKey(urn)) {
throw new NoSuchElementException("extension " + urn + " is not available");
}
return extensions.get(urn);
}
public static class Builder extends CoreResource.Builder {
private String userName;
private String password = "";
private Boolean active;
private String timezone;
private String locale;
private String preferredLanguage;
private String userType;
private String title;
private String profileUrl;
private String nickName;
private String displayName;
private Name name;
private List emails = new ArrayList<>();
private List phoneNumbers = new ArrayList<>();
private List ims = new ArrayList<>();
private List photos = new ArrayList<>();
private List addresses = new ArrayList<>();
private List groups = new ArrayList<>();
private List entitlements = new ArrayList<>();
private List roles = new ArrayList<>();
private List x509Certificates = new ArrayList<>();
private Map extensions = new HashMap<>();
/**
* This class is for generating the output of an User. It does not copy the password. If null is passed in,
* it returns null.
*
* @param user The user to prepare for output
* @return new (filtered) {@link User} object or null, if null was passed in.
*/
public static User generateForOutput(User user) {
if (user == null) {
return null;
}
Builder builder = new Builder(user);
builder.setPassword(null);
return builder.build();
}
public Builder(String userName) {
this();
if (userName == null || userName.isEmpty()) {
throw new IllegalArgumentException("userName must not be null or empty.");
}
this.userName = userName;
}
public Builder() {
super();
this.schemas.add(Constants.USER_CORE_SCHEMA);
}
public Builder(User user) {
super(user);
this.userName = user.userName;
this.name = user.name;
this.displayName = user.displayName;
this.nickName = user.nickName;
this.profileUrl = user.profileUrl;
this.title = user.title;
this.userType = user.userType;
this.preferredLanguage = user.preferredLanguage;
this.locale = user.locale;
this.timezone = user.timezone;
this.active = user.active;
this.password = user.password;
this.emails = Objects.firstNonNull(user.emails, this.emails);
this.phoneNumbers = Objects.firstNonNull(user.phoneNumbers, this.phoneNumbers);
this.ims = Objects.firstNonNull(user.ims, this.ims);
this.photos = Objects.firstNonNull(user.photos, this.photos);
this.addresses = Objects.firstNonNull(user.addresses, this.addresses);
this.groups = Objects.firstNonNull(user.groups, this.groups);
this.entitlements = Objects.firstNonNull(user.entitlements, this.entitlements);
this.roles = Objects.firstNonNull(user.roles, this.roles);
this.x509Certificates = Objects.firstNonNull(user.x509Certificates, this.x509Certificates);
this.extensions = Objects.firstNonNull(user.extensions, this.extensions);
}
public Builder setName(Name name) {
this.name = name;
return this;
}
public Builder setDisplayName(String displayName) {
this.displayName = displayName;
return this;
}
public Builder setNickName(String nickName) {
this.nickName = nickName;
return this;
}
public Builder setProfileUrl(String profileUrl) {
this.profileUrl = profileUrl;
return this;
}
public Builder setTitle(String title) {
this.title = title;
return this;
}
public Builder setUserType(String userType) {
this.userType = userType;
return this;
}
public Builder setPreferredLanguage(String preferredLanguage) {
this.preferredLanguage = preferredLanguage;
return this;
}
public Builder setLocale(String locale) {
this.locale = locale;
return this;
}
public Builder setTimezone(String timezone) {
this.timezone = timezone;
return this;
}
public Builder setActive(Boolean active) {
this.active = active;
return this;
}
public Builder setPassword(String password) {
this.password = password;
return this;
}
public Builder setEmails(List emails) {
this.emails = emails;
return this;
}
public Builder setPhoneNumbers(List phoneNumbers) {
this.phoneNumbers = phoneNumbers;
return this;
}
public Builder setIms(List ims) {
this.ims = ims;
return this;
}
public Builder setPhotos(List photos) {
this.photos = photos;
return this;
}
public Builder setAddresses(List addresses) {
this.addresses = addresses;
return this;
}
public Builder setGroups(List groups) {
this.groups = groups;
return this;
}
public Builder setEntitlements(List entitlements) {
this.entitlements = entitlements;
return this;
}
public Builder setRoles(List roles) {
this.roles = roles;
return this;
}
public Builder setX509Certificates(List x509Certificates) {
this.x509Certificates = x509Certificates;
return this;
}
public Builder addExtensions(Set extensions) {
for (Extension entry : extensions) {
this.addExtension(entry);
}
return this;
}
public Builder addExtension(Extension extension) {
extensions.put(extension.getUrn(), extension);
schemas.add(extension.getUrn());
return this;
}
@Override
public Builder setMeta(Meta meta) {
super.setMeta(meta);
return this;
}
@Override
public Builder setExternalId(String externalId) {
super.setExternalId(externalId);
return this;
}
@Override
public Builder setId(String id) {
super.setId(id);
return this;
}
@Override
public Builder setSchemas(Set schemas) {
super.setSchemas(schemas);
return this;
}
@Override
public User build() {
return new User(this);
}
}
}