List<SkillProficiency> skillProficiencyList
= new ArrayList<SkillProficiency>(employeeElementList.size() * 2);
long skillProficiencyId = 0L;
for (Element element : employeeElementList) {
assertElementName(element, "Employee");
Employee employee = new Employee();
employee.setId(id);
employee.setCode(element.getAttribute("ID").getValue());
employee.setName(element.getChild("Name").getText());
Element contractElement = element.getChild("ContractID");
Contract contract = contractMap.get(contractElement.getText());
if (contract == null) {
throw new IllegalArgumentException("The contract (" + contractElement.getText()
+ ") of employee (" + employee.getCode() + ") does not exist.");
}
employee.setContract(contract);
int estimatedRequestSize = (shiftDateMap.size() / employeeElementList.size()) + 1;
employee.setDayOffRequestMap(new HashMap<ShiftDate, DayOffRequest>(estimatedRequestSize));
employee.setDayOnRequestMap(new HashMap<ShiftDate, DayOnRequest>(estimatedRequestSize));
employee.setShiftOffRequestMap(new HashMap<Shift, ShiftOffRequest>(estimatedRequestSize));
employee.setShiftOnRequestMap(new HashMap<Shift, ShiftOnRequest>(estimatedRequestSize));
Element skillsElement = element.getChild("Skills");
if (skillsElement != null) {
List<Element> skillElementList = (List<Element>) skillsElement.getChildren();
for (Element skillElement : skillElementList) {
assertElementName(skillElement, "Skill");
Skill skill = skillMap.get(skillElement.getText());
if (skill == null) {
throw new IllegalArgumentException("The skill (" + skillElement.getText()
+ ") of employee (" + employee.getCode() + ") does not exist.");
}
SkillProficiency skillProficiency = new SkillProficiency();
skillProficiency.setId(skillProficiencyId);
skillProficiency.setEmployee(employee);
skillProficiency.setSkill(skill);
skillProficiencyList.add(skillProficiency);
skillProficiencyId++;
}
}
employeeList.add(employee);
if (employeeMap.containsKey(employee.getCode())) {
throw new IllegalArgumentException("There are 2 employees with the same code ("
+ employee.getCode() + ").");
}
employeeMap.put(employee.getCode(), employee);
id++;
}
nurseRoster.setEmployeeList(employeeList);
nurseRoster.setSkillProficiencyList(skillProficiencyList);
}