List<HarvesterSetting> currentSettings = null;
String firstSegment = pathSegments.get(0);
if (firstSegment.startsWith(ID_PREFIX)) {
int id = Integer.parseInt(firstSegment.substring(ID_PREFIX.length()));
HarvesterSetting setting = _entityManager.find(HarvesterSetting.class, id);
if (setting == null) {
currentSettings = Collections.emptyList();
pathSegments = Collections.emptyList();
} else {
currentSettings = Collections.singletonList(setting);
pathSegments = pathSegments.subList(1, pathSegments.size());
}
} else {
currentSettings = findRoots();
for (HarvesterSetting currentSetting : currentSettings) {
if (currentSetting.getName().equals(firstSegment)) {
pathSegments.remove(0);
currentSettings = Arrays.asList(currentSetting);
break;
}
}
}
for (String childName : pathSegments) {
List<HarvesterSetting> oldSettings = currentSettings;
currentSettings = new LinkedList<HarvesterSetting>();
for (HarvesterSetting setting : oldSettings) {
List<HarvesterSetting> children = findChildrenByName(setting.getId(), childName);
currentSettings.addAll(children);
}
}
return currentSettings;
}