Пример #1
0
  @Override
  public boolean createOrUpdateSparePart(
      String electronicShopID,
      String sparePartID,
      String name,
      String sparePartGroupID,
      String description,
      double deliveryPrice,
      String measuringUnit) {

    boolean flagNew = false;

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

    List<SparePart> spl = SparePart.queryGetByForeignID(sparePartID, 0, 1);
    SparePart sp;
    if (spl.size() == 0) {
      sp = new SparePart();
      flagNew = true;
    } else {
      sp = spl.get(0);
    }
    try {
      List<SparePartGroup> sparePartGroup =
          SparePartGroup.queryGetByForeignID(sparePartGroupID, 0, 1);
      if (sparePartGroup.size() == 0) {
        logger.warning("sparePartGroupID \"" + sparePartGroupID + "\" not known!");
        return false;
      }

      sp.setForeignID(sparePartID);
      sp.setSparePartGroupID(sparePartGroup.get(0).getID());
      sp.setName(name);
      sp.setDescription(description);
      sp.setDeliveryPrice(deliveryPrice);
      sp.setSalePrice(deliveryPrice); // <--- отначало продажната цена е същата като доставната !!!
      sp.setMeasuringUnit(measuringUnit);

      Transaction tr =
          DatastoreServiceFactory.getDatastoreService()
              .beginTransaction(TransactionOptions.Builder.withXG(true));
      sp.writeToDB();

      if (flagNew) {
        // добавяме нова част -> инициализираме записите за тази част във всички автосервизи
        SparePartAutoservice spa = new SparePartAutoservice();
        spa.setQuantityAvailable(0);
        spa.setQuantityBad(0);
        spa.setQuantityMinimum(0);
        spa.setQuantityOrdered(0);
        spa.setQuantityReserved(0);
        spa.setQuantityRequested(0);
        spa.setSparePartID(sp.getID());

        List<Autoservice> al = Autoservice.queryGetAll(0, 1000);
        for (Autoservice autoservice : al) {
          spa.setAutoserviceID(autoservice.getID());
          spa.writeToDB(true);
        }
      }

      tr.commit();

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

    return true;
  }
Пример #2
0
  private void addDebugAccounts() {

    // generate administrator employee
    if (Employee.countGetByName("Administrator") < 1) {
      Employee emp = new Employee();
      emp.setName("Administrator");
      emp.setFamily("n/a");
      emp.setAddressCity("n/a");
      emp.setAddressLine("n/a");
      emp.setMail("*****@*****.**");
      emp.setPhoneNumber("n/a");

      emp.writeToDB();
    }

    // generate administrator's autoservice; it's stupid I know :)
    if (Autoservice.countGetByName("Autoservice") < 1) {
      Autoservice autoservice = new Autoservice();
      autoservice.setName("Autoservice");
      autoservice.setAddressCity("n/a");
      autoservice.setAddressLine("n/a");
      autoservice.setMail("*****@*****.**");
      autoservice.setPhoneNumber("n/a");
      autoservice.setIBANNumber("n/a");
      autoservice.setSWIFTCode("n/a");
      autoservice.setRegistrationNumber("BG1209876");

      autoservice.writeToDB();
    }

    // generate admin account
    if (EmployeeAutoservice.countGetByUsername("admin") < 1) {
      EmployeeAutoservice empa = new EmployeeAutoservice();
      List<Autoservice> listAuto = Autoservice.queryGetByName("Autoservice", 0, 2);
      List<Employee> listEmp = Employee.queryGetByName("Administrator", 0, 2);
      if ((listAuto.size() != 1) || (listEmp.size() != 1)) {
        throw new RuntimeException("Oooopsssie :)");
      }

      empa.setAutoservice(listAuto.get(0));
      empa.setEmployee(listEmp.get(0));
      empa.setUsername("admin");
      empa.setPassword("1234");
      empa.setPosition(EmployeeAutoservice.ADMINISTRATOR);

      empa.writeToDB();
    }

    // generate manager account
    if (Employee.countGetByName("Manager") < 1) {
      Employee emp = new Employee();
      emp.setName("Manager");
      emp.setFamily("n/a");
      emp.setAddressCity("n/a");
      emp.setAddressLine("n/a");
      emp.setMail("*****@*****.**");
      emp.setPhoneNumber("n/a");

      emp.writeToDB();
    }

    if (EmployeeAutoservice.countGetByUsername("manager") < 1) {
      EmployeeAutoservice empa = new EmployeeAutoservice();
      List<Autoservice> listAuto = Autoservice.queryGetByName("Autoservice", 0, 2);
      List<Employee> listEmp = Employee.queryGetByName("Manager", 0, 2);
      if ((listAuto.size() != 1) || (listEmp.size() != 1)) {
        throw new RuntimeException("Oooopsssie :)");
      }

      empa.setAutoservice(listAuto.get(0));
      empa.setEmployee(listEmp.get(0));
      empa.setUsername("manager");
      empa.setPassword("1234");
      empa.setPosition(EmployeeAutoservice.MANAGER);

      empa.writeToDB();
    }

    // generate cashier account
    if (Employee.countGetByName("Cashier") < 1) {
      Employee emp = new Employee();
      emp.setName("Cashier");
      emp.setFamily("n/a");
      emp.setAddressCity("n/a");
      emp.setAddressLine("n/a");
      emp.setMail("*****@*****.**");
      emp.setPhoneNumber("n/a");

      emp.writeToDB();
    }

    if (EmployeeAutoservice.countGetByUsername("cashier") < 1) {
      EmployeeAutoservice empa = new EmployeeAutoservice();
      List<Autoservice> listAuto = Autoservice.queryGetByName("Autoservice", 0, 2);
      List<Employee> listEmp = Employee.queryGetByName("Cashier", 0, 2);
      if ((listAuto.size() != 1) || (listEmp.size() != 1)) {
        throw new RuntimeException("Oooopsssie :)");
      }

      empa.setAutoservice(listAuto.get(0));
      empa.setEmployee(listEmp.get(0));
      empa.setUsername("cashier");
      empa.setPassword("1234");
      empa.setPosition(EmployeeAutoservice.CASHIER);

      empa.writeToDB();
    }

    // generate warehouseman account
    if (Employee.countGetByName("Warehouseman") < 1) {
      Employee emp = new Employee();
      emp.setName("Warehouseman");
      emp.setFamily("n/a");
      emp.setAddressCity("n/a");
      emp.setAddressLine("n/a");
      emp.setMail("*****@*****.**");
      emp.setPhoneNumber("n/a");

      emp.writeToDB();
    }

    if (EmployeeAutoservice.countGetByUsername("warehouseman") < 1) {
      EmployeeAutoservice empa = new EmployeeAutoservice();
      List<Autoservice> listAuto = Autoservice.queryGetByName("Autoservice", 0, 2);
      List<Employee> listEmp = Employee.queryGetByName("Warehouseman", 0, 2);
      if ((listAuto.size() != 1) || (listEmp.size() != 1)) {
        throw new RuntimeException("Oooopsssie :)");
      }

      empa.setAutoservice(listAuto.get(0));
      empa.setEmployee(listEmp.get(0));
      empa.setUsername("warehouseman");
      empa.setPassword("1234");
      empa.setPosition(EmployeeAutoservice.WAREHOUSEMAN);

      empa.writeToDB();
    }

    // generate diagnostician account
    if (Employee.countGetByName("Diagnostician") < 1) {
      Employee emp = new Employee();
      emp.setName("Diagnostician");
      emp.setFamily("n/a");
      emp.setAddressCity("n/a");
      emp.setAddressLine("n/a");
      emp.setMail("*****@*****.**");
      emp.setPhoneNumber("n/a");

      emp.writeToDB();
    }

    if (EmployeeAutoservice.countGetByUsername("diagnostician") < 1) {
      EmployeeAutoservice empa = new EmployeeAutoservice();
      List<Autoservice> listAuto = Autoservice.queryGetByName("Autoservice", 0, 2);
      List<Employee> listEmp = Employee.queryGetByName("Diagnostician", 0, 2);
      if ((listAuto.size() != 1) || (listEmp.size() != 1)) {
        throw new RuntimeException("Oooopsssie :)");
      }

      empa.setAutoservice(listAuto.get(0));
      empa.setEmployee(listEmp.get(0));
      empa.setUsername("diagnostician");
      empa.setPassword("1234");
      empa.setPosition(EmployeeAutoservice.DIAGNOSTICIAN);

      empa.writeToDB();
    }

    // generate auto mechanic account
    if (Employee.countGetByName("Auto_Mechanic") < 1) {
      Employee emp = new Employee();
      emp.setName("Auto_Mechanic");
      emp.setFamily("n/a");
      emp.setAddressCity("n/a");
      emp.setAddressLine("n/a");
      emp.setMail("*****@*****.**");
      emp.setPhoneNumber("n/a");

      emp.writeToDB();
    }

    if (EmployeeAutoservice.countGetByUsername("auto_mechanic") < 1) {
      EmployeeAutoservice empa = new EmployeeAutoservice();
      List<Autoservice> listAuto = Autoservice.queryGetByName("Autoservice", 0, 2);
      List<Employee> listEmp = Employee.queryGetByName("Auto_Mechanic", 0, 2);
      if ((listAuto.size() != 1) || (listEmp.size() != 1)) {
        throw new RuntimeException("Oooopsssie :)");
      }

      empa.setAutoservice(listAuto.get(0));
      empa.setEmployee(listEmp.get(0));
      empa.setUsername("auto_mechanic");
      empa.setPassword("1234");
      empa.setPosition(EmployeeAutoservice.AUTO_MECHANIC);

      empa.writeToDB();
    }
  }