001//@formatter:off
002/*
003 * Customer 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 * Customer 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 CustomerEntity {
031
032    private static final Logger LOGGER = LoggerFactory.getLogger(CustomerEntity.class);
033
034    /**
035     * id of customer
036     */
037    private String customerId = null;
038
039    /**
040     * title field
041     */
042    private String title = null;
043
044    /**
045     * last name
046     */
047    private String lastName = null;
048
049    /**
050     * first name
051     */
052    private String firstName = null;
053
054    /**
055     * phone number
056     */
057    private String phone = null;
058
059    /**
060     * email address
061     */
062    private String email = null;
063
064    /**
065     * flag to indicate allowence for promotion activity
066     */
067    private boolean promotionOptIn = false;
068
069    // typically more attributes
070
071    /**
072     * Creates new customer entity
073     */
074    public CustomerEntity() {
075
076    }
077
078    /**
079     * Creates new entity from the given data
080     * 
081     * @param customerId identifier
082     * @param title person's title
083     * @param lastName person's last name
084     * @param firstName person's first name
085     * @param phone telephone number
086     * @param email email-address
087     * @param promotionOptIn opt-in-flag for promotion events
088     */
089    public CustomerEntity(String customerId, String title, String lastName, String firstName, String phone, String email, boolean promotionOptIn) {
090        this.customerId = customerId;
091        this.title = title;
092        this.lastName = lastName;
093        this.firstName = firstName;
094        this.phone = phone;
095        this.email = email;
096        this.promotionOptIn = promotionOptIn;
097    }
098
099    /**
100     * Returns the customerId
101     * 
102     * @return customerId
103     */
104    public String getCustomerId() {
105        return customerId;
106    }
107
108    /**
109     * Sets the customerId
110     * 
111     * @param customerId identifier
112     */
113    public void setCustomerId(String customerId) {
114        this.customerId = customerId;
115    }
116
117    /**
118     * Returns customer title
119     * 
120     * @return title of customer
121     */
122    public String getTitle() {
123        return title;
124    }
125
126    /**
127     * Sets the customer's title
128     * 
129     * @param title person's title
130     */
131    public void setTitle(String title) {
132        this.title = title;
133    }
134
135    /**
136     * Returns the last name of customer
137     * 
138     * @return lastName
139     */
140    public String getLastName() {
141        return lastName;
142    }
143
144    /**
145     * Sets the customer's last name
146     * 
147     * @param lastName person's last name
148     */
149    public void setLastName(String lastName) {
150        this.lastName = lastName;
151    }
152
153    /**
154     * Returns the customer's first name
155     * 
156     * @return firstName
157     */
158    public String getFirstName() {
159        return firstName;
160    }
161
162    /**
163     * Sets the customer's first name
164     * 
165     * @param firstName person's first name
166     */
167    public void setFirstName(String firstName) {
168        this.firstName = firstName;
169    }
170
171    /**
172     * Returns the customer's phone number
173     * 
174     * @return phone
175     */
176    public String getPhone() {
177        return phone;
178    }
179
180    /**
181     * Sets the customer's phone number
182     * 
183     * @param phone telephone number
184     */
185    public void setPhone(String phone) {
186        this.phone = phone;
187    }
188
189    /**
190     * Returns the customer's email address
191     * 
192     * @return email
193     */
194    public String getEmail() {
195        return email;
196    }
197
198    /**
199     * Sets the customer's email address
200     * 
201     * @param email email-address
202     */
203    public void setEmail(String email) {
204        this.email = email;
205    }
206
207    /**
208     * Returns whether the customer has agreed to receive advertisement media
209     * 
210     * @return true if customer has agreed, otherwise (default) false
211     */
212    public boolean isPromotionOptIn() {
213        return promotionOptIn;
214    }
215
216    /**
217     * Sets the customer's promotion status, whether to participate in sales promotion actions or not
218     * 
219     * @param promotionOptIn true means the customer has agreed to receive advertisement media
220     */
221    public void setPromotionOptIn(boolean promotionOptIn) {
222        this.promotionOptIn = promotionOptIn;
223    }
224
225    /**
226     * Returns a data transfer object corresponding to this entity
227     * 
228     * @return dto
229     */
230    public CustomerDto toDto() {
231        LOGGER.debug("{}.toDto() called", this.getClass().getSimpleName());
232        return new CustomerDto(customerId, title, lastName, firstName, phone, email, promotionOptIn);
233    }
234
235    /**
236     * Updates this entity from the given data transfer object
237     * 
238     * @param dto data transfer object to copy data from into this object
239     */
240    public void fromDto(CustomerDto dto) {
241        this.customerId = dto.getCustomerId();
242        this.title = dto.getTitle();
243        this.lastName = dto.getLastName();
244        this.firstName = dto.getFirstName();
245        this.phone = dto.getPhone();
246        this.email = dto.getEmail();
247        this.promotionOptIn = dto.isPromotionOptIn();
248    }
249
250    @Override
251    public String toString() {
252        return this.getClass().getSimpleName() + "({customerId=" + customerId + ", title=" + title + ", lastName=" + lastName + ", firstName=" + firstName
253                + ", phone=" + phone + ", email=" + email + ", promotionOptIn=" + promotionOptIn + "})";
254    }
255
256}