org.starhope.appius.mb
Class UserAddress

java.lang.Object
  extended by org.starhope.appius.util.ManagedReferenceHolder
      extended by org.starhope.appius.sql.SQLPeerDatum
          extended by org.starhope.appius.mb.UserAddress

public class UserAddress
extends SQLPeerDatum

Author:
brpocock

Field Summary
private  String address
           
private  String address2
           
private  String addressType
           
private  String city
           
private  String country
           
private  int database_id
           
private  boolean externallyValidated
           
private  BigDecimal latitude
           
private  String locality
           
private  BigDecimal longitude
           
private  String mail
           
private  String postalCode
           
private  String province
           
private static long serialVersionUID
           
private  String title
           
private  Person user
           
private  String validatedByDomain
           
private  Date validatedOn
           
private  String zipPlus4
           
 
Constructor Summary
UserAddress()
           
 
Method Summary
 void asyncValidate()
          Request an asynchronous validation against some online service or other (Google, Yahoo, whoever)
 boolean equals(String streetAddress, String otherCity, String otherProvince, String otherPostalCode, String otherCountry)
           Convenience method, to match up against the address fields as provided by Authorize.Net.
 void flush()
          This is an overriding method.
static UserAddress get(org.json.JSONObject object)
           
 String getAddress()
           
 String getAddress2()
           
 String getAddressPair()
           
 String getAddressType()
           
 String getApartment()
           
protected  String getCacheUniqueID()
           
 String getCity()
           
 String getCountry()
           
 BigDecimal getIntitude()
           
 BigDecimal getLatitude()
           
 String getLocality()
           
 String getMail()
           
 String getPostalCode()
           
 String getPropertyNumber()
           
 String getProvince()
           
 String getStreetName()
           
 String getStreetType()
           
 String getTitle()
           
 Person getUser()
           
 String getValidatedByDomain()
           
 Date getValidatedOn()
           
 String getZipPlus4()
           
 boolean isExternallyValidated()
           
 boolean isValidAddress()
          This method determines whether the supplied address is plausible to be valid.
 void set(org.json.JSONObject o)
           
protected  void set(ResultSet rs)
          This is an overriding method.
 void setAddress(String newAddress, String newAddress2)
           
 void setAddressType(String newAddressType)
           
 void setCity(String newCity)
           
 void setCountry(String newCountry)
           
 void setExternallyValidated(boolean externallyValidated)
           
 void setIntitude(BigDecimal longitude)
           
 void setLatitude(BigDecimal latitude)
           
 void setLocality(String locality)
           
 void setMail(String newMail)
           
 void setPostalCode(String newPostalCode)
           
 void setProvince(String newProvince)
           
 void setTitle(String newTitle)
           
 void setUser(Person newUser)
           
 void setValidatedByDomain(String validatedByDomain)
           
 void setValidatedOn(Date validated)
           
 void setZipPlus4(String newZipPlus4)
           
 org.json.JSONObject toJSON()
          This is an overriding method.
 
Methods inherited from class org.starhope.appius.sql.SQLPeerDatum
changed, findInCache, get, prepare, prepare, saveInCache
 
Methods inherited from class org.starhope.appius.util.ManagedReferenceHolder
deref, setRef
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

address

private String address

address2

private String address2

addressType

private String addressType

city

private String city

country

private String country

database_id

private int database_id

externallyValidated

private boolean externallyValidated

latitude

private BigDecimal latitude

locality

private String locality

longitude

private BigDecimal longitude

mail

private String mail

postalCode

private String postalCode

province

private String province

title

private String title

user

private Person user

validatedByDomain

private String validatedByDomain

validatedOn

private Date validatedOn

zipPlus4

private String zipPlus4
Constructor Detail

UserAddress

public UserAddress()
Method Detail

get

public static UserAddress get(org.json.JSONObject object)
                       throws NotFoundException,
                              org.json.JSONException
Parameters:
object - The JSON object containing the reference to an address
Returns:
the UserAddress requested
Throws:
NotFoundException - if the address couldn't be found in the database sense. (Does not necessarily mean that the address exists IRL)
org.json.JSONException - if the JSON data couldn't be decoded properly

asyncValidate

public void asyncValidate()
Request an asynchronous validation against some online service or other (Google, Yahoo, whoever)


equals

public boolean equals(String streetAddress,
                      String otherCity,
                      String otherProvince,
                      String otherPostalCode,
                      String otherCountry)

Convenience method, to match up against the address fields as provided by Authorize.Net. Plus, it might come in useful in other contexts as well.

Note that this method doesn't care about address line two, but it's quite strict on the rest. It would actually make sense to run both addresses through some minimal degree of conformance first, but that's outside the current SOW. TODO?

Parameters:
streetAddress - streetAddress
otherCity - city
otherProvince - province/state
otherPostalCode - postal/ZIP code
otherCountry - country
Returns:
True, if all of the fields match up.

flush

public void flush()
This is an overriding method.

Specified by:
flush in class SQLPeerDatum
See Also:
SQLPeerDatum.flush()

getAddress

public String getAddress()
Returns:
line 1 of the street address

getAddress2

public String getAddress2()
Returns:
line 2 of the street address

getAddressPair

public String getAddressPair()
Returns:
both lines of the street address, separated with a newline. If the address has only one line, it will not have a newline and a second line.

getAddressType

public String getAddressType()
Returns:
the type of address which this represents

getApartment

public String getApartment()
Returns:
the apartment number of the address

getCacheUniqueID

protected String getCacheUniqueID()
Specified by:
getCacheUniqueID in class SQLPeerDatum
Returns:
The local (Stringified) version of an unique ID; usually the database ID column
See Also:
SQLPeerDatum.getCacheUniqueID()

getCity

public String getCity()
Returns:
the city of the address

getCountry

public String getCountry()
Returns:
the country code for the address (2-char ISO code)

getIntitude

public BigDecimal getIntitude()
Returns:
the longitude (if known)

getLatitude

public BigDecimal getLatitude()
Returns:
the latitude (if known)

getLocality

public String getLocality()

getMail

public String getMail()
Returns:
the postal code of the address

getPostalCode

public String getPostalCode()
Returns:
the postal code of the address

getPropertyNumber

public String getPropertyNumber()
Returns:
the property number (house number) of the address

getProvince

public String getProvince()
Returns:
the province/state part of the address

getStreetName

public String getStreetName()
Returns:
the street name (without the street type, e.g. for "123 Sesame St" this would yield "Sesame")

getStreetType

public String getStreetType()
Returns:
the street type (e.g. "St" or "Ave")

getTitle

public String getTitle()
Returns:
the title for this address, supplied by the user: e.g. "Home" or "Office" perhaps

getUser

public Person getUser()
Returns:
The user owning this address

getValidatedByDomain

public String getValidatedByDomain()
Returns:
the domain of the service which validated this address (if any)

getValidatedOn

public Date getValidatedOn()
Returns:
the date at which this address was validated

getZipPlus4

public String getZipPlus4()
Returns:
the four-digit "PLUS-4" part of a ZIP code

isExternallyValidated

public boolean isExternallyValidated()
Returns:
true, if an external engine has validated the address

isValidAddress

public boolean isValidAddress()
This method determines whether the supplied address is plausible to be valid. TODO

Returns:
false, if the address is clearly not valid

set

public void set(org.json.JSONObject o)
Overrides:
set in class SQLPeerDatum
See Also:
CastsToJSON.set(org.json.JSONObject)

set

protected void set(ResultSet rs)
            throws SQLException
This is an overriding method.

Specified by:
set in class SQLPeerDatum
Throws:
SQLException - if the database fails somehow
See Also:
SQLPeerDatum.set(java.sql.ResultSet)

setAddress

public void setAddress(String newAddress,
                       String newAddress2)
Parameters:
newAddress - the first line of the address
newAddress2 - the second line

setAddressType

public void setAddressType(String newAddressType)
Parameters:
newAddressType - the type of the address

setCity

public void setCity(String newCity)
Parameters:
newCity - the city/town/village part of the address

setCountry

public void setCountry(String newCountry)
Parameters:
newCountry - the country code for the address

setExternallyValidated

public void setExternallyValidated(boolean externallyValidated)
Parameters:
externallyValidated - the externallyValidated to set

setIntitude

public void setIntitude(BigDecimal longitude)
Parameters:
longitude - the longitude to set

setLatitude

public void setLatitude(BigDecimal latitude)
Parameters:
latitude - the latitude to set

setLocality

public void setLocality(String locality)

setMail

public void setMail(String newMail)
Parameters:
newMail -
newPostalCode - the postal/ZIP code of the address

setPostalCode

public void setPostalCode(String newPostalCode)
Parameters:
newPostalCode - the postal/ZIP code of the address

setProvince

public void setProvince(String newProvince)
Parameters:
newProvince - the province/state/locality of the address

setTitle

public void setTitle(String newTitle)
Parameters:
newTitle - the user-visible title of the address

setUser

public void setUser(Person newUser)
Parameters:
newUser - the user whose address this is

setValidatedByDomain

public void setValidatedByDomain(String validatedByDomain)
Parameters:
validatedByDomain - the validatedByDomain to set

setValidatedOn

public void setValidatedOn(Date validated)
Parameters:
validated - the validated to set

setZipPlus4

public void setZipPlus4(String newZipPlus4)
Parameters:
newZipPlus4 - the ZIP+4 code for a US address

toJSON

public org.json.JSONObject toJSON()
This is an overriding method.

Overrides:
toJSON in class SQLPeerDatum
Returns:
See Also:
SQLPeerDatum.toJSON()