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