1   /**
2    * Copyright (c) 2000-2009 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   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
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  /**
32   * <a href="UserJSONSerializer.java.html"><b><i>View Source</i></b></a>
33   *
34   * <p>
35   * ServiceBuilder generated this class. Modifications in this class will be
36   * overwritten the next time is generated.
37   * </p>
38   *
39   * <p>
40   * This class is used by
41   * <code>com.liferay.portal.service.http.UserServiceJSON</code>
42   * to translate objects.
43   * </p>
44   *
45   * @author Brian Wing Shun Chan
46   *
47   * @see com.liferay.portal.service.http.UserServiceJSON
48   *
49   */
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("reminderQueryQuestion", model.getReminderQueryQuestion());
93          jsonObj.put("reminderQueryAnswer", model.getReminderQueryAnswer());
94          jsonObj.put("graceLoginCount", model.getGraceLoginCount());
95          jsonObj.put("screenName", model.getScreenName());
96          jsonObj.put("emailAddress", model.getEmailAddress());
97          jsonObj.put("openId", model.getOpenId());
98          jsonObj.put("portraitId", model.getPortraitId());
99          jsonObj.put("languageId", model.getLanguageId());
100         jsonObj.put("timeZoneId", model.getTimeZoneId());
101         jsonObj.put("greeting", model.getGreeting());
102         jsonObj.put("comments", model.getComments());
103         jsonObj.put("firstName", model.getFirstName());
104         jsonObj.put("middleName", model.getMiddleName());
105         jsonObj.put("lastName", model.getLastName());
106         jsonObj.put("jobTitle", model.getJobTitle());
107 
108         Date loginDate = model.getLoginDate();
109 
110         String loginDateJSON = StringPool.BLANK;
111 
112         if (loginDate != null) {
113             loginDateJSON = String.valueOf(loginDate.getTime());
114         }
115 
116         jsonObj.put("loginDate", loginDateJSON);
117         jsonObj.put("loginIP", model.getLoginIP());
118 
119         Date lastLoginDate = model.getLastLoginDate();
120 
121         String lastLoginDateJSON = StringPool.BLANK;
122 
123         if (lastLoginDate != null) {
124             lastLoginDateJSON = String.valueOf(lastLoginDate.getTime());
125         }
126 
127         jsonObj.put("lastLoginDate", lastLoginDateJSON);
128         jsonObj.put("lastLoginIP", model.getLastLoginIP());
129 
130         Date lastFailedLoginDate = model.getLastFailedLoginDate();
131 
132         String lastFailedLoginDateJSON = StringPool.BLANK;
133 
134         if (lastFailedLoginDate != null) {
135             lastFailedLoginDateJSON = String.valueOf(lastFailedLoginDate.getTime());
136         }
137 
138         jsonObj.put("lastFailedLoginDate", lastFailedLoginDateJSON);
139         jsonObj.put("failedLoginAttempts", model.getFailedLoginAttempts());
140         jsonObj.put("lockout", model.getLockout());
141 
142         Date lockoutDate = model.getLockoutDate();
143 
144         String lockoutDateJSON = StringPool.BLANK;
145 
146         if (lockoutDate != null) {
147             lockoutDateJSON = String.valueOf(lockoutDate.getTime());
148         }
149 
150         jsonObj.put("lockoutDate", lockoutDateJSON);
151         jsonObj.put("agreedToTermsOfUse", model.getAgreedToTermsOfUse());
152         jsonObj.put("active", model.getActive());
153 
154         return jsonObj;
155     }
156 
157     public static JSONArray toJSONArray(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 
167     public static JSONArray toJSONArray(
168         com.liferay.portal.model.User[][] models) {
169         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
170 
171         for (User[] model : models) {
172             jsonArray.put(toJSONArray(model));
173         }
174 
175         return jsonArray;
176     }
177 
178     public static JSONArray toJSONArray(
179         List<com.liferay.portal.model.User> models) {
180         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
181 
182         for (User model : models) {
183             jsonArray.put(toJSONObject(model));
184         }
185 
186         return jsonArray;
187     }
188 }