1 package com.leonarduk.clearcheckbook.dto;
2
3 import java.util.Map;
4
5 import org.apache.log4j.Logger;
6
7 /***
8 *
9 *
10 *
11 * @author Stephen Leonard
12 * @since 28 Jan 2014
13 *
14 * @version $Author:: $: Author of last commit
15 * @version $Rev:: $: Revision of last commit
16 * @version $Date:: $: Date of last commit
17 *
18 */
19 public class UserDataType extends AbstractDataType<UserDataType> {
20
21 enum Fields {
22 EMAIL, PASSWORD, USERNAME, APP
23 }
24
25 @Override
26 protected Enum<?>[] getFields() {
27 return Fields.values();
28 }
29
30 private static final Logger _logger = Logger.getLogger(UserDataType.class);
31
32 public static UserDataType create(String username, String email,
33 String password) {
34 return UserDataType.create(username, email, password, "JAVA");
35 }
36
37 /***
38 * Create user passing the optional application parameter.
39 *
40 * @param username
41 * @param email
42 * @param password
43 * @param application
44 * @return
45 */
46 public static UserDataType create(String username, String email,
47 String password, String application) {
48 UserDataType userDataType = new UserDataType();
49 userDataType.addField(Fields.EMAIL, email);
50 userDataType.addField(Fields.PASSWORD, password);
51 userDataType.addField(Fields.USERNAME, username);
52 userDataType.addField(Fields.APP, application);
53
54 _logger.debug("Created: " + userDataType);
55 return userDataType;
56 }
57
58 private UserDataType() {
59 }
60
61 public UserDataType(Map<String, String> fieldMap) {
62 super(fieldMap);
63 }
64
65 public String getApplication() {
66 return getValue(Fields.APP);
67 }
68
69 public String getEmail() {
70 return getValue(Fields.EMAIL);
71 }
72
73 @Override
74 protected Enum<?>[] getInsertFields() {
75 return new Fields[] { Fields.EMAIL, Fields.PASSWORD, Fields.USERNAME,
76 Fields.APP };
77 }
78
79 public String getPassword() {
80 return getValue(Fields.PASSWORD);
81 }
82
83 public String getUsername() {
84 return getValue(Fields.USERNAME);
85 }
86
87 @Override
88 public String toString() {
89 return "UserDataType [toString()=" + super.toString() + "]";
90 }
91
92 }