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.PasswordPolicy;
27  
28  import java.util.Date;
29  import java.util.List;
30  
31  /**
32   * <a href="PasswordPolicyJSONSerializer.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.PasswordPolicyServiceJSON</code>
42   * to translate objects.
43   * </p>
44   *
45   * @author Brian Wing Shun Chan
46   *
47   * @see com.liferay.portal.service.http.PasswordPolicyServiceJSON
48   *
49   */
50  public class PasswordPolicyJSONSerializer {
51      public static JSONObject toJSONObject(PasswordPolicy model) {
52          JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
53  
54          jsonObj.put("passwordPolicyId", model.getPasswordPolicyId());
55          jsonObj.put("companyId", model.getCompanyId());
56          jsonObj.put("userId", model.getUserId());
57          jsonObj.put("userName", model.getUserName());
58  
59          Date createDate = model.getCreateDate();
60  
61          String createDateJSON = StringPool.BLANK;
62  
63          if (createDate != null) {
64              createDateJSON = String.valueOf(createDate.getTime());
65          }
66  
67          jsonObj.put("createDate", createDateJSON);
68  
69          Date modifiedDate = model.getModifiedDate();
70  
71          String modifiedDateJSON = StringPool.BLANK;
72  
73          if (modifiedDate != null) {
74              modifiedDateJSON = String.valueOf(modifiedDate.getTime());
75          }
76  
77          jsonObj.put("modifiedDate", modifiedDateJSON);
78          jsonObj.put("defaultPolicy", model.getDefaultPolicy());
79          jsonObj.put("name", model.getName());
80          jsonObj.put("description", model.getDescription());
81          jsonObj.put("changeable", model.getChangeable());
82          jsonObj.put("changeRequired", model.getChangeRequired());
83          jsonObj.put("minAge", model.getMinAge());
84          jsonObj.put("checkSyntax", model.getCheckSyntax());
85          jsonObj.put("allowDictionaryWords", model.getAllowDictionaryWords());
86          jsonObj.put("minLength", model.getMinLength());
87          jsonObj.put("history", model.getHistory());
88          jsonObj.put("historyCount", model.getHistoryCount());
89          jsonObj.put("expireable", model.getExpireable());
90          jsonObj.put("maxAge", model.getMaxAge());
91          jsonObj.put("warningTime", model.getWarningTime());
92          jsonObj.put("graceLimit", model.getGraceLimit());
93          jsonObj.put("lockout", model.getLockout());
94          jsonObj.put("maxFailure", model.getMaxFailure());
95          jsonObj.put("lockoutDuration", model.getLockoutDuration());
96          jsonObj.put("requireUnlock", model.getRequireUnlock());
97          jsonObj.put("resetFailureCount", model.getResetFailureCount());
98  
99          return jsonObj;
100     }
101 
102     public static JSONArray toJSONArray(
103         com.liferay.portal.model.PasswordPolicy[] models) {
104         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
105 
106         for (PasswordPolicy model : models) {
107             jsonArray.put(toJSONObject(model));
108         }
109 
110         return jsonArray;
111     }
112 
113     public static JSONArray toJSONArray(
114         com.liferay.portal.model.PasswordPolicy[][] models) {
115         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
116 
117         for (PasswordPolicy[] model : models) {
118             jsonArray.put(toJSONArray(model));
119         }
120 
121         return jsonArray;
122     }
123 
124     public static JSONArray toJSONArray(
125         List<com.liferay.portal.model.PasswordPolicy> models) {
126         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
127 
128         for (PasswordPolicy model : models) {
129             jsonArray.put(toJSONObject(model));
130         }
131 
132         return jsonArray;
133     }
134 }