1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
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  /**
27   * <a href="UserJSONSerializer.java.html"><b><i>View Source</i></b></a>
28   *
29   * <p>
30   * ServiceBuilder generated this class. Modifications in this class will be
31   * overwritten the next time is generated.
32   * </p>
33   *
34   * <p>
35   * This class is used by {@link UserServiceJSON} to translate objects.
36   * </p>
37   *
38   * @author    Brian Wing Shun Chan
39   * @see       com.liferay.portal.service.http.UserServiceJSON
40   * @generated
41   */
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("reminderQueryQuestion", model.getReminderQueryQuestion());
85          jsonObj.put("reminderQueryAnswer", model.getReminderQueryAnswer());
86          jsonObj.put("graceLoginCount", model.getGraceLoginCount());
87          jsonObj.put("screenName", model.getScreenName());
88          jsonObj.put("emailAddress", model.getEmailAddress());
89          jsonObj.put("openId", model.getOpenId());
90          jsonObj.put("portraitId", model.getPortraitId());
91          jsonObj.put("languageId", model.getLanguageId());
92          jsonObj.put("timeZoneId", model.getTimeZoneId());
93          jsonObj.put("greeting", model.getGreeting());
94          jsonObj.put("comments", model.getComments());
95          jsonObj.put("firstName", model.getFirstName());
96          jsonObj.put("middleName", model.getMiddleName());
97          jsonObj.put("lastName", model.getLastName());
98          jsonObj.put("jobTitle", model.getJobTitle());
99  
100         Date loginDate = model.getLoginDate();
101 
102         String loginDateJSON = StringPool.BLANK;
103 
104         if (loginDate != null) {
105             loginDateJSON = String.valueOf(loginDate.getTime());
106         }
107 
108         jsonObj.put("loginDate", loginDateJSON);
109         jsonObj.put("loginIP", model.getLoginIP());
110 
111         Date lastLoginDate = model.getLastLoginDate();
112 
113         String lastLoginDateJSON = StringPool.BLANK;
114 
115         if (lastLoginDate != null) {
116             lastLoginDateJSON = String.valueOf(lastLoginDate.getTime());
117         }
118 
119         jsonObj.put("lastLoginDate", lastLoginDateJSON);
120         jsonObj.put("lastLoginIP", model.getLastLoginIP());
121 
122         Date lastFailedLoginDate = model.getLastFailedLoginDate();
123 
124         String lastFailedLoginDateJSON = StringPool.BLANK;
125 
126         if (lastFailedLoginDate != null) {
127             lastFailedLoginDateJSON = String.valueOf(lastFailedLoginDate.getTime());
128         }
129 
130         jsonObj.put("lastFailedLoginDate", lastFailedLoginDateJSON);
131         jsonObj.put("failedLoginAttempts", model.getFailedLoginAttempts());
132         jsonObj.put("lockout", model.getLockout());
133 
134         Date lockoutDate = model.getLockoutDate();
135 
136         String lockoutDateJSON = StringPool.BLANK;
137 
138         if (lockoutDate != null) {
139             lockoutDateJSON = String.valueOf(lockoutDate.getTime());
140         }
141 
142         jsonObj.put("lockoutDate", lockoutDateJSON);
143         jsonObj.put("agreedToTermsOfUse", model.getAgreedToTermsOfUse());
144         jsonObj.put("active", model.getActive());
145 
146         return jsonObj;
147     }
148 
149     public static JSONArray toJSONArray(com.liferay.portal.model.User[] models) {
150         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
151 
152         for (User model : models) {
153             jsonArray.put(toJSONObject(model));
154         }
155 
156         return jsonArray;
157     }
158 
159     public static JSONArray toJSONArray(
160         com.liferay.portal.model.User[][] models) {
161         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
162 
163         for (User[] model : models) {
164             jsonArray.put(toJSONArray(model));
165         }
166 
167         return jsonArray;
168     }
169 
170     public static JSONArray toJSONArray(
171         List<com.liferay.portal.model.User> models) {
172         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
173 
174         for (User model : models) {
175             jsonArray.put(toJSONObject(model));
176         }
177 
178         return jsonArray;
179     }
180 }