@Override
public void execute(IDataWrapper data) {
DataHelperRike<Milestone> helper = new DataHelperRike<Milestone>(Milestone.class);
Milestone milestone = null;
boolean newMilestoneCreated = false;
if (data.getRequestAttribute("id") != null && !data.getRequestAttribute("id").isEmpty()) {
milestone = helper.find(data.getRequestAttribute("id"));
}
if (milestone == null) {
newMilestoneCreated = true;
milestone = new Milestone();
}
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
milestone.setDueDate(format.parse(data.getRequestAttribute("due_date")));
} catch(Exception ignored) {
}
milestone.setTitle(data.getRequestAttribute("title"));
milestone.setUrl(data.getRequestAttribute("url"));
milestone.setCreated(new Date());
milestone.setCreator(SecurityHelper.getUser(data.getUser()).getEmailAddress());
milestone.setPerformance(0);
try {
milestone.setPerformance(Integer.valueOf(data.getRequestAttribute("performance"), 10));
} catch(Exception ignored) {}
milestone.setRelease("");
String release = data.getRequestAttribute("release");
if (release != null && release.equals("_new_")) {
milestone.setRelease(data.getRequestAttribute("new_release"));
} else if (release != null) {
milestone.setRelease(release);
}
helper.save(milestone);
data.setSessionAttribute("milestone", milestone);
data.setSessionAttribute("targetView", "viewMilestone");
String message = " changed Milestone #";
if (newMilestoneCreated) {
message = " created Milestone #";
}
ActivityLogHelper.log(message + milestone.getId() + " <a href=\"/web/guest/rike/-/show/milestone/" + milestone.getId() + "\">" + StringEscapeUtils.escapeHtml(milestone.getTitle()) + "</a>", "", milestone.getCreator(), data, milestone.toMap());
}