// find the story to update in the repository
Story story = storyRepository.findByPersistanceId(persistanceId);
// if the story is not found, return a global error
if (story == null) {
Errors errros = AgilePlanningObjectFactory.getErrors();
errros.reject("story.doesntExistsInDatabase");
return errros;
}
// update the story
story.setShortDescription(shortDescription);
story.setDescription(description);
story.setDaysEstimated(daysEstimated);
story.setPersistanceId(persistanceId);
story.setPersistanceVersion(persistanceVersion);
// find the riskLevel and business value
BusinessValue businessValue = businessValueRepository.findById(businessValueId);
story.setBusinessValue(businessValue);
RiskLevel riskLevel = riskLevelRepository.findById(riskLevelId);
story.setRiskLevel(riskLevel);
// validate
Errors errors = storyValidator.validate(story);
// persist
if (!errors.hasErrors()) {
storyRepository.addOrUpdate(story);
}
// return an empty error object (no validations are made)
return AgilePlanningObjectFactory.getErrors();