PageRenderTime 24ms CodeModel.GetById 6ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/v3.2/nimbits-model/src/com/nimbits/client/model/user/UserModel.java

http://nimbits-server.googlecode.com/
Java | 272 lines | 184 code | 63 blank | 25 comment | 6 complexity | 9d16bc9c6bdfcce019850f7c8d3c510e MD5 | raw file
  1/*
  2 * Copyright (c) 2010 Tonic Solutions LLC.
  3 *
  4 * http://www.nimbits.com
  5 *
  6 *
  7 * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  8 *
  9 * http://www.gnu.org/licenses/gpl.html
 10 *
 11 * Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 12 */
 13
 14package com.nimbits.client.model.user;
 15
 16
 17import com.nimbits.client.model.common.CommonFactoryLocator;
 18import com.nimbits.client.model.email.EmailAddress;
 19
 20import java.io.Serializable;
 21import java.util.ArrayList;
 22import java.util.Date;
 23import java.util.LinkedList;
 24import java.util.List;
 25
 26
 27//import com.google.appengine.api.users.User;
 28
 29
 30public class UserModel implements Serializable, User {
 31
 32    private long id;
 33
 34    private Date dateCreated;
 35
 36    private Date lastLoggedIn;
 37
 38    private List<Long> connections;
 39
 40    private String emailAddress;
 41
 42    private String facebookToken;
 43
 44    private String host;
 45
 46    private String secret;
 47
 48    private String twitterToken;
 49
 50    private String twitterTokenSecret;
 51
 52    private String userSource;
 53
 54    private String uuid;
 55
 56    private boolean restricted;
 57
 58    private boolean sendEmail;
 59
 60    private long facebookID;
 61
 62
 63    /**
 64     *
 65     */
 66    private static final long serialVersionUID = 1L;
 67
 68    public UserModel() {
 69    }
 70
 71    public UserModel(final long id) {
 72        this.id = id;
 73    }
 74
 75    public UserModel(final User u) {
 76        this.id = u.getId();
 77        this.dateCreated = u.getDateCreated();
 78        this.lastLoggedIn = u.getLastLoggedIn();
 79        this.sendEmail = u.getSendEmail();
 80        this.host = u.getHost();
 81        this.uuid = u.getUuid();
 82        this.secret = u.getSecret();
 83
 84        //Resolves Type 'org.datanucleus.sco.backed.ArrayList' was not included in the set of types which can be serialized by this SerializationPolicy
 85        final List<Long> l = new ArrayList<Long>();
 86        for (final long x : u.getConnections()) {
 87            l.add(x);
 88        }
 89
 90
 91        this.connections = l;
 92        this.restricted = u.isRestricted();
 93        this.emailAddress = u.getEmail().getValue();
 94        this.facebookToken = u.getFacebookToken();
 95        this.userSource = u.getUserSource();
 96        this.twitterToken = u.getTwitterToken();
 97        this.twitterTokenSecret = u.getTwitterTokenSecret();
 98        this.facebookID = u.getFacebookID();
 99    }
100
101//    public UserModel(final EmailAddress email, final String uuid) {
102//        this.dateCreated = new Date();
103//        this.email = email.getValue();
104//        this.sendEmail = true;
105//        this.uuid = uuid;
106//
107//    }
108
109    @Override
110    public void setEmail(final EmailAddress email) {
111        this.emailAddress = email.getValue();
112        // case
113    }
114
115    @Override
116    public List<Long> getConnections() {
117        if (connections == null) {
118            connections = new LinkedList<Long>();
119        }
120        return connections;
121    }
122
123    @Override
124    public boolean getSendEmail() {
125        return sendEmail;
126    }
127
128    @Override
129    public void setSendEmail(final boolean sendEmail) {
130        this.sendEmail = sendEmail;
131    }
132
133    @Override
134    public long getId() {
135        return id;
136    }
137
138    @Override
139    public void setId(final long id) {
140        this.id = id;
141    }
142
143    @Override
144    public Date getDateCreated() {
145        return new Date(this.dateCreated.getTime());
146    }
147
148    @Override
149    public Date getLastLoggedIn() {
150        return this.lastLoggedIn;
151    }
152
153    @Override
154    public void setLastLoggedIn(Date lastLoggedIn) {
155        this.lastLoggedIn = new Date(lastLoggedIn.getTime());
156    }
157
158    @Override
159    public void setDateCreated(final Date dateCreated) {
160        this.dateCreated = new Date(dateCreated.getTime());
161    }
162
163    @Override
164    public String getUserSource() {
165        return userSource;
166    }
167
168    @Override
169    public void setUserSource(final String userSource) {
170        this.userSource = userSource;
171    }
172
173    @Override
174    public String getTwitterTokenSecret() {
175        return twitterTokenSecret;
176    }
177
178    @Override
179    public void setTwitterTokenSecret(final String twitterTokenSecret) {
180        this.twitterTokenSecret = twitterTokenSecret;
181    }
182
183    @Override
184    public String getTwitterToken() {
185        return twitterToken;
186    }
187
188    @Override
189    public void setTwitterToken(final String twitterToken) {
190        this.twitterToken = twitterToken;
191    }
192
193    @Override
194    public String getFacebookToken() {
195        return facebookToken;
196    }
197
198    @Override
199    public void setFacebookToken(final String facebookToken) {
200        this.facebookToken = facebookToken;
201    }
202
203    @Override
204    public long getFacebookID() {
205        return facebookID;
206    }
207
208    @Override
209    public void setFacebookID(long facebookID) {
210        this.facebookID = facebookID;
211    }
212
213    @Override
214    public String getUuid() {
215        return uuid;
216    }
217
218    @Override
219    public void setUuid(final String uuid) {
220        this.uuid = uuid;
221    }
222
223    @Override
224    public String getHost() {
225        return host;
226    }
227
228    @Override
229    public void setHost(final String host) {
230        this.host = host;
231    }
232
233    @Override
234    public String getSecret() {
235        return secret;
236    }
237
238    @Override
239    public void setSecret(final String secret) {
240        this.secret = secret;
241    }
242
243    @Override
244    public boolean isRestricted() {
245        return restricted;
246    }
247
248    @Override
249    public void setRestricted(final boolean restricted) {
250        this.restricted = restricted;
251    }
252
253    @Override
254    public EmailAddress getEmail() {
255        return CommonFactoryLocator.getInstance().createEmailAddress(emailAddress);
256    }
257
258    @Override
259    public void addConnection(final long id) {
260        if (connections == null) {
261            connections = new ArrayList<Long>();
262        }
263        if (!connections.contains(id)) {
264            connections.add(id);
265        }
266    }
267
268    @Override
269    public void removeConnection(final long id) {
270        connections.remove(id);
271    }
272}