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.Contact;
27  
28  import java.util.Date;
29  import java.util.List;
30  
31  /**
32   * <a href="ContactJSONSerializer.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.ContactServiceJSON</code>
42   * to translate objects.
43   * </p>
44   *
45   * @author Brian Wing Shun Chan
46   *
47   * @see com.liferay.portal.service.http.ContactServiceJSON
48   *
49   */
50  public class ContactJSONSerializer {
51      public static JSONObject toJSONObject(Contact model) {
52          JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
53  
54          jsonObj.put("contactId", model.getContactId());
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("accountId", model.getAccountId());
79          jsonObj.put("parentContactId", model.getParentContactId());
80          jsonObj.put("firstName", model.getFirstName());
81          jsonObj.put("middleName", model.getMiddleName());
82          jsonObj.put("lastName", model.getLastName());
83          jsonObj.put("prefixId", model.getPrefixId());
84          jsonObj.put("suffixId", model.getSuffixId());
85          jsonObj.put("male", model.getMale());
86  
87          Date birthday = model.getBirthday();
88  
89          String birthdayJSON = StringPool.BLANK;
90  
91          if (birthday != null) {
92              birthdayJSON = String.valueOf(birthday.getTime());
93          }
94  
95          jsonObj.put("birthday", birthdayJSON);
96          jsonObj.put("smsSn", model.getSmsSn());
97          jsonObj.put("aimSn", model.getAimSn());
98          jsonObj.put("facebookSn", model.getFacebookSn());
99          jsonObj.put("icqSn", model.getIcqSn());
100         jsonObj.put("jabberSn", model.getJabberSn());
101         jsonObj.put("msnSn", model.getMsnSn());
102         jsonObj.put("mySpaceSn", model.getMySpaceSn());
103         jsonObj.put("skypeSn", model.getSkypeSn());
104         jsonObj.put("twitterSn", model.getTwitterSn());
105         jsonObj.put("ymSn", model.getYmSn());
106         jsonObj.put("employeeStatusId", model.getEmployeeStatusId());
107         jsonObj.put("employeeNumber", model.getEmployeeNumber());
108         jsonObj.put("jobTitle", model.getJobTitle());
109         jsonObj.put("jobClass", model.getJobClass());
110         jsonObj.put("hoursOfOperation", model.getHoursOfOperation());
111 
112         return jsonObj;
113     }
114 
115     public static JSONArray toJSONArray(
116         com.liferay.portal.model.Contact[] models) {
117         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
118 
119         for (Contact model : models) {
120             jsonArray.put(toJSONObject(model));
121         }
122 
123         return jsonArray;
124     }
125 
126     public static JSONArray toJSONArray(
127         com.liferay.portal.model.Contact[][] models) {
128         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
129 
130         for (Contact[] model : models) {
131             jsonArray.put(toJSONArray(model));
132         }
133 
134         return jsonArray;
135     }
136 
137     public static JSONArray toJSONArray(
138         List<com.liferay.portal.model.Contact> models) {
139         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
140 
141         for (Contact model : models) {
142             jsonArray.put(toJSONObject(model));
143         }
144 
145         return jsonArray;
146     }
147 }