return body;
}
@Override
protected Component createFooter(String wicketId) {
DelegatedMarkupPanel footer = new DelegatedMarkupPanel(wicketId, ArtifactNotificationRuleFormPopupPanel.class);
// Validate button
AjaxButton validate = new AjaxButton("save", ruleForm) {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
ArtifactNotificationRule rule = ArtifactNotificationRuleFormPopupPanel.this.getModelObject();
FollowedArtifact followedArtifact = rule.getFollowedArtifact();
if (StringUtils.hasText(rule.getRegex()) && rule.getType() != null) {
try {
if (artifactNotificationRuleService.isRuleValid(rule.getRegex())) {
ArtifactNotificationRule ruleDuplicate =
artifactNotificationRuleService.getByFollowedArtifactAndRegex(followedArtifact, rule.getRegex());
if (ruleDuplicate == null || rule.equals(ruleDuplicate)) {
artifactNotificationRuleService.update(rule);
getSession().success(getString("artifact.rules.edit.success"));
closePopup(target);
target.add(getPage());
} else {
LOGGER.warn("A rule with the same regex already exists");
getSession().error(getString("artifact.rules.add.notUnique"));
}
} else {
LOGGER.error("Invalid rule regex");
getSession().error(getString("artifact.rules.add.invalidRegex"));
}
} catch (Exception e) {
LOGGER.error("Error occured while updating the rule", e);
getSession().error(getString("artifact.rules.edit.error"));
}
}
FeedbackUtils.refreshFeedback(target, getPage());
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
FeedbackUtils.refreshFeedback(target, getPage());
}
};
validate.add(new Label("validateLabel", new ResourceModel("common.action.save")));
footer.add(validate);
// Cancel button
AbstractLink cancel = new AbstractLink("cancel") {
private static final long serialVersionUID = 1L;
};
addCancelBehavior(cancel);
footer.add(cancel);
return footer;
}