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