001
014
015 package com.liferay.portlet.asset.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.asset.model.AssetCategory;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class AssetCategoryJSONSerializer {
032 public static JSONObject toJSONObject(AssetCategory model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("uuid", model.getUuid());
036 jsonObj.put("categoryId", model.getCategoryId());
037 jsonObj.put("groupId", model.getGroupId());
038 jsonObj.put("companyId", model.getCompanyId());
039 jsonObj.put("userId", model.getUserId());
040 jsonObj.put("userName", model.getUserName());
041
042 Date createDate = model.getCreateDate();
043
044 String createDateJSON = StringPool.BLANK;
045
046 if (createDate != null) {
047 createDateJSON = String.valueOf(createDate.getTime());
048 }
049
050 jsonObj.put("createDate", createDateJSON);
051
052 Date modifiedDate = model.getModifiedDate();
053
054 String modifiedDateJSON = StringPool.BLANK;
055
056 if (modifiedDate != null) {
057 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
058 }
059
060 jsonObj.put("modifiedDate", modifiedDateJSON);
061 jsonObj.put("parentCategoryId", model.getParentCategoryId());
062 jsonObj.put("leftCategoryId", model.getLeftCategoryId());
063 jsonObj.put("rightCategoryId", model.getRightCategoryId());
064 jsonObj.put("name", model.getName());
065 jsonObj.put("title", model.getTitle());
066 jsonObj.put("vocabularyId", model.getVocabularyId());
067
068 return jsonObj;
069 }
070
071 public static JSONArray toJSONArray(
072 com.liferay.portlet.asset.model.AssetCategory[] models) {
073 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
074
075 for (AssetCategory model : models) {
076 jsonArray.put(toJSONObject(model));
077 }
078
079 return jsonArray;
080 }
081
082 public static JSONArray toJSONArray(
083 com.liferay.portlet.asset.model.AssetCategory[][] models) {
084 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
085
086 for (AssetCategory[] model : models) {
087 jsonArray.put(toJSONArray(model));
088 }
089
090 return jsonArray;
091 }
092
093 public static JSONArray toJSONArray(
094 List<com.liferay.portlet.asset.model.AssetCategory> models) {
095 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
096
097 for (AssetCategory model : models) {
098 jsonArray.put(toJSONObject(model));
099 }
100
101 return jsonArray;
102 }
103 }