List<PatternContractLine> patternContractLineList = new ArrayList<PatternContractLine>(
contractElementList.size() * 3);
long patternContractLineId = 0L;
for (Element element : contractElementList) {
assertElementName(element, "Contract");
Contract contract = new Contract();
contract.setId(id);
contract.setCode(element.getAttribute("ID").getValue());
contract.setDescription(element.getChild("Description").getText());
List<ContractLine> contractLineListOfContract = new ArrayList<ContractLine>(contractLineTypeListSize);
contractLineId = readBooleanContractLine(contract, contractLineList, contractLineListOfContract,
contractLineId, element.getChild("SingleAssignmentPerDay"),
ContractLineType.SINGLE_ASSIGNMENT_PER_DAY);
contractLineId = readMinMaxContractLine(contract, contractLineList, contractLineListOfContract,
contractLineId, element.getChild("MinNumAssignments"),
element.getChild("MaxNumAssignments"),
ContractLineType.TOTAL_ASSIGNMENTS);
contractLineId = readMinMaxContractLine(contract, contractLineList, contractLineListOfContract,
contractLineId, element.getChild("MinConsecutiveWorkingDays"),
element.getChild("MaxConsecutiveWorkingDays"),
ContractLineType.CONSECUTIVE_WORKING_DAYS);
contractLineId = readMinMaxContractLine(contract, contractLineList, contractLineListOfContract,
contractLineId, element.getChild("MinConsecutiveFreeDays"),
element.getChild("MaxConsecutiveFreeDays"),
ContractLineType.CONSECUTIVE_FREE_DAYS);
contractLineId = readMinMaxContractLine(contract, contractLineList, contractLineListOfContract,
contractLineId, element.getChild("MinConsecutiveWorkingWeekends"),
element.getChild("MaxConsecutiveWorkingWeekends"),
ContractLineType.CONSECUTIVE_WORKING_WEEKENDS);
contractLineId = readMinMaxContractLine(contract, contractLineList, contractLineListOfContract,
contractLineId, null,
element.getChild("MaxWorkingWeekendsInFourWeeks"),
ContractLineType.TOTAL_WORKING_WEEKENDS_IN_FOUR_WEEKS);
WeekendDefinition weekendDefinition = WeekendDefinition.valueOfCode(
element.getChild("WeekendDefinition").getText());
contract.setWeekendDefinition(weekendDefinition);
contractLineId = readBooleanContractLine(contract, contractLineList, contractLineListOfContract,
contractLineId, element.getChild("CompleteWeekends"),
ContractLineType.COMPLETE_WEEKENDS);
contractLineId = readBooleanContractLine(contract, contractLineList, contractLineListOfContract,
contractLineId, element.getChild("IdenticalShiftTypesDuringWeekend"),
ContractLineType.IDENTICAL_SHIFT_TYPES_DURING_WEEKEND);
contractLineId = readBooleanContractLine(contract, contractLineList, contractLineListOfContract,
contractLineId, element.getChild("NoNightShiftBeforeFreeWeekend"),
ContractLineType.NO_NIGHT_SHIFT_BEFORE_FREE_WEEKEND);
contractLineId = readBooleanContractLine(contract, contractLineList, contractLineListOfContract,
contractLineId, element.getChild("AlternativeSkillCategory"),
ContractLineType.ALTERNATIVE_SKILL_CATEGORY);
contract.setContractLineList(contractLineListOfContract);
List<Element> unwantedPatternElementList = (List<Element>) element.getChild("UnwantedPatterns")
.getChildren();
for (Element patternElement : unwantedPatternElementList) {
assertElementName(patternElement, "Pattern");
Pattern pattern = patternMap.get(patternElement.getText());
if (pattern == null) {
throw new IllegalArgumentException("The pattern (" + patternElement.getText()
+ ") of contract (" + contract.getCode() + ") does not exist.");
}
PatternContractLine patternContractLine = new PatternContractLine();
patternContractLine.setId(patternContractLineId);
patternContractLine.setContract(contract);
patternContractLine.setPattern(pattern);
patternContractLineList.add(patternContractLine);
patternContractLineId++;
}
contractList.add(contract);
if (contractMap.containsKey(contract.getCode())) {
throw new IllegalArgumentException("There are 2 contracts with the same code ("
+ contract.getCode() + ").");
}
contractMap.put(contract.getCode(), contract);
id++;
}
nurseRoster.setContractList(contractList);
nurseRoster.setContractLineList(contractLineList);
nurseRoster.setPatternContractLineList(patternContractLineList);