001
014
015 package com.liferay.portal.service.http;
016
017 import com.liferay.portal.kernel.json.JSONArray;
018 import com.liferay.portal.kernel.json.JSONFactoryUtil;
019 import com.liferay.portal.kernel.json.JSONObject;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portal.model.User;
022
023 import java.util.Date;
024 import java.util.List;
025
026
030 public class UserJSONSerializer {
031 public static JSONObject toJSONObject(User model) {
032 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
033
034 jsonObj.put("uuid", model.getUuid());
035 jsonObj.put("userId", model.getUserId());
036 jsonObj.put("companyId", model.getCompanyId());
037
038 Date createDate = model.getCreateDate();
039
040 String createDateJSON = StringPool.BLANK;
041
042 if (createDate != null) {
043 createDateJSON = String.valueOf(createDate.getTime());
044 }
045
046 jsonObj.put("createDate", createDateJSON);
047
048 Date modifiedDate = model.getModifiedDate();
049
050 String modifiedDateJSON = StringPool.BLANK;
051
052 if (modifiedDate != null) {
053 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
054 }
055
056 jsonObj.put("modifiedDate", modifiedDateJSON);
057 jsonObj.put("defaultUser", model.getDefaultUser());
058 jsonObj.put("contactId", model.getContactId());
059 jsonObj.put("password", model.getPassword());
060 jsonObj.put("passwordEncrypted", model.getPasswordEncrypted());
061 jsonObj.put("passwordReset", model.getPasswordReset());
062
063 Date passwordModifiedDate = model.getPasswordModifiedDate();
064
065 String passwordModifiedDateJSON = StringPool.BLANK;
066
067 if (passwordModifiedDate != null) {
068 passwordModifiedDateJSON = String.valueOf(passwordModifiedDate.getTime());
069 }
070
071 jsonObj.put("passwordModifiedDate", passwordModifiedDateJSON);
072 jsonObj.put("reminderQueryQuestion", model.getReminderQueryQuestion());
073 jsonObj.put("reminderQueryAnswer", model.getReminderQueryAnswer());
074 jsonObj.put("graceLoginCount", model.getGraceLoginCount());
075 jsonObj.put("screenName", model.getScreenName());
076 jsonObj.put("emailAddress", model.getEmailAddress());
077 jsonObj.put("facebookId", model.getFacebookId());
078 jsonObj.put("openId", model.getOpenId());
079 jsonObj.put("portraitId", model.getPortraitId());
080 jsonObj.put("languageId", model.getLanguageId());
081 jsonObj.put("timeZoneId", model.getTimeZoneId());
082 jsonObj.put("greeting", model.getGreeting());
083 jsonObj.put("comments", model.getComments());
084 jsonObj.put("firstName", model.getFirstName());
085 jsonObj.put("middleName", model.getMiddleName());
086 jsonObj.put("lastName", model.getLastName());
087 jsonObj.put("jobTitle", model.getJobTitle());
088
089 Date loginDate = model.getLoginDate();
090
091 String loginDateJSON = StringPool.BLANK;
092
093 if (loginDate != null) {
094 loginDateJSON = String.valueOf(loginDate.getTime());
095 }
096
097 jsonObj.put("loginDate", loginDateJSON);
098 jsonObj.put("loginIP", model.getLoginIP());
099
100 Date lastLoginDate = model.getLastLoginDate();
101
102 String lastLoginDateJSON = StringPool.BLANK;
103
104 if (lastLoginDate != null) {
105 lastLoginDateJSON = String.valueOf(lastLoginDate.getTime());
106 }
107
108 jsonObj.put("lastLoginDate", lastLoginDateJSON);
109 jsonObj.put("lastLoginIP", model.getLastLoginIP());
110
111 Date lastFailedLoginDate = model.getLastFailedLoginDate();
112
113 String lastFailedLoginDateJSON = StringPool.BLANK;
114
115 if (lastFailedLoginDate != null) {
116 lastFailedLoginDateJSON = String.valueOf(lastFailedLoginDate.getTime());
117 }
118
119 jsonObj.put("lastFailedLoginDate", lastFailedLoginDateJSON);
120 jsonObj.put("failedLoginAttempts", model.getFailedLoginAttempts());
121 jsonObj.put("lockout", model.getLockout());
122
123 Date lockoutDate = model.getLockoutDate();
124
125 String lockoutDateJSON = StringPool.BLANK;
126
127 if (lockoutDate != null) {
128 lockoutDateJSON = String.valueOf(lockoutDate.getTime());
129 }
130
131 jsonObj.put("lockoutDate", lockoutDateJSON);
132 jsonObj.put("agreedToTermsOfUse", model.getAgreedToTermsOfUse());
133 jsonObj.put("active", model.getActive());
134
135 return jsonObj;
136 }
137
138 public static JSONArray toJSONArray(com.liferay.portal.model.User[] models) {
139 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
140
141 for (User model : models) {
142 jsonArray.put(toJSONObject(model));
143 }
144
145 return jsonArray;
146 }
147
148 public static JSONArray toJSONArray(
149 com.liferay.portal.model.User[][] models) {
150 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
151
152 for (User[] model : models) {
153 jsonArray.put(toJSONArray(model));
154 }
155
156 return jsonArray;
157 }
158
159 public static JSONArray toJSONArray(
160 List<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 }