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.TasksReview;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class TasksReviewJSONSerializer {
032 public static JSONObject toJSONObject(TasksReview model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("reviewId", model.getReviewId());
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("proposalId", model.getProposalId());
061 jsonObj.put("assignedByUserId", model.getAssignedByUserId());
062 jsonObj.put("assignedByUserName", model.getAssignedByUserName());
063 jsonObj.put("stage", model.getStage());
064 jsonObj.put("completed", model.getCompleted());
065 jsonObj.put("rejected", model.getRejected());
066
067 return jsonObj;
068 }
069
070 public static JSONArray toJSONArray(
071 com.liferay.portlet.tasks.model.TasksReview[] models) {
072 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
073
074 for (TasksReview model : models) {
075 jsonArray.put(toJSONObject(model));
076 }
077
078 return jsonArray;
079 }
080
081 public static JSONArray toJSONArray(
082 com.liferay.portlet.tasks.model.TasksReview[][] models) {
083 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
084
085 for (TasksReview[] model : models) {
086 jsonArray.put(toJSONArray(model));
087 }
088
089 return jsonArray;
090 }
091
092 public static JSONArray toJSONArray(
093 List<com.liferay.portlet.tasks.model.TasksReview> models) {
094 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
095
096 for (TasksReview model : models) {
097 jsonArray.put(toJSONObject(model));
098 }
099
100 return jsonArray;
101 }
102 }