Ejemplo n.º 1
0
  public String execute() {
    String lMessage = "";
    String lResult = "NOK";
    JSONObject lElement = null;

    System.out.println("UpdateUser.execute() : " + status);
    /*
     * Evaluate new user values
     */
    if (!User.goodPassword(password)) {
      lMessage = "Ongeldig wachtwoord! " + password;
    } else if (!User.goodEmail(emailAddress)) {
      lMessage = "Ongeldig email adres!";
    } else if (name == null || name.length() <= 0 || !User.goodInputData(name)) {
      lMessage = "Ongeldig voornaam! |" + name + "|";
    } else if (surname == null || surname.length() <= 0 || !User.goodInputData(surname)) {
      lMessage = "Ongeldig achternaam!";
    } else if (address == null || address.length() <= 0 || !User.goodInputData(address)) {
      lMessage = "Ongeldig adres!";
    } else if (zipCode == null || zipCode.length() <= 0 || !User.goodInputData(zipCode)) {
      lMessage = "Ongeldig post code!";
    } else if (place == null || place.length() <= 0 || !User.goodInputData(place)) {
      lMessage = "Ongeldig woonplaats!";
    } else if (country == null || country.length() <= 0 || !User.goodInputData(country)) {
      lMessage = "Ongeldig land!";
    } else if (status == null || status.length() <= 0) // || !status.equals("^[\\d\\w]+$"))
    {
      lMessage = "Ongeldig status! " + status;
    } else {
      try {
        int lStatInt = Integer.parseInt(status);
        UserStatus lUserStatus = UserStatus.values()[lStatInt];
        System.out.println("UpdateUser.exec(0) : " + lUserStatus.name());
        User lUser =
            new User(
                username,
                password,
                emailAddress,
                name,
                surname,
                address,
                zipCode,
                place,
                country,
                null,
                null,
                lUserStatus);
        cUserService.update(lUser);
        System.out.println("UpdateUser.exec(1) : ");
      } catch (Exception lEx) {
        System.out.println("UpdateUser.exec(Exception) : " + lEx.toString());
      }

      lMessage = "Gebruiker gegevens aangepast.";
      lResult = "OK";
    }

    /*
     * Create JSON object.
     */
    try {
      System.out.println("UpdateUser.exec(2) : ");
      lElement = new JSONObject();
      lElement.put("Message", lMessage);
      lElement.put("Result", lResult);
      System.out.println("UpdateUser.exec(3) : ");
    } catch (Exception lEx) {
      System.out.println("UpdateUser.execute(Exception) : " + lEx.toString());
    }

    /*
     * Create output stream object.
     */
    try {
      inputStream = new StringBufferInputStream(lElement.toString());
    } catch (Exception lEx) {
      System.out.println("GetUser.execute(Exception) : " + lEx.toString());
    }

    return SUCCESS;
  }
Ejemplo n.º 2
0
public class UpdateUser extends ActionSupport {
  private UserServiceProvider cUserService = UserServiceProvider.getUserService();
  private String username = "";
  private String password = "";
  private String emailAddress = "";
  private String name = "";
  private String surname = "";
  private String address = "";
  private String zipCode = "";
  private String place = "";
  private String country = "";
  private String status = "";

  public InputStream inputStream;

  /*
   *
   */
  public String execute() {
    String lMessage = "";
    String lResult = "NOK";
    JSONObject lElement = null;

    System.out.println("UpdateUser.execute() : " + status);
    /*
     * Evaluate new user values
     */
    if (!User.goodPassword(password)) {
      lMessage = "Ongeldig wachtwoord! " + password;
    } else if (!User.goodEmail(emailAddress)) {
      lMessage = "Ongeldig email adres!";
    } else if (name == null || name.length() <= 0 || !User.goodInputData(name)) {
      lMessage = "Ongeldig voornaam! |" + name + "|";
    } else if (surname == null || surname.length() <= 0 || !User.goodInputData(surname)) {
      lMessage = "Ongeldig achternaam!";
    } else if (address == null || address.length() <= 0 || !User.goodInputData(address)) {
      lMessage = "Ongeldig adres!";
    } else if (zipCode == null || zipCode.length() <= 0 || !User.goodInputData(zipCode)) {
      lMessage = "Ongeldig post code!";
    } else if (place == null || place.length() <= 0 || !User.goodInputData(place)) {
      lMessage = "Ongeldig woonplaats!";
    } else if (country == null || country.length() <= 0 || !User.goodInputData(country)) {
      lMessage = "Ongeldig land!";
    } else if (status == null || status.length() <= 0) // || !status.equals("^[\\d\\w]+$"))
    {
      lMessage = "Ongeldig status! " + status;
    } else {
      try {
        int lStatInt = Integer.parseInt(status);
        UserStatus lUserStatus = UserStatus.values()[lStatInt];
        System.out.println("UpdateUser.exec(0) : " + lUserStatus.name());
        User lUser =
            new User(
                username,
                password,
                emailAddress,
                name,
                surname,
                address,
                zipCode,
                place,
                country,
                null,
                null,
                lUserStatus);
        cUserService.update(lUser);
        System.out.println("UpdateUser.exec(1) : ");
      } catch (Exception lEx) {
        System.out.println("UpdateUser.exec(Exception) : " + lEx.toString());
      }

      lMessage = "Gebruiker gegevens aangepast.";
      lResult = "OK";
    }

    /*
     * Create JSON object.
     */
    try {
      System.out.println("UpdateUser.exec(2) : ");
      lElement = new JSONObject();
      lElement.put("Message", lMessage);
      lElement.put("Result", lResult);
      System.out.println("UpdateUser.exec(3) : ");
    } catch (Exception lEx) {
      System.out.println("UpdateUser.execute(Exception) : " + lEx.toString());
    }

    /*
     * Create output stream object.
     */
    try {
      inputStream = new StringBufferInputStream(lElement.toString());
    } catch (Exception lEx) {
      System.out.println("GetUser.execute(Exception) : " + lEx.toString());
    }

    return SUCCESS;
  }

  /*
   * Getters 'n' Setters
   */

  public InputStream getInputStream() {
    return inputStream;
  }

  public void setInputStream(InputStream inputStream) {
    this.inputStream = inputStream;
  }

  public String getUsername() {
    return username;
  }

  public void setUsername(String username) {
    this.username = username;
  }

  public String getPassword() {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getEmailAddress() {
    return emailAddress;
  }

  public void setEmailAddress(String emailAddress) {
    this.emailAddress = emailAddress;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getSurname() {
    return surname;
  }

  public void setSurname(String surname) {
    this.surname = surname;
  }

  public String getAddress() {
    return address;
  }

  public void setAddress(String address) {
    this.address = address;
  }

  public String getZipCode() {
    return zipCode;
  }

  public void setZipCode(String zipCode) {
    this.zipCode = zipCode;
  }

  public String getPlace() {
    return place;
  }

  public void setPlace(String place) {
    this.place = place;
  }

  public String getCountry() {
    return country;
  }

  public void setCountry(String country) {
    this.country = country;
  }

  public String getStatus() {
    return status;
  }

  public void setStatus(String status) {
    this.status = status;
  }
}