Ejemplo n.º 1
0
  public void updateProfile(String key, Account pAccount)
      throws SQLException, ConnectionException, MissingDataException, NullAccountException,
          ProfileException, PasswordException, EmailException {
    try (Connection connect = DBConnection.getConnection()) {
      pAccount = testAccount(pAccount);

      String sql =
          "UPDATE account"
              + "set name = '"
              + Utility.Replace(testProfileData(pAccount.getName()))
              + "', surname = '"
              + Utility.Replace(testProfileData(pAccount.getSurname()))
              + "', password = '******', secondaryEmail = '"
              + testEmail(pAccount.getSecondaryEmail())
              + "WHERE email = '"
              + key
              + "'";

      String sql2 = "UPDATE " + pAccount.getTypeAccount();

      if (pAccount instanceof PhdStudent) {
        sql2 +=
            " set telephone = '"
                + testProfileData(((PhdStudent) pAccount).getTelephone())
                + "', link =  '"
                + testProfileData(((PhdStudent) pAccount).getLink())
                + "', deparment = '"
                + testProfileData(((PhdStudent) pAccount).getDepartment())
                + "', researchInterest = '"
                + testProfileData(((PhdStudent) pAccount).getResearchInterest())
                + "' WHERE fkAccount = '"
                + testProfileData(((PhdStudent) pAccount).getSecondaryEmail());
      }

      if (pAccount instanceof Professor) {
        sql2 +=
            " set link = '"
                + ((Professor) pAccount).getLink()
                + "', set department = '"
                + ((Professor) pAccount).getDepartment()
                + "' WHERE fkAccount = '"
                + ((Professor) pAccount).getSecondaryEmail()
                + "'";
      }

      if (pAccount.getTypeAccount().equals("basic")) // aggiorna solo info base
      Utility.executeOperation(connect, sql);
      else {
        Utility.executeOperation(connect, sql);
        Utility.executeOperation(connect, sql2);
      }

      connect.commit();
    }
  }
Ejemplo n.º 2
0
  public void changeType(Account pAccount, String newType)
      throws SQLException, ConnectionException, NullAccountException, EmailException {
    String demotionSql =
        "DELETE FROM " // cancella vecchie info
            + pAccount.getTypeAccount()
            + "WHERE fkAccount = '"
            + testEmail(pAccount.getSecondaryEmail())
            + "'";

    String toProfessorSql =
        "INSERT INTO professor " // se nuovo professor
            + "(fkAccount,link,department)"
            + "VALUES ('"
            + testEmail(pAccount.getSecondaryEmail())
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "'";

    String toPhdSql =
        "INSERT INTO phdstudent "
            + "(fkAccount,telephone,link,deparment,researchInterest,fkCycle"
            + "fkCurriculum, fkProfessor )" // nuovo dottorando
            + "VALUES ('"
            + testEmail(pAccount.getSecondaryEmail())
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "',"
            + "'"
            + "null"
            + "'";

    String changeTypeSql =
        "UPDATE account" // aggiorna il tipo
            + "set typeAccount = '"
            + newType
            + "' WHERE email = '"
            + pAccount.getEmail();

    Connection connect = null;
    try {
      connect = DBConnection.getConnection();
      pAccount = testAccount(pAccount);

      if (newType.equals("phdstudent") && pAccount.getTypeAccount().equals("basic")) {
        Utility.executeOperation(connect, toPhdSql); // diventa un dottorando
        Utility.executeOperation(connect, changeTypeSql); // cambia tipo in account
      } else if (newType.equals("phdstudent") && pAccount.getTypeAccount().equals("professor")) {
        Utility.executeOperation(connect, demotionSql); // perde info phd
        Utility.executeOperation(connect, toPhdSql); // nuove info prof
        Utility.executeOperation(connect, changeTypeSql);
      } else if (newType.equals("professor") && pAccount.getTypeAccount().equals("basic")) {
        Utility.executeOperation(connect, toProfessorSql);
        Utility.executeOperation(connect, changeTypeSql);
      } else if (newType.equals("professor") && pAccount.getTypeAccount().equals("phdstudent")) {
        Utility.executeOperation(connect, demotionSql);
        Utility.executeOperation(connect, toProfessorSql);
        Utility.executeOperation(connect, changeTypeSql);
      } else if (newType.equals("basic")) {
        Utility.executeOperation(connect, demotionSql);
        Utility.executeOperation(connect, changeTypeSql);
      }

    } finally {
      DBConnection.releaseConnection(connect);
    }
  }