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