001
014
015 package com.liferay.portlet.tasks.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.tasks.model.TasksProposal;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class TasksProposalJSONSerializer {
032 public static JSONObject toJSONObject(TasksProposal model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("proposalId", model.getProposalId());
036 jsonObj.put("groupId", model.getGroupId());
037 jsonObj.put("companyId", model.getCompanyId());
038 jsonObj.put("userId", model.getUserId());
039 jsonObj.put("userName", model.getUserName());
040
041 Date createDate = model.getCreateDate();
042
043 String createDateJSON = StringPool.BLANK;
044
045 if (createDate != null) {
046 createDateJSON = String.valueOf(createDate.getTime());
047 }
048
049 jsonObj.put("createDate", createDateJSON);
050
051 Date modifiedDate = model.getModifiedDate();
052
053 String modifiedDateJSON = StringPool.BLANK;
054
055 if (modifiedDate != null) {
056 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
057 }
058
059 jsonObj.put("modifiedDate", modifiedDateJSON);
060 jsonObj.put("classNameId", model.getClassNameId());
061 jsonObj.put("classPK", model.getClassPK());
062 jsonObj.put("name", model.getName());
063 jsonObj.put("description", model.getDescription());
064
065 Date publishDate = model.getPublishDate();
066
067 String publishDateJSON = StringPool.BLANK;
068
069 if (publishDate != null) {
070 publishDateJSON = String.valueOf(publishDate.getTime());
071 }
072
073 jsonObj.put("publishDate", publishDateJSON);
074
075 Date dueDate = model.getDueDate();
076
077 String dueDateJSON = StringPool.BLANK;
078
079 if (dueDate != null) {
080 dueDateJSON = String.valueOf(dueDate.getTime());
081 }
082
083 jsonObj.put("dueDate", dueDateJSON);
084
085 return jsonObj;
086 }
087
088 public static JSONArray toJSONArray(
089 com.liferay.portlet.tasks.model.TasksProposal[] models) {
090 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
091
092 for (TasksProposal model : models) {
093 jsonArray.put(toJSONObject(model));
094 }
095
096 return jsonArray;
097 }
098
099 public static JSONArray toJSONArray(
100 com.liferay.portlet.tasks.model.TasksProposal[][] models) {
101 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
102
103 for (TasksProposal[] model : models) {
104 jsonArray.put(toJSONArray(model));
105 }
106
107 return jsonArray;
108 }
109
110 public static JSONArray toJSONArray(
111 List<com.liferay.portlet.tasks.model.TasksProposal> models) {
112 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
113
114 for (TasksProposal model : models) {
115 jsonArray.put(toJSONObject(model));
116 }
117
118 return jsonArray;
119 }
120 }