001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.http;
022:
023: import com.liferay.portal.model.User;
024:
025: import com.liferay.util.JSONUtil;
026:
027: import org.json.JSONArray;
028: import org.json.JSONObject;
029:
030: import java.util.List;
031:
032: /**
033: * <a href="UserJSONSerializer.java.html"><b><i>View Source</i></b></a>
034: *
035: * <p>
036: * ServiceBuilder generated this class. Modifications in this class will be
037: * overwritten the next time is generated.
038: * </p>
039: *
040: * <p>
041: * This class is used by
042: * <code>com.liferay.portal.service.http.UserServiceJSON</code>
043: * to translate objects.
044: * </p>
045: *
046: * @author Brian Wing Shun Chan
047: *
048: * @see com.liferay.portal.service.http.UserServiceJSON
049: *
050: */
051: public class UserJSONSerializer {
052: public static JSONObject toJSONObject(User model) {
053: JSONObject jsonObj = new JSONObject();
054:
055: JSONUtil.put(jsonObj, "uuid", model.getUuid());
056: JSONUtil.put(jsonObj, "userId", model.getUserId());
057: JSONUtil.put(jsonObj, "companyId", model.getCompanyId());
058: JSONUtil.put(jsonObj, "createDate", model.getCreateDate());
059: JSONUtil.put(jsonObj, "modifiedDate", model.getModifiedDate());
060: JSONUtil.put(jsonObj, "defaultUser", model.getDefaultUser());
061: JSONUtil.put(jsonObj, "contactId", model.getContactId());
062: JSONUtil.put(jsonObj, "password", model.getPassword());
063: JSONUtil.put(jsonObj, "passwordEncrypted", model
064: .getPasswordEncrypted());
065: JSONUtil
066: .put(jsonObj, "passwordReset", model.getPasswordReset());
067: JSONUtil.put(jsonObj, "passwordModifiedDate", model
068: .getPasswordModifiedDate());
069: JSONUtil.put(jsonObj, "graceLoginCount", model
070: .getGraceLoginCount());
071: JSONUtil.put(jsonObj, "screenName", model.getScreenName());
072: JSONUtil.put(jsonObj, "emailAddress", model.getEmailAddress());
073: JSONUtil.put(jsonObj, "portraitId", model.getPortraitId());
074: JSONUtil.put(jsonObj, "languageId", model.getLanguageId());
075: JSONUtil.put(jsonObj, "timeZoneId", model.getTimeZoneId());
076: JSONUtil.put(jsonObj, "greeting", model.getGreeting());
077: JSONUtil.put(jsonObj, "comments", model.getComments());
078: JSONUtil.put(jsonObj, "loginDate", model.getLoginDate());
079: JSONUtil.put(jsonObj, "loginIP", model.getLoginIP());
080: JSONUtil
081: .put(jsonObj, "lastLoginDate", model.getLastLoginDate());
082: JSONUtil.put(jsonObj, "lastLoginIP", model.getLastLoginIP());
083: JSONUtil.put(jsonObj, "lastFailedLoginDate", model
084: .getLastFailedLoginDate());
085: JSONUtil.put(jsonObj, "failedLoginAttempts", model
086: .getFailedLoginAttempts());
087: JSONUtil.put(jsonObj, "lockout", model.getLockout());
088: JSONUtil.put(jsonObj, "lockoutDate", model.getLockoutDate());
089: JSONUtil.put(jsonObj, "agreedToTermsOfUse", model
090: .getAgreedToTermsOfUse());
091: JSONUtil.put(jsonObj, "active", model.getActive());
092:
093: return jsonObj;
094: }
095:
096: public static JSONArray toJSONArray(List models) {
097: JSONArray jsonArray = new JSONArray();
098:
099: for (int i = 0; i < models.size(); i++) {
100: User model = (User) models.get(i);
101:
102: jsonArray.put(toJSONObject(model));
103: }
104:
105: return jsonArray;
106: }
107: }
|