001//@formatter:off
002/*
003 * Address Entity - one of the business entities in this example.
004 * Code-Beispiel zum Buch Patterns Kompakt, Verlag Springer Vieweg
005 * Copyright 2014 Karl Eilebrecht
006 * 
007 * Licensed under the Apache License, Version 2.0 (the "License"):
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019//@formatter:on
020package de.calamanari.pk.transferobjectassembler;
021
022import org.slf4j.Logger;
023import org.slf4j.LoggerFactory;
024
025/**
026 * Address Entity - one of the business entities in this example.
027 * 
028 * @author <a href="mailto:Karl.Eilebrecht(a/t)calamanari.de">Karl Eilebrecht</a>
029 */
030public class AddressEntity {
031
032    private static final Logger LOGGER = LoggerFactory.getLogger(AddressEntity.class);
033
034    /**
035     * address identifier
036     */
037    private String addressId = null;
038
039    /**
040     * Id of customer
041     */
042    private String customerId = null;
043
044    /**
045     * street
046     */
047    private String street = null;
048
049    /**
050     * Zip code
051     */
052    private String zipCode = null;
053
054    /**
055     * city
056     */
057    private String city = null;
058
059    /**
060     * country
061     */
062    private String country = null;
063
064    /**
065     * salutation
066     */
067    private String salutation = null;
068
069    /**
070     * Creates new address entity
071     */
072    public AddressEntity() {
073
074    }
075
076    /**
077     * Creates new address entity from the given data
078     * 
079     * @param addressId identifier
080     * @param customerId related customer's identifier
081     * @param street address field
082     * @param zipCode address field
083     * @param city address field
084     * @param country address field
085     * @param salutation address field
086     */
087    public AddressEntity(String addressId, String customerId, String street, String zipCode, String city, String country, String salutation) {
088        this.addressId = addressId;
089        this.customerId = customerId;
090        this.street = street;
091        this.zipCode = zipCode;
092        this.city = city;
093        this.country = country;
094        this.salutation = salutation;
095    }
096
097    /**
098     * Returns the address ID
099     * 
100     * @return addressId
101     */
102    public String getAddressId() {
103        return addressId;
104    }
105
106    /**
107     * Sets the address ID
108     * 
109     * @param addressId identifier
110     */
111    public void setAddressId(String addressId) {
112        this.addressId = addressId;
113    }
114
115    /**
116     * Returns the customer ID
117     * 
118     * @return customerId
119     */
120    public String getCustomerId() {
121        return customerId;
122    }
123
124    /**
125     * Sets the customer ID
126     * 
127     * @param customerId related customer's identifier
128     */
129    public void setCustomerId(String customerId) {
130        this.customerId = customerId;
131    }
132
133    /**
134     * Returns street address
135     * 
136     * @return street
137     */
138    public String getStreet() {
139        return street;
140    }
141
142    /**
143     * Sets street address
144     * 
145     * @param street address field
146     */
147    public void setStreet(String street) {
148        this.street = street;
149    }
150
151    /**
152     * Returns the zipcode
153     * 
154     * @return zipCode
155     */
156    public String getZipCode() {
157        return zipCode;
158    }
159
160    /**
161     * Sets the zipCode
162     * 
163     * @param zipCode address field
164     */
165    public void setZipCode(String zipCode) {
166        this.zipCode = zipCode;
167    }
168
169    /**
170     * Returns the city name
171     * 
172     * @return city
173     */
174    public String getCity() {
175        return city;
176    }
177
178    /**
179     * Sets the city name
180     * 
181     * @param city address field
182     */
183    public void setCity(String city) {
184        this.city = city;
185    }
186
187    /**
188     * Returns the country name
189     * 
190     * @return country
191     */
192    public String getCountry() {
193        return country;
194    }
195
196    /**
197     * Sets the country
198     * 
199     * @param country address field
200     */
201    public void setCountry(String country) {
202        this.country = country;
203    }
204
205    /**
206     * Returns salutation for letters
207     * 
208     * @return salutation
209     */
210    public String getSalutation() {
211        return salutation;
212    }
213
214    /**
215     * Sets the salutation for letters
216     * 
217     * @param salutation address field
218     */
219    public void setSalutation(String salutation) {
220        this.salutation = salutation;
221    }
222
223    /**
224     * Returns a corresponding data transfer object for this Address
225     * 
226     * @return dto
227     */
228    public AddressDto toDto() {
229        LOGGER.debug("{}.toDto() called", this.getClass().getSimpleName());
230        return new AddressDto(addressId, customerId, street, zipCode, city, country, salutation);
231    }
232
233    /**
234     * Updates this entity from the given data transfer object
235     * 
236     * @param dto source data transfer object to copy data from into this instance
237     */
238    public void fromDto(AddressDto dto) {
239        this.addressId = dto.getAddressId();
240        this.customerId = dto.getCustomerId();
241        this.salutation = dto.getSalutation();
242        this.street = dto.getStreet();
243        this.zipCode = dto.getZipCode();
244        this.city = dto.getCity();
245        this.country = dto.getCountry();
246    }
247
248    @Override
249    public String toString() {
250        return this.getClass().getSimpleName() + "({addressId=" + addressId + ", customerId=" + customerId + ", street=" + street + ", zipCode=" + zipCode
251                + ", city=" + city + ", country=" + country + ", salutation=" + salutation + "})";
252    }
253
254}