1
22
23 package com.liferay.portal.service.http;
24
25 import com.liferay.portal.kernel.json.JSONArray;
26 import com.liferay.portal.kernel.json.JSONFactoryUtil;
27 import com.liferay.portal.kernel.json.JSONObject;
28 import com.liferay.portal.kernel.util.StringPool;
29 import com.liferay.portal.model.User;
30
31 import java.util.Date;
32 import java.util.List;
33
34
53 public class UserJSONSerializer {
54 public static JSONObject toJSONObject(User model) {
55 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
56
57 jsonObj.put("uuid", model.getUuid());
58 jsonObj.put("userId", model.getUserId());
59 jsonObj.put("companyId", model.getCompanyId());
60
61 Date createDate = model.getCreateDate();
62
63 String createDateJSON = StringPool.BLANK;
64
65 if (createDate != null) {
66 createDateJSON = String.valueOf(createDate.getTime());
67 }
68
69 jsonObj.put("createDate", createDateJSON);
70
71 Date modifiedDate = model.getModifiedDate();
72
73 String modifiedDateJSON = StringPool.BLANK;
74
75 if (modifiedDate != null) {
76 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
77 }
78
79 jsonObj.put("modifiedDate", modifiedDateJSON);
80 jsonObj.put("defaultUser", model.getDefaultUser());
81 jsonObj.put("contactId", model.getContactId());
82 jsonObj.put("password", model.getPassword());
83 jsonObj.put("passwordEncrypted", model.getPasswordEncrypted());
84 jsonObj.put("passwordReset", model.getPasswordReset());
85
86 Date passwordModifiedDate = model.getPasswordModifiedDate();
87
88 String passwordModifiedDateJSON = StringPool.BLANK;
89
90 if (passwordModifiedDate != null) {
91 passwordModifiedDateJSON = String.valueOf(passwordModifiedDate.getTime());
92 }
93
94 jsonObj.put("passwordModifiedDate", passwordModifiedDateJSON);
95 jsonObj.put("reminderQueryQuestion", model.getReminderQueryQuestion());
96 jsonObj.put("reminderQueryAnswer", model.getReminderQueryAnswer());
97 jsonObj.put("graceLoginCount", model.getGraceLoginCount());
98 jsonObj.put("screenName", model.getScreenName());
99 jsonObj.put("emailAddress", model.getEmailAddress());
100 jsonObj.put("openId", model.getOpenId());
101 jsonObj.put("portraitId", model.getPortraitId());
102 jsonObj.put("languageId", model.getLanguageId());
103 jsonObj.put("timeZoneId", model.getTimeZoneId());
104 jsonObj.put("greeting", model.getGreeting());
105 jsonObj.put("comments", model.getComments());
106 jsonObj.put("firstName", model.getFirstName());
107 jsonObj.put("middleName", model.getMiddleName());
108 jsonObj.put("lastName", model.getLastName());
109 jsonObj.put("jobTitle", model.getJobTitle());
110
111 Date loginDate = model.getLoginDate();
112
113 String loginDateJSON = StringPool.BLANK;
114
115 if (loginDate != null) {
116 loginDateJSON = String.valueOf(loginDate.getTime());
117 }
118
119 jsonObj.put("loginDate", loginDateJSON);
120 jsonObj.put("loginIP", model.getLoginIP());
121
122 Date lastLoginDate = model.getLastLoginDate();
123
124 String lastLoginDateJSON = StringPool.BLANK;
125
126 if (lastLoginDate != null) {
127 lastLoginDateJSON = String.valueOf(lastLoginDate.getTime());
128 }
129
130 jsonObj.put("lastLoginDate", lastLoginDateJSON);
131 jsonObj.put("lastLoginIP", model.getLastLoginIP());
132
133 Date lastFailedLoginDate = model.getLastFailedLoginDate();
134
135 String lastFailedLoginDateJSON = StringPool.BLANK;
136
137 if (lastFailedLoginDate != null) {
138 lastFailedLoginDateJSON = String.valueOf(lastFailedLoginDate.getTime());
139 }
140
141 jsonObj.put("lastFailedLoginDate", lastFailedLoginDateJSON);
142 jsonObj.put("failedLoginAttempts", model.getFailedLoginAttempts());
143 jsonObj.put("lockout", model.getLockout());
144
145 Date lockoutDate = model.getLockoutDate();
146
147 String lockoutDateJSON = StringPool.BLANK;
148
149 if (lockoutDate != null) {
150 lockoutDateJSON = String.valueOf(lockoutDate.getTime());
151 }
152
153 jsonObj.put("lockoutDate", lockoutDateJSON);
154 jsonObj.put("agreedToTermsOfUse", model.getAgreedToTermsOfUse());
155 jsonObj.put("active", model.getActive());
156
157 return jsonObj;
158 }
159
160 public static JSONArray toJSONArray(com.liferay.portal.model.User[] models) {
161 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
162
163 for (User model : models) {
164 jsonArray.put(toJSONObject(model));
165 }
166
167 return jsonArray;
168 }
169
170 public static JSONArray toJSONArray(
171 com.liferay.portal.model.User[][] models) {
172 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
173
174 for (User[] model : models) {
175 jsonArray.put(toJSONArray(model));
176 }
177
178 return jsonArray;
179 }
180
181 public static JSONArray toJSONArray(
182 List<com.liferay.portal.model.User> models) {
183 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
184
185 for (User model : models) {
186 jsonArray.put(toJSONObject(model));
187 }
188
189 return jsonArray;
190 }
191 }