189 lines
4.7 KiB
Java
189 lines
4.7 KiB
Java
package com.iamthefij.otbeta.api;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
|
|
/**
|
|
* Represents a company location
|
|
*/
|
|
public class Location {
|
|
// Always present
|
|
private final Integer mId;
|
|
private final String mExternalMappingId;
|
|
private final String mFeatures;
|
|
private final String mMms;
|
|
private final String mName;
|
|
private final String mPhone;
|
|
private final String mStatus;
|
|
private final String mStatusTillDate;
|
|
private final String mUuid;
|
|
private String mTimezone;
|
|
// Details only
|
|
private Address mAddress;
|
|
|
|
public Integer getId() {
|
|
return mId;
|
|
}
|
|
|
|
public String getUuid() {
|
|
return mUuid;
|
|
}
|
|
|
|
public String getName() {
|
|
return mName;
|
|
}
|
|
|
|
public String getExternalMappingId() {
|
|
return mExternalMappingId;
|
|
}
|
|
|
|
public String getTimezone() {
|
|
return mTimezone;
|
|
}
|
|
|
|
public String getPhone() {
|
|
return mPhone;
|
|
}
|
|
|
|
public String getFeatures() {
|
|
return mFeatures;
|
|
}
|
|
|
|
public String getStatus() {
|
|
return mStatus;
|
|
}
|
|
|
|
public String getStatusTillDate() {
|
|
return mStatusTillDate;
|
|
}
|
|
|
|
public String getMms() {
|
|
return mMms;
|
|
}
|
|
|
|
public Address getAddress() {
|
|
return mAddress;
|
|
}
|
|
|
|
public boolean hasAddress() {
|
|
return mAddress != null;
|
|
}
|
|
|
|
/**
|
|
* Creates a Location from a {@link JSONObject}
|
|
*/
|
|
public Location(JSONObject locationJSON) {
|
|
mId = locationJSON.optInt("id");
|
|
mUuid = locationJSON.optString("uuid");
|
|
mName = locationJSON.optString("name");
|
|
mExternalMappingId = locationJSON.optString("externalMappingId");
|
|
mTimezone = locationJSON.optString("timezone");
|
|
mPhone = locationJSON.optString("phone");
|
|
mFeatures = locationJSON.optString("features");
|
|
mStatus = locationJSON.optString("status");
|
|
mStatusTillDate = locationJSON.optString("statusTillDate");
|
|
mMms = locationJSON.optString("mms");
|
|
|
|
JSONObject address = locationJSON.optJSONObject("address");
|
|
if (address != null) {
|
|
mAddress = new Address();
|
|
mAddress.setAddressLine1(address.optString("addressLine1"));
|
|
mAddress.setAddressLine2(address.optString("addressLine2"));
|
|
mAddress.setLocality(address.optString("city"));
|
|
mAddress.setCountryCode(address.optString("country"));
|
|
mAddress.setPostalCode(address.optString("postalCode"));
|
|
mAddress.setAdminArea(address.optString("stateOrProvince"));
|
|
if (mTimezone == null) {
|
|
mTimezone = address.optString("timezone");
|
|
}
|
|
mAddress.setLatitude(address.optDouble("lat"));
|
|
mAddress.setLongitude(address.optDouble("lng"));
|
|
}
|
|
}
|
|
|
|
public class Address {
|
|
String mAddressLine1;
|
|
String mAddressLine2;
|
|
String mLocality;
|
|
String mCountryCode;
|
|
String mPostalCode;
|
|
String mAdminArea;
|
|
Double mLatitude;
|
|
Double mLongitude;
|
|
|
|
public String getAddressLine1() {
|
|
return mAddressLine1;
|
|
}
|
|
|
|
public void setAddressLine1(String addressLine) {
|
|
mAddressLine1 = addressLine;
|
|
}
|
|
|
|
public String getAddressLine2() {
|
|
return mAddressLine2;
|
|
}
|
|
|
|
public void setAddressLine2(String addressLine) {
|
|
mAddressLine2 = addressLine;
|
|
}
|
|
|
|
public String getLocality() {
|
|
return mLocality;
|
|
}
|
|
|
|
public void setLocality(String locality) {
|
|
mLocality = locality;
|
|
}
|
|
|
|
public String getCountryCode() {
|
|
return mCountryCode;
|
|
}
|
|
|
|
public void setCountryCode(String countryCode) {
|
|
mCountryCode = countryCode;
|
|
}
|
|
|
|
public String getPostalCode() {
|
|
return mPostalCode;
|
|
}
|
|
|
|
public void setPostalCode(String postalCode) {
|
|
mPostalCode = postalCode;
|
|
}
|
|
|
|
public String getAdminArea() {
|
|
return mAdminArea;
|
|
}
|
|
|
|
public void setAdminArea(String adminArea) {
|
|
mAdminArea = adminArea;
|
|
}
|
|
|
|
public Double getLatitude() {
|
|
return mLatitude;
|
|
}
|
|
|
|
public boolean hasLatitude() {
|
|
return mLatitude != null && !mLatitude.isNaN();
|
|
}
|
|
|
|
public void setLatitude(Double latitude) {
|
|
mLatitude = latitude;
|
|
}
|
|
|
|
public Double getLongitude() {
|
|
return mLongitude;
|
|
}
|
|
|
|
public boolean hasLongitude() {
|
|
return mLongitude != null && !mLongitude.isNaN();
|
|
}
|
|
|
|
public void setLongitude(Double longitude) {
|
|
mLongitude = longitude;
|
|
}
|
|
}
|
|
}
|