Beispiel #1
0
 /**
  * Adds an active reserve to client. Maybe is not used now (because all the reserves given in the
  * XML are done) but we contemplate the possibility of parsing active reserves.
  *
  * @param client
  * @param r
  */
 public void addActiveReserveToClient(String client, Reserve r) {
   for (Client c : lstClient) {
     if (c.compareById(client)) {
       c.setActiveReserve(r);
     }
   }
 }
Beispiel #2
0
  @GET
  @Path("/getclient")
  @Produces("application/json; charset=utf-8")
  // http://localhost:8080/ProjetRestFull/eources/getjson
  public JResponse getEtudiant(@QueryParam("numcli") int numCli) throws ParseException {
    try {
      EntityManager em = HibUtil.getEntityManager();
      em.getTransaction().begin();
      Client c = em.find(Client.class, numCli);
      Hibernate.initialize(c);

      // On met le séjour à null, sinon il y a des références circulaires.
      em.detach(c);
      c.setSejours(null);

      GenericEntity<Client> entity = new GenericEntity<Client>(c) {};
      JResponse r = JResponse.ok(entity).build();
      em.getTransaction().commit();
      HibUtil.closeEntityManager();
      return r;
    } catch (Exception e) {
      // em.getTransaction().commit();
      HibUtil.closeEntityManager();
      return null;
    }
  }
Beispiel #3
0
 /**
  * Adds a done reserve to the list of the client.
  *
  * @param client id that we use to find the client.
  * @param r reserve that we will add
  * @param falta The reserve can have admonishes
  */
 public void addReserveToClient(String client, Reserve r, int falta) {
   for (Client c : lstClient) {
     if (c.compareById(client)) {
       c.addReserveDone(r);
       c.updateAdmonish(falta);
     }
   }
 }
Beispiel #4
0
 @Override
 public void create(Client client) {
   try {
     preparedStatement =
         connection.prepareStatement(
             "INSERT  INTO clients(name,login,phone,email,password)" + " VALUES (?,?,?,?,?)");
     preparedStatement.setString(1, client.getName());
     preparedStatement.setString(2, client.getLogin());
     preparedStatement.setString(3, client.getPhone());
     preparedStatement.setString(4, client.getEmail());
     preparedStatement.setString(5, client.getPassword());
     preparedStatement.execute();
   } catch (SQLException e) {
     e.printStackTrace();
   }
 }
  @Override
  public boolean createOrUpdateVehicle(
      String electronicShopID,
      String VIN,
      String clientID,
      String vehicleModelID,
      String warrantyConditionsID,
      String engineNumber,
      String plateNumber,
      Date purchaseDate) {

    // check if we know that shop
    if (!ConfigurationProperties.getElectronicShopID().equals(electronicShopID)) {
      logger.warning("electronicShopID \"" + electronicShopID + "\" not known!");
      return false;
    }

    Vehicle v = new Vehicle();
    try {
      List<Client> client = Client.queryGetByForeignID(clientID, 0, 1);
      if (client.size() == 0) {
        logger.warning("clientID \"" + clientID + "\" not known!");
        return false;
      }

      List<Vehicle> vl = Vehicle.queryGetByVIN(VIN, 0, 1, client.get(0).getID());
      if (vl.size() == 1) {
        v = vl.get(0);
      }

      List<VehicleModel> vehicleModel = VehicleModel.queryGetByForeignID(vehicleModelID, 0, 1);
      if (vehicleModel.size() == 0) {
        logger.warning("vehicleModelID \"" + vehicleModelID + "\" not known!");
        return false;
      }

      List<WarrantyConditions> warrantyConditions =
          WarrantyConditions.queryGetByForeignID(warrantyConditionsID, 0, 1);
      if (warrantyConditions.size() == 0) {
        logger.warning("warrantyConditionsID \"" + warrantyConditionsID + "\" not known!");
        return false;
      }

      v.setVIN(VIN);
      v.setClientID(client.get(0).getID());
      v.setVehicleModelID(vehicleModel.get(0).getID());
      v.setWarrantyConditionsID(warrantyConditions.get(0).getID());
      v.setEngineNumber(engineNumber);
      v.setPlateNumber(plateNumber);
      v.setPurchaseDate(purchaseDate);
      v.setMileage(0); // приемаме, че магазина продава само нови автомобили
      v.setWarrantyOK(Vehicle.WARRANTY_YES);
      v.writeToDB();
    } catch (RuntimeException e) {
      logger.log(Level.WARNING, "Can't write to DB!", e);
      return false;
    }

    return true;
  }
Beispiel #6
0
 @GET
 @Path("/deleteclient")
 @Produces("text/plain")
 public String deleteClient(@QueryParam("numCli") int numCli) throws ParseException {
   EntityManager em = HibUtil.getEntityManager();
   em.getTransaction().begin();
   Client cli = em.find(Client.class, numCli);
   List<Sejour> sejs = cli.getSejours();
   for (Sejour s : sejs) {
     s.removeAllActivites();
     em.remove(s);
   }
   em.remove(cli);
   em.getTransaction().commit();
   HibUtil.closeEntityManager();
   return "ok";
 }
Beispiel #7
0
 @GET
 @Path("/getclients")
 @Produces("application/json; charset=utf-8")
 // http://localhost:8080/ProjetRestFull/eources/getjson
 public JResponse getEtudiantToJSONText() throws ParseException {
   EntityManager em = HibUtil.getEntityManager();
   em.getTransaction().begin();
   List<Client> clis = em.createQuery("from Client").getResultList();
   Hibernate.initialize(clis);
   for (Client c : clis) {
     // On met le séjour à null, sinon il y a des références circulaires.
     em.detach(c);
     c.setSejours(null);
   }
   GenericEntity<List<Client>> entity = new GenericEntity<List<Client>>(clis) {};
   JResponse r = JResponse.ok(entity).build();
   em.getTransaction().commit();
   HibUtil.closeEntityManager();
   return r;
 }
Beispiel #8
0
  /** The admin can see a report of a given month and year. */
  private void seeReport() {
    int m, a;
    boolean check = false;
    m = 0;
    a = 0;

    // Ask for a month until the number of the month is correct.
    while (!check) {
      Consola.escriu("Insert the number of the month you would like to see");
      m = Consola.llegeixInt();
      if ((0 < m) && (m < 13)) {
        check = true;
      } else {
        Consola.escriu("Your number is incorrect. Please, try it again");
      }
    }

    check = false;
    // Ask for a year until the number of the year is correct.
    while (!check) {
      Consola.escriu("Insert the number of the year you would like to check");
      a = Consola.llegeixInt();

      // This can be changed. If the application is running for years, then
      // sure some years past 2017 would be correct years too.
      if (0 < a && 2017 >= a) {
        check = true;
      } else {
        Consola.escriu("Your number is incorrect. Please, try it again");
      }
    }
    Consola.escriu("");
    Consola.escriu("**MONTHLY REPORT**");
    Consola.escriu("");
    for (Client c : lstClient) {
      c.printDNI();
      Consola.escriu("Reserves done by this client: ");
      c.printReservesByMonthYear(m, a);
      Consola.escriu("-----------------------");
    }
  }
  @Test
  public void testCreaSequenza() {

    try {
      client1 = new Client(TestSequence1.port, TestSequence1.nomeServer);
      client1.connettiUtente(TestSequence1.nomeTest, TestSequence1.passwordTest);

      ArrayList<Project> pList = client1.mostraProgetti();
      ArrayList<User> uList = client1.mostraContatti();
      Project test = pList.get(0);

      client1.addActivity(test, TestSequence1.nomeA, "", uList.get(0), 0);
      client1.addActivity(test, TestSequence1.nomeA + "1", "", uList.get(0), 1);
      client1.startProject(test);

      assertEquals(
          "L'attività deve essere in corso",
          StateActivity.IN_CORSO,
          test.getListActivities().get(0).getStatoActivity());
      assertEquals(
          "La seconda attività deve essere IN_ATTESA",
          StateActivity.IN_ATTESA,
          test.getListActivities().get(1).getStatoActivity());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @Override
  public boolean createOrUpdateCompany(
      String electronicShopID,
      String clientID,
      String name,
      String contactPerson,
      String addressCity,
      String addressLine,
      String phoneNumber,
      String mail,
      String IBANNumber,
      String SWIFTCode,
      String registrationNumber,
      String VATNumber) {

    // check if we know that shop
    if (!ConfigurationProperties.getElectronicShopID().equals(electronicShopID)) {
      logger.warning("electronicShopID \"" + electronicShopID + "\" not known!");
      return false;
    }

    List<Client> cl = Client.queryGetByForeignID(clientID, 0, 1);
    List<Company> cmpnl = null;
    Client c;
    if (cl.size() == 0) {
      c = new Client();
    } else {
      c = cl.get(0);
      cmpnl = Company.queryGetAll(0, 1, c.getID());
    }

    Company cmpn;
    if ((cmpnl == null) || (cmpnl.size() == 0)) {
      cmpn = new Company();
    } else {
      cmpn = cmpnl.get(0);
    }
    try {
      c.setForeignID(clientID);
      c.setAddressCity(addressCity);
      c.setAddressLine(addressLine);
      c.setMail(mail);
      c.setPhoneNumber(phoneNumber);
      c.setIBANNumber(IBANNumber);
      c.setSWIFTCode(SWIFTCode);

      cmpn.setName(name);
      cmpn.setContactPerson(contactPerson);
      cmpn.setRegistrationNumber(registrationNumber);
      if (!"".equals(VATNumber)) {
        cmpn.setVATNumber(VATNumber);
      }
      c.setCompany(cmpn);
      c.writeToDB();

    } catch (RuntimeException e) {
      logger.log(Level.WARNING, "Can't write to DB!", e);
      return false;
    }

    return true;
  }
  @Override
  public boolean createOrUpdatePerson(
      String electronicShopID,
      String clientID,
      String name,
      String family,
      String addressCity,
      String addressLine,
      String phoneNumber,
      String mail,
      String IBANNumber,
      String SWIFTCode) {

    // check if we know that shop
    if (!ConfigurationProperties.getElectronicShopID().equals(electronicShopID)) {
      logger.warning("electronicShopID \"" + electronicShopID + "\" not known!");
      return false;
    }

    List<Client> cl = Client.queryGetByForeignID(clientID, 0, 1);
    List<Person> pl = null;
    Client c;
    if (cl.size() == 0) {
      c = new Client();
    } else {
      c = cl.get(0);
      pl = Person.queryGetAll(0, 1, c.getID());
    }

    Person p;
    if ((pl == null) || (pl.size() == 0)) {
      p = new Person();
    } else {
      p = pl.get(0);
    }
    try {
      c.setForeignID(clientID);
      c.setAddressCity(addressCity);
      c.setAddressLine(addressLine);
      c.setMail(mail);
      c.setPhoneNumber(phoneNumber);
      c.setIBANNumber(IBANNumber);
      c.setSWIFTCode(SWIFTCode);

      p.setName(name);
      p.setFamily(family);
      c.setPerson(p);
      c.writeToDB();

    } catch (RuntimeException e) {
      logger.log(Level.WARNING, "Can't write to DB!", e);
      return false;
    }

    return true;
  }
Beispiel #12
0
 @POST
 @Path("updateclient")
 @Consumes({MediaType.APPLICATION_JSON})
 @Produces("text/plain")
 public String updateClient(Client cliParam) {
   EntityManager em = HibUtil.getEntityManager();
   em.getTransaction().begin();
   Client cli = em.find(Client.class, cliParam.getNumCli());
   if (cliParam.getAdrRueCli() != null) {
     cli.setAdrRueCli(cliParam.getAdrRueCli());
   }
   if (cliParam.getNomCli() != null) {
     cli.setNomCli(cliParam.getNomCli());
   }
   if (cliParam.getVilleCli() != null) {
     cli.setVilleCli(cliParam.getVilleCli());
   }
   if (cliParam.getAdrRueCli() != null) {
     cli.setAdrRueCli(cliParam.getAdrRueCli());
   }
   if (cliParam.getCpCli() != null) {
     cli.setCpCli(cliParam.getCpCli());
   }
   if (cliParam.getNumPieceCli() != null) {
     cli.setNumPieceCli(cliParam.getNumPieceCli());
   }
   if (cliParam.getPieceCli() != null) {
     cli.setPieceCli(cliParam.getPieceCli());
   }
   em.getTransaction().commit();
   HibUtil.closeEntityManager();
   return "ok";
 }
Beispiel #13
0
  /** The client can book a moto if he/she hasn't an active reserve. */
  private void book() {
    boolean r = ((Client) current).hasActiveReserve();
    boolean correct = false;
    boolean check = false;
    int hours = 0;
    int days = 0;
    int month = 0;
    int year = 0;
    Calendar date = null;
    if (!r) {
      while (!correct) {
        Consola.escriu("Insert a date (hh/dd/mm/yyyy)");
        String fecha = Consola.llegeixString();
        String[] parser = fecha.split("/");
        date = Consola.llegeixDataSistema();
        try {
          hours = Integer.parseInt(parser[0]);
          days = Integer.parseInt(parser[1]);
          month = Integer.parseInt(parser[2]) - 1;
          year = Integer.parseInt(parser[3]);

          while (!check) {
            check = true;
            if (hours > 20 || hours <= 8) {
              check = false;
              Consola.escriu(
                  "The inserted hour is incorrect (8-20 hours only accepted). Please insert it again");
              hours = Consola.llegeixInt();
            }
          }
          check = false;
          while (!check) {
            check = true;
            if (days > 31 || days <= 0) {
              check = false;
              Consola.escriu("The inserted day is incorrect. Please insert it again");
              days = Consola.llegeixInt();
            }
          }
          check = false;
          while (!check) {
            check = true;
            if (month > 12 || month <= 0) {
              check = false;
              Consola.escriu("The inserted month is incorrect. Please insert it again");
              month = Consola.llegeixInt();
            }
          }
          check = false;
          while (!check) {
            check = true;
            if (year >= 2017 || year <= 0) {
              check = false;
              Consola.escriu("The inserted year is incorrect. Please insert it again");
              year = Consola.llegeixInt();
            }
          }

          date.set(year, month, days, hours, 0);
          Calendar currentDate = Consola.llegeixDataSistema();
          correct = currentDate.before(date);

          if (!correct) {
            Consola.escriu("Invalid date, insert again");
          }
        } catch (Exception ex) {
          Consola.escriu(
              "There's a invalid character in the date or an enmpy value, please, write again the date:");
        }
      }

      // Trying to get our starter local.
      Local localS = bookGetLocalS();
      // If it is different from null, then we can keep going.
      if (localS != null) {
        // We can try to get our ending local.
        Local localE = bookGetLocalE();
        // And if indeed we can reach up to an ending local, we can keep going.
        if (localE != null) {
          // We DON'T have to check the same for the motos, because it is considered that a local is
          // available
          // If it has a X amount of motos. So if we reach here, then our starting local is HAS
          // motos for sure.
          Moto motoreta = bookGetMoto(localS);

          Consola.escriu("Insert number of days you would like to reserve:");
          int cantDias = Consola.llegeixInt();
          Consola.escriu("Insert number of hours you would like to reserve:");
          int cantHoras = Consola.llegeixInt();
          this.bookPrintInfo(localS, localE, motoreta, date, cantDias, cantHoras);
          Consola.escriu("Insert an S to confirm or an N to cancel the reserve");
          String ans = Consola.llegeixString();
          correct = checkYesNo(ans);
          if (correct) {
            ((Client) current)
                .addActiveReserve(localS, localE, date, cantHoras, cantDias, motoreta);
            String code = new String();
            code =
                ((Client) current).getId()
                    + localS.getId()
                    + localE.getId()
                    + motoreta.getId()
                    + Integer.toString(cantHoras)
                    + Integer.toString(cantDias);
            code =
                code
                    + date.get(Calendar.HOUR_OF_DAY)
                    + date.get(Calendar.DAY_OF_MONTH)
                    + Integer.toString(date.get(Calendar.MONTH) + 1)
                    + date.get(Calendar.YEAR);
            ((Client) current).setCodeToActiveReserve(code);
            Consola.escriu("Code: " + code);
            Consola.escriu("The reserve has been done and saved");
          }
        }
      }
    } else {
      Consola.escriu("You have already done a reserve");
    }
  }
Beispiel #14
0
  /** Manager method. It allows the admin to recieve a moto from a client. */
  public void pickUpMoto() {
    String code, answer;
    boolean check = false;
    boolean yesNo;
    boolean yesNoDesperfecto = true;
    Client myclient = null;
    Moto m;
    Local lend;

    Consola.escriu("Insert the code");
    code = Consola.llegeixString();

    code = this.checkCode(code);

    if (!code.equals("")) {
      for (int i = 0; i <= this.lstClient.size() && !check; i++) {
        check = this.lstClient.get(i).compareCode(code);

        if (check) {
          myclient = this.lstClient.get(i);
        }
      }

      m = myclient.getMotoFromActiveReserve();
      lend = myclient.getLocalEFromActiveReserve();

      Consola.escriu("Insert a 'S' if the moto is broken, insert a 'N' otherwise");
      answer = Consola.llegeixString();

      yesNo = this.checkYesNo(answer);
      if (!yesNo) {
        Consola.escriu("Insert a 'S' to admonish a minor flaw, a 'N' otherwise");
        answer = Consola.llegeixString();

        yesNoDesperfecto = this.checkYesNo(answer);

      } else {
        m.changeStatusNonAvailable();
      }

      if (yesNoDesperfecto) {
        myclient.admonish();
      }

      myclient.printActiveReserve();

      Consola.escriu("Insert a 'S' if the moto has been returned with delay or a 'N' otherwise");

      answer = Consola.llegeixString();

      yesNo = this.checkYesNo(answer);

      if (yesNo) {
        myclient.delay();
      }
      Consola.escriu("Write 'S' to confirm or 'N' to cancel");
      answer = Consola.llegeixString();

      yesNo = this.checkYesNo(answer);

      if (yesNo) {
        this.pickUpMakeChange(m, lend);
        myclient.changeActiveToDone();

      } else {
        myclient.removeAdmonishFromActiveReserve();
        myclient.removeDelayFromActiveReserve();
        m.changeStatusAvailable();
        Consola.escriu("Cancelled");
      }
    }
  }
Beispiel #15
0
  /** A supposed existent user tries to login to our system. */
  private void logIn() {
    boolean check;
    boolean exists = false;
    int tries = 0;
    String user, pass;
    Person pers = null;

    /** Trying to select the person by its username. Maximum number of tries: 3. */
    while (!exists && tries < 3) {
      int i;
      Consola.escriu("Insert username: "******"Invalid username, please try again.");
        tries += 1;
      }
    }

    /**
     * If we reached the end, we wither have a person or we have more than 3 tries. More than 3
     * tries means that exists = false. Let's ask for the password in the case that exists is true.
     */
    if (exists) {
      exists = false;
      tries = 0; // You can try 3 times for your password.

      while (!exists && tries < 3) {
        Consola.escriu("Insert password: "******"Correct password");
        } else {
          Consola.escriu("Incorrect password.");
          tries += 1;
        }
      }
    }

    /**
     * We can have two situations: either we have a correct person (with correct user and password)
     * or we have exceeded the maximum tries permited. If we have a correct person, we show the
     * pertinent menu. If we reach here with more than 3 tries, then you can't log in.
     */
    if (pers instanceof Client && tries < 3) {
      // Given the client, we have to check if he can logIn
      // id est, if he has less than 3 admonishes.
      if (((Client) pers).canLogIn()) {
        // Succeed, the client can log in and is now in use of our application.
        current = pers;
        selectOptionMenuClient();
      } else {
        // Our client can log in =( Inform him/her.
        Consola.escriu("You have 3 admonishes, you can't log in, sorry.");
      }
    } else if (pers instanceof Manager && tries < 3) {
      current = pers;
      selectOptionMenuManager();
    } else if (pers instanceof Admin && tries < 3) {
      current = pers;
      selectOptionMenuAdmin();
    } else {
      Consola.escriu("You've exceeded the maximum permited tries");
    }
  }