// Resource security panel
//--------------------------------
form.add(new ResourceSecurityPanel("security", resourceTO));
//--------------------------------
final AjaxButton submit = new IndicatingAjaxButton("apply", new ResourceModel("submit", "submit")) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
final ResourceTO resourceTO = (ResourceTO) form.getDefaultModelObject();
boolean accountIdError = false;
if (resourceTO.getUmapping() == null || resourceTO.getUmapping().getItems().isEmpty()) {
resourceTO.setUmapping(null);
} else {
int uAccountIdCount = 0;
for (MappingItemTO item : resourceTO.getUmapping().getItems()) {
if (item.isAccountid()) {
uAccountIdCount++;
}
}
accountIdError = uAccountIdCount != 1;
}
if (resourceTO.getRmapping() == null || resourceTO.getRmapping().getItems().isEmpty()) {
resourceTO.setRmapping(null);
} else {
int rAccountIdCount = 0;
for (MappingItemTO item : resourceTO.getRmapping().getItems()) {
if (item.isAccountid()) {
rAccountIdCount++;
}
}
accountIdError |= rAccountIdCount != 1;
}
if (accountIdError) {
error(getString("accountIdValidation"));
target.add(feedbackPanel);
} else {
try {
if (createFlag) {
restClient.create(resourceTO);
} else {
restClient.update(resourceTO);
}
((Resources) pageRef.getPage()).setModalResult(true);
window.close(target);
} catch (Exception e) {
LOG.error("Failure managing resource {}", resourceTO, e);
error(getString("error") + ": " + e.getMessage());
target.add(feedbackPanel);
}
}
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
target.add(feedbackPanel);
}
};
form.add(submit);
form.setDefaultButton(submit);
final AjaxButton cancel = new IndicatingAjaxButton("cancel", new ResourceModel("cancel")) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
window.close(target);
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
}
};
cancel.setDefaultFormProcessing(false);
form.add(cancel);
add(form);
MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, xmlRolesReader.getAllAllowedRoles("Resources",