org.starhope.appius.mb
Class UserAddress

java.lang.Object
  extended by org.starhope.appius.sql.SQLPeerDatum
      extended by org.starhope.appius.mb.UserAddress
All Implemented Interfaces:
Serializable, Comparable<Object>

public class UserAddress
extends SQLPeerDatum

Author:
brpocock@star-hope.org
See Also:
Serialized Form

Field Summary
private  String address
          Street address (or similar), line 1 (of 2)
private  String address2
          Street address (or similar), line 2 (of 2)
private  String addressType
          The type of location described; might be e.g.
private  String city
          The city, town, village, &c.
private  String country
          The 2-digit ISO country code
private  int database_id
          The unique ID for storing this address into the database (if so stored)
private  BigDecimal latitude
          if known, the latitude of the address
private  String locality
          the locality or other subdivisional indicia of the address
private  BigDecimal longitude
          if known, the longitude of the address
private  String mail
          an eMail address
private  String phone
          a telephone number with local formatting as desired
private  String postalCode
          The postal or ZIP code.
private  String province
          The state or province
private static long serialVersionUID
          Java serializations user ID
private  String title
          A user-selected title for convenience of user selection of an address from a collection
private  AbstractPerson user
          The user affiliated with this address
private  String validatedByDomain
          The Internet Domain Name of the service used for validation (e.g.
private  Date validatedOn
          The date of validation, if this address has been externally validated; else, null
private  String zipPlus4
          WRITEME
 
Constructor Summary
UserAddress(String addressFirst, String addressSecond, String theCity, String stateProvinceOrLocality, String theCountry, String thePostalCode, String phoneNumber, String electronicMail)
          WRITEME: Document this constructor brpocock@star-hope.org
 
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()
          WRITEME: document this method (brpocock@star-hope.org, Sep 24, 2009)
 String getMail()
           
 String getPhone()
          WRITEME: document this method (brpocock@star-hope.org, Sep 24, 2009)
 String getPostalCode()
           
 String getPropertyNumber()
           
 String getProvince()
           
 String getStreetName()
           
 String getStreetType()
           
 String getTitle()
           
 AbstractPerson 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 setLatitude(BigDecimal latitude1)
           
 void setLocality(String locality1)
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 void setLongitude(BigDecimal longitude1)
           
 void setMail(String newMail)
           
 void setPhone(String phone1)
          WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)
 void setPostalCode(String newPostalCode)
           
 void setProvince(String newProvince)
           
 void setTitle(String newTitle)
           
 void setUser(AbstractPerson newUser)
           
 void setValidatedByDomain(String validatedByDomain1)
           
 void setValidatedOn(Date validated)
           
 void setZipPlus4(String newZipPlus4)
           
 org.json.JSONObject toJSON()
          This is an overriding method.
 boolean validate()
          This method should validate the supplied address by passing it through a geocoding service or similar methods.
 
Methods inherited from class org.starhope.appius.sql.SQLPeerDatum
changed, compareTo, findInCache, get, saveInCache
 
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
Java serializations user ID

See Also:
Constant Field Values

address

private String address
Street address (or similar), line 1 (of 2)

See Also:
address2

address2

private String address2
Street address (or similar), line 2 (of 2)

See Also:
address

addressType

private String addressType
The type of location described; might be e.g. Billing, Home, Office.


city

private String city
The city, town, village, &c. part of the address


country

private String country
The 2-digit ISO country code


database_id

private final int database_id
The unique ID for storing this address into the database (if so stored)

See Also:
Constant Field Values

latitude

private BigDecimal latitude
if known, the latitude of the address


locality

private String locality
the locality or other subdivisional indicia of the address


longitude

private BigDecimal longitude
if known, the longitude of the address


mail

private String mail
an eMail address


phone

private String phone
a telephone number with local formatting as desired


postalCode

private String postalCode
The postal or ZIP code. US ZIP codes must not have the ZIP+4 or 12-digit format in this variable.


province

private String province
The state or province


title

private String title
A user-selected title for convenience of user selection of an address from a collection


user

private AbstractPerson user
The user affiliated with this address


validatedByDomain

private String validatedByDomain
The Internet Domain Name of the service used for validation (e.g. "google.com" for Google Maps); null, if the address has not been validated


validatedOn

private Date validatedOn
The date of validation, if this address has been externally validated; else, null


zipPlus4

private String zipPlus4
WRITEME

Constructor Detail

UserAddress

public UserAddress(String addressFirst,
                   String addressSecond,
                   String theCity,
                   String stateProvinceOrLocality,
                   String theCountry,
                   String thePostalCode,
                   String phoneNumber,
                   String electronicMail)
WRITEME: Document this constructor brpocock@star-hope.org

Parameters:
addressFirst - WRITEME
addressSecond - WRITEME
theCity - WRITEME
stateProvinceOrLocality - WRITEME
theCountry - WRITEME
thePostalCode - WRITEME
phoneNumber - WRITEME
electronicMail - WRITEME
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()
WRITEME: document this method (brpocock@star-hope.org, Sep 24, 2009)

Returns:
WRITEME

getMail

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

getPhone

public String getPhone()
WRITEME: document this method (brpocock@star-hope.org, Sep 24, 2009)

Returns:
WRITEME

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 AbstractPerson 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” only after an external validation has been performed upon this address, e.g. via Google Maps or similar

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
Parameters:
o - The JSON data to be used to set the value of this object
See Also:
org.starhope.appius.util.CastsToJSON#set(org.json.JSONObject)

set

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

Specified by:
set in class SQLPeerDatum
Parameters:
rs - The result of an SQL query, with the cursor already pointed at the row describing this specific instance of the object.
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

setLatitude

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

setLocality

public void setLocality(String locality1)
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Parameters:
locality1 - WRITEME

setLongitude

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

setMail

public void setMail(String newMail)
Parameters:
newMail - WRITEME

setPhone

public void setPhone(String phone1)
WRITEME: document this method (brpocock@star-hope.org, Sep 23, 2009)

Parameters:
phone1 - WRITEME

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(AbstractPerson newUser)
Parameters:
newUser - the user whose address this is

setValidatedByDomain

public void setValidatedByDomain(String validatedByDomain1)
Parameters:
validatedByDomain1 - 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:
This object's data, serialized into JSON form.
See Also:
SQLPeerDatum.toJSON()

validate

public boolean validate()
This method should validate the supplied address by passing it through a geocoding service or similar methods. A minimum level of validation should include an integrity check that values such as ZIP code and city are plausible, even if it does not accurately determine such details as the street address's actual existence.

Returns:
True, if the address supplied appears to be potentially valid