1   /**
2    * Copyright (c) 2000-2008 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("graceLoginCount", model.getGraceLoginCount());
96          jsonObj.put("screenName", model.getScreenName());
97          jsonObj.put("emailAddress", model.getEmailAddress());
98          jsonObj.put("openId", model.getOpenId());
99          jsonObj.put("portraitId", model.getPortraitId());
100         jsonObj.put("languageId", model.getLanguageId());
101         jsonObj.put("timeZoneId", model.getTimeZoneId());
102         jsonObj.put("greeting", model.getGreeting());
103         jsonObj.put("comments", model.getComments());
104 
105         Date loginDate = model.getLoginDate();
106 
107         String loginDateJSON = StringPool.BLANK;
108 
109         if (loginDate != null) {
110             loginDateJSON = String.valueOf(loginDate.getTime());
111         }
112 
113         jsonObj.put("loginDate", loginDateJSON);
114         jsonObj.put("loginIP", model.getLoginIP());
115 
116         Date lastLoginDate = model.getLastLoginDate();
117 
118         String lastLoginDateJSON = StringPool.BLANK;
119 
120         if (lastLoginDate != null) {
121             lastLoginDateJSON = String.valueOf(lastLoginDate.getTime());
122         }
123 
124         jsonObj.put("lastLoginDate", lastLoginDateJSON);
125         jsonObj.put("lastLoginIP", model.getLastLoginIP());
126 
127         Date lastFailedLoginDate = model.getLastFailedLoginDate();
128 
129         String lastFailedLoginDateJSON = StringPool.BLANK;
130 
131         if (lastFailedLoginDate != null) {
132             lastFailedLoginDateJSON = String.valueOf(lastFailedLoginDate.getTime());
133         }
134 
135         jsonObj.put("lastFailedLoginDate", lastFailedLoginDateJSON);
136         jsonObj.put("failedLoginAttempts", model.getFailedLoginAttempts());
137         jsonObj.put("lockout", model.getLockout());
138 
139         Date lockoutDate = model.getLockoutDate();
140 
141         String lockoutDateJSON = StringPool.BLANK;
142 
143         if (lockoutDate != null) {
144             lockoutDateJSON = String.valueOf(lockoutDate.getTime());
145         }
146 
147         jsonObj.put("lockoutDate", lockoutDateJSON);
148         jsonObj.put("agreedToTermsOfUse", model.getAgreedToTermsOfUse());
149         jsonObj.put("active", model.getActive());
150 
151         return jsonObj;
152     }
153 
154     public static JSONArray toJSONArray(
155         List<com.liferay.portal.model.User> models) {
156         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
157 
158         for (User model : models) {
159             jsonArray.put(toJSONObject(model));
160         }
161 
162         return jsonArray;
163     }
164 }