001
014
015 package com.liferay.portlet.polls.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.polls.model.PollsQuestion;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class PollsQuestionJSONSerializer {
032 public static JSONObject toJSONObject(PollsQuestion model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("uuid", model.getUuid());
036 jsonObj.put("questionId", model.getQuestionId());
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 expirationDate = model.getExpirationDate();
065
066 String expirationDateJSON = StringPool.BLANK;
067
068 if (expirationDate != null) {
069 expirationDateJSON = String.valueOf(expirationDate.getTime());
070 }
071
072 jsonObj.put("expirationDate", expirationDateJSON);
073
074 Date lastVoteDate = model.getLastVoteDate();
075
076 String lastVoteDateJSON = StringPool.BLANK;
077
078 if (lastVoteDate != null) {
079 lastVoteDateJSON = String.valueOf(lastVoteDate.getTime());
080 }
081
082 jsonObj.put("lastVoteDate", lastVoteDateJSON);
083
084 return jsonObj;
085 }
086
087 public static JSONArray toJSONArray(
088 com.liferay.portlet.polls.model.PollsQuestion[] models) {
089 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
090
091 for (PollsQuestion model : models) {
092 jsonArray.put(toJSONObject(model));
093 }
094
095 return jsonArray;
096 }
097
098 public static JSONArray toJSONArray(
099 com.liferay.portlet.polls.model.PollsQuestion[][] models) {
100 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
101
102 for (PollsQuestion[] model : models) {
103 jsonArray.put(toJSONArray(model));
104 }
105
106 return jsonArray;
107 }
108
109 public static JSONArray toJSONArray(
110 List<com.liferay.portlet.polls.model.PollsQuestion> models) {
111 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
112
113 for (PollsQuestion model : models) {
114 jsonArray.put(toJSONObject(model));
115 }
116
117 return jsonArray;
118 }
119 }