Search in sources :

Example 1 with Department

use of com.dala.data.department.Department in project DoodleVerse by davidemarcoli.

the class FakeGenerator method generateDepartment.

/**
 * Generate random departments
 * @param count the number of randomly generated departments
 * @return the generated departments
 */
public ArrayList<Department> generateDepartment(int count) {
    ArrayList<Department> departments = new ArrayList<>();
    List<Person> persons = personRepository.findAll();
    for (int i = 0; i < count; i++) {
        ArrayList<Department> childDepartments = new ArrayList<>();
        List<Person> departmentWorkers = new ArrayList<>();
        for (int personCount = 0; personCount < MathUtils.getInstance().randomMinMax(1, 5); personCount++) {
            Person person = persons.get(MathUtils.getInstance().randomMinMax(0, persons.size() - 1));
            if (!departmentWorkers.contains(person)) {
                departmentWorkers.add(person);
            }
        }
        if (departmentWorkers.isEmpty()) {
            List<Person> person = personRepository.saveAllAndFlush(generateRandomPersons(MathUtils.getInstance().randomMinMax(1, 5)));
            departmentWorkers.addAll(person);
        }
        for (int j = 0; j < MathUtils.getInstance().randomMinMax(0, 5); j++) {
            departmentWorkers.clear();
            for (int personCount = 0; personCount < MathUtils.getInstance().randomMinMax(1, 5); personCount++) {
                Person person = persons.get(MathUtils.getInstance().randomMinMax(0, persons.size() - 1));
                if (!departmentWorkers.contains(person)) {
                    departmentWorkers.add(person);
                }
            }
            if (departmentWorkers.isEmpty()) {
                List<Person> person = personRepository.saveAllAndFlush(generateRandomPersons(MathUtils.getInstance().randomMinMax(1, 5)));
                departmentWorkers.addAll(person);
            }
            Department childDepartment = new Department(0L, faker.commerce().department(), departmentWorkers, null);
            System.out.println(childDepartment);
            childDepartment = departmentRepository.saveAndFlush(childDepartment);
            childDepartments.add(childDepartment);
        }
        Department department = departmentRepository.saveAndFlush(new Department(0L, faker.commerce().department(), null, childDepartments));
        departments.add(department);
    }
    return departments;
}
Also used : Department(com.dala.data.department.Department) ArrayList(java.util.ArrayList) Person(com.dala.data.person.Person)

Example 2 with Department

use of com.dala.data.department.Department in project DoodleVerse by davidemarcoli.

the class FakeGenerator method generateCompanies.

/**
 * Generate random companys
 * @param count the number of randomly generated companys
 * @return the generated companys
 */
public ArrayList<Company> generateCompanies(int count) {
    ArrayList<Company> companies = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        ArrayList<Department> departments = generateDepartment(10);
        companies.add(new Company(0L, faker.company().name(), departments));
    }
    return companies;
}
Also used : Company(com.dala.data.company.Company) Department(com.dala.data.department.Department) ArrayList(java.util.ArrayList)

Aggregations

Department (com.dala.data.department.Department)2 ArrayList (java.util.ArrayList)2 Company (com.dala.data.company.Company)1 Person (com.dala.data.person.Person)1