001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
027     * @author    Brian Wing Shun Chan
028     * @generated
029     */
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("digest", model.getDigest());
073                    jsonObj.put("reminderQueryQuestion", model.getReminderQueryQuestion());
074                    jsonObj.put("reminderQueryAnswer", model.getReminderQueryAnswer());
075                    jsonObj.put("graceLoginCount", model.getGraceLoginCount());
076                    jsonObj.put("screenName", model.getScreenName());
077                    jsonObj.put("emailAddress", model.getEmailAddress());
078                    jsonObj.put("facebookId", model.getFacebookId());
079                    jsonObj.put("openId", model.getOpenId());
080                    jsonObj.put("portraitId", model.getPortraitId());
081                    jsonObj.put("languageId", model.getLanguageId());
082                    jsonObj.put("timeZoneId", model.getTimeZoneId());
083                    jsonObj.put("greeting", model.getGreeting());
084                    jsonObj.put("comments", model.getComments());
085                    jsonObj.put("firstName", model.getFirstName());
086                    jsonObj.put("middleName", model.getMiddleName());
087                    jsonObj.put("lastName", model.getLastName());
088                    jsonObj.put("jobTitle", model.getJobTitle());
089    
090                    Date loginDate = model.getLoginDate();
091    
092                    String loginDateJSON = StringPool.BLANK;
093    
094                    if (loginDate != null) {
095                            loginDateJSON = String.valueOf(loginDate.getTime());
096                    }
097    
098                    jsonObj.put("loginDate", loginDateJSON);
099                    jsonObj.put("loginIP", model.getLoginIP());
100    
101                    Date lastLoginDate = model.getLastLoginDate();
102    
103                    String lastLoginDateJSON = StringPool.BLANK;
104    
105                    if (lastLoginDate != null) {
106                            lastLoginDateJSON = String.valueOf(lastLoginDate.getTime());
107                    }
108    
109                    jsonObj.put("lastLoginDate", lastLoginDateJSON);
110                    jsonObj.put("lastLoginIP", model.getLastLoginIP());
111    
112                    Date lastFailedLoginDate = model.getLastFailedLoginDate();
113    
114                    String lastFailedLoginDateJSON = StringPool.BLANK;
115    
116                    if (lastFailedLoginDate != null) {
117                            lastFailedLoginDateJSON = String.valueOf(lastFailedLoginDate.getTime());
118                    }
119    
120                    jsonObj.put("lastFailedLoginDate", lastFailedLoginDateJSON);
121                    jsonObj.put("failedLoginAttempts", model.getFailedLoginAttempts());
122                    jsonObj.put("lockout", model.getLockout());
123    
124                    Date lockoutDate = model.getLockoutDate();
125    
126                    String lockoutDateJSON = StringPool.BLANK;
127    
128                    if (lockoutDate != null) {
129                            lockoutDateJSON = String.valueOf(lockoutDate.getTime());
130                    }
131    
132                    jsonObj.put("lockoutDate", lockoutDateJSON);
133                    jsonObj.put("agreedToTermsOfUse", model.getAgreedToTermsOfUse());
134                    jsonObj.put("active", model.getActive());
135    
136                    return jsonObj;
137            }
138    
139            public static JSONArray toJSONArray(com.liferay.portal.model.User[] models) {
140                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
141    
142                    for (User model : models) {
143                            jsonArray.put(toJSONObject(model));
144                    }
145    
146                    return jsonArray;
147            }
148    
149            public static JSONArray toJSONArray(
150                    com.liferay.portal.model.User[][] models) {
151                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
152    
153                    for (User[] model : models) {
154                            jsonArray.put(toJSONArray(model));
155                    }
156    
157                    return jsonArray;
158            }
159    
160            public static JSONArray toJSONArray(
161                    List<com.liferay.portal.model.User> models) {
162                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
163    
164                    for (User model : models) {
165                            jsonArray.put(toJSONObject(model));
166                    }
167    
168                    return jsonArray;
169            }
170    }