001
014
015 package com.liferay.portlet.softwarecatalog.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.softwarecatalog.model.SCProductVersion;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class SCProductVersionJSONSerializer {
032 public static JSONObject toJSONObject(SCProductVersion model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("productVersionId", model.getProductVersionId());
036 jsonObj.put("companyId", model.getCompanyId());
037 jsonObj.put("userId", model.getUserId());
038 jsonObj.put("userName", model.getUserName());
039
040 Date createDate = model.getCreateDate();
041
042 String createDateJSON = StringPool.BLANK;
043
044 if (createDate != null) {
045 createDateJSON = String.valueOf(createDate.getTime());
046 }
047
048 jsonObj.put("createDate", createDateJSON);
049
050 Date modifiedDate = model.getModifiedDate();
051
052 String modifiedDateJSON = StringPool.BLANK;
053
054 if (modifiedDate != null) {
055 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
056 }
057
058 jsonObj.put("modifiedDate", modifiedDateJSON);
059 jsonObj.put("productEntryId", model.getProductEntryId());
060 jsonObj.put("version", model.getVersion());
061 jsonObj.put("changeLog", model.getChangeLog());
062 jsonObj.put("downloadPageURL", model.getDownloadPageURL());
063 jsonObj.put("directDownloadURL", model.getDirectDownloadURL());
064 jsonObj.put("repoStoreArtifact", model.getRepoStoreArtifact());
065
066 return jsonObj;
067 }
068
069 public static JSONArray toJSONArray(
070 com.liferay.portlet.softwarecatalog.model.SCProductVersion[] models) {
071 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
072
073 for (SCProductVersion model : models) {
074 jsonArray.put(toJSONObject(model));
075 }
076
077 return jsonArray;
078 }
079
080 public static JSONArray toJSONArray(
081 com.liferay.portlet.softwarecatalog.model.SCProductVersion[][] models) {
082 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
083
084 for (SCProductVersion[] model : models) {
085 jsonArray.put(toJSONArray(model));
086 }
087
088 return jsonArray;
089 }
090
091 public static JSONArray toJSONArray(
092 List<com.liferay.portlet.softwarecatalog.model.SCProductVersion> models) {
093 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
094
095 for (SCProductVersion model : models) {
096 jsonArray.put(toJSONObject(model));
097 }
098
099 return jsonArray;
100 }
101 }