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