* @param applyToAll <code>true</code> to apply action to current set
* @throws Exception if an exception occurs
*/
private void executeAction(ActionEvent event, final RequestContext context,
MmdActionCriteria actionCriteria, Publisher publisher, boolean applyToAll) throws Exception {
MessageBroker msgBroker = extractMessageBroker();
// check to ensure that records were selected
if (actionCriteria.getSelectedRecordIdSet().size() == 0 && applyToAll==false) {
msgBroker.addErrorMessage("catalog.publication.manageMetadata.action.err.noneSelected");
} else {
// check the publisher
Publisher publisherForAction = publisher;
if (!publisher.getIsAdministrator()) {
String sOwner = getQueryCriteria().getOwner();
if (sOwner.length() == 0) {
sOwner = publisher.getKey();
}
if (!sOwner.equalsIgnoreCase(publisher.getKey())) {
if (!Publisher.buildSelectablePublishers(context, true).containsKey(sOwner)) {
throw new NotAuthorizedException("Not authorized.");
} else {
publisherForAction = new Publisher(context, sOwner);
}
}
}
// execute the request
MmdCriteria criteria = new MmdCriteria();
criteria.setActionCriteria(actionCriteria);
if (_metadataAccessPolicyConfig==null) {
getSelectablePublishers().build(context, true);
prepareAccessPolicyConfig(context);
prepareGroups(context);
prepareActionCriteria(context);
}
String defaultGroup = _metadataAccessPolicyConfig.getAccessToGroupDN();
if (defaultGroup != null && defaultGroup.trim().length() > 0) {
ArrayList<String> defaultAcl = new ArrayList<String>();
defaultAcl.add(getActionCriteria().getToggleMetadataAccessPolicy());
criteria.getActionCriteria().setMetadataAccessPolicy(defaultAcl);
}
MmdActionRequest request = new MmdActionRequest(context,publisherForAction,criteria,getResult());
if (!applyToAll) {
request.execute();
} else {
if (!_queryCriteriaForAction.getIsEmpty()) {
request.execute(_queryCriteriaForAction);
}
}
// set the success message
int nModified = getActionResult().getNumberOfRecordsModified();
if (nModified > 0) {
String sKey = "catalog.publication.manageMetadata.action.success";
if (actionCriteria.getActionKey().equalsIgnoreCase("delete")) {
sKey += ".delete";
}
String[] args = new String[1];
args[0] = "" + nModified;
msgBroker.addSuccessMessage(sKey, args);
}
if (request.hadUnalteredDraftDocuments()) {
msgBroker.addErrorMessage("catalog.publication.manageMetadata.action.err.draftUnaltered");
}
}
}