001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.http;
016    
017    import com.liferay.portal.kernel.json.JSONArray;
018    import com.liferay.portal.kernel.json.JSONFactoryUtil;
019    import com.liferay.portal.kernel.json.JSONObject;
020    import com.liferay.portal.kernel.util.StringPool;
021    
022    import com.liferay.portlet.messageboards.model.MBThread;
023    
024    import java.util.Date;
025    import java.util.List;
026    
027    /**
028     * @author    Brian Wing Shun Chan
029     * @generated
030     */
031    public class MBThreadJSONSerializer {
032            public static JSONObject toJSONObject(MBThread model) {
033                    JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034    
035                    jsonObj.put("threadId", model.getThreadId());
036                    jsonObj.put("groupId", model.getGroupId());
037                    jsonObj.put("categoryId", model.getCategoryId());
038                    jsonObj.put("rootMessageId", model.getRootMessageId());
039                    jsonObj.put("messageCount", model.getMessageCount());
040                    jsonObj.put("viewCount", model.getViewCount());
041                    jsonObj.put("lastPostByUserId", model.getLastPostByUserId());
042    
043                    Date lastPostDate = model.getLastPostDate();
044    
045                    String lastPostDateJSON = StringPool.BLANK;
046    
047                    if (lastPostDate != null) {
048                            lastPostDateJSON = String.valueOf(lastPostDate.getTime());
049                    }
050    
051                    jsonObj.put("lastPostDate", lastPostDateJSON);
052                    jsonObj.put("priority", model.getPriority());
053                    jsonObj.put("status", model.getStatus());
054                    jsonObj.put("statusByUserId", model.getStatusByUserId());
055                    jsonObj.put("statusByUserName", model.getStatusByUserName());
056    
057                    Date statusDate = model.getStatusDate();
058    
059                    String statusDateJSON = StringPool.BLANK;
060    
061                    if (statusDate != null) {
062                            statusDateJSON = String.valueOf(statusDate.getTime());
063                    }
064    
065                    jsonObj.put("statusDate", statusDateJSON);
066    
067                    return jsonObj;
068            }
069    
070            public static JSONArray toJSONArray(
071                    com.liferay.portlet.messageboards.model.MBThread[] models) {
072                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
073    
074                    for (MBThread model : models) {
075                            jsonArray.put(toJSONObject(model));
076                    }
077    
078                    return jsonArray;
079            }
080    
081            public static JSONArray toJSONArray(
082                    com.liferay.portlet.messageboards.model.MBThread[][] models) {
083                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
084    
085                    for (MBThread[] model : models) {
086                            jsonArray.put(toJSONArray(model));
087                    }
088    
089                    return jsonArray;
090            }
091    
092            public static JSONArray toJSONArray(
093                    List<com.liferay.portlet.messageboards.model.MBThread> models) {
094                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
095    
096                    for (MBThread model : models) {
097                            jsonArray.put(toJSONObject(model));
098                    }
099    
100                    return jsonArray;
101            }
102    }