001
014
015 package com.liferay.portlet.shopping.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.shopping.model.ShoppingOrder;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class ShoppingOrderJSONSerializer {
032 public static JSONObject toJSONObject(ShoppingOrder model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("orderId", model.getOrderId());
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("number", model.getNumber());
061 jsonObj.put("tax", model.getTax());
062 jsonObj.put("shipping", model.getShipping());
063 jsonObj.put("altShipping", model.getAltShipping());
064 jsonObj.put("requiresShipping", model.getRequiresShipping());
065 jsonObj.put("insure", model.getInsure());
066 jsonObj.put("insurance", model.getInsurance());
067 jsonObj.put("couponCodes", model.getCouponCodes());
068 jsonObj.put("couponDiscount", model.getCouponDiscount());
069 jsonObj.put("billingFirstName", model.getBillingFirstName());
070 jsonObj.put("billingLastName", model.getBillingLastName());
071 jsonObj.put("billingEmailAddress", model.getBillingEmailAddress());
072 jsonObj.put("billingCompany", model.getBillingCompany());
073 jsonObj.put("billingStreet", model.getBillingStreet());
074 jsonObj.put("billingCity", model.getBillingCity());
075 jsonObj.put("billingState", model.getBillingState());
076 jsonObj.put("billingZip", model.getBillingZip());
077 jsonObj.put("billingCountry", model.getBillingCountry());
078 jsonObj.put("billingPhone", model.getBillingPhone());
079 jsonObj.put("shipToBilling", model.getShipToBilling());
080 jsonObj.put("shippingFirstName", model.getShippingFirstName());
081 jsonObj.put("shippingLastName", model.getShippingLastName());
082 jsonObj.put("shippingEmailAddress", model.getShippingEmailAddress());
083 jsonObj.put("shippingCompany", model.getShippingCompany());
084 jsonObj.put("shippingStreet", model.getShippingStreet());
085 jsonObj.put("shippingCity", model.getShippingCity());
086 jsonObj.put("shippingState", model.getShippingState());
087 jsonObj.put("shippingZip", model.getShippingZip());
088 jsonObj.put("shippingCountry", model.getShippingCountry());
089 jsonObj.put("shippingPhone", model.getShippingPhone());
090 jsonObj.put("ccName", model.getCcName());
091 jsonObj.put("ccType", model.getCcType());
092 jsonObj.put("ccNumber", model.getCcNumber());
093 jsonObj.put("ccExpMonth", model.getCcExpMonth());
094 jsonObj.put("ccExpYear", model.getCcExpYear());
095 jsonObj.put("ccVerNumber", model.getCcVerNumber());
096 jsonObj.put("comments", model.getComments());
097 jsonObj.put("ppTxnId", model.getPpTxnId());
098 jsonObj.put("ppPaymentStatus", model.getPpPaymentStatus());
099 jsonObj.put("ppPaymentGross", model.getPpPaymentGross());
100 jsonObj.put("ppReceiverEmail", model.getPpReceiverEmail());
101 jsonObj.put("ppPayerEmail", model.getPpPayerEmail());
102 jsonObj.put("sendOrderEmail", model.getSendOrderEmail());
103 jsonObj.put("sendShippingEmail", model.getSendShippingEmail());
104
105 return jsonObj;
106 }
107
108 public static JSONArray toJSONArray(
109 com.liferay.portlet.shopping.model.ShoppingOrder[] models) {
110 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
111
112 for (ShoppingOrder model : models) {
113 jsonArray.put(toJSONObject(model));
114 }
115
116 return jsonArray;
117 }
118
119 public static JSONArray toJSONArray(
120 com.liferay.portlet.shopping.model.ShoppingOrder[][] models) {
121 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
122
123 for (ShoppingOrder[] model : models) {
124 jsonArray.put(toJSONArray(model));
125 }
126
127 return jsonArray;
128 }
129
130 public static JSONArray toJSONArray(
131 List<com.liferay.portlet.shopping.model.ShoppingOrder> models) {
132 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
133
134 for (ShoppingOrder model : models) {
135 jsonArray.put(toJSONObject(model));
136 }
137
138 return jsonArray;
139 }
140 }