Guest User

Untitled

a guest
Jun 28th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 KB | None | 0 0
  1. package csc200.group8.app.network.requests;
  2.  
  3. import java.io.UnsupportedEncodingException;
  4. import java.net.URLEncoder;
  5. import java.util.Calendar;
  6.  
  7. import csc200.group8.app.model.User;
  8. import csc200.group8.app.model.StatusCode;
  9.  
  10. import csc200.group8.app.model.ReturnedObjectCallBack;
  11. import csc200.group8.app.model.uiinteraction.CallBack;
  12.  
  13. public class CreateUserRequest implements ServerRequest
  14. {
  15.     private String name;
  16.     private String libraryNumber;
  17.     private String userName;
  18.     private String password;
  19.     private Calendar dob;
  20.     private boolean locationVisible;
  21.    
  22.     private CallBack callback = null;
  23.     private ReturnedObjectCallBack<User> roCallback = null;
  24.    
  25.     private boolean complete = false;
  26.    
  27.     public CreateUserRequest(CallBack callback, String name, String libraryNumber,
  28.                             String userName, String password, Calendar dob,
  29.                             boolean locationVisible)
  30.     {
  31.         this.name = name;
  32.         this.libraryNumber = libraryNumber;
  33.         this.userName = userName;
  34.         this.password = password;
  35.         this.dob = dob;
  36.         this.locationVisible = locationVisible;
  37.         this.callback = callback;
  38.     }
  39.    
  40.     public CreateUserRequest(ReturnedObjectCallBack<User> roCallback, String name,
  41.                             String libraryNumber, String userName, String password,
  42.                             Calendar dob, boolean locationVisible)
  43.     {
  44.         this.name = name;
  45.         this.libraryNumber = libraryNumber;
  46.         this.userName = userName;
  47.         this.password = password;
  48.         this.dob = dob;
  49.         this.locationVisible = locationVisible;
  50.         this.callback = roCallback;
  51.         this.roCallback = roCallback;
  52.     }
  53.    
  54.  
  55.     public String getURL()
  56.     {
  57.         int locstat = 0;//Used to encode the locationStatus. 0 = public. 1 = private.
  58.         if(locationVisible == false)
  59.         {
  60.             locstat = 1;
  61.         }
  62.         return URLEncoder.encode("create_user.php?name=" + name + "&lib_no=" + libraryNumber +
  63.                                     "&username=" + userName + "&password=" + password + "&dob=" + dob.toString()
  64.                                     +  "&location_status=" + locstat + "&access_level=0");
  65.     }
  66.  
  67.     public boolean isCompleted()
  68.     {
  69.         return complete;
  70.     }
  71.  
  72.     public void complete(SuccessStatus status, String response)
  73.     {
  74.         //below lines need copy pasting in from somewhere
  75.         User user = new User(response parsing...);
  76.        
  77.        
  78.         //I'll add something in here later to submit the created user to the model
  79.         if(status == SuccessStatus.SUCCESS)
  80.         {
  81.             if(rcCallback != null)
  82.             {
  83.                 roCallback.setReturnedObject(user);
  84.             }
  85.             callback.notify(StatusCode.SUCCESS);
  86.         }
  87.         else
  88.         {
  89.             callback.notify(StatusCode.NETWORK_FAILURE);
  90.         }
  91.     }
  92. }
Add Comment
Please, Sign In to add comment