String msg =
"Updates are only accepted if the policy content is available. " +
"So no updates will be done. " + "policy id: " + policy.getId() +
", policy path: " + policy.getPath() + ".";
log.error(msg);
throw new GovernanceException(msg);
}
boolean succeeded = false;
String url = policy.getUrl();
try {
registry.beginTransaction();
// getting the old policy.
Policy oldPolicy = getPolicy(policy.getId());
if (oldPolicy == null) {
addPolicy(policy);
return;
}
Resource policyResource = registry.newResource();
policyResource.setMediaType(GovernanceConstants.POLICY_XML_MEDIA_TYPE);
// setting the policy content
setContent(policy, policyResource);
// remove the old policy resource.
registry.delete(oldPolicy.getPath());
String tmpPath;
if (policy.getQName() != null) {
tmpPath = "/" + policy.getQName().getLocalPart();
} else if (url != null) {
tmpPath = RegistryUtils.getResourceName(new URL(url).getFile().replace("~", ""));
} else {
String msg =
"Error in identifying the name for the policy. State the name for the policy.";
log.error(msg);
throw new GovernanceException(msg);
}
registry.put(tmpPath, policyResource);
policy.updatePath();
succeeded = true;
} catch (RegistryException e) {
String msg =
"Error in updating the policy, policy id: " + policy.getId() +
", policy path: " + policy.getPath() + ".";
log.error(msg, e);
throw new GovernanceException(msg, e);
} catch (MalformedURLException e) {
String msg = "Malformed url found, url " + url + ".";
log.error(msg, e);
throw new GovernanceException(msg, e);
} finally {
if (succeeded) {
try {
registry.commitTransaction();
} catch (RegistryException e) {