1
22
23 package com.liferay.portlet.documentlibrary.service.http;
24
25 import com.liferay.portal.kernel.json.JSONArray;
26 import com.liferay.portal.kernel.json.JSONFactoryUtil;
27 import com.liferay.portal.kernel.json.JSONObject;
28 import com.liferay.portal.kernel.util.StringPool;
29
30 import com.liferay.portlet.documentlibrary.model.DLFileEntry;
31
32 import java.util.Date;
33 import java.util.List;
34
35
54 public class DLFileEntryJSONSerializer {
55 public static JSONObject toJSONObject(DLFileEntry model) {
56 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
57
58 jsonObj.put("uuid", model.getUuid());
59 jsonObj.put("fileEntryId", model.getFileEntryId());
60 jsonObj.put("companyId", model.getCompanyId());
61 jsonObj.put("userId", model.getUserId());
62 jsonObj.put("userName", model.getUserName());
63 jsonObj.put("versionUserId", model.getVersionUserId());
64 jsonObj.put("versionUserName", model.getVersionUserName());
65
66 Date createDate = model.getCreateDate();
67
68 String createDateJSON = StringPool.BLANK;
69
70 if (createDate != null) {
71 createDateJSON = String.valueOf(createDate.getTime());
72 }
73
74 jsonObj.put("createDate", createDateJSON);
75
76 Date modifiedDate = model.getModifiedDate();
77
78 String modifiedDateJSON = StringPool.BLANK;
79
80 if (modifiedDate != null) {
81 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
82 }
83
84 jsonObj.put("modifiedDate", modifiedDateJSON);
85 jsonObj.put("folderId", model.getFolderId());
86 jsonObj.put("name", model.getName());
87 jsonObj.put("title", model.getTitle());
88 jsonObj.put("description", model.getDescription());
89 jsonObj.put("version", model.getVersion());
90 jsonObj.put("size", model.getSize());
91 jsonObj.put("readCount", model.getReadCount());
92 jsonObj.put("extraSettings", model.getExtraSettings());
93
94 return jsonObj;
95 }
96
97 public static JSONArray toJSONArray(
98 List<com.liferay.portlet.documentlibrary.model.DLFileEntry> models) {
99 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
100
101 for (DLFileEntry model : models) {
102 jsonArray.put(toJSONObject(model));
103 }
104
105 return jsonArray;
106 }
107 }