1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.http;
24  
25  import com.liferay.portal.kernel.json.JSONArray;
26  import com.liferay.portal.kernel.json.JSONFactoryUtil;
27  import com.liferay.portal.kernel.json.JSONObject;
28  import com.liferay.portal.kernel.util.StringPool;
29  import com.liferay.portal.model.User;
30  
31  import java.util.Date;
32  import java.util.List;
33  
34  /**
35   * <a href="UserJSONSerializer.java.html"><b><i>View Source</i></b></a>
36   *
37   * <p>
38   * ServiceBuilder generated this class. Modifications in this class will be
39   * overwritten the next time is generated.
40   * </p>
41   *
42   * <p>
43   * This class is used by
44   * <code>com.liferay.portal.service.http.UserServiceJSON</code>
45   * to translate objects.
46   * </p>
47   *
48   * @author Brian Wing Shun Chan
49   *
50   * @see com.liferay.portal.service.http.UserServiceJSON
51   *
52   */
53  public class UserJSONSerializer {
54      public static JSONObject toJSONObject(User model) {
55          JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
56  
57          jsonObj.put("uuid", model.getUuid());
58          jsonObj.put("userId", model.getUserId());
59          jsonObj.put("companyId", model.getCompanyId());
60  
61          Date createDate = model.getCreateDate();
62  
63          String createDateJSON = StringPool.BLANK;
64  
65          if (createDate != null) {
66              createDateJSON = String.valueOf(createDate.getTime());
67          }
68  
69          jsonObj.put("createDate", createDateJSON);
70  
71          Date modifiedDate = model.getModifiedDate();
72  
73          String modifiedDateJSON = StringPool.BLANK;
74  
75          if (modifiedDate != null) {
76              modifiedDateJSON = String.valueOf(modifiedDate.getTime());
77          }
78  
79          jsonObj.put("modifiedDate", modifiedDateJSON);
80          jsonObj.put("defaultUser", model.getDefaultUser());
81          jsonObj.put("contactId", model.getContactId());
82          jsonObj.put("password", model.getPassword());
83          jsonObj.put("passwordEncrypted", model.getPasswordEncrypted());
84          jsonObj.put("passwordReset", model.getPasswordReset());
85  
86          Date passwordModifiedDate = model.getPasswordModifiedDate();
87  
88          String passwordModifiedDateJSON = StringPool.BLANK;
89  
90          if (passwordModifiedDate != null) {
91              passwordModifiedDateJSON = String.valueOf(passwordModifiedDate.getTime());
92          }
93  
94          jsonObj.put("passwordModifiedDate", passwordModifiedDateJSON);
95          jsonObj.put("reminderQueryQuestion", model.getReminderQueryQuestion());
96          jsonObj.put("reminderQueryAnswer", model.getReminderQueryAnswer());
97          jsonObj.put("graceLoginCount", model.getGraceLoginCount());
98          jsonObj.put("screenName", model.getScreenName());
99          jsonObj.put("emailAddress", model.getEmailAddress());
100         jsonObj.put("openId", model.getOpenId());
101         jsonObj.put("portraitId", model.getPortraitId());
102         jsonObj.put("languageId", model.getLanguageId());
103         jsonObj.put("timeZoneId", model.getTimeZoneId());
104         jsonObj.put("greeting", model.getGreeting());
105         jsonObj.put("comments", model.getComments());
106 
107         Date loginDate = model.getLoginDate();
108 
109         String loginDateJSON = StringPool.BLANK;
110 
111         if (loginDate != null) {
112             loginDateJSON = String.valueOf(loginDate.getTime());
113         }
114 
115         jsonObj.put("loginDate", loginDateJSON);
116         jsonObj.put("loginIP", model.getLoginIP());
117 
118         Date lastLoginDate = model.getLastLoginDate();
119 
120         String lastLoginDateJSON = StringPool.BLANK;
121 
122         if (lastLoginDate != null) {
123             lastLoginDateJSON = String.valueOf(lastLoginDate.getTime());
124         }
125 
126         jsonObj.put("lastLoginDate", lastLoginDateJSON);
127         jsonObj.put("lastLoginIP", model.getLastLoginIP());
128 
129         Date lastFailedLoginDate = model.getLastFailedLoginDate();
130 
131         String lastFailedLoginDateJSON = StringPool.BLANK;
132 
133         if (lastFailedLoginDate != null) {
134             lastFailedLoginDateJSON = String.valueOf(lastFailedLoginDate.getTime());
135         }
136 
137         jsonObj.put("lastFailedLoginDate", lastFailedLoginDateJSON);
138         jsonObj.put("failedLoginAttempts", model.getFailedLoginAttempts());
139         jsonObj.put("lockout", model.getLockout());
140 
141         Date lockoutDate = model.getLockoutDate();
142 
143         String lockoutDateJSON = StringPool.BLANK;
144 
145         if (lockoutDate != null) {
146             lockoutDateJSON = String.valueOf(lockoutDate.getTime());
147         }
148 
149         jsonObj.put("lockoutDate", lockoutDateJSON);
150         jsonObj.put("agreedToTermsOfUse", model.getAgreedToTermsOfUse());
151         jsonObj.put("active", model.getActive());
152 
153         return jsonObj;
154     }
155 
156     public static JSONArray toJSONArray(
157         List<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 }