List<ShiftTypeSkillRequirement> shiftTypeSkillRequirementList
= new ArrayList<ShiftTypeSkillRequirement>(shiftTypeElementList.size() * 2);
long shiftTypeSkillRequirementId = 0L;
for (Element element : shiftTypeElementList) {
assertElementName(element, "Shift");
ShiftType shiftType = new ShiftType();
shiftType.setId(id);
shiftType.setCode(element.getAttribute("ID").getValue());
shiftType.setIndex(index);
String startTimeString = element.getChild("StartTime").getText();
shiftType.setStartTimeString(startTimeString);
String endTimeString = element.getChild("EndTime").getText();
shiftType.setEndTimeString(endTimeString);
shiftType.setNight(startTimeString.compareTo(endTimeString) > 0);
shiftType.setDescription(element.getChild("Description").getText());
Element skillsElement = element.getChild("Skills");
if (skillsElement != null) {
List<Element> skillElementList = (List<Element>) skillsElement.getChildren();
for (Element skillElement : skillElementList) {
assertElementName(skillElement, "Skill");
ShiftTypeSkillRequirement shiftTypeSkillRequirement = new ShiftTypeSkillRequirement();
shiftTypeSkillRequirement.setId(shiftTypeSkillRequirementId);
shiftTypeSkillRequirement.setShiftType(shiftType);
Skill skill = skillMap.get(skillElement.getText());
if (skill == null) {
throw new IllegalArgumentException("The skill (" + skillElement.getText()
+ ") of shiftType (" + shiftType.getCode() + ") does not exist.");
}
shiftTypeSkillRequirement.setSkill(skill);
shiftTypeSkillRequirementList.add(shiftTypeSkillRequirement);
shiftTypeSkillRequirementId++;
}
}
shiftTypeList.add(shiftType);
if (shiftTypeMap.containsKey(shiftType.getCode())) {
throw new IllegalArgumentException("There are 2 shiftTypes with the same code ("
+ shiftType.getCode() + ").");
}
shiftTypeMap.put(shiftType.getCode(), shiftType);
id++;
index++;
}
nurseRoster.setShiftTypeList(shiftTypeList);
nurseRoster.setShiftTypeSkillRequirementList(shiftTypeSkillRequirementList);