Exemple #1
0
 @Override
 public WUser isAuthorized() throws IllegalArgumentException {
   Logger.getLogger(getClass()).debug("called isAuthorized()");
   if (Session.Instance().getValue(this, USER_TOKEN) != null) {
     final String authToken = Session.Instance().getValue(this, USER_TOKEN).toString();
     WUser user = new WUser();
     user.setToken(authToken);
     return user;
   }
   return null;
 }
Exemple #2
0
 public Boolean registerUser(WUser user) throws IllegalArgumentException {
   JsonRegisterUserReguest request =
       new JsonRegisterUserReguest(
           user.getEmail(), user.getLogin(), user.getPassword(), serverUrl);
   JsonRegisterUserResponse response = new JsonRegisterUserResponse();
   response.parseJson(request.doRequest());
   if (response.getErrno() == Errno.SUCCESS) {
     return true;
   } else {
     return false;
   }
 }
Exemple #3
0
 @Override
 public Boolean subscribe(WChannel ch, WUser u) throws IllegalArgumentException {
   JsonSubscribeRequest request = new JsonSubscribeRequest(u.getToken(), ch.getName(), serverUrl);
   JsonSubscribeResponse response = new JsonSubscribeResponse();
   response.parseJson(request.doRequest());
   if (response.getErrno() == Errno.SUCCESS) {
     return true;
   } else {
     return false;
   }
 }
Exemple #4
0
 @Override
 public List<WChannel> availableChannels(WUser u) throws IllegalArgumentException {
   JsonAvailableChannelRequest request = new JsonAvailableChannelRequest(u.getToken(), serverUrl);
   JsonAvailableChannelResponse response = new JsonAvailableChannelResponse();
   response.parseJson(request.doRequest());
   List<WChannel> channels = new ArrayList<WChannel>();
   for (int i = 0; i < response.getChannels().size(); i++) {
     WChannel channel = JGeoConnector.toWChannel(response.getChannels().get(i));
     channels.add(channel);
   }
   return channels;
 }
Exemple #5
0
 @Override
 public WUser login(WUser user) throws IllegalArgumentException {
   Logger.getLogger(getClass()).debug("called login()");
   JsonLoginRequest request = new JsonLoginRequest(user.getLogin(), user.getPassword(), serverUrl);
   JsonLoginResponse response = new JsonLoginResponse();
   response.parseJson(request.doRequest());
   if (response.getAuthString() == null) {
     return null;
   } else {
     WUser newUser = new WUser(user.getLogin(), user.getPassword());
     newUser.setToken(response.getAuthString());
     newUser.setStatus(Response.STATUS_SUCCES);
     Session.Instance().addValue(this, USER_TOKEN, newUser.getToken());
     return newUser;
   }
 }
Exemple #6
0
 @Override
 public List<WMark> getTags(WUser u, WChannel ch, int amount) throws IllegalArgumentException {
   JsonFilterChannelRequest request =
       new JsonFilterChannelRequest(u.getToken(), ch.getName(), amount, serverUrl);
   JsonFilterChannelResponse response = new JsonFilterChannelResponse();
   response.parseJson(request.doRequest());
   List<WMark> marks = new ArrayList<WMark>();
   for (int i = 0; i < response.getChannels().size(); i++) {
     for (int j = 0; j < response.getChannels().get(i).getMarks().size(); j++) {
       WMark mark = JGeoConnector.toWTag(response.getChannels().get(i).getMarks().get(j));
       marks.add(mark);
     }
   }
   return marks;
 }
Exemple #7
0
 @Override
 public List<WMark> getTags(WUser u, double latitude, double longitude, double radius)
     throws IllegalArgumentException {
   JsonLoadTagsRequest request =
       new JsonLoadTagsRequest(u.getToken(), latitude, longitude, radius, serverUrl);
   JsonLoadTagsResponse response = new JsonLoadTagsResponse();
   response.parseJson(request.doRequest());
   List<WMark> marks = new ArrayList<WMark>();
   for (int i = 0; i < response.getChannels().size(); i++) {
     for (int j = 0; j < response.getChannels().get(i).getMarks().size(); j++) {
       WMark mark = JGeoConnector.toWTag(response.getChannels().get(i).getMarks().get(j));
       marks.add(mark);
     }
   }
   return marks;
 }
Exemple #8
0
 @Override
 public WUser addUser(WUser user) throws IllegalArgumentException {
   JsonAddUserRequest request =
       new JsonAddUserRequest(user.getEmail(), user.getLogin(), user.getPassword(), serverUrl);
   JsonAddUserResponse response = new JsonAddUserResponse();
   response.parseJson(request.doRequest());
   if (response.getAuthToken() == null) {
     return null;
   } else {
     WUser newUser = new WUser(user.getLogin(), user.getPassword());
     newUser.setEmail(user.getEmail());
     newUser.setPassword(user.getPassword());
     newUser.setToken(response.getAuthToken());
     return newUser;
   }
 }