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.calendar.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.calendar.model.CalEvent;
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 CalEventJSONSerializer {
032            public static JSONObject toJSONObject(CalEvent model) {
033                    JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034    
035                    jsonObj.put("uuid", model.getUuid());
036                    jsonObj.put("eventId", model.getEventId());
037                    jsonObj.put("groupId", model.getGroupId());
038                    jsonObj.put("companyId", model.getCompanyId());
039                    jsonObj.put("userId", model.getUserId());
040                    jsonObj.put("userName", model.getUserName());
041    
042                    Date createDate = model.getCreateDate();
043    
044                    String createDateJSON = StringPool.BLANK;
045    
046                    if (createDate != null) {
047                            createDateJSON = String.valueOf(createDate.getTime());
048                    }
049    
050                    jsonObj.put("createDate", createDateJSON);
051    
052                    Date modifiedDate = model.getModifiedDate();
053    
054                    String modifiedDateJSON = StringPool.BLANK;
055    
056                    if (modifiedDate != null) {
057                            modifiedDateJSON = String.valueOf(modifiedDate.getTime());
058                    }
059    
060                    jsonObj.put("modifiedDate", modifiedDateJSON);
061                    jsonObj.put("title", model.getTitle());
062                    jsonObj.put("description", model.getDescription());
063    
064                    Date startDate = model.getStartDate();
065    
066                    String startDateJSON = StringPool.BLANK;
067    
068                    if (startDate != null) {
069                            startDateJSON = String.valueOf(startDate.getTime());
070                    }
071    
072                    jsonObj.put("startDate", startDateJSON);
073    
074                    Date endDate = model.getEndDate();
075    
076                    String endDateJSON = StringPool.BLANK;
077    
078                    if (endDate != null) {
079                            endDateJSON = String.valueOf(endDate.getTime());
080                    }
081    
082                    jsonObj.put("endDate", endDateJSON);
083                    jsonObj.put("durationHour", model.getDurationHour());
084                    jsonObj.put("durationMinute", model.getDurationMinute());
085                    jsonObj.put("allDay", model.getAllDay());
086                    jsonObj.put("timeZoneSensitive", model.getTimeZoneSensitive());
087                    jsonObj.put("type", model.getType());
088                    jsonObj.put("repeating", model.getRepeating());
089                    jsonObj.put("recurrence", model.getRecurrence());
090                    jsonObj.put("remindBy", model.getRemindBy());
091                    jsonObj.put("firstReminder", model.getFirstReminder());
092                    jsonObj.put("secondReminder", model.getSecondReminder());
093    
094                    return jsonObj;
095            }
096    
097            public static JSONArray toJSONArray(
098                    com.liferay.portlet.calendar.model.CalEvent[] models) {
099                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
100    
101                    for (CalEvent model : models) {
102                            jsonArray.put(toJSONObject(model));
103                    }
104    
105                    return jsonArray;
106            }
107    
108            public static JSONArray toJSONArray(
109                    com.liferay.portlet.calendar.model.CalEvent[][] models) {
110                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
111    
112                    for (CalEvent[] model : models) {
113                            jsonArray.put(toJSONArray(model));
114                    }
115    
116                    return jsonArray;
117            }
118    
119            public static JSONArray toJSONArray(
120                    List<com.liferay.portlet.calendar.model.CalEvent> models) {
121                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
122    
123                    for (CalEvent model : models) {
124                            jsonArray.put(toJSONObject(model));
125                    }
126    
127                    return jsonArray;
128            }
129    }