1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights 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 {@link UserServiceJSON} to translate objects.
44   * </p>
45   *
46   * @author    Brian Wing Shun Chan
47   * @see       com.liferay.portal.service.http.UserServiceJSON
48   * @generated
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         jsonObj.put("firstName", model.getFirstName());
102         jsonObj.put("middleName", model.getMiddleName());
103         jsonObj.put("lastName", model.getLastName());
104         jsonObj.put("jobTitle", model.getJobTitle());
105 
106         Date loginDate = model.getLoginDate();
107 
108         String loginDateJSON = StringPool.BLANK;
109 
110         if (loginDate != null) {
111             loginDateJSON = String.valueOf(loginDate.getTime());
112         }
113 
114         jsonObj.put("loginDate", loginDateJSON);
115         jsonObj.put("loginIP", model.getLoginIP());
116 
117         Date lastLoginDate = model.getLastLoginDate();
118 
119         String lastLoginDateJSON = StringPool.BLANK;
120 
121         if (lastLoginDate != null) {
122             lastLoginDateJSON = String.valueOf(lastLoginDate.getTime());
123         }
124 
125         jsonObj.put("lastLoginDate", lastLoginDateJSON);
126         jsonObj.put("lastLoginIP", model.getLastLoginIP());
127 
128         Date lastFailedLoginDate = model.getLastFailedLoginDate();
129 
130         String lastFailedLoginDateJSON = StringPool.BLANK;
131 
132         if (lastFailedLoginDate != null) {
133             lastFailedLoginDateJSON = String.valueOf(lastFailedLoginDate.getTime());
134         }
135 
136         jsonObj.put("lastFailedLoginDate", lastFailedLoginDateJSON);
137         jsonObj.put("failedLoginAttempts", model.getFailedLoginAttempts());
138         jsonObj.put("lockout", model.getLockout());
139 
140         Date lockoutDate = model.getLockoutDate();
141 
142         String lockoutDateJSON = StringPool.BLANK;
143 
144         if (lockoutDate != null) {
145             lockoutDateJSON = String.valueOf(lockoutDate.getTime());
146         }
147 
148         jsonObj.put("lockoutDate", lockoutDateJSON);
149         jsonObj.put("agreedToTermsOfUse", model.getAgreedToTermsOfUse());
150         jsonObj.put("active", model.getActive());
151 
152         return jsonObj;
153     }
154 
155     public static JSONArray toJSONArray(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 
165     public static JSONArray toJSONArray(
166         com.liferay.portal.model.User[][] models) {
167         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
168 
169         for (User[] model : models) {
170             jsonArray.put(toJSONArray(model));
171         }
172 
173         return jsonArray;
174     }
175 
176     public static JSONArray toJSONArray(
177         List<com.liferay.portal.model.User> models) {
178         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
179 
180         for (User model : models) {
181             jsonArray.put(toJSONObject(model));
182         }
183 
184         return jsonArray;
185     }
186 }