Esempio n. 1
0
 private void updateView() {
   if (employee != null) {
     txfName.setText(employee.getName());
     txfWage.setText("" + employee.getWage());
     Company companyOfEmployee = employee.getCompany();
     if (companyOfEmployee == null) cbxCompanies.setSelectedIndex(0);
     else {
       int index = 0;
       boolean found = false;
       int i = 0;
       while (!found && i < cbxCompanies.getItemCount()) {
         Company company = cbxCompanies.getItemAt(i);
         if (company == companyOfEmployee) {
           found = true;
           index = i;
         } else i++;
       }
       cbxCompanies.setSelectedIndex(index);
     }
   } else {
     txfName.setText("");
     txfWage.setText("");
     cbxCompanies.setSelectedIndex(0);
   }
 }
Esempio n. 2
0
  /**
   * Simple example using dynamic JP QL to retrieve all Employee instances sorted by lastName and
   * firstName. The resulting set of employees is then printed out with their related address and
   * phone numbers. The result of this is a large quantity of SQL. The following test cases
   * illustrate how this can be optimized.
   */
  @Test
  public void readAllEmployees() {
    EntityManager em = getEMF().createEntityManager();

    List<Employee> emps =
        em.createQuery("SELECT e FROM Employee e WHERE e.firstName LIKE '%'").getResultList();

    Assert.assertNotNull(emps);
    for (Employee emp : emps) {
      System.out.println(emp.toDetailedString());
    }

    em.close();
  }
Esempio n. 3
0
    // This method is called when a button is pressed.
    public void actionPerformed(ActionEvent e) {
      if (e.getSource() == btnOk) {
        String name = txfName.getText().trim();
        if (name.length() == 0) {
          // TODO: notify user
          return;
        }
        String wageStr = txfWage.getText().trim();
        if (wageStr.length() == 0) {
          // TODO: notify user
          return;
        }
        int wage = -1;
        try {
          wage = Integer.parseInt(wageStr);
        } catch (NumberFormatException ex) {
          // TODO: notify user
          return;
        }
        if (wage < 0) {
          // TODO: notify user
          return;
        }

        Company company = null;
        if (cbxCompanies.getSelectedIndex() >= 1) {
          company = (Company) cbxCompanies.getItemAt(cbxCompanies.getSelectedIndex());
        }

        /** ** update storage *** */
        if (employee == null) {
          Employee newEmployee = service.createEmployee(name, wage);
          if (company != null) service.updateCompanyOfEmployee(newEmployee, company);
        } else {
          if (!employee.getName().equals(name) || employee.getWage() != wage)
            service.updateEmployee(employee, name, wage);
          if (employee.getCompany() != company) service.updateCompanyOfEmployee(employee, company);
        }

        closedByOk = true;
        EmployeeCUDialog.this.setVisible(false);
      }

      if (e.getSource() == btnCancel) {
        closedByOk = false;
        EmployeeCUDialog.this.setVisible(false);
      }
    }
Esempio n. 4
0
  /**
   * Read in all employees using a JOIN FETCH on the address and phone numbers. the result (with
   * weaving) will be 1 SQL statement.
   *
   * <p>Note: With joining across a 1:M the DISTINCT is required to get a unique set of results
   */
  @Test
  public void readAllEmployeesWithJoinFetch() {
    EntityManager em = getEMF().createEntityManager();

    List<Employee> emps =
        em.createQuery(
                "SELECT DISTINCT e FROM Employee e JOIN FETCH e.address JOIN FETCH e.phoneNumbers ORDER BY e.lastName ASC, e.firstName ASC")
            .getResultList();

    Assert.assertNotNull(emps);
    for (Employee emp : emps) {
      System.out.println(emp.toDetailedString());
    }

    em.close();
  }
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO Auto-generated method stub
    HttpSession session = request.getSession();
    String email = request.getParameter("email");

    FoodOrderController foodOrderController = new FoodOrderController();
    List<FoodOrder> foodOrderList = foodOrderController.getFoodOrderSet(email);
    EmployeeController userController = new EmployeeController();

    Employee employee = userController.retrieveEmployeeViaEmail(email);

    session.setAttribute("name", employee.getName());
    session.setAttribute("email", employee.getEmail());
    session.setAttribute("contactNumber", employee.getContactNo());
    session.setAttribute("status", employee.getStatus());
    session.setAttribute("orderHistory", foodOrderList);
    DecimalFormat df = new DecimalFormat("####0.00");
    session.setAttribute("amountOwed", df.format(employee.getAmountOwed()));

    response.sendRedirect("adminProfile.jsp");
  }
Esempio n. 6
0
 public void addEmployee(Employee employee) {
   employees.add(employee);
   employee.getProjects().add(this);
 }
  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();
    }
  }
  public void setup() {
    // Populate database.
    // First delete all old records.
    this.entityManager.createQuery("Delete from PhoneNumber p").executeUpdate();
    this.entityManager.createQuery("Delete from Employee e").executeUpdate();
    this.entityManager.createQuery("Delete from Address a").executeUpdate();
    for (int j = 0; j < 100; j++) {
      Employee empInsert = new Employee();
      empInsert.setFirstName("Brendan");
      empInsert.setMale();
      empInsert.setLastName("" + j + "");
      empInsert.setSalary(100000);
      EmploymentPeriod employmentPeriod = new EmploymentPeriod();
      java.sql.Date startDate = new java.sql.Date(new java.util.Date().getTime());
      employmentPeriod.setStartDate(startDate);
      empInsert.setPeriod(employmentPeriod);
      empInsert.setAddress(new Address());
      empInsert.getAddress().setCity("Nepean");
      empInsert.getAddress().setPostalCode("N5J2N5");
      empInsert.getAddress().setProvince("ON");
      empInsert.getAddress().setStreet("1111 Mountain Blvd. Floor 13, suite " + j);
      empInsert.getAddress().setCountry("Canada");
      empInsert.addPhoneNumber(new PhoneNumber("Work Fax", "613", "2255943"));
      empInsert.addPhoneNumber(new PhoneNumber("Home", "613", "2224599"));
      this.entityManager.persist(empInsert);
    }

    for (int j = 0; j < 50; j++) {
      Project project = new SmallProject();
      project.setName("Tracker");
      this.entityManager.persist(project);
      project = new LargeProject();
      project.setName("Tracker");
      this.entityManager.persist(project);
    }
  }
 public long insert(Employee employee) {
   this.entityManager.persist(employee);
   this.entityManager.flush();
   return employee.getId();
 }
 public Employee fetchById(long id) {
   Employee employee = this.entityManager.find(Employee.class, id);
   employee.getAddress();
   employee.getManager();
   return employee;
 }
Esempio n. 11
0
 public String findItemEmployeeName(Integer id) {
   Employee e = activityService.findItem(id).getEmployee();
   return e.getFirstname() + " " + e.getLastname();
 }
Esempio n. 12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_info);

    Log.d("TEST", "Edit Info Activity");
    final Context context = this;
    Bundle extras = getIntent().getExtras();
    employeeID = 0;
    userIsManager = 0;
    if (extras != null) {
      employeeID = new Integer(extras.getString("employeeID")).intValue();
      Log.d("TEST", "employeeID" + employeeID);
      userIsManager = new Integer(extras.getString("userIsManager")).intValue();
      userID = new Integer(extras.getString("userID")).intValue();
      Log.d("TEST", extras.getString("userIsManager"));
    }
    File path = context.getFilesDir();
    File file = new File(path, "employee.txt");
    // fetch the data from the textfile
    fetch = new FetchData();
    fetch.parseData(context);
    Log.d("TEST", "employeeID" + employeeID);
    employee = fetch.getEmployee(employeeID);
    EmployeeInfo info = employee.getEmployeeInfo();
    Log.d("TEST", "Employee: " + employeeID + " is " + info.getFirstName());
    Utils utils = new Utils();
    // Below is just setting the text inside the textviews to what their current values are
    EditText firstName = (EditText) findViewById(R.id.firstName);
    int byteLength = info.getFirstName().length();
    byte[] bytes = info.getFirstName().getBytes();
    char[] chars = utils.converToCharArray(bytes, byteLength);
    firstName.setText(chars, 0, byteLength);

    EditText ssn = (EditText) findViewById(R.id.ssn);
    byteLength = info.getSSN().toString().length();
    bytes = info.getSSN().toString().getBytes();
    chars = utils.converToCharArray(bytes, byteLength);
    ssn.setText(chars, 0, byteLength);

    EditText phone = (EditText) findViewById(R.id.phoneNumber);
    byteLength = info.getPhone().length();
    bytes = info.getPhone().getBytes();
    chars = utils.converToCharArray(bytes, byteLength);
    phone.setText(chars, 0, byteLength);

    EditText address = (EditText) findViewById(R.id.address);
    byteLength = info.getAddress().length();
    bytes = info.getAddress().getBytes();
    chars = utils.converToCharArray(bytes, byteLength);
    address.setText(chars, 0, byteLength);

    EditText lastName = (EditText) findViewById(R.id.lastName);
    byteLength = info.getLastName().length();
    bytes = info.getLastName().getBytes();
    chars = utils.converToCharArray(bytes, byteLength);
    lastName.setText(chars, 0, byteLength);

    EditText password = (EditText) findViewById(R.id.password);
    byteLength = info.getPassword().length();
    bytes = info.getPassword().getBytes();
    chars = utils.converToCharArray(bytes, byteLength);
    password.setText(chars, 0, byteLength);

    Button logoutButton = (Button) findViewById(R.id.logoutButton);

    logoutButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent intent = new Intent(context, LoginActivity.class);
            Log.d("TEST", "Logout Activity" + employeeID);
            startActivity(intent);
          }
        });

    Button updateButton = (Button) findViewById(R.id.updateButton);

    // updating objects and database with new info
    updateButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Employee currentEmployee = fetch.getEmployee(employeeID);
            EditText firstName = (EditText) findViewById(R.id.firstName);
            currentEmployee.getEmployeeInfo().setFirstName(firstName.getText().toString());
            EditText lastName = (EditText) findViewById(R.id.lastName);
            currentEmployee.getEmployeeInfo().setLastName(lastName.getText().toString());
            EditText ssn = (EditText) findViewById(R.id.ssn);
            currentEmployee.getEmployeeInfo().setSSN(ssn.getText().toString());
            EditText phone = (EditText) findViewById(R.id.phoneNumber);
            currentEmployee.getEmployeeInfo().setPhone(phone.getText().toString());
            EditText address = (EditText) findViewById(R.id.address);
            currentEmployee.getEmployeeInfo().setAddress(address.getText().toString());
            EditText password = (EditText) findViewById(R.id.password);
            currentEmployee.getEmployeeInfo().setPassword(password.getText().toString());
            fetch.updateEmployee(currentEmployee);
            WriteData writer = new WriteData();
            writer.updateDatabase(context, fetch.getEmployeeArray(), fetch.getNumberOfEmployee());
            Intent intent = new Intent(context, EditInfo.class);
            Bundle extras = new Bundle();
            extras.putString("employeeID", Integer.toString(employeeID));
            extras.putString("userID", Integer.toString(userID));
            extras.putString("userIsManager", Integer.toString(userIsManager));
            intent.putExtras(extras);
            Log.d("TEST", "update Activity" + employeeID);
            startActivity(intent);
          }
        });

    EditText lookupFirstName = (EditText) findViewById(R.id.lookupFirstName);
    EditText lookupLastName = (EditText) findViewById(R.id.lookupLastName);
    Button lookupButton = (Button) findViewById(R.id.lookupButton);
    // if you arent a manager you cant look up employees
    if (userIsManager == 0) {
      lookupFirstName.setVisibility(View.INVISIBLE);
      lookupLastName.setVisibility(View.INVISIBLE);
      lookupButton.setVisibility(View.INVISIBLE);
    }

    lookupButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {

            EditText lookupFirstName = (EditText) findViewById(R.id.lookupFirstName);
            EditText lookupLastName = (EditText) findViewById(R.id.lookupLastName);
            int lookupID =
                fetch.lookUpEmployeeID(
                    lookupFirstName.getText().toString(), lookupLastName.getText().toString());
            // if employee exists
            if (lookupID > 0) {
              Intent intent;
              // if looking up yourself, make it edittable
              if (userID == lookupID) {
                intent = new Intent(context, EditInfo.class);
              } else { // else make it view only
                intent = new Intent(context, ViewEmployeeInfo.class);
              }
              Bundle extras = new Bundle();
              extras.putString("employeeID", Integer.toString(lookupID));
              extras.putString("userID", Integer.toString(userID));
              extras.putString("userIsManager", Integer.toString(userIsManager));
              intent.putExtras(extras);
              Log.d("TEST", "Lookup Activity" + employeeID);
              startActivity(intent);
            } else {
              Intent intent = new Intent(context, EditInfo.class);
              Bundle extras = new Bundle();
              extras.putString("employeeID", Integer.toString(employeeID));
              extras.putString("userID", Integer.toString(userID));
              extras.putString("userIsManager", Integer.toString(userIsManager));
              intent.putExtras(extras);
              Log.d("TEST", "Lookup Activity Failed" + employeeID);
              startActivity(intent);
            }
          }
        });
  }
Esempio n. 13
0
  public Employee removeEmployee(Employee employee) {
    getEmployees().remove(employee);
    employee.setDepartment(null);

    return employee;
  }
Esempio n. 14
0
  public Employee addEmployee(Employee employee) {
    getEmployees().add(employee);
    employee.setDepartment(this);

    return employee;
  }