예제 #1
0
  @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;
  }
예제 #2
0
  @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;
  }
예제 #3
0
  @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;
  }