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
107 Date loginDate = model.getLoginDate();
108
109 String loginDateJSON = StringPool.BLANK;
110
111 if (loginDate != null) {
112 loginDateJSON = String.valueOf(loginDate.getTime());
113 }
114
115 jsonObj.put("loginDate", loginDateJSON);
116 jsonObj.put("loginIP", model.getLoginIP());
117
118 Date lastLoginDate = model.getLastLoginDate();
119
120 String lastLoginDateJSON = StringPool.BLANK;
121
122 if (lastLoginDate != null) {
123 lastLoginDateJSON = String.valueOf(lastLoginDate.getTime());
124 }
125
126 jsonObj.put("lastLoginDate", lastLoginDateJSON);
127 jsonObj.put("lastLoginIP", model.getLastLoginIP());
128
129 Date lastFailedLoginDate = model.getLastFailedLoginDate();
130
131 String lastFailedLoginDateJSON = StringPool.BLANK;
132
133 if (lastFailedLoginDate != null) {
134 lastFailedLoginDateJSON = String.valueOf(lastFailedLoginDate.getTime());
135 }
136
137 jsonObj.put("lastFailedLoginDate", lastFailedLoginDateJSON);
138 jsonObj.put("failedLoginAttempts", model.getFailedLoginAttempts());
139 jsonObj.put("lockout", model.getLockout());
140
141 Date lockoutDate = model.getLockoutDate();
142
143 String lockoutDateJSON = StringPool.BLANK;
144
145 if (lockoutDate != null) {
146 lockoutDateJSON = String.valueOf(lockoutDate.getTime());
147 }
148
149 jsonObj.put("lockoutDate", lockoutDateJSON);
150 jsonObj.put("agreedToTermsOfUse", model.getAgreedToTermsOfUse());
151 jsonObj.put("active", model.getActive());
152
153 return jsonObj;
154 }
155
156 public static JSONArray toJSONArray(
157 List<com.liferay.portal.model.User> models) {
158 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
159
160 for (User model : models) {
161 jsonArray.put(toJSONObject(model));
162 }
163
164 return jsonArray;
165 }
166 }