/*
* 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.storage.entities;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Lob;
import javax.persistence.Table;
import org.hibernate.annotations.Type;
import org.osiam.resources.scim.Address;
/**
* Address Entity
*/
@Entity
@Table(name = "scim_address",
indexes = {
@Index(columnList = "type"),
@Index(columnList = "country, region, locality, postalCode, streetAddress"),
})
public class AddressEntity extends BaseMultiValuedAttributeEntity {
/**
* <p>
* The type of this Address.
* </p>
*
* <p>
* Custom type mapping is provided by {@link org.osiam.storage.entities.jpa_converters.AddressTypeConverter}.
* </p>
*/
@Basic
private Address.Type type; // @Basic is needed for JPA meta model generator
@Lob
@Type(type = "org.hibernate.type.StringClobType")
private String formatted;
private String streetAddress;
private String locality;
private String region;
private String postalCode;
private String country;
public Address.Type getType() {
return type;
}
public void setType(Address.Type type) {
this.type = type;
}
public String getFormatted() {
return formatted;
}
public void setFormatted(String formatted) {
this.formatted = formatted;
}
public String getStreetAddress() {
return streetAddress;
}
public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}
public String getLocality() {
return locality;
}
public void setLocality(String locality) {
this.locality = locality;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (country == null ? 0 : country.hashCode());
result = prime * result + (formatted == null ? 0 : formatted.hashCode());
result = prime * result + (locality == null ? 0 : locality.hashCode());
result = prime * result + (postalCode == null ? 0 : postalCode.hashCode());
result = prime * result + (region == null ? 0 : region.hashCode());
result = prime * result + (streetAddress == null ? 0 : streetAddress.hashCode());
result = prime * result + (type == null ? 0 : type.hashCode());
return result;
}
@Override
@SuppressWarnings("all")
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
AddressEntity other = (AddressEntity) obj;
if (country == null) {
if (other.country != null) {
return false;
}
} else if (!country.equals(other.country)) {
return false;
}
if (formatted == null) {
if (other.formatted != null) {
return false;
}
} else if (!formatted.equals(other.formatted)) {
return false;
}
if (locality == null) {
if (other.locality != null) {
return false;
}
} else if (!locality.equals(other.locality)) {
return false;
}
if (postalCode == null) {
if (other.postalCode != null) {
return false;
}
} else if (!postalCode.equals(other.postalCode)) {
return false;
}
if (region == null) {
if (other.region != null) {
return false;
}
} else if (!region.equals(other.region)) {
return false;
}
if (streetAddress == null) {
if (other.streetAddress != null) {
return false;
}
} else if (!streetAddress.equals(other.streetAddress)) {
return false;
}
if (type == null) {
if (other.type != null) {
return false;
}
} else if (!type.equals(other.type)) {
return false;
}
return true;
}
@Override
public String toString() {
return "AddressEntity [type=" + type + ", formatted=" + formatted + ", streetAddress=" + streetAddress
+ ", locality=" + locality + ", region=" + region + ", postalCode=" + postalCode + ", country="
+ country + ", primary=" + isPrimary() + "]";
}
}