package fr.inria.anhalytics.commons.entities;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author azhar
 */
public class Address {

    private Long addressId;
    private String addrLine = "";
    private String postBox = "";
    private String postCode = "";
    private String settlement = "";
    private String region = "";
    private Country country;

    public Address() {
    }

    public Address(Long addressId, String addrLine, String postBox, String postCode, String settlement, String region, Country country) {
        this.addressId = addressId;
        this.addrLine = addrLine;
        this.postBox = postBox;
        this.postCode = postCode;
        this.settlement = settlement;
        this.region = region;
        this.country = country;
    }

    /**
     * @return the addressId
     */
    public Long getAddressId() {
        return addressId;
    }

    /**
     * @param addressId the addressId to set
     */
    public void setAddressId(Long addressId) {
        this.addressId = addressId;
    }

    /**
     * @return the addrLine
     */
    public String getAddrLine() {
        return addrLine;
    }

    /**
     * @param addrLine the addrLine to set
     */
    public void setAddrLine(String addrLine) {
        if(addrLine.length() > 150)
            addrLine = addrLine.substring(0, 149);
        this.addrLine = addrLine;
    }

    /**
     * @return the postBox
     */
    public String getPostBox() {
        return postBox;
    }

    /**
     * @param postBox the postBox to set
     */
    public void setPostBox(String postBox) {
        if(postBox.length() > 45)
            postBox = postBox.substring(0, 44);
        this.postBox = postBox;
    }

    /**
     * @return the postCode
     */
    public String getPostCode() {
        return postCode;
    }

    /**
     * @param postCode the postCode to set
     */
    public void setPostCode(String postCode) {
        if(postCode.length() > 45)
            postCode = postCode.substring(0, 44);
        this.postCode = postCode;
    }

    /**
     * @return the Settlement
     */
    public String getSettlement() {
        return settlement;
    }

    /**
     * @param Settlement the Settlement to set
     */
    public void setSettlement(String settlement) {
        if(settlement.length() > 45)
            settlement = settlement.substring(0, 44);
        this.settlement = settlement;
    }

    /**
     * @return the region
     */
    public String getRegion() {
        return region;
    }

    /**
     * @param region the region to set
     */
    public void setRegion(String region) {
        if(region.length() > 45)
            region = region.substring(0, 44);
        this.region = region;
    }

    /**
     * @return the country
     */
    public Country getCountry() {
        return country;
    }

    /**
     * @param country the country to set
     */
    public void setCountry(Country country) {
        this.country = country;
    }

    public Map<String, Object> getAddressDocument() {
        Map<String, Object> addressDocument = new HashMap<String, Object>();
        addressDocument.put("addressId", this.getAddressId());
        addressDocument.put("addrLine", this.getAddrLine());
        addressDocument.put("country", this.getCountry().getIso());
        addressDocument.put("postBox", this.getPostBox());
        addressDocument.put("postCode", this.getPostCode());
        addressDocument.put("region", this.getRegion());
        addressDocument.put("settlement", this.getSettlement());
        return addressDocument;

    }
}

@@ -1267,16 +1267,17 @@
       if
+ 
 (addrLin
@@ -1293,16 +1293,18 @@
 ) %3E 150)
+ %7B
 %0A       
@@ -1347,16 +1347,26 @@
 , 149);%0A
+        %7D%0A
         
@@ -1613,24 +1613,25 @@
 %7B%0A        if
+ 
 (postBox.len
@@ -1633,32 +1633,34 @@
 x.length() %3E 45)
+ %7B
 %0A            pos
@@ -1684,32 +1684,42 @@
 bstring(0, 44);%0A
+        %7D%0A
         this.pos
@@ -1967,16 +1967,17 @@
       if
+ 
 (postCod
@@ -1984,32 +1984,34 @@
 e.length() %3E 45)
+ %7B
 %0A            pos
@@ -2037,32 +2037,42 @@
 bstring(0, 44);%0A
+        %7D%0A
         this.pos
@@ -2336,16 +2336,17 @@
       if
+ 
 (settlem
@@ -2355,32 +2355,34 @@
 t.length() %3E 45)
+ %7B
 %0A            set
@@ -2412,32 +2412,42 @@
 bstring(0, 44);%0A
+        %7D%0A
         this.set
@@ -2687,16 +2687,17 @@
       if
+ 
 (region.
@@ -2710,16 +2710,18 @@
 () %3E 45)
+ %7B
 %0A       
@@ -2751,32 +2751,42 @@
 bstring(0, 44);%0A
+        %7D%0A
         this.reg
@@ -3307,24 +3307,69 @@
 ddrLine());%0A
+        if (this.getCountry() != null) %7B%0A    
         addr
@@ -3420,24 +3420,99 @@
 .getIso());%0A
+        %7D else %7B%0A            addressDocument.put(%22country%22, %22%22);%0A        %7D%0A
         addr

Correct when country is null.